[PATCH] D36655: Move SampleProfileLoader pass before all simplification passes.

Dehao Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 13 14:12:38 PDT 2017


danielcdh updated this revision to Diff 110893.
danielcdh added a comment.

update


https://reviews.llvm.org/D36655

Files:
  lib/Passes/PassBuilder.cpp
  test/Other/new-pm-pgo.ll


Index: test/Other/new-pm-pgo.ll
===================================================================
--- test/Other/new-pm-pgo.ll
+++ test/Other/new-pm-pgo.ll
@@ -13,11 +13,11 @@
 ; USE: Running pass: PGOInstrumentationUse
 ; SAMPLE_USE_O: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}>
 ; SAMPLE_USE_PRE_LINK: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}>
-; SAMPLE_USE: Running pass: SimplifyCFGPass
-; SAMPLE_USE: Running pass: SROA
-; SAMPLE_USE: Running pass: EarlyCSEPass
-; SAMPLE_USE: Running pass: LowerExpectIntrinsicPass
-; SAMPLE_USE_POST_LINK: Running pass: InstCombinePass
+; SAMPLE_USE-NOT: Running pass: SimplifyCFGPass
+; SAMPLE_USE-NOT: Running pass: SROA
+; SAMPLE_USE-NOT: Running pass: EarlyCSEPass
+; SAMPLE_USE-NOT: Running pass: LowerExpectIntrinsicPass
+; SAMPLE_USE_POST_LINK: Running pass: ModuleToFunctionPassAdaptor<{{.*}}InstCombinePass{{.*}}>
 ; SAMPLE_USE: Running pass: SampleProfileLoaderPass
 ; SAMPLE_USE_O: Running pass: PGOIndirectCallPromotion
 ; SAMPLE_USE_POST_LINK-NOT: Running pass: GlobalOptPass
Index: lib/Passes/PassBuilder.cpp
===================================================================
--- lib/Passes/PassBuilder.cpp
+++ lib/Passes/PassBuilder.cpp
@@ -533,26 +533,8 @@
   // libraries and other oracles.
   MPM.addPass(InferFunctionAttrsPass());
 
-  // Create an early function pass manager to cleanup the output of the
-  // frontend.
-  FunctionPassManager EarlyFPM(DebugLogging);
-  EarlyFPM.addPass(SimplifyCFGPass());
-  EarlyFPM.addPass(SROA());
-  EarlyFPM.addPass(EarlyCSEPass());
-  EarlyFPM.addPass(LowerExpectIntrinsicPass());
-  // In SamplePGO ThinLTO backend, we need instcombine before profile annotation
-  // to convert bitcast to direct calls so that they can be inlined during the
-  // profile annotation prepration step.
-  // More details about SamplePGO design can be found in:
-  // https://research.google.com/pubs/pub45290.html
-  // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured.
-  if (PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
-      Phase == ThinLTOPhase::PostLink)
-    EarlyFPM.addPass(InstCombinePass());
-  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
-
   if (PGOOpt && !PGOOpt->SampleProfileFile.empty()) {
-    // Annotate sample profile right after early FPM to ensure freshness of
+    // Annotate sample profile before early FPM to ensure freshness of
     // the debug info.
     MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
     // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard
@@ -566,6 +548,15 @@
                                            true));
   }
 
+  // Create an early function pass manager to cleanup the output of the
+  // frontend.
+  FunctionPassManager EarlyFPM(DebugLogging);
+  EarlyFPM.addPass(SimplifyCFGPass());
+  EarlyFPM.addPass(SROA());
+  EarlyFPM.addPass(EarlyCSEPass());
+  EarlyFPM.addPass(LowerExpectIntrinsicPass());
+  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
+
   // Interprocedural constant propagation now that basic cleanup has occured
   // and prior to optimizing globals.
   // FIXME: This position in the pipeline hasn't been carefully considered in
@@ -861,6 +852,15 @@
     MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
                                          false /* SamplePGO */));
 
+  // In SamplePGO ThinLTO backend, we need instcombine before profile
+  // annotation to convert bitcast to direct calls so that they can be
+  // inlined during the profile annotation prepration step.
+  // More details about SamplePGO design can be found in:
+  // https://research.google.com/pubs/pub45290.html
+  // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured.
+  if (PGOOpt && !PGOOpt->SampleProfileFile.empty())
+    MPM.addPass(createModuleToFunctionPassAdaptor(InstCombinePass()));
+
   // Add the core simplification pipeline.
   MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
                                                 DebugLogging));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36655.110893.patch
Type: text/x-patch
Size: 4117 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170813/545a6769/attachment.bin>


More information about the llvm-commits mailing list