[midend-GVN]重构GVN的值编号系统
This commit is contained in:
@@ -19,8 +19,11 @@ public:
|
||||
void run(Function* func, AnalysisManager* AM, bool& changed);
|
||||
|
||||
private:
|
||||
// 值编号的哈希表:Value -> 代表值
|
||||
std::unordered_map<Value*, Value*> hashtable;
|
||||
// 新的值编号系统
|
||||
std::unordered_map<Value*, unsigned> valueToNumber; // Value -> 值编号
|
||||
std::unordered_map<unsigned, Value*> numberToValue; // 值编号 -> 代表值
|
||||
std::unordered_map<std::string, unsigned> expressionToNumber; // 表达式 -> 值编号
|
||||
unsigned nextValueNumber = 1;
|
||||
|
||||
// 已访问的基本块集合
|
||||
std::unordered_set<BasicBlock*> visited;
|
||||
@@ -39,31 +42,27 @@ private:
|
||||
void computeRPO(Function* func);
|
||||
void dfs(BasicBlock* bb);
|
||||
|
||||
// 检查哈希表并获取值编号
|
||||
Value* checkHashtable(Value* value);
|
||||
// 新的值编号方法
|
||||
unsigned getValueNumber(Value* value);
|
||||
unsigned assignValueNumber(Value* value);
|
||||
|
||||
// 为不同类型的指令获取值编号
|
||||
Value* getValueNumber(Instruction* inst);
|
||||
Value* getValueNumber(BinaryInst* inst);
|
||||
Value* getValueNumber(UnaryInst* inst);
|
||||
Value* getValueNumber(GetElementPtrInst* inst);
|
||||
Value* getValueNumber(LoadInst* inst);
|
||||
Value* getValueNumber(CallInst* inst);
|
||||
// 基本块处理
|
||||
void processBasicBlock(BasicBlock* bb, bool& changed);
|
||||
|
||||
// 访问指令并进行GVN优化
|
||||
void visitInstruction(Instruction* inst);
|
||||
// 指令处理
|
||||
bool processInstruction(Instruction* inst);
|
||||
|
||||
// 检查是否可以安全地用一个值替换另一个值
|
||||
bool canReplace(Instruction* original, Value* replacement);
|
||||
// 表达式构建和查找
|
||||
std::string buildExpressionKey(Instruction* inst);
|
||||
Value* findExistingValue(const std::string& exprKey, Instruction* inst);
|
||||
|
||||
// 检查两个load指令之间是否有store指令修改了相同的内存位置
|
||||
bool hasInterveningStore(LoadInst* earlierLoad, LoadInst* laterLoad, Value* ptr);
|
||||
// 支配关系和安全性检查
|
||||
bool dominates(Instruction* a, Instruction* b);
|
||||
bool isMemorySafe(LoadInst* earlierLoad, LoadInst* laterLoad);
|
||||
|
||||
// 使受store指令影响的load指令失效
|
||||
void invalidateLoadsAffectedByStore(StoreInst* storeInst);
|
||||
|
||||
// 生成表达式的标准化字符串
|
||||
std::string getCanonicalExpression(Instruction* inst);
|
||||
// 清理方法
|
||||
void eliminateRedundantInstructions(bool& changed);
|
||||
void invalidateMemoryValues(StoreInst* store);
|
||||
};
|
||||
|
||||
// GVN优化遍类
|
||||
|
||||
Reference in New Issue
Block a user