]> granicus.if.org Git - llvm/commitdiff
Make new PM honor -fdebug-info-for-profiling
authorDehao Chen <dehao@google.com>
Wed, 26 Jul 2017 15:01:20 +0000 (15:01 +0000)
committerDehao Chen <dehao@google.com>
Wed, 26 Jul 2017 15:01:20 +0000 (15:01 +0000)
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

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

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

index 156fc9c7edf2a7e5c09a02d073facbacc162738f..5756f49752b091643c8b5a61eec2f23e92c5ac5f 100644 (file)
@@ -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.
index 9e0cf27aa17b5b4a98374fa8ed47051e81ef8870..20fc475305af6e7430bec650dace6d9fbd18eff3 100644 (file)
@@ -535,6 +535,8 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   // 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());
index 2388019c104f3be2a7c82eb63a1259fce6aa856d..a5ade773a8765f1295dfbc25fb7d0b173b543ff4 100644 (file)
@@ -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
index 3445b7a4e2beb5dd3ef5002eefdad32bc4822df3..32f71a5beda6c7cc8f286d67e9d11ffd9dc1b81d 100644 (file)
@@ -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 Arg0, Module &M, TargetMachine *TM,
       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);