[PATCH] D115205: [CSSPGO] Use nested context-sensitive profile.

Hongtao Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 6 16:54:17 PST 2021


hoy created this revision.
Herald added subscribers: ormris, modimo, wenlei, hiraditya, eraman.
hoy requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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
  !Attributes: 2
  !CFGChecksum: 281479271677951

Specific work included in this change:
	○ A recursive profile converter to convert CS flat profile to nested profile.
	○ Extended function checksum and attribute metadata to be stored in nested way for text profile and extbinary profile.
	○ Unified 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:


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115205

Files:
  llvm/include/llvm/ProfileData/SampleProf.h
  llvm/include/llvm/ProfileData/SampleProfReader.h
  llvm/include/llvm/ProfileData/SampleProfWriter.h
  llvm/include/llvm/Transforms/IPO/SampleContextTracker.h
  llvm/lib/ProfileData/SampleProf.cpp
  llvm/lib/ProfileData/SampleProfReader.cpp
  llvm/lib/ProfileData/SampleProfWriter.cpp
  llvm/lib/Transforms/IPO/SampleContextTracker.cpp
  llvm/lib/Transforms/IPO/SampleProfile.cpp
  llvm/test/Transforms/SampleProfile/csspgo-inline.ll
  llvm/test/Transforms/SampleProfile/csspgo-use-preinliner.ll
  llvm/test/tools/llvm-profdata/Inputs/cs-sample-preinline.proftext
  llvm/test/tools/llvm-profdata/Inputs/cs-sample.proftext
  llvm/test/tools/llvm-profdata/cs-sample-nested-profile.test
  llvm/test/tools/llvm-profdata/cs-sample-trimmer.test
  llvm/test/tools/llvm-profgen/cs-preinline.test
  llvm/test/tools/llvm-profgen/merge-cold-profile.test
  llvm/test/tools/llvm-profgen/truncated-pseudoprobe.test
  llvm/tools/llvm-profdata/llvm-profdata.cpp
  llvm/tools/llvm-profgen/ProfileGenerator.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115205.392232.patch
Type: text/x-patch
Size: 51359 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211207/d190d348/attachment.bin>


More information about the llvm-commits mailing list