[CFG]增加分支优化,为SCCP调用做铺垫,预备修改phi定义

This commit is contained in:
rain2133
2025-07-17 16:50:09 +08:00
parent 009f54863e
commit 77fae4d662
3 changed files with 90 additions and 1 deletions

View File

@@ -172,7 +172,7 @@ enum class LatticeValue {
//TODO: 下列数据结构考虑集成到类中,避免重命名问题
static std::set<Instruction *> Worklist;
static std::unordered_set<BasicBlock*> Executable_Blocks;
static std::unordered_set<std::pair<BasicBlock *, BasicBlock *> > Executable_Edges;
static std::queue<std::pair<BasicBlock *, BasicBlock *> > Executable_Edges;
static std::map<Value*, LatticeValue> valueState;
class SCCP {

View File

@@ -31,6 +31,8 @@ class SysYCFGOpt {
for (auto &function : functions) {
bool changed = false;
while(changed){
changed = false;
changed |= SysYCondBr2Br(function.second.get(), pBuilder);
// 删除br后面的无用指令
changed |= SysYDelInstAfterBr(function.second.get());
// 合并空基本块
@@ -52,6 +54,7 @@ public:
static bool SysYBlockMerge(Function *func); // 合并基本块(主要针对嵌套if while的exit块
// 也可以修改IR生成实现回填机制
static bool SysYAddReturn(Function *func, IRBuilder* pBuilder); // 添加return指令(主要针对Void函数)
static bool SysYCondBr2Br(Function *func, IRBuilder* pBuilder); // 条件分支(已知cond的值)转换为无条件分支
};
} // namespace sysy