[deploy]最终提交版本

This commit is contained in:
Lixuanwang
2025-08-05 20:57:23 +08:00
parent 926e765451
commit db00d02494
4 changed files with 3 additions and 667 deletions

View File

@@ -122,7 +122,6 @@ std::string RISCv64CodeGen::module_gen() {
ss << " .align 3\n";
ss << ".globl " << global->getName() << "\n";
if (global->getName() == "a0" && total_size == 16384) foo2 = 1;
ss << ".type " << global->getName() << ", @object\n";
ss << ".size " << global->getName() << ", " << total_size << "\n";
ss << global->getName() << ":\n";
@@ -138,16 +137,6 @@ std::string RISCv64CodeGen::module_gen() {
for (GlobalValue* global : data_globals) {
Type* allocated_type = global->getType()->as<PointerType>()->getBaseType();
unsigned total_size = getTypeSizeInBytes(allocated_type);
// 在这里插入新逻辑
if (global->getName() == "c0" &&
global->getInitValues().getValues().size() == 4 &&
dynamic_cast<ConstantValue*>(global->getInitValues().getValues()[0])->getInt() == 6 &&
dynamic_cast<ConstantValue*>(global->getInitValues().getValues()[1])->getInt() == 7 &&
dynamic_cast<ConstantValue*>(global->getInitValues().getValues()[2])->getInt() == 8 &&
dynamic_cast<ConstantValue*>(global->getInitValues().getValues()[3])->getInt() == 9) {
foo4 = 1;
}
ss << " .align 3\n";
ss << ".globl " << global->getName() << "\n";
@@ -199,13 +188,11 @@ std::string RISCv64CodeGen::module_gen() {
ss << ".text\n";
for (const auto& func_pair : module->getFunctions()) {
if (func_pair.second.get() && !func_pair.second->getBasicBlocks().empty()) {
if (func_pair.second.get()->getName() == "param16") {foo=1; return std::string(AC::riscv_assembly_text);};
ss << function_gen(func_pair.second.get());
if (DEBUG) std::cerr << "Function: " << func_pair.first << " generated.\n";
}
}
}
// if (foo2 || foo3 || foo4) { std::cerr << ss.str(); exit(-1);}
return ss.str();
}
@@ -215,8 +202,6 @@ std::string RISCv64CodeGen::function_gen(Function* func) {
// 阶段 1: 指令选择 (sysy::IR -> LLIR with virtual registers)
RISCv64ISel isel;
std::unique_ptr<MachineFunction> mfunc = isel.runOnFunction(func);
if (isel.foo3)
foo3 = isel.foo3;
// 第一次调试打印输出
std::stringstream ss_after_isel;
RISCv64AsmPrinter printer_isel(mfunc.get());
@@ -252,23 +237,19 @@ std::string RISCv64CodeGen::function_gen(Function* func) {
// 阶段 3: 物理寄存器分配 (Register Allocation)
// 首先尝试图着色分配器
if (foo2 || foo3 || foo4) {
std::cerr << "Info: Skipping Graph Coloring due to fool reasons .\n";
foo1 = 1; // 强制使用线性扫描分配器
}
if (DEBUG) std::cerr << "Attempting Register Allocation with Graph Coloring...\n";
if (!foo1) {
if (!gc_failed) {
RISCv64RegAlloc gc_alloc(mfunc.get());
bool success_gc = gc_alloc.run();
if (!success_gc) {
gc_failed = 1; // 后续不再尝试图着色分配器
std::cerr << "Warning: Graph coloring register allocation failed function '"
<< func->getName()
<< "'. Switching to Linear Scan allocator."
<< std::endl;
foo1 = 1;
RISCv64ISel isel_gc_fallback;
mfunc = isel_gc_fallback.runOnFunction(func);
EliminateFrameIndicesPass efi_pass_gc_fallback;