[llvm] r309121 - Make new PM honor -fdebug-info-for-profiling

Dehao Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 26 08:01:20 PDT 2017


Author: dehao
Date: Wed Jul 26 08:01:20 2017
New Revision: 309121

URL: http://llvm.org/viewvc/llvm-project?rev=309121&view=rev
Log:
Make new PM honor -fdebug-info-for-profiling

Summary: The new PM needs to invoke add-discriminator pass when building with -fdebug-info-for-profiling.

Reviewers: chandlerc, davidxl

Reviewed By: chandlerc

Subscribers: sanjoy, llvm-commits

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

Modified:
    llvm/trunk/include/llvm/Passes/PassBuilder.h
    llvm/trunk/lib/Passes/PassBuilder.cpp
    llvm/trunk/test/Other/new-pm-pgo.ll
    llvm/trunk/tools/opt/NewPMDriver.cpp

Modified: llvm/trunk/include/llvm/Passes/PassBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Passes/PassBuilder.h?rev=309121&r1=309120&r2=309121&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Passes/PassBuilder.h (original)
+++ llvm/trunk/include/llvm/Passes/PassBuilder.h Wed Jul 26 08:01:20 2017
@@ -30,13 +30,16 @@ class TargetMachine;
 /// A struct capturing PGO tunables.
 struct PGOOptions {
   PGOOptions(std::string ProfileGenFile = "", std::string ProfileUseFile = "",
-             std::string SampleProfileFile = "", bool RunProfileGen = false)
+             std::string SampleProfileFile = "", bool RunProfileGen = false,
+             bool SamplePGOSupport = false)
       : ProfileGenFile(ProfileGenFile), ProfileUseFile(ProfileUseFile),
-        SampleProfileFile(SampleProfileFile), RunProfileGen(RunProfileGen) {}
+        SampleProfileFile(SampleProfileFile), RunProfileGen(RunProfileGen),
+        SamplePGOSupport(SamplePGOSupport || !SampleProfileFile.empty()) {}
   std::string ProfileGenFile;
   std::string ProfileUseFile;
   std::string SampleProfileFile;
   bool RunProfileGen;
+  bool SamplePGOSupport;
 };
 
 /// \brief This class provides access to building LLVM's passes.

Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=309121&r1=309120&r2=309121&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Wed Jul 26 08:01:20 2017
@@ -535,6 +535,8 @@ PassBuilder::buildModuleSimplificationPi
   // Create an early function pass manager to cleanup the output of the
   // frontend.
   FunctionPassManager EarlyFPM(DebugLogging);
+  if (PGOOpt && PGOOpt->SamplePGOSupport)
+    EarlyFPM.addPass(AddDiscriminatorsPass());
   EarlyFPM.addPass(SimplifyCFGPass());
   EarlyFPM.addPass(SROA());
   EarlyFPM.addPass(EarlyCSEPass());

Modified: llvm/trunk/test/Other/new-pm-pgo.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/new-pm-pgo.ll?rev=309121&r1=309120&r2=309121&view=diff
==============================================================================
--- llvm/trunk/test/Other/new-pm-pgo.ll (original)
+++ llvm/trunk/test/Other/new-pm-pgo.ll Wed Jul 26 08:01:20 2017
@@ -2,10 +2,13 @@
 ; RUN: llvm-profdata merge %S/Inputs/new-pm-pgo.proftext -o %t.profdata
 ; RUN: opt -debug-pass-manager -passes='default<O2>' -pgo-kind=new-pm-pgo-instr-use-pipeline -profile-file='%t.profdata' %s 2>&1 |FileCheck %s --check-prefixes=USE
 ; RUN: opt -debug-pass-manager -passes='default<O2>' -pgo-kind=new-pm-pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 |FileCheck %s --check-prefixes=SAMPLE_USE
+; RUN: opt -debug-pass-manager -passes='default<O2>' -new-pm-debug-info-for-profiling %s 2>&1 |FileCheck %s --check-prefixes=SAMPLE_GEN
 ;
 ; GEN: Running pass: PGOInstrumentationGen
 ; USE: Running pass: PGOInstrumentationUse
+; SAMPLE_USE: Running pass: AddDiscriminators
 ; SAMPLE_USE: Running pass: SampleProfileLoaderPass
+; SAMPLE_GEN: Running pass: AddDiscriminators
 
 define void @foo() {
   ret void

Modified: llvm/trunk/tools/opt/NewPMDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/NewPMDriver.cpp?rev=309121&r1=309120&r2=309121&view=diff
==============================================================================
--- llvm/trunk/tools/opt/NewPMDriver.cpp (original)
+++ llvm/trunk/tools/opt/NewPMDriver.cpp Wed Jul 26 08:01:20 2017
@@ -94,6 +94,9 @@ static cl::opt<PGOKind> PGOKindFlag(
                           "Use sampled profile to guide PGO.")));
 static cl::opt<std::string> ProfileFile(
     "profile-file", cl::desc("Path to the profile."), cl::Hidden);
+static cl::opt<bool> DebugInfoForProfiling(
+    "new-pm-debug-info-for-profiling", cl::init(false), cl::Hidden,
+    cl::desc("Emit special debug info to enable PGO profile generation."));
 /// @}}
 
 template <typename PassManagerT>
@@ -179,7 +182,10 @@ bool llvm::runPassPipeline(StringRef Arg
       P = PGOOptions("", "", ProfileFile, false);
       break;
     case NoPGO:
-      P = None;      
+      if (DebugInfoForProfiling)
+        P = PGOOptions("", "", "", false, true);
+      else
+        P = None;
   }
   PassBuilder PB(TM, P);
   registerEPCallbacks(PB, VerifyEachPass, DebugPM);




More information about the llvm-commits mailing list