summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Passes/PassBuilder.h7
-rw-r--r--llvm/lib/Passes/PassBuilder.cpp2
-rw-r--r--llvm/test/Other/new-pm-pgo.ll3
-rw-r--r--llvm/tools/opt/NewPMDriver.cpp8
4 files changed, 17 insertions, 3 deletions
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 156fc9c7edf..5756f49752b 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -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.
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 9e0cf27aa17..20fc475305a 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -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());
diff --git a/llvm/test/Other/new-pm-pgo.ll b/llvm/test/Other/new-pm-pgo.ll
index 2388019c104..a5ade773a87 100644
--- a/llvm/test/Other/new-pm-pgo.ll
+++ b/llvm/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>' -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
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index 3445b7a4e2b..32f71a5beda 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -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);
OpenPOWER on IntegriCloud