[all-commits] [llvm/llvm-project] ddf186: BPF: add AdjustOpt IR pass to generate verifier fr...

yonghong-song via All-commits all-commits at lists.llvm.org
Wed Oct 7 08:50:40 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: ddf1864ace484035e3cde5e83b3a31ac81e059c6
      https://github.com/llvm/llvm-project/commit/ddf1864ace484035e3cde5e83b3a31ac81e059c6
  Author: Yonghong Song <yhs at fb.com>
  Date:   2020-10-07 (Wed, 07 Oct 2020)

  Changed paths:
    M llvm/lib/Target/BPF/BPF.h
    A llvm/lib/Target/BPF/BPFAdjustOpt.cpp
    M llvm/lib/Target/BPF/BPFTargetMachine.cpp
    M llvm/lib/Target/BPF/CMakeLists.txt
    A llvm/test/CodeGen/BPF/adjust-opt-icmp1.ll
    A llvm/test/CodeGen/BPF/adjust-opt-icmp2.ll
    A llvm/test/CodeGen/BPF/adjust-opt-speculative1.ll
    A llvm/test/CodeGen/BPF/adjust-opt-speculative2.ll

  Log Message:
  -----------
  BPF: add AdjustOpt IR pass to generate verifier friendly codes

Add an IR phase right before main module optimization.
This is to modify IR to restrict certain downward optimizations
in order to generate verifier friendly code.
  > prevent certain instcombine optimizations, handling both
    in-block/cross-block instcombines.
  > avoid speculative code motion if the variable used in
    condition is also used in the later blocks.

Internally, a bpf IR builtin
  result = __builtin_bpf_passthrough(seq_num, result)
is used to enforce ordering. This builtin is only used
during target independent IR optimizations and it will
be removed at the beginning of target dependent IR
optimizations.

For example, removing the following workaround,
  --- a/tools/testing/selftests/bpf/progs/test_sysctl_loop1.c
  +++ b/tools/testing/selftests/bpf/progs/test_sysctl_loop1.c
  @@ -47,7 +47,7 @@ int sysctl_tcp_mem(struct bpf_sysctl *ctx)
          /* a workaround to prevent compiler from generating
           * codes verifier cannot handle yet.
           */
  -       volatile int ret;
  +       int ret;
this patch is able to generate code which passed the verifier.

To disable optimization, users need to use "opt" command like below:
  clang -target bpf -O2 -S -emit-llvm -Xclang -disable-llvm-passes test.c
  // disable icmp serialization
  opt -O2 -bpf-disable-serialize-icmp test.ll | llvm-dis > t.ll
  // disable avoid-speculation
  opt -O2 -bpf-disable-avoid-speculation test.ll | llvm-dis > t.ll
  llc t.ll

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




More information about the All-commits mailing list