[PATCH] D74668: [Clang][BPF] implement __builtin_btf_type_id() builtin function

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 15 08:42:55 PST 2020


yonghong-song created this revision.
yonghong-song added reviewers: ast, anakryiko.
yonghong-song added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.
yonghong-song added a comment.

The corresponding LLVM side of change is https://reviews.llvm.org/D74572


Such a builtin function is mostly useful to preserve btf type id
for non-global data. For example,

  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 implemented a BPF specific builtin

  u32 btf_type_id = __builtin_btf_type_id(param)

which will return a btf type id for the "param".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74668

Files:
  clang/include/clang/Basic/BuiltinsBPF.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin-bpf-btf-type-id.c
  clang/test/Sema/builtin-bpf-btf-type-id.c
  llvm/include/llvm/IR/IntrinsicsBPF.td

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74668.244828.patch
Type: text/x-patch
Size: 9193 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200215/0535ba0e/attachment-0001.bin>


More information about the llvm-commits mailing list