[backend]开始区分调用者保存寄存器与被调用者保存寄存器

This commit is contained in:
Lixuanwang
2025-07-26 12:39:17 +08:00
parent 5bfa6d72a2
commit e57ac7709d
2 changed files with 9 additions and 2 deletions

View File

@ -436,8 +436,12 @@ void RISCv64RegAlloc::rewriteFunction() {
if (reg_op->isVirtual()) {
unsigned vreg = reg_op->getVRegNum();
if (color_map.count(vreg)) {
// 如果vreg被成功着色替换为物理寄存器
reg_op->setPReg(color_map.at(vreg));
PhysicalReg preg = color_map.at(vreg);
reg_op->setPReg(preg);
// 检查这个物理寄存器是否是 s0-s11
if (preg >= PhysicalReg::S0 && preg <= PhysicalReg::S11) {
used_callee_saved_regs.insert(preg);
}
} else if (spilled_vregs.count(vreg)) {
// 如果vreg被溢出替换为专用的溢出物理寄存器t6
reg_op->setPReg(PhysicalReg::T6);

View File

@ -54,8 +54,11 @@ private:
// 这个map将在run()函数开始时被填充并在rewriteFunction()中使用。
std::map<unsigned, Value*> vreg_to_value_map;
std::set<PhysicalReg> used_callee_saved_regs;
// 用于计算类型大小的辅助函数
unsigned getTypeSizeInBytes(Type* type);
};
} // namespace sysy