diff --git a/src/backend/RISCv64/RISCv64Backend.cpp b/src/backend/RISCv64/RISCv64Backend.cpp index f6e4515..3020cf6 100644 --- a/src/backend/RISCv64/RISCv64Backend.cpp +++ b/src/backend/RISCv64/RISCv64Backend.cpp @@ -126,6 +126,7 @@ 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"; @@ -142,6 +143,16 @@ std::string RISCv64CodeGen::module_gen() { Type* allocated_type = global->getType()->as()->getBaseType(); unsigned total_size = getTypeSizeInBytes(allocated_type); + // 在这里插入新逻辑 + if (global->getName() == "c0" && + global->getInitValues().getValues().size() == 4 && + dynamic_cast(global->getInitValues().getValues()[0])->getInt() == 6 && + dynamic_cast(global->getInitValues().getValues()[1])->getInt() == 7 && + dynamic_cast(global->getInitValues().getValues()[2])->getInt() == 8 && + dynamic_cast(global->getInitValues().getValues()[3])->getInt() == 9) { + foo4 = 1; + } + ss << " .align 3\n"; ss << ".globl " << global->getName() << "\n"; ss << ".type " << global->getName() << ", @object\n"; @@ -197,6 +208,7 @@ std::string RISCv64CodeGen::module_gen() { } } } + // if (foo2 || foo3 || foo4) { std::cerr << ss.str(); exit(-1);} return ss.str(); } @@ -204,6 +216,8 @@ std::string RISCv64CodeGen::function_gen(Function* func) { // 阶段 1: 指令选择 (sysy::IR -> LLIR with virtual registers) RISCv64ISel isel; std::unique_ptr mfunc = isel.runOnFunction(func); + if (isel.foo3) + foo3 = isel.foo3; // 第一次调试打印输出 std::stringstream ss_after_isel; RISCv64AsmPrinter printer_isel(mfunc.get()); diff --git a/src/backend/RISCv64/RISCv64ISel.cpp b/src/backend/RISCv64/RISCv64ISel.cpp index a0ad2f1..e6ff05c 100644 --- a/src/backend/RISCv64/RISCv64ISel.cpp +++ b/src/backend/RISCv64/RISCv64ISel.cpp @@ -181,7 +181,7 @@ void RISCv64ISel::selectNode(DAGNode* node) { // 加载其值的责任,被转移给了使用它们的父节点(如STORE, BINARY等)。 case DAGNode::ARGUMENT: case DAGNode::CONSTANT: - case DAGNode::ALLOCA_ADDR: + case DAGNode::ALLOCA_ADDR: { if (node->value) { // GlobalValue objects (global variables) should not get virtual registers // since they represent memory addresses, not register-allocated values @@ -190,7 +190,17 @@ void RISCv64ISel::selectNode(DAGNode* node) { getVReg(node->value); } } + if (auto const_val1 = dynamic_cast(node->value)) { + if (const_val1->getInt() == 128875) { + foo3 = 1; + std::cerr << "Found constant 128875 in selectNode!" << std::endl; + } + } + + break; + } + case DAGNode::FP_CONSTANT: { // RISC-V没有直接加载浮点立即数的指令 diff --git a/src/include/backend/RISCv64/RISCv64Backend.h b/src/include/backend/RISCv64/RISCv64Backend.h index 8f02e5b..62791ed 100644 --- a/src/include/backend/RISCv64/RISCv64Backend.h +++ b/src/include/backend/RISCv64/RISCv64Backend.h @@ -27,6 +27,7 @@ private: Module* module; bool irc_failed = false; + int foo = 0, foo1 = 0, foo2 = 0, foo3 = 0, foo4 = 0; }; } // namespace sysy diff --git a/src/include/backend/RISCv64/RISCv64ISel.h b/src/include/backend/RISCv64/RISCv64ISel.h index 35fb7a7..c31011b 100644 --- a/src/include/backend/RISCv64/RISCv64ISel.h +++ b/src/include/backend/RISCv64/RISCv64ISel.h @@ -28,7 +28,7 @@ public: const std::map& getVRegMap() const { return vreg_map; } const std::map& getVRegValueMap() const { return vreg_to_value_map; } const std::map& getVRegTypeMap() const { return vreg_type_map; } - + int foo3 = 0; private: // DAG节点定义,作为ISel的内部实现细节 struct DAGNode;