deploy-20250820-3 #1

Merged
gh0s7 merged 352 commits from deploy-20250820-3 into master 2025-08-20 21:20:33 +08:00
5 changed files with 33 additions and 4 deletions
Showing only changes of commit 751d3df2ac - Show all commits

View File

@@ -109,6 +109,34 @@ public:
}
// PHI指令消除相关方法
static bool eliminateRedundantPhisInFunction(Function* func){
bool changed = false;
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(DEBUG){
std::cout << "Checking Phi: " << phi->getName() << " with " << incoming.size() << " incoming values." << std::endl;
}
if (incoming.size() == 1) {
Value *singleVal = incoming[0].second;
inst->replaceAllUsesWith(singleVal);
toDelete.push_back(inst.get());
}
}
else
break; // 只处理Phi指令
}
}
for (auto *phi : toDelete) {
usedelete(phi);
changed = true; // 标记为已更改
}
return changed; // 返回是否有删除发生
}
//该实现参考了libdivide的算法
static std::pair<int, int> computeMulhMagicNumbers(int divisor) {

View File

@@ -74,6 +74,7 @@ void DCEContext::run(Function *func, AnalysisManager *AM, bool &changed) {
}
}
}
changed |= SysYIROptUtils::eliminateRedundantPhisInFunction(func); // 如果有活跃指令,则标记为已更改
}
// 判断指令是否是"天然活跃"的实现

View File

@@ -39,7 +39,7 @@ bool GVN::runOnFunction(Function *func, AnalysisManager &AM) {
}
std::cout << "=== GVN completed for function: " << func->getName() << " ===" << std::endl;
}
changed |= SysYIROptUtils::eliminateRedundantPhisInFunction(func);
return changed;
}

View File

@@ -133,6 +133,7 @@ bool InductionVariableEliminationContext::run(Function* F, AnalysisManager& AM)
printDebugInfo();
}
modified |= SysYIROptUtils::eliminateRedundantPhisInFunction(F);
return modified;
}

View File

@@ -1357,9 +1357,8 @@ void SCCPContext::run(Function *func, AnalysisManager &AM) {
bool changed_control_flow = SimplifyControlFlow(func);
// 如果任何一个阶段修改了 IR标记分析结果为失效
if (changed_constant_propagation || changed_control_flow) {
// AM.invalidate(); // 假设有这样的方法来使所有分析结果失效
}
bool changed = changed_constant_propagation || changed_control_flow;
changed |= SysYIROptUtils::eliminateRedundantPhisInFunction(func);
}
// SCCP Pass methods