]> granicus.if.org Git - llvm/commitdiff
Hook the sample PGO machinery in the new PM
authorDehao Chen <dehao@google.com>
Thu, 29 Jun 2017 23:33:05 +0000 (23:33 +0000)
committerDehao Chen <dehao@google.com>
Thu, 29 Jun 2017 23:33:05 +0000 (23:33 +0000)
Summary: This patch hooks up SampleProfileLoaderPass with the new PM.

Reviewers: chandlerc, davidxl, davide, tejohnson

Reviewed By: chandlerc, tejohnson

Subscribers: tejohnson, llvm-commits, sanjoy

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306763 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Passes/PassBuilder.h
include/llvm/Transforms/SampleProfile.h
lib/Passes/PassBuilder.cpp
lib/Transforms/IPO/SampleProfile.cpp

index 12b05e4ff0c5b9ebd2cefbe55f2a897691e28089..ff1958397331841b6e924188cb6c2d9be59aaabd 100644 (file)
@@ -31,8 +31,8 @@ class TargetMachine;
 struct PGOOptions {
   std::string ProfileGenFile = "";
   std::string ProfileUseFile = "";
+  std::string SampleProfileFile = "";
   bool RunProfileGen = false;
-  bool SamplePGO = false;
 };
 
 /// \brief This class provides access to building LLVM's passes.
index 93fa9532cc3a7ad98aabc76ddea683bbaa5c56cd..c984fe74ba939c1ab8ef020ca2f284b45e259120 100644 (file)
@@ -21,6 +21,10 @@ namespace llvm {
 class SampleProfileLoaderPass : public PassInfoMixin<SampleProfileLoaderPass> {
 public:
   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+  SampleProfileLoaderPass(std::string File = "") : ProfileFileName(File) {}
+
+private:
+  std::string ProfileFileName;
 };
 
 } // End llvm namespace
index bc73cdda88b64a9c88ad4d5794ae03fbc44b1dfa..0380bd991d71720f46a60ff61976848f09ab8663 100644 (file)
@@ -535,13 +535,17 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
 
   // Add all the requested passes for PGO, if requested.
   if (PGOOpt) {
-    assert(PGOOpt->RunProfileGen || PGOOpt->SamplePGO ||
+    assert(PGOOpt->RunProfileGen || !PGOOpt->SampleProfileFile.empty() ||
            !PGOOpt->ProfileUseFile.empty());
-    addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
-                      PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
+    if (PGOOpt->SampleProfileFile.empty())
+      addPGOInstrPasses(MPM, DebugLogging, Level, PGOOpt->RunProfileGen,
+                        PGOOpt->ProfileGenFile, PGOOpt->ProfileUseFile);
+    else
+      MPM.addPass(SampleProfileLoaderPass(PGOOpt->SampleProfileFile));
 
     // Indirect call promotion that promotes intra-module targes only.
-    MPM.addPass(PGOIndirectCallPromotion(false, PGOOpt && PGOOpt->SamplePGO));
+    MPM.addPass(PGOIndirectCallPromotion(
+        false, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
   }
 
   // Require the GlobalsAA analysis for the module so we can query it within
@@ -776,9 +780,9 @@ PassBuilder::buildThinLTODefaultPipeline(OptimizationLevel Level,
   // During the ThinLTO backend phase we perform early indirect call promotion
   // here, before globalopt. Otherwise imported available_externally functions
   // look unreferenced and are removed.
-  MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
-                                       PGOOpt && PGOOpt->SamplePGO &&
-                                           !PGOOpt->ProfileUseFile.empty()));
+  MPM.addPass(PGOIndirectCallPromotion(
+      true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty() &&
+                            !PGOOpt->ProfileUseFile.empty()));
 
   // Add the core simplification pipeline.
   MPM.addPass(buildModuleSimplificationPipeline(Level, DebugLogging));
@@ -818,8 +822,8 @@ ModulePassManager PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
     // left by the earlier promotion pass that promotes intra-module targets.
     // This two-step promotion is to save the compile time. For LTO, it should
     // produce the same result as if we only do promotion here.
-    MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */,
-                                         PGOOpt && PGOOpt->SamplePGO));
+    MPM.addPass(PGOIndirectCallPromotion(
+        true /* InLTO */, PGOOpt && !PGOOpt->SampleProfileFile.empty()));
 
     // Propagate constants at call sites into the functions they call.  This
     // opens opportunities for globalopt (and inlining) by substituting function
index 656421ee58df8d8587acd818647a67ddded3d819..ac4765f960756c6f150aa8c039add3383548fe86 100644 (file)
@@ -1484,7 +1484,8 @@ bool SampleProfileLoader::runOnFunction(Function &F) {
 PreservedAnalyses SampleProfileLoaderPass::run(Module &M,
                                                ModuleAnalysisManager &AM) {
 
-  SampleProfileLoader SampleLoader(SampleProfileFile);
+  SampleProfileLoader SampleLoader(
+      ProfileFileName.empty() ? SampleProfileFile : ProfileFileName);
 
   SampleLoader.doInitialization(M);