[PATCH] D132569: [llvm-profdata] Improve profile supplementation

Rong Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 24 08:49:26 PDT 2022


xur created this revision.
xur added reviewers: davidxl, tmsriram.
Herald added subscribers: Enna1, wenlei, hiraditya, kristof.beyls.
Herald added a project: All.
xur requested review of this revision.
Herald added a project: LLVM.

This patch improves the llvm-profdata feature that supplements instr profile
with sample profile.

This patch has the following changes:
(1) Handling of internal linkage functions (static functions)
Static functions in FDO have a prefix of source file name, while they do not
have one in SampleFDO. Current implementation does not handle this and we are
not updating the profile for static functions. This patch fixes this.

(2) Handling of -funique-internal-linakge-symbols
Again this is for the internal linkage functions. Option
-funique-internal-linakge-symbols can now be applied to both FDO and SampleFDO
compilation. When it is used, it demangles internal linkage function names and
adds a hash value as the postfix.

When both SampleFDO and FDO profiles use this option, or both
not use this option, changes in (1) should handle this.

Here we also handle when the SampleFDO profile using this option while FDO
profile not using this option, or vice versa.

There is one case where this patch won't work: If one of the profiles used
mangled name and the other does not. For example, if the SampleFDO profile
uses clang c-compiler and without -funique-internal-linakge-symbols, while
the FDO profile uses -funique-internal-linakge-symbols. The SampleFDO profile
contains unmangled names while the FDO profile contains mangled names. If
both profiles use c++ compiler, this won't happen. We think this use case
is rare and does not justify the effort to fix.

(3) Not promoting warm function to hot
Current implementation promotes a non-cold function in the SampleFDO profile
into a hot function in the FDO profile. This is too aggressive. This patch
promotes a hot functions in the SampleFDO profile into a hot function, and a
warm function in SampleFDO into a warm function in FDO.

(4) Adjust the heuristics
We now use the count size in FDO as the main factor to deal with pre-inliner.
Currently we use the number of sample records in the SampleFDO profile. But
that only counts the top-level body sample records (not including the nested
call-sites). We are seeing some big functions not being updated because of
this. I think using the count size in FDO profile is more reasonable to judge if
the function is likely to be inlined to the callers in pre-inliner.


https://reviews.llvm.org/D132569

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  llvm/include/llvm/ProfileData/SampleProf.h
  llvm/lib/ProfileData/ProfileSummaryBuilder.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/test/Transforms/PGOProfile/Inputs/sample-profile-hot.proftext
  llvm/test/Transforms/PGOProfile/Inputs/sample-profile-warm.proftext
  llvm/test/Transforms/PGOProfile/Inputs/sample-profile.proftext
  llvm/test/Transforms/PGOProfile/Inputs/suppl-profile.proftext
  llvm/test/Transforms/PGOProfile/suppl-profile.ll
  llvm/test/tools/llvm-profdata/Inputs/FUnique.afdotext
  llvm/test/tools/llvm-profdata/Inputs/FUnique.proftext
  llvm/test/tools/llvm-profdata/Inputs/NoFUnique.afdotext
  llvm/test/tools/llvm-profdata/Inputs/NoFUnique.proftext
  llvm/test/tools/llvm-profdata/Inputs/mix_instr_small.proftext
  llvm/test/tools/llvm-profdata/suppl-instr-with-sample-static-func.test
  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: D132569.455237.patch
Type: text/x-patch
Size: 23394 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220824/cac9a060/attachment.bin>


More information about the llvm-commits mailing list