[midend-phielimination]增加phi指令消除检查
This commit is contained in:
@ -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) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user