diff --git a/src/RISCv64Backend.cpp b/src/RISCv64Backend.cpp index 82ac0f4..5d02946 100644 --- a/src/RISCv64Backend.cpp +++ b/src/RISCv64Backend.cpp @@ -1121,6 +1121,35 @@ std::map> RISCv64CodeGen::build_interference_ } } } + // --- 新增修复逻辑:处理指令内部操作数之间的干扰 --- + // 对于 store 指令,要存储的值和目标地址指针是同时活跃的,必须互相干扰。 + if (auto store = dynamic_cast(inst)) { + Value* val_operand = store->getValue(); + Value* ptr_operand = store->getPointer(); + + if (value_vreg_map.count(val_operand) && value_vreg_map.count(ptr_operand)) { + const std::string& val_vreg = value_vreg_map.at(val_operand); + const std::string& ptr_vreg = value_vreg_map.at(ptr_operand); + if (val_vreg != ptr_vreg) { + graph[val_vreg].insert(ptr_vreg); + graph[ptr_vreg].insert(val_vreg); + } + } + } + // 可选:为其他有两个或以上源操作数的指令(如 add)添加类似逻辑, + // 确保它们的操作数虚拟寄存器互相干扰。 + else if (auto bin = dynamic_cast(inst)) { + Value* lhs_operand = bin->getLhs(); + Value* rhs_operand = bin->getRhs(); + if (value_vreg_map.count(lhs_operand) && value_vreg_map.count(rhs_operand)) { + const std::string& lhs_vreg = value_vreg_map.at(lhs_operand); + const std::string& rhs_vreg = value_vreg_map.at(rhs_operand); + if (lhs_vreg != rhs_vreg) { + graph[lhs_vreg].insert(rhs_vreg); + graph[rhs_vreg].insert(rhs_vreg); + } + } + } } return graph; }