[backend-optpatch]对RISCv64ISel.cpp优化判断提供补丁过滤
This commit is contained in:
@ -103,7 +103,29 @@ void RISCv64ISel::select() {
|
||||
}
|
||||
}
|
||||
|
||||
if (optLevel > 0) {
|
||||
// 仅当函数满足特定条件时,才需要保存参数寄存器,应用更精细的过滤规则
|
||||
// 1. 函数包含call指令 (非叶子函数): 参数寄存器(a0-a7)是调用者保存的,
|
||||
// call指令可能会覆盖这些寄存器,因此必须保存。
|
||||
// 2. 函数包含alloca指令 (需要栈分配)。
|
||||
// 3. 函数的指令数量超过一个阈值(如20),意味着它是一个复杂的叶子函数,
|
||||
// 为安全起见,保存其参数。
|
||||
// 简单的叶子函数 (如min) 则可以跳过这个步骤进行优化。
|
||||
auto shouldSaveArgs = [](Function* func) {
|
||||
if (!func) return false;
|
||||
int instruction_count = 0;
|
||||
for (const auto& bb : func->getBasicBlocks()) {
|
||||
for (const auto& inst : bb->getInstructions()) {
|
||||
if (dynamic_cast<CallInst*>(inst.get()) || dynamic_cast<AllocaInst*>(inst.get())) {
|
||||
return true; // 发现call或alloca,立即返回true
|
||||
}
|
||||
instruction_count++;
|
||||
}
|
||||
}
|
||||
// 如果没有call或alloca,则检查指令数量
|
||||
return instruction_count > 45;
|
||||
};
|
||||
|
||||
if (optLevel > 0 && shouldSaveArgs(F)) {
|
||||
if (F && !F->getBasicBlocks().empty()) {
|
||||
// 定位到第一个MachineBasicBlock,也就是函数入口
|
||||
BasicBlock* first_ir_block = F->getBasicBlocks_NoRange().front().get();
|
||||
|
||||
Reference in New Issue
Block a user