[all-commits] [llvm/llvm-project] 54d9f7: BPF: move AbstractMemberAccess and PreserveDIType ...

yonghong-song via All-commits all-commits at lists.llvm.org
Mon Sep 28 16:56:59 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 54d9f743c8b0f501288119123cf1828bf7ade69c
      https://github.com/llvm/llvm-project/commit/54d9f743c8b0f501288119123cf1828bf7ade69c
  Author: Yonghong Song <yhs at fb.com>
  Date:   2020-09-28 (Mon, 28 Sep 2020)

  Changed paths:
    M clang/test/CodeGen/bpf-attr-preserve-access-index-1.c
    M clang/test/CodeGen/bpf-attr-preserve-access-index-2.c
    M clang/test/CodeGen/bpf-attr-preserve-access-index-3.c
    M clang/test/CodeGen/bpf-attr-preserve-access-index-4.c
    M clang/test/CodeGen/bpf-attr-preserve-access-index-5.c
    M clang/test/CodeGen/bpf-attr-preserve-access-index-6.c
    M clang/test/CodeGen/bpf-attr-preserve-access-index-7.c
    M clang/test/CodeGen/bpf-attr-preserve-access-index-8.c
    M clang/test/CodeGen/bpf-preserve-access-index.c
    M clang/test/CodeGen/builtin-bpf-btf-type-id.c
    M clang/test/CodeGen/builtin-preserve-access-index-typedef.c
    M clang/test/CodeGen/builtins-bpf-preserve-field-info-1.c
    M clang/test/CodeGen/builtins-bpf-preserve-field-info-2.c
    M clang/test/CodeGen/builtins-bpf-preserve-field-info-3.c
    M clang/test/CodeGen/builtins-bpf-preserve-field-info-4.c
    M llvm/include/llvm/IR/IntrinsicsBPF.td
    M llvm/lib/Target/BPF/BPF.h
    M llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
    M llvm/lib/Target/BPF/BPFCORE.h
    A llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
    M llvm/lib/Target/BPF/BPFPreserveDIType.cpp
    M llvm/lib/Target/BPF/BPFTargetMachine.cpp
    M llvm/lib/Target/BPF/CMakeLists.txt
    M llvm/test/CodeGen/BPF/BTF/builtin-btf-type-id.ll
    M llvm/test/CodeGen/BPF/CORE/field-reloc-alu32.ll
    A llvm/test/CodeGen/BPF/CORE/field-reloc-bitfield-1-bpfeb.ll
    M llvm/test/CodeGen/BPF/CORE/field-reloc-bitfield-1.ll
    A llvm/test/CodeGen/BPF/CORE/field-reloc-bitfield-2-bpfeb.ll
    M llvm/test/CodeGen/BPF/CORE/field-reloc-bitfield-2.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-array-2.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-array.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-byte-size-1.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-byte-size-2.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-byte-size-3.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-byte-size-4.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-existence-1.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-existence-2.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-existence-3.ll
    A llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-lshift-1-bpfeb.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-lshift-1.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-lshift-2.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-rshift-1.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-rshift-2.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-rshift-3.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-signedness-1.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-signedness-2.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-fieldinfo-signedness-3.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-struct.ll
    R llvm/test/CodeGen/BPF/CORE/intrinsic-transforms.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-typeinfo-enum-value.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-typeinfo-type-exist.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-typeinfo-type-size-1.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-typeinfo-type-size-2.ll
    M llvm/test/CodeGen/BPF/CORE/intrinsic-union.ll
    M llvm/test/CodeGen/BPF/CORE/no-elf-ama-symbol.ll
    M llvm/test/CodeGen/BPF/CORE/no-narrow-load.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-access-str.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-basic.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-cast-array-1.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-cast-array-2.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-cast-struct-1.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-cast-struct-2.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-cast-struct-3.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-cast-union-1.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-cast-union-2.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-end-load.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-end-ret.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-fieldinfo-1.ll
    A llvm/test/CodeGen/BPF/CORE/offset-reloc-fieldinfo-2-bpfeb.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-fieldinfo-2.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-global-1.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-global-2.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-global-3.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-ignore.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-middle-chain.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-multi-array-1.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-multi-array-2.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-multilevel.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-pointer-1.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-pointer-2.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-struct-anonymous.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-struct-array.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-typedef-array.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-typedef-struct-2.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-typedef-struct.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-typedef-union-2.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-typedef-union.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-typedef.ll
    M llvm/test/CodeGen/BPF/CORE/offset-reloc-union.ll
    M llvm/test/CodeGen/BPF/CORE/store-addr.ll

  Log Message:
  -----------
  BPF: move AbstractMemberAccess and PreserveDIType passes to EP_EarlyAsPossible

