[llvm] [BPF] Emit ABI-accurate BTF prototypes for DW_CC_nocall (PR #198426)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 4 20:01:01 PDT 2026
================
@@ -1344,12 +1577,55 @@ void BTFDebug::beginFunctionImpl(const MachineFunction *MF) {
}
// Construct subprogram func proto type.
- uint32_t ProtoTypeId;
- visitSubroutineType(SP->getType(), true, FuncArgNames, ProtoTypeId);
-
- // Construct subprogram func type
+ uint32_t ProtoTypeId, FuncTypeId;
uint8_t Scope = SP->isLocalToUnit() ? BTF::FUNC_STATIC : BTF::FUNC_GLOBAL;
- uint32_t FuncTypeId = processDISubprogram(SP, ProtoTypeId, Scope);
+ bool IsNocall = SP->getType()->getCC() == dwarf::DW_CC_nocall;
+ bool UseFilteredParams = false;
+ bool VoidReturn = MF->getFunction().getReturnType()->isVoidTy();
+
+ if (IsNocall) {
+ // For DW_CC_nocall functions, try to build a FUNC_PROTO reflecting
+ // the true ABI: only parameters that survived optimization and whose
+ // first 5 arguments map to the correct BPF registers (R1-R5).
+ const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();
+ DITypeArray Elements = SP->getType()->getTypeArray();
+
+ SmallDenseMap<uint32_t, Register> EntryRegMap =
+ collectNocallEntryArgRegs(*MF);
+
+ SmallVector<uint32_t, 8> SortedAlive;
+ for (const auto &[ArgNo, Reg] : EntryRegMap)
+ SortedAlive.push_back(ArgNo);
+ llvm::sort(SortedAlive);
+
+ UseFilteredParams = canUseNocallOptimizedSignature(
+ *MF, Elements, SortedAlive, EntryRegMap, *TRI);
----------------
yonghong-song wrote:
@eddyz87 Just pushed commit 4 to simplify the code as mentioned in the above.
https://github.com/llvm/llvm-project/pull/198426
More information about the llvm-commits
mailing list