[PATCH] D81981: [PGO] Supplement PGO profile with Sample profile

Wei Mi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 16 17:01:12 PDT 2020


wmi created this revision.
wmi added reviewers: xur, davidxl, wenlei.
Herald added subscribers: hiraditya, kristof.beyls, eraman.
Herald added a project: LLVM.

PGO profile is usually more precise than sample profile. However, PGO profile needs to be collected from loadtest and loadtest may not be representative enough to the production workload. Sample profile collected from production can be used as a supplement -- especially for functions cold in loadtest but warm/hot in production, we can use function entry count in sample profile to scale up the related function in PGO profile.

The implementation contains changes in compiler side and llvm-profdata side. In compiler side, during PGO instrumentation and profile-use phase, the patch will guarantee there is a counter in entry block for each function and the counter will be at the first entry in the counter vector. We will use llvm-profdata to merge PGO profile and sample profile, and the output will be a new PGO profile with some counters scaled up. If a function is never executed in PGO profile but hot in sample profile, llvm-profdata will reset the entry count using the related entry count in sample profile multiplied by a scalefactor, at the same time leaving the rest of the counters as zero. If a function has non-zero/cold entry count, but is hot in sample profile, all the counters inside of the function will be scaled up equally.

In the long run, it may be useful to let compiler support using PGO profile and sample profile at the same time, but that requires more careful design and more substantial changes to make two profiles work seamlessly. The patch here serves as a simple intermediate solution.


Repository:
  rL LLVM

https://reviews.llvm.org/D81981

Files:
  llvm/include/llvm/ProfileData/InstrProf.h
  llvm/include/llvm/ProfileData/InstrProfWriter.h
  llvm/include/llvm/ProfileData/ProfileCommon.h
  llvm/lib/Analysis/ProfileSummaryInfo.cpp
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/ProfileData/InstrProfWriter.cpp
  llvm/lib/ProfileData/ProfileSummaryBuilder.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/test/Instrumentation/InstrProfiling/instr-entry-block.ll
  llvm/test/tools/llvm-profdata/Inputs/mix_instr.proftext
  llvm/test/tools/llvm-profdata/Inputs/mix_sample.proftext
  llvm/test/tools/llvm-profdata/suppl-instr-with-sample.test
  llvm/tools/llvm-profdata/llvm-profdata.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81981.271239.patch
Type: text/x-patch
Size: 22240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200617/fcdd04c0/attachment.bin>


More information about the llvm-commits mailing list