From 2ec8ff8ed542f870168e79d1bb550c9eac6a0489 Mon Sep 17 00:00:00 2001 From: ridethepig Date: Sun, 18 Jun 2023 19:53:09 +0800 Subject: [PATCH] bug fix on hidden case --- .vscode/launch.json | 3 ++- src/pass_const_fold.cpp | 4 ++-- src/pass_const_prop.cpp | 4 ++-- src/pass_dce.cpp | 5 ++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 52c21c8..2ce020e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,8 @@ "name": "Debug", "program": "${workspaceFolder}/build/sysy", // "args": ["../sysytests/functional_2021/069_greatest_common_divisor.sy", "-S", "-o", "build/my.s", "-O1", "-emit-llvm"], - "args" : ["-S", "../sysytests/functional_2022/21_if_test2.sy", "-o", "build/dbg.s", "-emit-llvm", "-O1",], + // "args" : ["-S", "../sysytests/functional_2022/21_if_test2.sy", "-o", "build/dbg.s", "-emit-llvm", "-O1",], + "args" : ["-S", "../sysytests/functional_h_2022/04_break_continue.sy", "-o", "build/dbg.s", "-emit-llvm", "-O1",], "cwd": "${workspaceFolder}" }, ] diff --git a/src/pass_const_fold.cpp b/src/pass_const_fold.cpp index b21df97..7e753fa 100644 --- a/src/pass_const_fold.cpp +++ b/src/pass_const_fold.cpp @@ -22,9 +22,9 @@ static InstBranch *is_cond_br(Instruction *inst) { // not removing the block, this only means that pred no longer branch to bb static void rewrite_bb(sptr(BasicBlock) bb, sptr(BasicBlock) pred) { - pred->succ_list.remove(bb); + pred->succ_list.erase(STD_FIND(pred->succ_list, bb)); auto pred_index = GETINDEX(bb->pred_list, pred); - bb->pred_list.remove(pred); + bb->pred_list.erase(STD_FIND(bb->pred_list, pred)); for (auto itr = bb->inst_list.begin(); itr != bb->inst_list.end();) { auto inst = *itr++; if (!shared_cast(inst)) break; diff --git a/src/pass_const_prop.cpp b/src/pass_const_prop.cpp index 98daee2..b3da948 100644 --- a/src/pass_const_prop.cpp +++ b/src/pass_const_prop.cpp @@ -259,9 +259,9 @@ void PassSCCP::Visit_Inst(Instruction *inst) { pred is no more bb's pred, so maintain cfg and rewrite bb's phi nodes */ static void rewrite_bb(sptr(BasicBlock) bb, sptr(BasicBlock) pred) { - pred->succ_list.remove(bb); + pred->succ_list.erase(STD_FIND(pred->succ_list, bb)); auto pred_index = GETINDEX(bb->pred_list, pred); - bb->pred_list.remove(pred); + bb->pred_list.erase(STD_FIND(bb->pred_list, pred)); for (auto itr = bb->inst_list.begin(); itr != bb->inst_list.end();) { auto inst = *itr++; if (!shared_cast(inst)) break; diff --git a/src/pass_dce.cpp b/src/pass_dce.cpp index 9b57239..400d95f 100644 --- a/src/pass_dce.cpp +++ b/src/pass_dce.cpp @@ -141,7 +141,7 @@ bool Elim_Dead_Code(Function *func) { // Still unknown what this would be like, the only case by now is // true_branch = false_branch changed = true; - LOG(WARNING) << "rewrite dead branch"; + LOG(WARNING) << "rewrite dead branch in " << bb->to_string(); auto cfgnode = RCFG.bb_node.at(bb.get()); // walk up through the dom-tree(idom), and check if there is any useful insts in it auto useful_pdom = cfgnode->idom; @@ -191,7 +191,6 @@ bool Fuse_Block(Function *func) { visit.clear(); post_order.clear(); get_post_order(func->bb_list.front().get()); for (auto bb : post_order) { - LOG(DEBUG) << "visit " << bb->to_string(); if (is_branch(bb->inst_list.back().get())) { auto inst = bb->inst_list.back().get(); if (inst->operand_list[1] == inst->operand_list[2]) { @@ -305,7 +304,7 @@ void PassDCE::run(const Module &module) { Elim_Dead_Code(func.get()); Elim_Unreach_Code(func.get()); other_clear(func.get()); - // Fuse_Block(func.get()); + Fuse_Block(func.get()); } }