Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
educg-net-17291-1894922
Compiler2023-KleeDontKnow-3046
Commits
b96c45ef
Commit
b96c45ef
authored
1 year ago
by
张涵景
Browse files
Options
Download
Patches
Plain Diff
bug mixed
parent
f622580a
submit9
peephole
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/LIR-opt/Peephole.cpp
+28
-9
src/LIR-opt/Peephole.cpp
with
28 additions
and
9 deletions
+28
-9
src/LIR-opt/Peephole.cpp
+
28
−
9
View file @
b96c45ef
...
...
@@ -254,7 +254,7 @@ void Peephole::opt3(){
auto
block
=
*
block_iter
;
std
::
set
<
MachineInstruction
*>
instToRemove
;
for
(
MachineInstruction
*
machineInstruction
:
block
->
inst_list
){
if
(
machineInstruction
->
isJump
()){
if
(
machineInstruction
->
isJump
()
&&
!
(
*
(
block
->
inst_list
.
begin
()))
->
isJump
()
){
auto
JumpLabelOld
=
machineInstruction
->
use_list
[
0
];
// J .LabelOld
string
LabelName
=
JumpLabelOld
->
label
;
...
...
@@ -280,16 +280,35 @@ void Peephole::opt4() {
for
(
auto
mFunc
:
mUnit
->
func_list
)
{
for
(
auto
curMB
:
mFunc
->
block_list
)
{
for
(
auto
inst_iter
=
curMB
->
inst_list
.
begin
();
inst_iter
!=
curMB
->
inst_list
.
end
();
++
inst_iter
)
{
if
((
*
inst_iter
)
->
isBne
()
&&
++
inst_iter
--
!=
curMB
->
inst_list
.
end
())
{
auto
branch
=
dynamic_cast
<
BranchMInstruction
*>
(
*
inst_iter
);
auto
jump
=
dynamic_cast
<
JumpMInstruction
*>
(
*
(
++
inst_iter
--
));
// if ((*inst_iter)->isBne() && ++inst_iter-- != curMB->inst_list.end()) {
// auto branch = dynamic_cast<BranchMInstruction*>(*inst_iter);
// auto jump = dynamic_cast<JumpMInstruction*>(*(++inst_iter--));
//
// auto label = branch->use_list[2];
// branch->use_list[2] = jump->use_list[0];
// jump->use_list[0] = label;
//
// //默认 optype = bne
// branch->optype = BranchMInstruction::BEQ;
// }
if
((
*
inst_iter
)
->
isBne
()){
if
(
next
(
inst_iter
,
1
)
!=
curMB
->
inst_list
.
end
()){
auto
nextinst
=
*
next
(
inst_iter
,
1
);
if
(
nextinst
->
isJump
()){
auto
branch
=
*
inst_iter
;
auto
j
=
nextinst
;
auto
label
=
branch
->
use_list
[
2
];
branch
->
use_list
[
2
]
=
jump
->
use_list
[
0
];
jump
->
use_list
[
0
]
=
label
;
assert
(
branch
->
use_list
[
2
]
->
type
==
MachineOperand
::
LABEL
);
assert
(
j
->
use_list
[
0
]
->
type
==
MachineOperand
::
LABEL
);
string
branchLabelName
=
branch
->
use_list
[
2
]
->
label
;
string
jumpLabelName
=
j
->
use_list
[
0
]
->
label
;
//默认 optype = bne
branch
->
optype
=
BranchMInstruction
::
BEQ
;
branch
->
use_list
[
2
]
->
label
=
jumpLabelName
;
j
->
use_list
[
0
]
->
label
=
branchLabelName
;
branch
->
optype
=
BranchMInstruction
::
BEQ
;
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets