[all-commits] [llvm/llvm-project] 29b36a: [BPF] Emit ABI-accurate BTF prototypes for DW_CC_n...

yonghong-song via All-commits all-commits at lists.llvm.org
Mon Jun 8 21:08:43 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 29b36a16f111e5a57264c5706b254c82ff0a24bc
      https://github.com/llvm/llvm-project/commit/29b36a16f111e5a57264c5706b254c82ff0a24bc
  Author: yonghong-song <yhs at fb.com>
  Date:   2026-06-08 (Mon, 08 Jun 2026)

  Changed paths:
    M llvm/lib/Target/BPF/BTFDebug.cpp
    M llvm/lib/Target/BPF/BTFDebug.h
    A llvm/test/CodeGen/BPF/BTF/func-nocall-all-dead.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-bool-arg.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-const-arg.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-const-no-shift.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-dead-arg.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-dead-type-mismatch.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-decl-tag.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-mixed-types.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-multi-dead.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-no-dead-arg.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-stack-arg-i64.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-stack-arg.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-stack-homed-arg.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-undef-dead-arg.ll
    A llvm/test/CodeGen/BPF/BTF/func-nocall-void-return.ll

  Log Message:
  -----------
  [BPF] Emit ABI-accurate BTF prototypes for DW_CC_nocall (#198426)

DW_CC_nocall subprograms can end up with an optimized IR signature that no
longer matches the original source-level DISubroutineType. Dead argument
elimination may drop source parameters, and the return value may be
removed entirely, while the debug type still describes the original
prototype. In that case BTFDebug emits a FUNC_PROTO that no longer
matches the real BPF ABI.

Teach BTFDebug to derive a filtered FUNC_PROTO for nocall functions.

Detecting surviving arguments (collectNocallEntryArgRegs):

Scan all DBG_VALUE instructions in the entry block while tracking which
registers have been redefined by non-debug instructions:

- A DBG_VALUE whose register has not been redefined records a
  register-passed argument (R1-R5 at function entry).
- A DBG_VALUE whose register was most recently loaded via LDD $r11,
  offset records a stack-passed argument (beyond the first five).
  LowerFormalArguments always places stack argument loads in the entry
  block, so scanning MF.front() is sufficient.
- Indirect DBG_VALUEs (describing memory locations, e.g. spills to
  [$r10 + offset]) are skipped -- the register is a base address,
  not the argument value.
- DBG_VALUEs with immediate operands (constant-propagated args) are
  skipped because MO.isReg() returns false.

Emitting a filtered prototype:

A filtered prototype (true ABI signature) is emitted when all of the
following hold:
  - The number of surviving source arguments equals the number of
    optimized IR arguments (no merging or splitting).
  - Every surviving source argument matches the corresponding IR type
    (pointer, same-width integer/boolean/float, or same-width enum).
  - For up to the first std::size(CC_BPF64_ArgRegs) surviving
    arguments, entry-block DBG_VALUEs assign BPF registers in order
    R1..R5.

The original source prototype is used as fallback when:
  - The surviving source arg count differs from the IR arg count.
  - Any surviving source type does not match its IR type (e.g. structs).
  - The register assignment does not follow R1..R5 order.

Independently, if the IR return type is void but the debug info declares a
non-void return, the emitted BTF return type becomes void. This applies
regardless of whether the parameter list is filtered.

When using the filtered prototype, decl_tag component indices are
remapped to the filtered parameter list.

Add coverage for dead register and stack args, all-dead args, unchanged
signatures, const/bool/mixed types, type mismatches, decl_tags, poisoned
DBG_VALUE inputs, and voided returns.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list