[backend]添加了一个Pass,将调用者、被调用者寄存器实现转移到其中

This commit is contained in:
Lixuanwang
2025-07-26 18:38:04 +08:00
parent 8ae7478ef3
commit 540742be0c
7 changed files with 142 additions and 57 deletions

View File

@@ -36,7 +36,6 @@ void RISCv64RegAlloc::handleCallingConvention() {
// 获取函数的Argument对象列表
if (F) {
auto& args = F->getArguments();
// RISC-V RV64G调用约定前8个整型/指针参数通过 a0-a7 传递
int arg_idx = 0;
// 遍历 AllocaInst* 列表
@@ -494,10 +493,6 @@ void RISCv64RegAlloc::rewriteFunction() {
if (color_map.count(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);
@@ -512,14 +507,16 @@ void RISCv64RegAlloc::rewriteFunction() {
// 对这个基址寄存器,执行与情况一完全相同的替换逻辑
if(base_reg_op->isVirtual()){
unsigned vreg = base_reg_op->getVRegNum();
if(color_map.count(vreg)) {
// 如果基址vreg被成功着色替换
base_reg_op->setPReg(color_map.at(vreg));
} else if (spilled_vregs.count(vreg)) {
// 如果基址vreg被溢出替换为t6
base_reg_op->setPReg(PhysicalReg::T6);
}
unsigned vreg = base_reg_op->getVRegNum();
if(color_map.count(vreg)) {
// 如果基址vreg被成功着色替换
PhysicalReg preg = color_map.at(vreg);
base_reg_op->setPReg(preg);
} else if (spilled_vregs.count(vreg)) {
// 如果基址vreg被溢出替换为t6
base_reg_op->setPReg(PhysicalReg::T6);
}
}
}
}