[llvm] [BPF] Emit ABI-accurate BTF prototypes for DW_CC_nocall (PR #198426)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 22 15:15:10 PDT 2026
================
@@ -47,6 +51,149 @@ static const DIType *tryRemoveAtomicType(const DIType *Ty) {
return Ty;
}
+static const DIType *stripDITypeAttributes(const DIType *Ty) {
+ while (const auto *DTy = dyn_cast_or_null<DIDerivedType>(Ty)) {
+ switch (DTy->getTag()) {
+ case dwarf::DW_TAG_atomic_type:
+ case dwarf::DW_TAG_const_type:
+ case dwarf::DW_TAG_restrict_type:
+ case dwarf::DW_TAG_typedef:
+ case dwarf::DW_TAG_volatile_type:
+ Ty = DTy->getBaseType();
+ break;
+ default:
+ return Ty;
+ }
+ }
+ return Ty;
+}
+
+static bool sourceArgMatchesIRType(const DIType *SourceTy, Type *IRTy) {
+ SourceTy = stripDITypeAttributes(SourceTy);
+
+ // All pointers are opaque in LLVM IR, so any source-level pointer matches any
+ // IR pointer regardless of pointee type.
+ if (const auto *DTy = dyn_cast<DIDerivedType>(SourceTy))
+ return DTy->getTag() == dwarf::DW_TAG_pointer_type && IRTy->isPointerTy();
+
+ if (const auto *BTy = dyn_cast<DIBasicType>(SourceTy)) {
+ uint64_t SizeInBits = BTy->getSizeInBits();
+ if (BTy->getEncoding() == dwarf::DW_ATE_float)
+ return IRTy->isFloatingPointTy() &&
+ IRTy->getPrimitiveSizeInBits() == SizeInBits;
+ // _Bool is 8 bits in DWARF/source but lowered to i1 in LLVM IR.
+ if (BTy->getEncoding() == dwarf::DW_ATE_boolean && IRTy->isIntegerTy(1))
+ return true;
+ return IRTy->isIntegerTy(SizeInBits);
+ }
+
+ const auto *CTy = dyn_cast<DICompositeType>(SourceTy);
+ if (!CTy)
+ return false;
+
+ switch (CTy->getTag()) {
+ case dwarf::DW_TAG_enumeration_type:
+ return IRTy->isIntegerTy(CTy->getSizeInBits());
+ default:
+ return false;
+ }
+}
+
+/// Collect the physical register each source argument lives in by scanning the
+/// leading DBG_VALUE instructions in the entry block (stops at the first
+/// non-debug instruction).
+static DenseMap<uint32_t, Register>
+collectNocallEntryArgRegs(const MachineFunction &MF) {
+ DenseMap<uint32_t, Register> EntryRegMap;
----------------
eddyz87 wrote:
Nit: there is a `SmallDenseMap` to avoid heap allocations.
https://github.com/llvm/llvm-project/pull/198426
More information about the llvm-commits
mailing list