[midend-SCCP]修改BaiscBlock的析构逻辑,将CFG修改的职责交给优化遍,注释Mem2Reg的调试信息。
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
#include "SCCP.h"
|
||||
#include "Dom.h"
|
||||
#include "Liveness.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath> // For std::fmod, std::fabs
|
||||
@ -236,6 +238,8 @@ SSAPValue SCCPContext::ComputeConstant(UnaryInst *unaryInst, SSAPValue operandVa
|
||||
if (operandVal.constant_type == ValueType::Integer) {
|
||||
int val = std::get<int>(operandVal.constantVal);
|
||||
switch (unaryInst->getKind()) {
|
||||
case Instruction::kAdd:
|
||||
return SSAPValue(val);
|
||||
case Instruction::kNeg:
|
||||
return SSAPValue(-val);
|
||||
case Instruction::kNot:
|
||||
@ -246,6 +250,8 @@ SSAPValue SCCPContext::ComputeConstant(UnaryInst *unaryInst, SSAPValue operandVa
|
||||
} else if (operandVal.constant_type == ValueType::Float) {
|
||||
float val = std::get<float>(operandVal.constantVal);
|
||||
switch (unaryInst->getKind()) {
|
||||
case Instruction::kAdd:
|
||||
return SSAPValue(val);
|
||||
case Instruction::kFNeg:
|
||||
return SSAPValue(-val);
|
||||
case Instruction::kFNot:
|
||||
@ -593,6 +599,7 @@ bool SCCPContext::PropagateConstants(Function *func) {
|
||||
}
|
||||
|
||||
// 实际删除指令
|
||||
// TODO: 删除的逻辑需要考虑修改
|
||||
for (Instruction *inst : instsToDelete) {
|
||||
// 在尝试删除之前,先检查指令是否仍然附加到其父基本块。
|
||||
// 如果它已经没有父块,可能说明它已被其他方式处理或已处于无效状态。
|
||||
@ -752,6 +759,7 @@ void SCCPContext::RemoveDeadBlock(BasicBlock *bb, Function *func) {
|
||||
}
|
||||
for (BasicBlock *succ : succs_to_update) {
|
||||
RemovePhiIncoming(succ, bb);
|
||||
succ->removePredecessor(bb);
|
||||
}
|
||||
|
||||
func->removeBasicBlock(bb); // 从函数中移除基本块
|
||||
@ -864,7 +872,9 @@ bool SCCP::runOnFunction(Function *F, AnalysisManager &AM) {
|
||||
}
|
||||
|
||||
void SCCP::getAnalysisUsage(std::set<void *> &analysisDependencies, std::set<void *> &analysisInvalidations) const {
|
||||
analysisInvalidations.insert(nullptr); // 表示使所有默认分析失效
|
||||
// analysisInvalidations.insert(nullptr); // 表示使所有默认分析失效
|
||||
analysisInvalidations.insert(&DominatorTreeAnalysisPass::ID); // 支配树可能受影响
|
||||
analysisInvalidations.insert(&LivenessAnalysisPass::ID); // 活跃性分析很可能失效
|
||||
}
|
||||
|
||||
} // namespace sysy
|
||||
Reference in New Issue
Block a user