[PATCH] D35744: Make new PM honor -fdebug-info-for-profiling

Dehao Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 25 21:27:13 PDT 2017


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

update flag name and add test.


https://reviews.llvm.org/D35744

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


Index: tools/opt/NewPMDriver.cpp
===================================================================
--- tools/opt/NewPMDriver.cpp
+++ tools/opt/NewPMDriver.cpp
@@ -81,7 +81,7 @@
     cl::desc("A textual description of the function pass pipeline inserted at "
              "the VectorizerStart extension point into default pipelines"),
     cl::Hidden);
-enum PGOKind { NoPGO, InstrGen, InstrUse, SampleUse };
+enum PGOKind { NoPGO, InstrGen, InstrUse, SampleUse, SampleGen };
 static cl::opt<PGOKind> PGOKindFlag(
     "pgo-kind", cl::init(NoPGO), cl::Hidden,
     cl::desc("The kind of profile guided optimization"),
@@ -91,7 +91,10 @@
                clEnumValN(InstrUse, "new-pm-pgo-instr-use-pipeline",
                           "Use instrumented profile to guide PGO."),
                clEnumValN(SampleUse, "new-pm-pgo-sample-use-pipeline",
-                          "Use sampled profile to guide PGO.")));
+                          "Use sampled profile to guide PGO."),
+               clEnumValN(SampleGen, "new-pm-pgo-sample-gen-pipeline",
+                          "Emit special debug info to enable PGO profile "
+                          "generation")));
 static cl::opt<std::string> ProfileFile(
     "profile-file", cl::desc("Path to the profile."), cl::Hidden);
 /// @}}
@@ -178,6 +181,9 @@
     case SampleUse:
       P = PGOOptions("", "", ProfileFile, false);
       break;
+    case SampleGen:
+      P = PGOOptions("", "", "", false, true);
+      break;
     case NoPGO:
       P = None;      
   }
Index: test/Other/new-pm-pgo.ll
===================================================================
--- test/Other/new-pm-pgo.ll
+++ test/Other/new-pm-pgo.ll
@@ -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>' -pgo-kind=new-pm-pgo-sample-gen-pipeline %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: lib/Passes/PassBuilder.cpp
===================================================================
--- lib/Passes/PassBuilder.cpp
+++ lib/Passes/PassBuilder.cpp
@@ -535,6 +535,8 @@
   // 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: include/llvm/Passes/PassBuilder.h
===================================================================
--- include/llvm/Passes/PassBuilder.h
+++ include/llvm/Passes/PassBuilder.h
@@ -30,13 +30,16 @@
 /// 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35744.108212.patch
Type: text/x-patch
Size: 4133 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170726/885808b3/attachment.bin>


More information about the llvm-commits mailing list