Skip to content

Commit e90d015

Browse files
committedJul 26, 2017
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 llvm-svn: 309121
1 parent 6d8de5c commit e90d015

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed
 

‎llvm/include/llvm/Passes/PassBuilder.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ class TargetMachine;
3030
/// A struct capturing PGO tunables.
3131
struct PGOOptions {
3232
PGOOptions(std::string ProfileGenFile = "", std::string ProfileUseFile = "",
33-
std::string SampleProfileFile = "", bool RunProfileGen = false)
33+
std::string SampleProfileFile = "", bool RunProfileGen = false,
34+
bool SamplePGOSupport = false)
3435
: ProfileGenFile(ProfileGenFile), ProfileUseFile(ProfileUseFile),
35-
SampleProfileFile(SampleProfileFile), RunProfileGen(RunProfileGen) {}
36+
SampleProfileFile(SampleProfileFile), RunProfileGen(RunProfileGen),
37+
SamplePGOSupport(SamplePGOSupport || !SampleProfileFile.empty()) {}
3638
std::string ProfileGenFile;
3739
std::string ProfileUseFile;
3840
std::string SampleProfileFile;
3941
bool RunProfileGen;
42+
bool SamplePGOSupport;
4043
};
4144

4245
/// \brief This class provides access to building LLVM's passes.

‎llvm/lib/Passes/PassBuilder.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
535535
// Create an early function pass manager to cleanup the output of the
536536
// frontend.
537537
FunctionPassManager EarlyFPM(DebugLogging);
538+
if (PGOOpt && PGOOpt->SamplePGOSupport)
539+
EarlyFPM.addPass(AddDiscriminatorsPass());
538540
EarlyFPM.addPass(SimplifyCFGPass());
539541
EarlyFPM.addPass(SROA());
540542
EarlyFPM.addPass(EarlyCSEPass());

‎llvm/test/Other/new-pm-pgo.ll

+3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
; RUN: llvm-profdata merge %S/Inputs/new-pm-pgo.proftext -o %t.profdata
33
; 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
44
; 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
5+
; RUN: opt -debug-pass-manager -passes='default<O2>' -new-pm-debug-info-for-profiling %s 2>&1 |FileCheck %s --check-prefixes=SAMPLE_GEN
56
;
67
; GEN: Running pass: PGOInstrumentationGen
78
; USE: Running pass: PGOInstrumentationUse
9+
; SAMPLE_USE: Running pass: AddDiscriminators
810
; SAMPLE_USE: Running pass: SampleProfileLoaderPass
11+
; SAMPLE_GEN: Running pass: AddDiscriminators
912

1013
define void @foo() {
1114
ret void

‎llvm/tools/opt/NewPMDriver.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ static cl::opt<PGOKind> PGOKindFlag(
9494
"Use sampled profile to guide PGO.")));
9595
static cl::opt<std::string> ProfileFile(
9696
"profile-file", cl::desc("Path to the profile."), cl::Hidden);
97+
static cl::opt<bool> DebugInfoForProfiling(
98+
"new-pm-debug-info-for-profiling", cl::init(false), cl::Hidden,
99+
cl::desc("Emit special debug info to enable PGO profile generation."));
97100
/// @}}
98101

99102
template <typename PassManagerT>
@@ -179,7 +182,10 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
179182
P = PGOOptions("", "", ProfileFile, false);
180183
break;
181184
case NoPGO:
182-
P = None;
185+
if (DebugInfoForProfiling)
186+
P = PGOOptions("", "", "", false, true);
187+
else
188+
P = None;
183189
}
184190
PassBuilder PB(TM, P);
185191
registerEPCallbacks(PB, VerifyEachPass, DebugPM);

0 commit comments

Comments
 (0)
Please sign in to comment.