Skip to content

Commit e877d83

Browse files
committed
[SampleFDO] Support running sample loader in O0 mode
1 parent 8e6856e commit e877d83

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ static cl::opt<std::string> InstrumentColdFuncOnlyPath(
302302

303303
extern cl::opt<std::string> UseCtxProfile;
304304
extern cl::opt<bool> PGOInstrumentColdFunctionOnly;
305+
extern cl::opt<bool> DisableSampleLoaderInlining;
305306

306307
namespace llvm {
307308
extern cl::opt<bool> EnableMemProfContextDisambiguation;
@@ -2138,6 +2139,18 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
21382139
if (PGOOpt && PGOOpt->DebugInfoForProfiling)
21392140
MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
21402141

2142+
if (PGOOpt && PGOOpt->Action == PGOOptions::SampleUse) {
2143+
// Explicitly disable sample loader inlining in O0 pipeline.
2144+
if (!DisableSampleLoaderInlining.getNumOccurrences())
2145+
DisableSampleLoaderInlining = true;
2146+
MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
2147+
PGOOpt->ProfileRemappingFile,
2148+
ThinOrFullLTOPhase::None));
2149+
// Cache ProfileSummaryAnalysis once to avoid the potential need to insert
2150+
// RequireAnalysisPass for PSI before subsequent non-module passes.
2151+
MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
2152+
}
2153+
21412154
invokePipelineEarlySimplificationEPCallbacks(MPM, Level);
21422155

21432156
// Build a minimal pipeline based on the semantics required by LLVM,

llvm/lib/Transforms/IPO/SampleProfile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static cl::opt<bool> ProfileSizeInline(
192192
// Since profiles are consumed by many passes, turning on this option has
193193
// side effects. For instance, pre-link SCC inliner would see merged profiles
194194
// and inline the hot functions (that are skipped in this pass).
195-
static cl::opt<bool> DisableSampleLoaderInlining(
195+
cl::opt<bool> DisableSampleLoaderInlining(
196196
"disable-sample-loader-inlining", cl::Hidden, cl::init(false),
197197
cl::desc("If true, artifically skip inline transformation in sample-loader "
198198
"pass, and merge (or scale) profiles (as configured by "

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@
99
; RUN: |FileCheck %s --check-prefixes=USE_POST_LINK,USE
1010
; RUN: opt -debug-pass-manager -passes='lto<O0>' -pgo-kind=pgo-instr-use-pipeline -profile-file='%t.profdata' %s 2>&1 \
1111
; RUN: |FileCheck %s --check-prefixes=USE_POST_LINK,USE
12+
; RUN: opt -debug-pass-manager -passes='default<O0>' -pgo-kind=pgo-sample-use-pipeline -profile-file='%S/Inputs/new-pm-pgo.prof' %s 2>&1 \
13+
; RUN: |FileCheck %s --check-prefixes=SAMPLE_USE
1214

13-
;
1415
; GEN: Running pass: PGOInstrumentationGen
1516
; USE_DEFAULT: Running pass: PGOInstrumentationUse
1617
; USE_PRE_LINK: Running pass: PGOInstrumentationUse
1718
; USE_POST_LINK-NOT: Running pass: PGOInstrumentationUse
1819
; USE-NOT: Running pass: PGOIndirectCallPromotion
1920
; USE-NOT: Running pass: PGOMemOPSizeOpt
2021

22+
; SAMPLE_USE: Running pass: AddDiscriminatorsPass
23+
; SAMPLE_USE: Running pass: SampleProfileLoaderPass
24+
2125
define void @foo() {
2226
ret void
2327
}

0 commit comments

Comments
 (0)