Files
mysysy/src/include/SysYIROptUtils.h
rain2133 87d38be255 [midend]更新遍静态ID定义方法,
注册遍模板函数重构(针对遍的不同构造方法),
修复phi指令更新引起的旧代码错误,
将CFG优化适配到现有终端框架中,
独立CFG优化方法使得其他优化遍能独立调用,
usedelete方法回调取消删除功能。
IRGenerator代码风格修改。
2025-07-23 17:19:11 +08:00

33 lines
782 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include "IR.h"
namespace sysy {
// 优化工具类,包含一些通用的优化方法
// 这些方法可以在不同的优化 pass 中复用
// 例如删除use关系,判断是否是全局变量等
class SysYIROptUtils{
public:
// 仅仅删除use关系
static void usedelete(Instruction *instr) {
for (auto &use : instr->getOperands()) {
Value* val = use->getValue();
val->removeUse(use);
}
}
// 判断是否是全局变量
static bool isGlobal(Value *val) {
auto gval = dynamic_cast<GlobalValue *>(val);
return gval != nullptr;
}
// 判断是否是数组
static bool isArr(Value *val) {
auto aval = dynamic_cast<AllocaInst *>(val);
return aval != nullptr && aval->getNumDims() != 0;
}
};
}// namespace sysy