[all-commits] [llvm/llvm-project] 6b01b4: [BPF] preserve debuginfo types for builtin __built...

yonghong-song via All-commits all-commits at lists.llvm.org
Fri May 15 08:13:24 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 6b01b465388b204d543da3cf49efd6080db094a9
      https://github.com/llvm/llvm-project/commit/6b01b465388b204d543da3cf49efd6080db094a9
  Author: Yonghong Song <yhs at fb.com>
  Date:   2020-05-15 (Fri, 15 May 2020)

  Changed paths:
    M llvm/lib/Target/BPF/BPF.h
    M llvm/lib/Target/BPF/BPFCORE.h
    M llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
    A llvm/lib/Target/BPF/BPFPreserveDIType.cpp
    M llvm/lib/Target/BPF/BPFTargetMachine.cpp
    M llvm/lib/Target/BPF/BTFDebug.cpp
    M llvm/lib/Target/BPF/BTFDebug.h
    M llvm/lib/Target/BPF/CMakeLists.txt
    A llvm/test/CodeGen/BPF/BTF/builtin-btf-type-id.ll

  Log Message:
  -----------
  [BPF] preserve debuginfo types for builtin __builtin__btf_type_id()

The builtin function
  u32 btf_type_id = __builtin_btf_type_id(param, 0)
can help preserve type info for the following use case:
  extern void foo(..., void *data, int size);
  int test(...) {
    struct t { int a; int b; int c; } d;
    d.a = ...; d.b = ...; d.c = ...;
    foo(..., &d, sizeof(d));
  }

The function "foo" in the above only see raw data and does not
know what type of the data is. In certain cases, e.g., logging,
the additional type information will help pretty print.

This patch handles the builtin in BPF backend. It includes
an IR pass to translate the IR intrinsic to a load of
a global variable which carries the metadata, and an MI
pass to remove the intermediate load of the global variable.
Finally, in AsmPrinter pass, proper instruction are generated.

In the above example, the second argument for __builtin_btf_type_id()
is 0, which means a relocation for local adjustment,
i.e., w.r.t. bpf program BTF change,  will be generated.
The value 1 for the second argument means
a relocation for remote adjustment, e.g., against vmlinux.

Differential Revision: https://reviews.llvm.org/D74572




More information about the All-commits mailing list