Move abstractMemberAccess and PreserveDIType passes as early as
possible, right after clang code generation.

Currently, compiler may transform the above code
  p1 = llvm.bpf.builtin.preserve.struct.access(base, 0, 0);
  p2 = llvm.bpf.builtin.preserve.struct.access(p1, 1, 2);
  a = llvm.bpf.builtin.preserve_field_info(p2, EXIST);
  if (a) {
    p1 = llvm.bpf.builtin.preserve.struct.access(base, 0, 0);
    p2 = llvm.bpf.builtin.preserve.struct.access(p1, 1, 2);
    bpf_probe_read(buf, buf_size, p2);
  }
to
  p1 = llvm.bpf.builtin.preserve.struct.access(base, 0, 0);
  p2 = llvm.bpf.builtin.preserve.struct.access(p1, 1, 2);
  a = llvm.bpf.builtin.preserve_field_info(p2, EXIST);
  if (a) {
    bpf_probe_read(buf, buf_size, p2);
  }
and eventually assembly code looks like
  reloc_exist = 1;
  reloc_member_offset = 10; //calculate member offset from base
  p2 = base + reloc_member_offset;
  if (reloc_exist) {
    bpf_probe_read(bpf, buf_size, p2);
  }
if during libbpf relocation resolution, reloc_exist is actually
resolved to 0 (not exist), reloc_member_offset relocation cannot
be resolved and will be patched with illegal instruction.
This will cause verifier failure.

This patch attempts to address this issue by do chaining
analysis and replace chains with special globals right
after clang code gen. This will remove the cse possibility
described in the above. The IR typically looks like
  %6 = load @llvm.sk_buff:0:50$0:0:0:2:0
  %7 = bitcast %struct.sk_buff* %2 to i8*
  %8 = getelementptr i8, i8* %7, %6
for a particular address computation relocation.

But this transformation has another consequence, code sinking
may happen like below:
  PHI = <possibly different @preserve_*_access_globals>
  %7 = bitcast %struct.sk_buff* %2 to i8*
  %8 = getelementptr i8, i8* %7, %6

For such cases, we will not able to generate relocations since
multiple relocations are merged into one.

This patch introduced a passthrough builtin
to prevent such optimization. Looks like inline assembly has more
impact for optimizaiton, e.g., inlining. Using passthrough has
less impact on optimizations.

A new IR pass is introduced at the beginning of target-dependent
IR optimization, which does:
  - report fatal error if any reloc global in PHI nodes
  - remove all bpf passthrough builtin functions

Changes for existing CORE tests:
  - for clang tests, add "-Xclang -disable-llvm-passes" flags to
    avoid builtin->reloc_global transformation so the test is still
    able to check correctness for clang generated IR.
  - for llvm CodeGen/BPF tests, add "opt -O2 <ir_file> | llvm-dis" command
    before "llc" command since "opt" is needed to call newly-placed
    builtin->reloc_global transformation. Add target triple in the IR
    file since "opt" requires it.
  - Since target triple is added in IR file, if a test may produce
    different results for different endianness, two tests will be
    created, one for bpfeb and another for bpfel, e.g., some tests
    for relocation of lshift/rshift of bitfields.
  - field-reloc-bitfield-1.ll has different relocations compared to
    old codes. This is because for the structure in the test,
    new code returns struct layout alignment 4 while old code
    is 8. Align 8 is more precise and permits double load. With align 4,
    the new mechanism uses 4-byte load, so generating different
    relocations.
  - test intrinsic-transforms.ll is removed. This is used to test
    cse on intrinsics so we do not lose metadata. Now metadata is attached
    to global and not instruction, it won't get lost with cse.

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




More information about the All-commits mailing list