Commit b96c45ef authored by 张涵景's avatar 张涵景
Browse files

bug mixed

No related merge requests found
Showing with 28 additions and 9 deletions
+28 -9
......@@ -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;
}
}
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment