llvm.org GIT mirror llvm / 0922b28
[PGO] IRPGO pre-cleanup pass changes This patch adds a selected set of cleanup passes including a pre-inline pass before LLVM IR PGO instrumentation. The inline is only intended to apply those obvious/trivial ones before instrumentation so that much less instrumentation is needed to get better profiling information. This will drastically improve the instrumented code performance for large C++ applications. Another benefit is the context sensitive counts that can potentially improve the PGO optimization. Differential Revision: http://reviews.llvm.org/D21405 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275588 91177308-0d34-0410-b5e6-96231b3b80d8 Rong Xu 3 years ago
2 changed file(s) with 44 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
124124 "enable-loop-versioning-licm", cl::init(false), cl::Hidden,
125125 cl::desc("Enable the experimental Loop Versioning LICM pass"));
126126
127 static cl::opt
128 DisablePreInliner("disable-preinline", cl::init(false), cl::Hidden,
129 cl::desc("Disable pre-instrumentation inliner"));
130
131 static cl::opt PreInlineThreshold(
132 "preinline-threshold", cl::Hidden, cl::init(75), cl::ZeroOrMore,
133 cl::desc("Control the amount of inlining in pre-instrumentation inliner "
134 "(default = 75)"));
135
127136 PassManagerBuilder::PassManagerBuilder() {
128137 OptLevel = 2;
129138 SizeLevel = 0;
228237
229238 // Do PGO instrumentation generation or use pass as the option specified.
230239 void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM) {
240 if (PGOInstrGen.empty() && PGOInstrUse.empty())
241 return;
242 // Perform the preinline and cleanup passes for O1 and above.
243 // And avoid doing them if optimizing for size.
244 if (OptLevel > 0 && SizeLevel == 0 && !DisablePreInliner) {
245 // Create preinline pass.
246 MPM.add(createFunctionInliningPass(PreInlineThreshold));
247 MPM.add(createSROAPass());
248 MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
249 MPM.add(createCFGSimplificationPass()); // Merge & remove BBs
250 MPM.add(createInstructionCombiningPass()); // Combine silly seq's
251 addExtensionsToPM(EP_Peephole, MPM);
252 }
231253 if (!PGOInstrGen.empty()) {
232254 MPM.add(createPGOInstrumentationGenLegacyPass());
233255 // Add the profile lowering pass.
0 ; RUN: opt < %s -O2 -profile-generate=default.profraw -S | FileCheck %s --check-prefix=GEN
1 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
2 target triple = "x86_64-unknown-linux-gnu"
3
4 define i32 @foo(i32 %i) {
5 entry:
6 ; GEN: %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_foo
7 ; GEN-NOT: %pgocount.i = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc__stdin__bar
8 %call = call i32 @bar()
9 %add = add nsw i32 %i, %call
10 ret i32 %add
11 }
12
13 define internal i32 @bar() {
14 ; check that bar is inlined into foo and eliminiated from IR.
15 ; GEN-NOT: define internal i32 @bar
16 entry:
17 %call = call i32 (...) @bar1()
18 ret i32 %call
19 }
20
21 declare i32 @bar1(...)