[all-commits] [llvm/llvm-project] 5740bb: [CSSPGO] Use nested context-sensitive profile.

Hongtao Yu via All-commits all-commits at lists.llvm.org
Tue Dec 14 14:41:20 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5740bb801a14efd5239a0e521395c09e71e61f5c
      https://github.com/llvm/llvm-project/commit/5740bb801a14efd5239a0e521395c09e71e61f5c
  Author: Hongtao Yu <hoy at fb.com>
  Date:   2021-12-14 (Tue, 14 Dec 2021)

  Changed paths:
    M llvm/include/llvm/ProfileData/SampleProf.h
    M llvm/include/llvm/ProfileData/SampleProfReader.h
    M llvm/include/llvm/ProfileData/SampleProfWriter.h
    M llvm/include/llvm/Transforms/IPO/ProfiledCallGraph.h
    M llvm/include/llvm/Transforms/IPO/SampleContextTracker.h
    M llvm/lib/ProfileData/ProfileSummaryBuilder.cpp
    M llvm/lib/ProfileData/SampleProf.cpp
    M llvm/lib/ProfileData/SampleProfReader.cpp
    M llvm/lib/ProfileData/SampleProfWriter.cpp
    M llvm/lib/Transforms/IPO/SampleContextTracker.cpp
    M llvm/lib/Transforms/IPO/SampleProfile.cpp
    A llvm/test/Transforms/SampleProfile/Inputs/inline-priority.prof
    M llvm/test/Transforms/SampleProfile/csspgo-inline.ll
    M llvm/test/Transforms/SampleProfile/csspgo-use-preinliner.ll
    M llvm/test/Transforms/SampleProfile/inline-mergeprof.ll
    M llvm/test/Transforms/SampleProfile/inline.ll
    A llvm/test/tools/llvm-profdata/Inputs/cs-sample-preinline-probe.proftext
    A llvm/test/tools/llvm-profdata/Inputs/cs-sample-preinline.proftext
    M llvm/test/tools/llvm-profdata/Inputs/cs-sample.proftext
    A llvm/test/tools/llvm-profdata/cs-sample-nested-profile.test
    M llvm/test/tools/llvm-profdata/cs-sample-trimmer.test
    M llvm/test/tools/llvm-profgen/cs-preinline.test
    M llvm/test/tools/llvm-profgen/merge-cold-profile.test
    M llvm/test/tools/llvm-profgen/truncated-pseudoprobe.test
    M llvm/tools/llvm-profdata/llvm-profdata.cpp
    M llvm/tools/llvm-profgen/PerfReader.cpp
    M llvm/tools/llvm-profgen/PerfReader.h
    M llvm/tools/llvm-profgen/ProfileGenerator.cpp
    M llvm/tools/llvm-profgen/ProfileGenerator.h
    M llvm/tools/llvm-profgen/llvm-profgen.cpp

  Log Message:
  -----------
  [CSSPGO] Use nested context-sensitive profile.

CSSPGO currently employs a flat profile format for context-sensitive profiles. Such a flat profile allows for precisely manipulating contexts that is either inlined or not inlined. This is a benefit over the nested profile format used by non-CS AutoFDO. A downside of this is the longer build time due to parsing the indexing the full CS contexts.

For a CS flat profile, though only the context profiles relevant to a module are loaded when that module is compiled, the cost to figure out what profiles are relevant is noticeably high when there're many contexts,  since the sample reader will need to scan all context strings anyway. On the contrary, a nested function profile has its related inline subcontexts isolated from other unrelated contexts. Therefore when compiling a set of functions, unrelated contexts will never need to be scanned.

In this change we are exploring using nested profile format for CSSPGO. This is expected to work based on an assumption that with a preinliner-computed profile all contexts are precomputed and expected to be inlined by the compiler. Contexts not expected to be inlined will be cut off and returned to corresponding base profiles (for top-level outlined functions). This naturally forms a nested profile where all nested contexts are expected to be inlined. The compiler will less likely optimize on derived contexts that are not precomputed.

A CS-nested profile will look exactly the same with regular nested profile except that each nested profile can come with an attributes. With pseudo probes,  a nested profile shown as below can also have a CFG checksum.

```

main:1968679:12
 2: 24
 3: 28 _Z5funcAi:18
 3.1: 28 _Z5funcBi:30
 3: _Z5funcAi:1467398
  0: 10
  1: 10 _Z8funcLeafi:11
  3: 24
  1: _Z8funcLeafi:1467299
   0: 6
   1: 6
   3: 287884
   4: 287864 _Z3fibi:315608
   15: 23
   !CFGChecksum: 138828622701
   !Attributes: 2
  !CFGChecksum: 281479271677951
  !Attributes: 2
```

Specific work included in this change:
- A recursive profile converter to convert CS flat profile to nested profile.
- Extend function checksum and attribute metadata to be stored in nested way for text profile and extbinary profile.
- Unifiy sample loader inliner path for CS and preinlined nested profile.
 - Changes in the sample loader to support probe-based nested profile.

I've seen promising results regarding build time. A nested profile can result in a 20% shorter build time than a CS flat profile while keep an on-par performance. This is with -duplicate-contexts-into-base=1.

Test Plan:

Reviewed By: wenlei

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




More information about the All-commits mailing list