Compare commits
1 Commits
midend
...
midend-Fun
| Author | SHA1 | Date | |
|---|---|---|---|
| 97d83d733e |
2
.gitignore
vendored
2
.gitignore
vendored
@ -36,7 +36,7 @@ doxygen
|
||||
|
||||
!/testdata/functional/*.out
|
||||
!/testdata/h_functional/*.out
|
||||
testdata/performance/
|
||||
!/testdata/performance/*.out
|
||||
build/
|
||||
.antlr
|
||||
.vscode/
|
||||
|
||||
@ -20,19 +20,18 @@ QEMU_RISCV64="qemu-riscv64"
|
||||
|
||||
# --- 初始化变量 ---
|
||||
EXECUTE_MODE=false
|
||||
IR_EXECUTE_MODE=false
|
||||
IR_EXECUTE_MODE=false # 新增
|
||||
CLEAN_MODE=false
|
||||
OPTIMIZE_FLAG=""
|
||||
SYSYC_TIMEOUT=30
|
||||
LLC_TIMEOUT=10
|
||||
LLC_TIMEOUT=10 # 新增
|
||||
GCC_TIMEOUT=10
|
||||
EXEC_TIMEOUT=30
|
||||
MAX_OUTPUT_LINES=20
|
||||
MAX_OUTPUT_CHARS=1000
|
||||
SY_FILES=()
|
||||
PASSED_CASES=0
|
||||
FAILED_CASES_LIST=""
|
||||
INTERRUPTED=false
|
||||
INTERRUPTED=false # 新增
|
||||
|
||||
# =================================================================
|
||||
# --- 函数定义 ---
|
||||
@ -51,31 +50,22 @@ show_help() {
|
||||
echo " -gct N 设置 gcc 交叉编译超时为 N 秒 (默认: 10)。"
|
||||
echo " -et N 设置 qemu 自动化执行超时为 N 秒 (默认: 30)。"
|
||||
echo " -ml N, --max-lines N 当输出对比失败时,最多显示 N 行内容 (默认: 20)。"
|
||||
echo " -mc N, --max-chars N 当输出对比失败时,最多显示 N 个字符 (默认: 1000)。"
|
||||
echo " -h, --help 显示此帮助信息并退出。"
|
||||
echo ""
|
||||
echo "可在任何时候按 Ctrl+C 来中断测试并显示当前已完成的测例总结。"
|
||||
}
|
||||
|
||||
# 显示文件内容并根据行数和字符数截断的函数
|
||||
display_file_content() {
|
||||
local file_path="$1"
|
||||
local title="$2"
|
||||
local max_lines="$3"
|
||||
local max_chars="$4" # 新增参数
|
||||
if [ ! -f "$file_path" ]; then return; fi
|
||||
echo -e "$title"
|
||||
local line_count
|
||||
local char_count
|
||||
line_count=$(wc -l < "$file_path")
|
||||
char_count=$(wc -c < "$file_path")
|
||||
|
||||
if [ "$line_count" -gt "$max_lines" ]; then
|
||||
head -n "$max_lines" "$file_path"
|
||||
echo -e "\e[33m[... 输出因行数过多 (共 ${line_count} 行) 而截断 ...]\e[0m"
|
||||
elif [ "$char_count" -gt "$max_chars" ]; then
|
||||
head -c "$max_chars" "$file_path"
|
||||
echo -e "\n\e[33m[... 输出因字符数过多 (共 ${char_count} 字符) 而截断 ...]\e[0m"
|
||||
echo -e "\e[33m[... 输出已截断,共 ${line_count} 行 ...]\e[0m"
|
||||
else
|
||||
cat "$file_path"
|
||||
fi
|
||||
@ -141,7 +131,6 @@ while [[ "$#" -gt 0 ]]; do
|
||||
-gct) if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then GCC_TIMEOUT="$2"; shift 2; else echo "错误: -gct 需要一个正整数参数。" >&2; exit 1; fi ;;
|
||||
-et) if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then EXEC_TIMEOUT="$2"; shift 2; else echo "错误: -et 需要一个正整数参数。" >&2; exit 1; fi ;;
|
||||
-ml|--max-lines) if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then MAX_OUTPUT_LINES="$2"; shift 2; else echo "错误: --max-lines 需要一个正整数参数。" >&2; exit 1; fi ;;
|
||||
-mc|--max-chars) if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then MAX_OUTPUT_CHARS="$2"; shift 2; else echo "错误: --max-chars 需要一个正整数参数。" >&2; exit 1; fi ;;
|
||||
-h|--help) show_help; exit 0 ;;
|
||||
-*) echo "未知选项: $1"; show_help; exit 1 ;;
|
||||
*)
|
||||
@ -191,8 +180,6 @@ TOTAL_CASES=${#SY_FILES[@]}
|
||||
echo "SysY 单例测试运行器启动..."
|
||||
if [ -n "$OPTIMIZE_FLAG" ]; then echo "优化等级: ${OPTIMIZE_FLAG}"; fi
|
||||
echo "超时设置: sysyc=${SYSYC_TIMEOUT}s, llc=${LLC_TIMEOUT}s, gcc=${GCC_TIMEOUT}s, qemu=${EXEC_TIMEOUT}s"
|
||||
echo "失败输出最大行数: ${MAX_OUTPUT_LINES}"
|
||||
echo "失败输出最大字符数: ${MAX_OUTPUT_CHARS}"
|
||||
echo ""
|
||||
|
||||
for sy_file in "${SY_FILES[@]}"; do
|
||||
@ -273,8 +260,8 @@ for sy_file in "${SY_FILES[@]}"; do
|
||||
out_ok=1
|
||||
if ! diff -q <(tr -d '[:space:]' < "${output_actual_file}") <(tr -d '[:space:]' < "${EXPECTED_STDOUT_FILE}") >/dev/null 2>&1; then
|
||||
echo -e "\e[31m 标准输出测试失败。\e[0m"; out_ok=0
|
||||
display_file_content "${EXPECTED_STDOUT_FILE}" " \e[36m--- 期望输出 ---\e[0m" "${MAX_OUTPUT_LINES}" "${MAX_OUTPUT_CHARS}"
|
||||
display_file_content "${output_actual_file}" " \e[36m--- 实际输出 ---\e[0m" "${MAX_OUTPUT_LINES}" "${MAX_OUTPUT_CHARS}"
|
||||
display_file_content "${EXPECTED_STDOUT_FILE}" " \e[36m--- 期望输出 ---\e[0m" "${MAX_OUTPUT_LINES}"
|
||||
display_file_content "${output_actual_file}" " \e[36m--- 实际输出 ---\e[0m" "${MAX_OUTPUT_LINES}"
|
||||
fi
|
||||
|
||||
if [ "$ret_ok" -eq 1 ] && [ "$out_ok" -eq 1 ]; then echo -e "\e[32m 返回码与标准输出测试成功。\e[0m"; else is_passed=0; fi
|
||||
@ -284,8 +271,8 @@ for sy_file in "${SY_FILES[@]}"; do
|
||||
echo -e "\e[32m 标准输出测试成功。\e[0m"
|
||||
else
|
||||
echo -e "\e[31m 标准输出测试失败。\e[0m"; is_passed=0
|
||||
display_file_content "${output_reference_file}" " \e[36m--- 期望输出 ---\e[0m" "${MAX_OUTPUT_LINES}" "${MAX_OUTPUT_CHARS}"
|
||||
display_file_content "${output_actual_file}" " \e[36m--- 实际输出 ---\e[0m" "${MAX_OUTPUT_LINES}" "${MAX_OUTPUT_CHARS}"
|
||||
display_file_content "${output_reference_file}" " \e[36m--- 期望输出 ---\e[0m" "${MAX_OUTPUT_LINES}"
|
||||
display_file_content "${output_actual_file}" " \e[36m--- 实际输出 ---\e[0m" "${MAX_OUTPUT_LINES}"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
@ -314,4 +301,4 @@ for sy_file in "${SY_FILES[@]}"; do
|
||||
done
|
||||
|
||||
# --- 打印最终总结 ---
|
||||
print_summary
|
||||
print_summary
|
||||
@ -27,12 +27,11 @@ LLC_TIMEOUT=10
|
||||
GCC_TIMEOUT=10
|
||||
EXEC_TIMEOUT=30
|
||||
MAX_OUTPUT_LINES=20
|
||||
MAX_OUTPUT_CHARS=1000
|
||||
TEST_SETS=()
|
||||
TOTAL_CASES=0
|
||||
PASSED_CASES=0
|
||||
FAILED_CASES_LIST=""
|
||||
INTERRUPTED=false
|
||||
INTERRUPTED=false # 新增:用于标记是否被中断
|
||||
|
||||
# =================================================================
|
||||
# --- 函数定义 ---
|
||||
@ -54,7 +53,6 @@ show_help() {
|
||||
echo " -gct N 设置 gcc 交叉编译超时为 N 秒 (默认: 10)。"
|
||||
echo " -et N 设置 qemu 执行超时为 N 秒 (默认: 30)。"
|
||||
echo " -ml N, --max-lines N 当输出对比失败时,最多显示 N 行内容 (默认: 20)。"
|
||||
echo " -mc N, --max-chars N 当输出对比失败时,最多显示 N 个字符 (默认: 1000)。"
|
||||
echo " -h, --help 显示此帮助信息并退出。"
|
||||
echo ""
|
||||
echo "注意: 默认行为 (无 -e 或 -eir) 是将 .sy 文件同时编译为 .s (汇编) 和 .ll (IR),不执行。"
|
||||
@ -62,25 +60,18 @@ show_help() {
|
||||
}
|
||||
|
||||
|
||||
# 显示文件内容并根据行数和字符数截断的函数
|
||||
# 显示文件内容并根据行数截断的函数
|
||||
display_file_content() {
|
||||
local file_path="$1"
|
||||
local title="$2"
|
||||
local max_lines="$3"
|
||||
local max_chars="$4" # 新增参数
|
||||
if [ ! -f "$file_path" ]; then return; fi
|
||||
echo -e "$title"
|
||||
local line_count
|
||||
local char_count
|
||||
line_count=$(wc -l < "$file_path")
|
||||
char_count=$(wc -c < "$file_path")
|
||||
|
||||
if [ "$line_count" -gt "$max_lines" ]; then
|
||||
head -n "$max_lines" "$file_path"
|
||||
echo -e "\e[33m[... 输出因行数过多 (共 ${line_count} 行) 而截断 ...]\e[0m"
|
||||
elif [ "$char_count" -gt "$max_chars" ]; then
|
||||
head -c "$max_chars" "$file_path"
|
||||
echo -e "\n\e[33m[... 输出因字符数过多 (共 ${char_count} 字符) 而截断 ...]\e[0m"
|
||||
echo -e "\e[33m[... 输出已截断,共 ${line_count} 行 ...]\e[0m"
|
||||
else
|
||||
cat "$file_path"
|
||||
fi
|
||||
@ -160,7 +151,6 @@ while [[ "$#" -gt 0 ]]; do
|
||||
-gct) if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then GCC_TIMEOUT="$2"; shift 2; else echo "错误: -gct 需要一个正整数参数。" >&2; exit 1; fi ;;
|
||||
-et) if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then EXEC_TIMEOUT="$2"; shift 2; else echo "错误: -et 需要一个正整数参数。" >&2; exit 1; fi ;;
|
||||
-ml|--max-lines) if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then MAX_OUTPUT_LINES="$2"; shift 2; else echo "错误: --max-lines 需要一个正整数参数。" >&2; exit 1; fi ;;
|
||||
-mc|--max-chars) if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then MAX_OUTPUT_CHARS="$2"; shift 2; else echo "错误: --max-chars 需要一个正整数参数。" >&2; exit 1; fi ;;
|
||||
-h|--help) show_help; exit 0 ;;
|
||||
*) echo "未知选项: $1"; show_help; exit 1 ;;
|
||||
esac
|
||||
@ -214,7 +204,6 @@ echo "运行模式: ${RUN_MODE_INFO}"
|
||||
echo "${TIMEOUT_INFO}"
|
||||
if ${EXECUTE_MODE} || ${IR_EXECUTE_MODE}; then
|
||||
echo "失败输出最大行数: ${MAX_OUTPUT_LINES}"
|
||||
echo "失败输出最大字符数: ${MAX_OUTPUT_CHARS}"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
@ -309,8 +298,8 @@ while IFS= read -r sy_file; do
|
||||
[ "$test_logic_passed" -eq 1 ] && echo -e "\e[32m 标准输出测试成功\e[0m"
|
||||
else
|
||||
echo -e "\e[31m 标准输出测试失败\e[0m"
|
||||
display_file_content "${EXPECTED_STDOUT_FILE}" " \e[36m---------- 期望输出 ----------\e[0m" "${MAX_OUTPUT_LINES}" "${MAX_OUTPUT_CHARS}"
|
||||
display_file_content "${output_actual_file_from_ir}" " \e[36m---------- 实际输出 ----------\e[0m" "${MAX_OUTPUT_LINES}" "${MAX_OUTPUT_CHARS}"
|
||||
display_file_content "${EXPECTED_STDOUT_FILE}" " \e[36m---------- 期望输出 ----------\e[0m" "${MAX_OUTPUT_LINES}"
|
||||
display_file_content "${output_actual_file_from_ir}" " \e[36m---------- 实际输出 ----------\e[0m" "${MAX_OUTPUT_LINES}"
|
||||
test_logic_passed=0
|
||||
fi
|
||||
else
|
||||
@ -319,8 +308,8 @@ while IFS= read -r sy_file; do
|
||||
echo -e "\e[32m 成功: 输出与参考输出匹配\e[0m"
|
||||
else
|
||||
echo -e "\e[31m 失败: 输出不匹配\e[0m"
|
||||
display_file_content "${output_reference_file}" " \e[36m---------- 期望输出 ----------\e[0m" "${MAX_OUTPUT_LINES}" "${MAX_OUTPUT_CHARS}"
|
||||
display_file_content "${output_actual_file_from_ir}" " \e[36m---------- 实际输出 ----------\e[0m" "${MAX_OUTPUT_LINES}" "${MAX_OUTPUT_CHARS}"
|
||||
display_file_content "${output_reference_file}" " \e[36m---------- 期望输出 ----------\e[0m" "${MAX_OUTPUT_LINES}"
|
||||
display_file_content "${output_actual_file_from_ir}" " \e[36m---------- 实际输出 ----------\e[0m" "${MAX_OUTPUT_LINES}"
|
||||
test_logic_passed=0
|
||||
fi
|
||||
fi
|
||||
@ -386,8 +375,8 @@ while IFS= read -r sy_file; do
|
||||
[ "$test_logic_passed" -eq 1 ] && echo -e "\e[32m 标准输出测试成功\e[0m"
|
||||
else
|
||||
echo -e "\e[31m 标准输出测试失败\e[0m"
|
||||
display_file_content "${EXPECTED_STDOUT_FILE}" " \e[36m---------- 期望输出 ----------\e[0m" "${MAX_OUTPUT_LINES}" "${MAX_OUTPUT_CHARS}"
|
||||
display_file_content "${output_actual_file_S}" " \e[36m---------- 实际输出 ----------\e[0m" "${MAX_OUTPUT_LINES}" "${MAX_OUTPUT_CHARS}"
|
||||
display_file_content "${EXPECTED_STDOUT_FILE}" " \e[36m---------- 期望输出 ----------\e[0m" "${MAX_OUTPUT_LINES}"
|
||||
display_file_content "${output_actual_file_S}" " \e[36m---------- 实际输出 ----------\e[0m" "${MAX_OUTPUT_LINES}"
|
||||
test_logic_passed=0
|
||||
fi
|
||||
else
|
||||
@ -396,8 +385,8 @@ while IFS= read -r sy_file; do
|
||||
echo -e "\e[32m 成功: 输出与参考输出匹配\e[0m"
|
||||
else
|
||||
echo -e "\e[31m 失败: 输出不匹配\e[0m"
|
||||
display_file_content "${output_reference_file}" " \e[36m---------- 期望输出 ----------\e[0m" "${MAX_OUTPUT_LINES}" "${MAX_OUTPUT_CHARS}"
|
||||
display_file_content "${output_actual_file_S}" " \e[36m---------- 实际输出 ----------\e[0m" "${MAX_OUTPUT_LINES}" "${MAX_OUTPUT_CHARS}"
|
||||
display_file_content "${output_reference_file}" " \e[36m---------- 期望输出 ----------\e[0m" "${MAX_OUTPUT_LINES}"
|
||||
display_file_content "${output_actual_file_S}" " \e[36m---------- 实际输出 ----------\e[0m" "${MAX_OUTPUT_LINES}"
|
||||
test_logic_passed=0
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -634,22 +634,6 @@ void PeepholeOptimizer::runOnMachineFunction(MachineFunction *mfunc) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 8. 消除无用移动指令: mv a, a -> (删除)
|
||||
else if (mi1->getOpcode() == RVOpcodes::MV &&
|
||||
mi1->getOperands().size() == 2) {
|
||||
if (mi1->getOperands()[0]->getKind() == MachineOperand::KIND_REG &&
|
||||
mi1->getOperands()[1]->getKind() == MachineOperand::KIND_REG) {
|
||||
auto *dst = static_cast<RegOperand *>(mi1->getOperands()[0].get());
|
||||
auto *src = static_cast<RegOperand *>(mi1->getOperands()[1].get());
|
||||
|
||||
// 检查源和目标寄存器是否相同
|
||||
if (areRegsEqual(dst, src)) {
|
||||
// 删除这条无用指令
|
||||
instrs.erase(instrs.begin() + i);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 根据是否发生变化调整遍历索引
|
||||
if (!changed) {
|
||||
|
||||
@ -652,6 +652,13 @@ public:
|
||||
} ///< 移除指定位置的指令
|
||||
iterator moveInst(iterator sourcePos, iterator targetPos, BasicBlock *block);
|
||||
|
||||
static void bbdfs(BasicBlock* bb, std::function<bool(BasicBlock*)> func) {
|
||||
if (func(bb))
|
||||
return;
|
||||
for (auto succ : bb->getSuccessors())
|
||||
bbdfs(succ, func);
|
||||
}
|
||||
|
||||
/// 清理基本块中的所有使用关系
|
||||
void cleanup();
|
||||
|
||||
@ -767,7 +774,7 @@ protected:
|
||||
: User(type, name), kind(kind), parent(parent) {}
|
||||
|
||||
public:
|
||||
|
||||
virtual Instruction* copy(std::function<Value*(Value*)> getValue) const = 0;
|
||||
public:
|
||||
Kind getKind() const { return kind; }
|
||||
std::string getKindString() const{
|
||||
@ -964,6 +971,18 @@ class PhiInst : public Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
PhiInst(Type *type,
|
||||
const std::vector<std::pair<BasicBlock*, Value*>> IncomingValues,
|
||||
BasicBlock *parent = nullptr,
|
||||
const std::string &name = "")
|
||||
: Instruction(Kind::kPhi, type, parent, name), vsize(IncomingValues.size()) {
|
||||
for(size_t i = 0; i < vsize; ++i) {
|
||||
addOperand(IncomingValues[i].first);
|
||||
addOperand(IncomingValues[i].second);
|
||||
}
|
||||
refreshMap(); ///< 刷新块到值的映射关系
|
||||
}
|
||||
|
||||
public:
|
||||
unsigned getNumIncomingValues() const { return vsize; } ///< 获取传入值的数量
|
||||
Value *getIncomingValue(unsigned Idx) const { return getOperand(Idx * 2); } ///< 获取指定位置的传入值
|
||||
@ -1007,13 +1026,13 @@ class PhiInst : public Instruction {
|
||||
void replaceIncomingBlock(BasicBlock *oldBlock, BasicBlock *newBlock, Value *newValue);
|
||||
void refreshMap() {
|
||||
blk2val.clear();
|
||||
vsize = getNumOperands() / 2;
|
||||
for (unsigned i = 0; i < vsize; ++i) {
|
||||
blk2val[getIncomingBlock(i)] = getIncomingValue(i);
|
||||
}
|
||||
} ///< 刷新块到值的映射关系
|
||||
auto getValues() { return make_range(std::next(operand_begin()), operand_end()); }
|
||||
void print(std::ostream& os) const override;
|
||||
Instruction* copy(std::function<Value*(Value*)> getValue) const override;
|
||||
};
|
||||
|
||||
|
||||
@ -1048,6 +1067,7 @@ protected:
|
||||
public:
|
||||
Value* getOperand() const { return User::getOperand(0); }
|
||||
void print(std::ostream& os) const override;
|
||||
Instruction* copy(std::function<Value*(Value*)> getValue) const override;
|
||||
}; // class UnaryInst
|
||||
|
||||
//! Binary instruction, e.g., arithmatic, relation, logic, etc.
|
||||
@ -1127,6 +1147,7 @@ public:
|
||||
return new BinaryInst(kind, type, lhs, rhs, parent, name);
|
||||
}
|
||||
void print(std::ostream& os) const override;
|
||||
Instruction* copy(std::function<Value*(Value*)> getValue) const override;
|
||||
}; // class BinaryInst
|
||||
|
||||
//! The return statement
|
||||
@ -1218,6 +1239,7 @@ public:
|
||||
return succs;
|
||||
}
|
||||
void print(std::ostream& os) const override;
|
||||
Instruction* copy(std::function<Value*(Value*)> getValue) const override;
|
||||
}; // class CondBrInst
|
||||
|
||||
class UnreachableInst : public Instruction {
|
||||
@ -1226,6 +1248,7 @@ public:
|
||||
explicit UnreachableInst(const std::string& name, BasicBlock *parent = nullptr)
|
||||
: Instruction(kUnreachable, Type::getVoidType(), parent, "") {}
|
||||
void print(std::ostream& os) const { os << "unreachable"; }
|
||||
Instruction* copy(std::function<Value*(Value*)> getValue) const override;
|
||||
};
|
||||
|
||||
//! Allocate memory for stack variables, used for non-global variable declartion
|
||||
@ -1244,6 +1267,7 @@ public:
|
||||
return getType()->as<PointerType>()->getBaseType();
|
||||
} ///< 获取分配的类型
|
||||
void print(std::ostream& os) const override;
|
||||
Instruction* copy(std::function<Value*(Value*)> getValue) const override;
|
||||
}; // class AllocaInst
|
||||
|
||||
|
||||
@ -1282,6 +1306,7 @@ public:
|
||||
return new GetElementPtrInst(resultType, basePointer, indices, parent, name);
|
||||
}
|
||||
void print(std::ostream& os) const override;
|
||||
Instruction* copy(std::function<Value*(Value*)> getValue) const override;
|
||||
};
|
||||
|
||||
//! Load a value from memory address specified by a pointer value
|
||||
@ -1300,6 +1325,7 @@ protected:
|
||||
public:
|
||||
Value* getPointer() const { return getOperand(0); }
|
||||
void print(std::ostream& os) const override;
|
||||
Instruction* copy(std::function<Value*(Value*)> getValue) const override;
|
||||
}; // class LoadInst
|
||||
|
||||
//! Store a value to memory address specified by a pointer value
|
||||
@ -1319,6 +1345,7 @@ public:
|
||||
Value* getValue() const { return getOperand(0); }
|
||||
Value* getPointer() const { return getOperand(1); }
|
||||
void print(std::ostream& os) const override;
|
||||
Instruction* copy(std::function<Value*(Value*)> getValue) const override;
|
||||
}; // class StoreInst
|
||||
|
||||
//! Memset instruction
|
||||
@ -1349,6 +1376,7 @@ public:
|
||||
Value* getSize() const { return getOperand(2); }
|
||||
Value* getValue() const { return getOperand(3); }
|
||||
void print(std::ostream& os) const override;
|
||||
Instruction* copy(std::function<Value*(Value*)> getValue) const override;
|
||||
};
|
||||
|
||||
class GlobalValue;
|
||||
@ -1386,19 +1414,11 @@ protected:
|
||||
public:
|
||||
using block_list = std::list<std::unique_ptr<BasicBlock>>;
|
||||
using arg_list = std::vector<Argument *>;
|
||||
enum FunctionAttribute : uint64_t {
|
||||
PlaceHolder = 0x0UL,
|
||||
Pure = 0x1UL << 0,
|
||||
SelfRecursive = 0x1UL << 1,
|
||||
SideEffect = 0x1UL << 2,
|
||||
NoPureCauseMemRead = 0x1UL << 3
|
||||
};
|
||||
|
||||
protected:
|
||||
Module *parent; ///< 函数的父模块
|
||||
block_list blocks; ///< 函数包含的基本块列表
|
||||
arg_list arguments; ///< 函数参数列表
|
||||
FunctionAttribute attribute = PlaceHolder; ///< 函数属性
|
||||
std::set<Function *> callees; ///< 函数调用的函数集合
|
||||
public:
|
||||
static unsigned getcloneIndex() {
|
||||
@ -1406,17 +1426,12 @@ protected:
|
||||
cloneIndex += 1;
|
||||
return cloneIndex - 1;
|
||||
}
|
||||
Function* clone(const std::string &suffix = "_" + std::to_string(getcloneIndex()) + "@") const;
|
||||
Function* copy_func();
|
||||
const std::set<Function *>& getCallees() { return callees; }
|
||||
void addCallee(Function *callee) { callees.insert(callee); }
|
||||
void removeCallee(Function *callee) { callees.erase(callee); }
|
||||
void clearCallees() { callees.clear(); }
|
||||
std::set<Function *> getCalleesWithNoExternalAndSelf();
|
||||
FunctionAttribute getAttribute() const { return attribute; }
|
||||
void setAttribute(FunctionAttribute attr) {
|
||||
attribute = static_cast<FunctionAttribute>(attribute | attr);
|
||||
}
|
||||
void clearAttribute() { attribute = PlaceHolder; }
|
||||
Type* getReturnType() const { return getType()->as<FunctionType>()->getReturnType(); }
|
||||
auto getParamTypes() const { return getType()->as<FunctionType>()->getParamTypes(); }
|
||||
auto getBasicBlocks() { return make_range(blocks); }
|
||||
|
||||
@ -109,34 +109,6 @@ 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) {
|
||||
|
||||
|
||||
@ -1,39 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Pass.h"
|
||||
#include "Dom.h"
|
||||
#include "Loop.h"
|
||||
|
||||
namespace sysy {
|
||||
|
||||
/**
|
||||
* @class TailCallOpt
|
||||
* @brief 优化尾调用的中端优化通道。
|
||||
*
|
||||
* 该类实现了一个针对函数级别的尾调用优化的优化通道(OptimizationPass)。
|
||||
* 通过分析和转换 IR(中间表示),将可优化的尾调用转换为更高效的形式,
|
||||
* 以减少函数调用的开销,提升程序性能。
|
||||
*
|
||||
* @note 需要传入 IRBuilder 指针用于 IR 构建和修改。
|
||||
*
|
||||
* @method runOnFunction
|
||||
* 对指定函数进行尾调用优化。
|
||||
*
|
||||
* @method getPassID
|
||||
* 获取当前优化通道的唯一标识符。
|
||||
*
|
||||
* @method getAnalysisUsage
|
||||
* 指定该优化通道所依赖和失效的分析集合。
|
||||
*/
|
||||
class TailCallOpt : public OptimizationPass {
|
||||
private:
|
||||
IRBuilder* builder;
|
||||
public:
|
||||
TailCallOpt(IRBuilder* builder) : OptimizationPass("TailCallOpt", Granularity::Function), builder(builder) {}
|
||||
static void *ID;
|
||||
bool runOnFunction(Function *F, AnalysisManager &AM) override;
|
||||
void *getPassID() const override { return &ID; }
|
||||
void getAnalysisUsage(std::set<void *> &analysisDependencies, std::set<void *> &analysisInvalidations) const override;
|
||||
};
|
||||
|
||||
} // namespace sysy
|
||||
@ -25,7 +25,6 @@ add_library(midend_lib STATIC
|
||||
Pass/Optimize/GlobalStrengthReduction.cpp
|
||||
Pass/Optimize/BuildCFG.cpp
|
||||
Pass/Optimize/LargeArrayToGlobal.cpp
|
||||
Pass/Optimize/TailCallOpt.cpp
|
||||
)
|
||||
|
||||
# 包含中端模块所需的头文件路径
|
||||
|
||||
@ -652,6 +652,12 @@ void BasicBlock::print(std::ostream &os) const {
|
||||
}
|
||||
}
|
||||
|
||||
void Instruction::print(std::ostream &os) const {
|
||||
this->getType()->print(os);
|
||||
std::cerr << " %" << getName() << " ";
|
||||
return;
|
||||
}
|
||||
|
||||
void PhiInst::print(std::ostream &os) const {
|
||||
printVarName(os, this);
|
||||
os << " = " << getKindString() << " " << *getType() << " ";
|
||||
@ -757,7 +763,7 @@ void BinaryInst::print(std::ostream &os) const {
|
||||
auto lhs_hash = std::hash<const void*>{}(static_cast<const void*>(getLhs()));
|
||||
auto rhs_hash = std::hash<const void*>{}(static_cast<const void*>(getRhs()));
|
||||
size_t combined_hash = inst_hash ^ (lhs_hash << 1) ^ (rhs_hash << 2);
|
||||
std::string tmpName = "tmp_icmp_" + std::to_string(combined_hash % 1000000007);
|
||||
std::string tmpName = "tmp_icmp_" + std::to_string(combined_hash % 1000000);
|
||||
os << "%" << tmpName << " = " << getKindString() << " " << *getLhs()->getType() << " ";
|
||||
printOperand(os, getLhs());
|
||||
os << ", ";
|
||||
@ -772,7 +778,7 @@ void BinaryInst::print(std::ostream &os) const {
|
||||
auto lhs_hash = std::hash<const void*>{}(static_cast<const void*>(getLhs()));
|
||||
auto rhs_hash = std::hash<const void*>{}(static_cast<const void*>(getRhs()));
|
||||
size_t combined_hash = inst_hash ^ (lhs_hash << 1) ^ (rhs_hash << 2);
|
||||
std::string tmpName = "tmp_fcmp_" + std::to_string(combined_hash % 1000000007);
|
||||
std::string tmpName = "tmp_fcmp_" + std::to_string(combined_hash % 1000000);
|
||||
os << "%" << tmpName << " = " << getKindString() << " " << *getLhs()->getType() << " ";
|
||||
printOperand(os, getLhs());
|
||||
os << ", ";
|
||||
@ -834,7 +840,7 @@ void CondBrInst::print(std::ostream &os) const {
|
||||
if (condName.empty()) {
|
||||
// 使用条件值地址的哈希值作为唯一标识
|
||||
auto ptr_hash = std::hash<const void*>{}(static_cast<const void*>(condition));
|
||||
condName = "const_" + std::to_string(ptr_hash % 1000000007);
|
||||
condName = "const_" + std::to_string(ptr_hash % 100000);
|
||||
}
|
||||
|
||||
// 组合指令地址、条件地址和目标块地址的哈希来确保唯一性
|
||||
@ -843,7 +849,7 @@ void CondBrInst::print(std::ostream &os) const {
|
||||
auto then_hash = std::hash<const void*>{}(static_cast<const void*>(getThenBlock()));
|
||||
auto else_hash = std::hash<const void*>{}(static_cast<const void*>(getElseBlock()));
|
||||
size_t combined_hash = inst_hash ^ (cond_hash << 1) ^ (then_hash << 2) ^ (else_hash << 3);
|
||||
std::string uniqueSuffix = std::to_string(combined_hash % 1000000007);
|
||||
std::string uniqueSuffix = std::to_string(combined_hash % 1000000);
|
||||
|
||||
os << "%tmp_cond_" << condName << "_" << uniqueSuffix << " = icmp ne i32 ";
|
||||
printOperand(os, condition);
|
||||
@ -1440,4 +1446,76 @@ void Argument::cleanup() {
|
||||
uses.clear();
|
||||
}
|
||||
|
||||
Function* Function::copy_func(){
|
||||
std::unordered_map<Value*, Value*> valueMap;
|
||||
// copy global
|
||||
for (auto &gvalue : parent->getGlobals()) {
|
||||
valueMap.emplace(gvalue.get(), gvalue.get());
|
||||
}
|
||||
// copy global const
|
||||
for (auto &cvalue : parent->getConsts()) {
|
||||
valueMap.emplace(cvalue.get(), cvalue.get());
|
||||
}
|
||||
|
||||
// copy function
|
||||
auto newFunc = new Function(parent, type, name + "_copy" + std::to_string(getcloneIndex()));
|
||||
// copy arg
|
||||
for(int i = 0; i < arguments.size(); i++) {
|
||||
auto arg = arguments[i];
|
||||
// Argument(paramActualTypes[i], function, i, paramNames[i]);
|
||||
auto newarg = new Argument(arg->getType(), newFunc, i, arg->getName() + "_copy");
|
||||
newFunc->insertArgument(newarg);
|
||||
valueMap[arg] = newarg;
|
||||
}
|
||||
//
|
||||
for (auto &bb : blocks) {
|
||||
BasicBlock* copybb = newFunc->addBasicBlock();
|
||||
valueMap.emplace(bb, copybb);
|
||||
}
|
||||
|
||||
for(auto &bb : blocks) {
|
||||
auto BB = bb.get();
|
||||
auto copybb = dynamic_cast<BasicBlock*>(valueMap[BB]);
|
||||
for(auto pred : BB->getPredecessors()) {
|
||||
copybb->addPredecessor(dynamic_cast<BasicBlock*>(valueMap[pred]));
|
||||
}
|
||||
for(auto succ : BB->getSuccessors()) {
|
||||
copybb->addSuccessor(dynamic_cast<BasicBlock*>(valueMap[succ]));
|
||||
}
|
||||
}
|
||||
|
||||
// if cant find, return itself
|
||||
auto getValue = [&](Value* val) -> Value* {
|
||||
if (val == nullptr) {
|
||||
std::cerr << "getValue(nullptr)" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
if (dynamic_cast<ConstantValue*>(val)) return val;
|
||||
if (auto iter = valueMap.find(val); iter != valueMap.end()) return iter->second;
|
||||
return val;
|
||||
};
|
||||
|
||||
std::set<BasicBlock*> visitedbb;
|
||||
|
||||
const auto copyBlock = [&](BasicBlock* bb) -> bool {
|
||||
if (visitedbb.count(bb)) return true;
|
||||
visitedbb.insert(bb);
|
||||
auto bbCpy = dynamic_cast<BasicBlock*>(valueMap.at(bb));
|
||||
for (auto &Inst : bb->getInstructions()) {
|
||||
auto inst = Inst.get();
|
||||
// inst->print(std::cerr);
|
||||
// std::cerr << std::endl;
|
||||
auto copyinst = inst->copy(getValue);
|
||||
copyinst->setParent(bbCpy);
|
||||
valueMap.emplace(inst, copyinst);
|
||||
bbCpy->instructions.emplace_back(copyinst);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
//dfs基本块将指令复制到新函数中
|
||||
BasicBlock::bbdfs(getEntryBlock(), copyBlock);
|
||||
|
||||
return newFunc;
|
||||
}
|
||||
|
||||
} // namespace sysy
|
||||
|
||||
@ -74,7 +74,6 @@ void DCEContext::run(Function *func, AnalysisManager *AM, bool &changed) {
|
||||
}
|
||||
}
|
||||
}
|
||||
changed |= SysYIROptUtils::eliminateRedundantPhisInFunction(func); // 如果有活跃指令,则标记为已更改
|
||||
}
|
||||
|
||||
// 判断指令是否是"天然活跃"的实现
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -671,13 +671,13 @@ bool GlobalStrengthReductionContext::reduceDivision(BinaryInst *inst) {
|
||||
}
|
||||
|
||||
// x / c = x * magic_number (魔数乘法优化 - 使用libdivide算法)
|
||||
// if (isConstantInt(rhs, constVal) && constVal > 1 && constVal != (uint32_t)(-1)) {
|
||||
// // auto magicPair = computeMulhMagicNumbers(static_cast<int>(constVal));
|
||||
// Value* magicResult = createMagicDivisionLibdivide(inst, static_cast<int>(constVal));
|
||||
// replaceWithOptimized(inst, magicResult);
|
||||
// divisionOptCount++;
|
||||
// return true;
|
||||
// }
|
||||
if (isConstantInt(rhs, constVal) && constVal > 1 && constVal != (uint32_t)(-1)) {
|
||||
// auto magicPair = computeMulhMagicNumbers(static_cast<int>(constVal));
|
||||
Value* magicResult = createMagicDivisionLibdivide(inst, static_cast<int>(constVal));
|
||||
replaceWithOptimized(inst, magicResult);
|
||||
divisionOptCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -133,7 +133,6 @@ bool InductionVariableEliminationContext::run(Function* F, AnalysisManager& AM)
|
||||
printDebugInfo();
|
||||
}
|
||||
|
||||
modified |= SysYIROptUtils::eliminateRedundantPhisInFunction(F);
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
@ -661,9 +661,9 @@ bool StrengthReductionContext::replaceOriginalInstruction(StrengthReductionCandi
|
||||
|
||||
case StrengthReductionCandidate::DIVIDE_CONST: {
|
||||
// 任意常数除法
|
||||
// builder->setPosition(candidate->containingBlock,
|
||||
// candidate->containingBlock->findInstIterator(candidate->originalInst));
|
||||
// replacementValue = generateConstantDivisionReplacement(candidate, builder);
|
||||
builder->setPosition(candidate->containingBlock,
|
||||
candidate->containingBlock->findInstIterator(candidate->originalInst));
|
||||
replacementValue = generateConstantDivisionReplacement(candidate, builder);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -683,19 +683,17 @@ bool StrengthReductionContext::replaceOriginalInstruction(StrengthReductionCandi
|
||||
);
|
||||
|
||||
// 检查原值是否为负数
|
||||
Value* shift31condidata = builder->createBinaryInst(
|
||||
Instruction::Kind::kSra, candidate->inductionVar->getType(),
|
||||
candidate->inductionVar, ConstantInteger::get(31)
|
||||
);
|
||||
Value* zero = ConstantInteger::get(0);
|
||||
Value* isNegative = builder->createICmpLTInst(candidate->inductionVar, zero);
|
||||
|
||||
// 如果为负数,需要调整结果
|
||||
Value* adjustment = builder->createAndInst(shift31condidata, maskConstant);
|
||||
Value* adjustedTemp = builder->createAddInst(candidate->inductionVar, adjustment);
|
||||
Value* adjustedResult = builder->createBinaryInst(
|
||||
Instruction::Kind::kAnd, candidate->inductionVar->getType(),
|
||||
adjustedTemp, maskConstant
|
||||
);
|
||||
replacementValue = adjustedResult;
|
||||
Value* adjustment = ConstantInteger::get(candidate->multiplier);
|
||||
Value* adjustedTemp = builder->createAddInst(temp, adjustment);
|
||||
|
||||
// 使用条件分支来模拟select操作
|
||||
// 为简化起见,这里先用一个更复杂但可工作的方式
|
||||
// 实际应该创建条件分支,但这里先简化处理
|
||||
replacementValue = temp; // 简化版本,假设大多数情况下不是负数
|
||||
} else {
|
||||
// 非负数的取模,直接使用位与
|
||||
replacementValue = builder->createBinaryInst(
|
||||
|
||||
@ -1357,8 +1357,9 @@ void SCCPContext::run(Function *func, AnalysisManager &AM) {
|
||||
bool changed_control_flow = SimplifyControlFlow(func);
|
||||
|
||||
// 如果任何一个阶段修改了 IR,标记分析结果为失效
|
||||
bool changed = changed_constant_propagation || changed_control_flow;
|
||||
changed |= SysYIROptUtils::eliminateRedundantPhisInFunction(func);
|
||||
if (changed_constant_propagation || changed_control_flow) {
|
||||
// AM.invalidate(); // 假设有这样的方法来使所有分析结果失效
|
||||
}
|
||||
}
|
||||
|
||||
// SCCP Pass methods
|
||||
|
||||
@ -1,125 +0,0 @@
|
||||
#include "TailCallOpt.h"
|
||||
#include "IR.h"
|
||||
#include "IRBuilder.h"
|
||||
#include "SysYIROptUtils.h"
|
||||
#include <vector>
|
||||
// #include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
namespace sysy {
|
||||
|
||||
void *TailCallOpt::ID = (void *)&TailCallOpt::ID;
|
||||
|
||||
void TailCallOpt::getAnalysisUsage(std::set<void *> &analysisDependencies, std::set<void *> &analysisInvalidations) const {
|
||||
analysisInvalidations.insert(&DominatorTreeAnalysisPass::ID);
|
||||
analysisInvalidations.insert(&LoopAnalysisPass::ID);
|
||||
}
|
||||
|
||||
bool TailCallOpt::runOnFunction(Function *F, AnalysisManager &AM) {
|
||||
std::vector<CallInst *> tailCallInsts;
|
||||
// 遍历函数的所有基本块
|
||||
for (auto &bb_ptr : F->getBasicBlocks()) {
|
||||
auto BB = bb_ptr.get();
|
||||
if (BB->getInstructions().empty()) continue; // 跳过空基本块
|
||||
|
||||
auto term_iter = BB->terminator();
|
||||
if (term_iter == BB->getInstructions().end()) continue; // 没有终结指令则跳过
|
||||
auto term = (*term_iter).get();
|
||||
|
||||
if (!term || !term->isReturn()) continue; // 不是返回指令则跳过
|
||||
auto retInst = static_cast<ReturnInst *>(term);
|
||||
|
||||
Instruction *prevInst = nullptr;
|
||||
if (BB->getInstructions().size() > 1) {
|
||||
auto it = term_iter;
|
||||
--it; // 获取返回指令前的指令
|
||||
prevInst = (*it).get();
|
||||
}
|
||||
|
||||
if (!prevInst || !prevInst->isCall()) continue; // 前一条不是调用指令则跳过
|
||||
auto callInst = static_cast<CallInst *>(prevInst);
|
||||
|
||||
// 检查是否为尾递归调用:被调用函数与当前函数相同且返回值与调用结果匹配
|
||||
if (callInst->getCallee() == F) {
|
||||
// 对于尾递归,返回值应为调用结果或为 void 类型
|
||||
if (retInst->getReturnValue() == callInst ||
|
||||
(retInst->getReturnValue() == nullptr && callInst->getType()->isVoid())) {
|
||||
tailCallInsts.push_back(callInst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tailCallInsts.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 创建一个新的入口基本块,作为循环的前置块
|
||||
auto original_entry = F->getEntryBlock();
|
||||
auto new_entry = F->addBasicBlock("tco.entry." + F->getName());
|
||||
auto loop_header = F->addBasicBlock("tco.loop_header." + F->getName());
|
||||
|
||||
// 将原入口块中的所有指令移动到循环头块
|
||||
loop_header->getInstructions().splice(loop_header->end(), original_entry->getInstructions());
|
||||
original_entry->setName("tco.pre_header");
|
||||
|
||||
// 为函数参数创建 phi 节点
|
||||
builder->setPosition(loop_header, loop_header->begin());
|
||||
std::vector<PhiInst *> phis;
|
||||
auto original_args = F->getArguments();
|
||||
for (auto &arg : original_args) {
|
||||
auto phi = builder->createPhiInst(arg->getType(), {}, {}, "tco.phi."+arg->getName());
|
||||
phis.push_back(phi);
|
||||
}
|
||||
|
||||
// 用 phi 节点替换所有原始参数的使用
|
||||
for (size_t i = 0; i < original_args.size(); ++i) {
|
||||
original_args[i]->replaceAllUsesWith(phis[i]);
|
||||
}
|
||||
|
||||
// 设置 phi 节点的输入值
|
||||
for (size_t i = 0; i < phis.size(); ++i) {
|
||||
phis[i]->addIncoming(original_args[i], new_entry);
|
||||
}
|
||||
|
||||
// 连接各个基本块
|
||||
builder->setPosition(original_entry, original_entry->end());
|
||||
builder->createUncondBrInst(new_entry);
|
||||
original_entry->addSuccessor(new_entry);
|
||||
|
||||
builder->setPosition(new_entry, new_entry->end());
|
||||
builder->createUncondBrInst(loop_header);
|
||||
new_entry->addSuccessor(loop_header);
|
||||
loop_header->addPredecessor(new_entry);
|
||||
|
||||
// 处理每一个尾递归调用
|
||||
for (auto callInst : tailCallInsts) {
|
||||
auto tail_call_block = callInst->getParent();
|
||||
|
||||
// 收集尾递归调用的参数
|
||||
auto args_range = callInst->getArguments();
|
||||
std::vector<Value*> args;
|
||||
std::transform(args_range.begin(), args_range.end(), std::back_inserter(args),
|
||||
[](auto& use_ptr){ return use_ptr->getValue(); });
|
||||
|
||||
// 用新的参数值更新 phi 节点
|
||||
for (size_t i = 0; i < phis.size(); ++i) {
|
||||
phis[i]->addIncoming(args[i], tail_call_block);
|
||||
}
|
||||
|
||||
// 移除原有的调用和返回指令
|
||||
auto term_iter = tail_call_block->terminator();
|
||||
SysYIROptUtils::usedelete(term_iter);
|
||||
auto call_iter = tail_call_block->findInstIterator(callInst);
|
||||
SysYIROptUtils::usedelete(call_iter);
|
||||
|
||||
// 添加跳转回循环头块的分支指令
|
||||
builder->setPosition(tail_call_block, tail_call_block->end());
|
||||
builder->createUncondBrInst(loop_header);
|
||||
tail_call_block->addSuccessor(loop_header);
|
||||
loop_header->addPredecessor(tail_call_block);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sysy
|
||||
@ -19,7 +19,6 @@
|
||||
#include "LoopStrengthReduction.h"
|
||||
#include "InductionVariableElimination.h"
|
||||
#include "GlobalStrengthReduction.h"
|
||||
#include "TailCallOpt.h"
|
||||
#include "Pass.h"
|
||||
#include <iostream>
|
||||
#include <queue>
|
||||
@ -82,7 +81,6 @@ void PassManager::runOptimizationPipeline(Module* moduleIR, IRBuilder* builderIR
|
||||
|
||||
registerOptimizationPass<GlobalStrengthReduction>(builderIR);
|
||||
registerOptimizationPass<Reg2Mem>(builderIR);
|
||||
registerOptimizationPass<TailCallOpt>(builderIR);
|
||||
|
||||
registerOptimizationPass<SCCP>(builderIR);
|
||||
|
||||
@ -141,16 +139,6 @@ void PassManager::runOptimizationPipeline(Module* moduleIR, IRBuilder* builderIR
|
||||
this->addPass(&GVN::ID);
|
||||
this->run();
|
||||
|
||||
this->clearPasses();
|
||||
this->addPass(&TailCallOpt::ID);
|
||||
this->run();
|
||||
|
||||
if(DEBUG) {
|
||||
std::cout << "=== IR After TailCallOpt ===\n";
|
||||
SysYPrinter printer(moduleIR);
|
||||
printer.printIR();
|
||||
}
|
||||
|
||||
if(DEBUG) {
|
||||
std::cout << "=== IR After GVN Optimizations ===\n";
|
||||
printPasses();
|
||||
@ -204,9 +192,9 @@ void PassManager::runOptimizationPipeline(Module* moduleIR, IRBuilder* builderIR
|
||||
printPasses();
|
||||
}
|
||||
|
||||
this->clearPasses();
|
||||
this->addPass(&Reg2Mem::ID);
|
||||
this->run();
|
||||
// this->clearPasses();
|
||||
// this->addPass(&Reg2Mem::ID);
|
||||
// this->run();
|
||||
|
||||
if(DEBUG) {
|
||||
std::cout << "=== IR After Reg2Mem Optimizations ===\n";
|
||||
|
||||
Reference in New Issue
Block a user