[all-commits] [llvm/llvm-project] 64fa8c: [CSSPGO] Pseudo probe instrumentation pass

Hongtao Yu via All-commits all-commits at lists.llvm.org
Mon Nov 30 10:17:20 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 64fa8cce225f7d8bd499e3a99caa850b764ff109
      https://github.com/llvm/llvm-project/commit/64fa8cce225f7d8bd499e3a99caa850b764ff109
  Author: Hongtao Yu <hoy at fb.com>
  Date:   2020-11-30 (Mon, 30 Nov 2020)

  Changed paths:
    A llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
    M llvm/lib/Passes/PassBuilder.cpp
    M llvm/lib/Passes/PassRegistry.def
    M llvm/lib/Transforms/IPO/CMakeLists.txt
    A llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
    A llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll

  Log Message:
  -----------
  [CSSPGO] Pseudo probe instrumentation pass

This change introduces a pseudo probe instrumentation pass for block instrumentation. Please refer to https://reviews.llvm.org/D86193 for the whole story.

Given the following LLVM IR:

```
define internal void @foo2(i32 %x, void (i32)* %f) !dbg !4 {
bb0:
  %cmp = icmp eq i32 %x, 0
   br i1 %cmp, label %bb1, label %bb2
bb1:
   br label %bb3
bb2:
   br label %bb3
bb3:
   ret void
}
```

The instrumented IR will look like below. Note that each llvm.pseudoprobe intrinsic call represents a pseudo probe at a block, of which the first parameter is the GUID of the probe’s owner function and the second parameter is the probe’s ID.

```
define internal void @foo2(i32 %x, void (i32)* %f) !dbg !4 {
bb0:
   %cmp = icmp eq i32 %x, 0
   call void @llvm.pseudoprobe(i64 837061429793323041, i64 1)
   br i1 %cmp, label %bb1, label %bb2
bb1:
   call void @llvm.pseudoprobe(i64 837061429793323041, i64 2)
   br label %bb3
bb2:
   call void @llvm.pseudoprobe(i64 837061429793323041, i64 3)
   br label %bb3
bb3:
   call void @llvm.pseudoprobe(i64 837061429793323041, i64 4)
   ret void
}
```

Reviewed By: wmi

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


  Commit: c083fededfa63df6e1a560334bdb78797da9ee57
      https://github.com/llvm/llvm-project/commit/c083fededfa63df6e1a560334bdb78797da9ee57
  Author: Hongtao Yu <hoy at fb.com>
  Date:   2020-11-30 (Mon, 30 Nov 2020)

  Changed paths:
    M clang/include/clang/Basic/CodeGenOptions.def
    M clang/include/clang/Driver/Options.td
    M clang/lib/CodeGen/BackendUtil.cpp
    M clang/lib/Driver/ToolChains/Clang.cpp
    M clang/lib/Frontend/CompilerInvocation.cpp
    A clang/test/CodeGen/pseudo-probe-emit.c
    M llvm/include/llvm/Passes/PassBuilder.h
    M llvm/lib/Passes/PassBuilder.cpp

  Log Message:
  -----------
  [CSSPGO] A Clang switch -fpseudo-probe-for-profiling for pseudo-probe instrumentation.

This change introduces a new clang switch `-fpseudo-probe-for-profiling` to enable AutoFDO with pseudo instrumentation. Please refer to https://reviews.llvm.org/D86193 for the whole story.

One implication from pseudo-probe instrumentation is that the profile is now sensitive to CFG changes. We perform the pseudo instrumentation very early in the pre-LTO pipeline, before any CFG transformation. This ensures that the CFG instrumented and annotated is stable and optimization-resilient.

The early instrumentation also allows the inliner to duplicate probes for inlined instances. When a probe along with the other instructions of a callee function are inlined into its caller function, the GUID of the callee function goes with the probe. This allows samples collected on inlined probes to be reported for the original callee function.

Reviewed By: wmi

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


Compare: https://github.com/llvm/llvm-project/compare/7c4555f60d96...c083fededfa6


More information about the All-commits mailing list