[PATCH] D85174: BPF: simplify IR generation for __builtin_btf_type_id()

Yonghong Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 3 17:17:26 PDT 2020


yonghong-song created this revision.
yonghong-song added reviewers: ast, anakryiko.
yonghong-song added a project: clang.
Herald added subscribers: llvm-commits, cfe-commits, JDevlieghere, hiraditya.
Herald added a project: LLVM.
yonghong-song requested review of this revision.

This patch simplified IR generation for __builtin_btf_type_id().
For __builtin_btf_type_id(obj, flag), previously IR builtin
looks like

  if (obj is a lvalue)
    llvm.bpf.btf.type.id(obj.ptr, 1, flag)  !type
  else
    llvm.bpf.btf.type.id(obj, 0, flag)  !type

The purpose of the 2nd argument is to differentiate

  __builtin_btf_type_id(obj, flag) where obj is a lvalue

vs.

  __builtin_btf_type_id(obj.ptr, flag)

Note that obj or obj.ptr is never used by the backend
and the `obj` argument is only used to derive the type.
This code sequence is subject to potential llvm CSE when

- obj is the same .e.g., nullptr
- flag is the same
- metadata type is different, e.g., typedef of struct "s" and strust "s".

In the above, we don't want CSE since their metadata is different.

This patch change IR builtin to

  llvm.bpf.btf.type.id(seq_num, flag)  !type

and seq_num is always increasing. This will prevent potential
llvm CSE.

Also report an error if the type name is empty for 
remote relocation since remote relocation needs non-empty
type name to do relocation against vmlinux.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85174

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtin-bpf-btf-type-id.c
  llvm/include/llvm/IR/IntrinsicsBPF.td
  llvm/lib/Target/BPF/BPFPreserveDIType.cpp
  llvm/test/CodeGen/BPF/BTF/builtin-btf-type-id.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85174.282773.patch
Type: text/x-patch
Size: 17145 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200804/b24ad8f0/attachment-0001.bin>


More information about the cfe-commits mailing list