[midend]重构了src目录
This commit is contained in:
@@ -16,7 +16,6 @@ using namespace antlr4;
|
||||
#include "SysYIRCFGOpt.h" // 包含 CFG 优化
|
||||
#include "RISCv64Backend.h"
|
||||
#include "Pass.h" // 包含新的 Pass 框架
|
||||
#include "AddressCalculationExpansion.h"
|
||||
|
||||
using namespace sysy;
|
||||
|
||||
@@ -139,69 +138,6 @@ int main(int argc, char **argv) {
|
||||
// 好像都不用传递module和builder了,因为 PassManager 初始化了
|
||||
passManager.runOptimizationPipeline(moduleIR, builder, optLevel);
|
||||
|
||||
|
||||
|
||||
|
||||
AddressCalculationExpansion ace(moduleIR, builder);
|
||||
if (ace.run()) {
|
||||
if (DEBUG) cout << "AddressCalculationExpansion made changes.\n";
|
||||
// 如果 ACE 改变了IR,并且 DEBUG 模式开启,可以考虑打印IR
|
||||
if (DEBUG) {
|
||||
cout << "=== After AddressCalculationExpansion ===\n";
|
||||
SysYPrinter(moduleIR).printIR();
|
||||
}
|
||||
} else {
|
||||
if (DEBUG) cout << "AddressCalculationExpansion made no changes.\n";
|
||||
}
|
||||
|
||||
|
||||
// 根据优化级别,执行额外的优化 pass
|
||||
if (optLevel >= 1) {
|
||||
if (DEBUG) cout << "Applying additional -O" << optLevel << " optimizations...\n";
|
||||
// 放置 -O1 及其以上级别要启用的额外优化 pass
|
||||
// 例如:
|
||||
// MyNewOptimizationPass newOpt(moduleIR, builder);
|
||||
// newOpt.run();
|
||||
|
||||
// 占位符注释,替换为你的具体优化 pass
|
||||
// cout << "--- Additional Pass: MyCustomOpt1 ---" << endl;
|
||||
// MyCustomOpt1 opt1_pass(moduleIR, builder);
|
||||
// opt1_pass.run();
|
||||
|
||||
// cout << "--- Additional Pass: MyCustomOpt2 ---" << endl;
|
||||
// MyCustomOpt2 opt2_pass(moduleIR, builder, &cfa); // 假设需要CFA
|
||||
// opt2_pass.run();
|
||||
// ... 更多 -O1 特有的优化
|
||||
// DeadCodeElimination dce(moduleIR, &cfa, &ava);
|
||||
// dce.runDCEPipeline();
|
||||
// if (DEBUG) {
|
||||
// cout << "=== After 1st DCE (Default) ===\n";
|
||||
// SysYPrinter(moduleIR).printIR();
|
||||
// }
|
||||
|
||||
// Mem2Reg mem2reg(moduleIR, builder, &cfa, &ava);
|
||||
// mem2reg.mem2regPipeline();
|
||||
// if (DEBUG) {
|
||||
// cout << "=== After Mem2Reg (Default) ===\n";
|
||||
// SysYPrinter(moduleIR).printIR();
|
||||
// }
|
||||
|
||||
// Reg2Mem reg2mem(moduleIR, builder);
|
||||
// reg2mem.DeletePhiInst();
|
||||
// if (DEBUG) {
|
||||
// cout << "=== After Reg2Mem (Default) ===\n";
|
||||
// SysYPrinter(moduleIR).printIR();
|
||||
// }
|
||||
|
||||
// dce.runDCEPipeline(); // 第二次 DCE (默认)
|
||||
// if (DEBUG) {
|
||||
// cout << "=== After 2nd DCE (Default) ===\n";
|
||||
// SysYPrinter(moduleIR).printIR();
|
||||
// }
|
||||
} else {
|
||||
if (DEBUG) cout << "No additional middle-end optimizations applied for -O" << optLevel << ".\n";
|
||||
}
|
||||
|
||||
// 5. 根据 argStopAfter 决定后续操作
|
||||
// a) 如果指定停止在 IR 阶段,则打印最终 IR 并退出
|
||||
if (argStopAfter == "ir" || argStopAfter == "ird") {
|
||||
@@ -218,6 +154,7 @@ int main(int argc, char **argv) {
|
||||
DEBUG = 1;
|
||||
DEEPDEBUG = 1;
|
||||
}
|
||||
|
||||
sysy::RISCv64CodeGen codegen(moduleIR); // 传入优化后的 moduleIR
|
||||
string asmCode = codegen.code_gen();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user