]> granicus.if.org Git - llvm/commit
[PGO] Context sensitive PGO (part 1)
authorRong Xu <xur@google.com>
Tue, 26 Feb 2019 22:37:46 +0000 (22:37 +0000)
committerRong Xu <xur@google.com>
Tue, 26 Feb 2019 22:37:46 +0000 (22:37 +0000)
commita764eb906a0680dd5bbf1189e35a70e5117c43f7
tree6143b9d2dc751cfe8181e5d2700459e4ab3ea75b
parent1a46c551c7ee2fab1d7630da17c7a9e40326a785
[PGO] Context sensitive PGO (part 1)

Current PGO profile counts are not context sensitive. The branch probabilities
for the inlined functions are kept the same for all call-sites, and they might
be very different from the actual branch probabilities. These suboptimal
profiles can greatly affect some downstream optimizations, in particular for
the machine basic block placement optimization.

In this patch, we propose to have a post-inline PGO instrumentation/use pass,
which we called Context Sensitive PGO (CSPGO). For the users who want the best
possible performance, they can perform a second round of PGO instrument/use on
the top of the regular PGO. They will have two sets of profile counts. The
first pass profile will be manly for inline, indirect-call promotion, and
CGSCC simplification pass optimizations. The second pass profile is for
post-inline optimizations and code-gen optimizations.

A typical usage:
// Regular PGO instrumentation and generate pass1 profile.
> clang -O2 -fprofile-generate source.c -o gen
> ./gen
> llvm-profdata merge default.*profraw -o pass1.profdata
// CSPGO instrumentation.
> clang -O2 -fprofile-use=pass1.profdata -fcs-profile-generate -o gen2
> ./gen2
// Merge two sets of profiles
> llvm-profdata merge default.*profraw pass1.profdata -o profile.profdata
// Use the combined profile. Pass manager will invoke two PGO use passes.
> clang -O2 -fprofile-use=profile.profdata -o use

This change touches many components in the compiler. The reviewed patch
(D54175) will committed in phrases.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354930 91177308-0d34-0410-b5e6-96231b3b80d8
14 files changed:
include/llvm/InitializePasses.h
include/llvm/LTO/Config.h
include/llvm/LinkAllPasses.h
include/llvm/ProfileData/InstrProf.h
include/llvm/ProfileData/InstrProfData.inc
include/llvm/Transforms/Instrumentation.h
include/llvm/Transforms/Instrumentation/InstrProfiling.h
include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
lib/Passes/PassBuilder.cpp
lib/ProfileData/InstrProf.cpp
lib/Transforms/Instrumentation/InstrProfiling.cpp
lib/Transforms/Instrumentation/PGOInstrumentation.cpp
tools/gold/gold-plugin.cpp
tools/llvm-lto2/llvm-lto2.cpp