[midend-phielimination]增加phi指令消除检查

This commit is contained in:
rain2133
2025-08-19 01:08:05 +08:00
parent ad74e435ba
commit ce4d4b5f5b

View File

@ -109,6 +109,28 @@ public:
}
// PHI指令消除相关方法
static void eliminateRedundantPhisInFunction(Function* func){
std::vector<Instruction *> toDelete;
for (auto &bb : func->getBasicBlocks()) {
for (auto &inst : bb->getInstructions()) {
if (auto phi = dynamic_cast<PhiInst *>(inst.get())) {
auto incoming = phi->getIncomingValues();
if (incoming.size() == 1) {
Value *singleVal = incoming[0].first;
inst->replaceAllUsesWith(singleVal);
toDelete.push_back(inst.get());
}
}
else
break; // 只处理Phi指令
}
}
for (auto *phi : toDelete) {
usedelete(phi);
}
}
//该实现参考了libdivide的算法
static std::pair<int, int> computeMulhMagicNumbers(int divisor) {