[midend][backend]同步后端逻辑,修复编译错误
This commit is contained in:
@@ -47,45 +47,45 @@ void RISCv64AsmPrinter::printPrologue() {
|
||||
*OS << " addi s0, sp, " << aligned_stack_size << "\n";
|
||||
}
|
||||
|
||||
// 为函数参数分配寄存器
|
||||
Function* F = MFunc->getFunc();
|
||||
if (F && F->getEntryBlock()) {
|
||||
int arg_idx = 0;
|
||||
RISCv64ISel* isel = MFunc->getISel();
|
||||
// // 为函数参数分配寄存器
|
||||
// Function* F = MFunc->getFunc();
|
||||
// if (F && F->getEntryBlock()) {
|
||||
// int arg_idx = 0;
|
||||
// RISCv64ISel* isel = MFunc->getISel();
|
||||
|
||||
// 获取函数所有参数的类型列表
|
||||
auto param_types = F->getParamTypes();
|
||||
// // 获取函数所有参数的类型列表
|
||||
// auto param_types = F->getParamTypes();
|
||||
|
||||
for (AllocaInst* alloca_for_param : F->getEntryBlock()->getArguments()) {
|
||||
if (arg_idx >= 8) break;
|
||||
// for (AllocaInst* alloca_for_param : F->getEntryBlock()->getArguments()) {
|
||||
// if (arg_idx >= 8) break;
|
||||
|
||||
unsigned vreg = isel->getVReg(alloca_for_param);
|
||||
if (frame_info.alloca_offsets.count(vreg)) {
|
||||
int offset = frame_info.alloca_offsets.at(vreg);
|
||||
auto arg_reg = static_cast<PhysicalReg>(static_cast<int>(PhysicalReg::A0) + arg_idx);
|
||||
// unsigned vreg = isel->getVReg(alloca_for_param);
|
||||
// if (frame_info.alloca_offsets.count(vreg)) {
|
||||
// int offset = frame_info.alloca_offsets.at(vreg);
|
||||
// auto arg_reg = static_cast<PhysicalReg>(static_cast<int>(PhysicalReg::A0) + arg_idx);
|
||||
|
||||
// 1. 获取当前参数的真实类型
|
||||
// 注意:F->getParamTypes() 返回的是一个 range-based view,需要转换为vector或直接使用
|
||||
Type* current_param_type = nullptr;
|
||||
int temp_idx = 0;
|
||||
for(auto p_type : param_types) {
|
||||
if (temp_idx == arg_idx) {
|
||||
current_param_type = p_type;
|
||||
break;
|
||||
}
|
||||
temp_idx++;
|
||||
}
|
||||
assert(current_param_type && "Could not find parameter type.");
|
||||
// // 1. 获取当前参数的真实类型
|
||||
// // 注意:F->getParamTypes() 返回的是一个 range-based view,需要转换为vector或直接使用
|
||||
// Type* current_param_type = nullptr;
|
||||
// int temp_idx = 0;
|
||||
// for(auto p_type : param_types) {
|
||||
// if (temp_idx == arg_idx) {
|
||||
// current_param_type = p_type;
|
||||
// break;
|
||||
// }
|
||||
// temp_idx++;
|
||||
// }
|
||||
// assert(current_param_type && "Could not find parameter type.");
|
||||
|
||||
// 2. 根据类型决定使用 "sw" 还是 "sd"
|
||||
const char* store_op = current_param_type->isPointer() ? "sd" : "sw";
|
||||
// // 2. 根据类型决定使用 "sw" 还是 "sd"
|
||||
// const char* store_op = current_param_type->isPointer() ? "sd" : "sw";
|
||||
|
||||
// 3. 打印正确的存储指令
|
||||
*OS << " " << store_op << " " << regToString(arg_reg) << ", " << offset << "(s0)\n";
|
||||
}
|
||||
arg_idx++;
|
||||
}
|
||||
}
|
||||
// // 3. 打印正确的存储指令
|
||||
// *OS << " " << store_op << " " << regToString(arg_reg) << ", " << offset << "(s0)\n";
|
||||
// }
|
||||
// arg_idx++;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void RISCv64AsmPrinter::printEpilogue() {
|
||||
|
||||
Reference in New Issue
Block a user