Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/include/llvm/Transforms/IPO/SampleProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class SampleProfileLoaderPass : public PassInfoMixin<SampleProfileLoaderPass> {
SampleProfileLoaderPass(
std::string File = "", std::string RemappingFile = "",
ThinOrFullLTOPhase LTOPhase = ThinOrFullLTOPhase::None,
IntrusiveRefCntPtr<vfs::FileSystem> FS = nullptr);
IntrusiveRefCntPtr<vfs::FileSystem> FS = nullptr,
bool DisableSampleProfileInlining = false);

PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);

Expand All @@ -50,6 +51,7 @@ class SampleProfileLoaderPass : public PassInfoMixin<SampleProfileLoaderPass> {
std::string ProfileRemappingFileName;
const ThinOrFullLTOPhase LTOPhase;
IntrusiveRefCntPtr<vfs::FileSystem> FS;
bool DisableSampleProfileInlining;
};

} // end namespace llvm
Expand Down
11 changes: 11 additions & 0 deletions llvm/lib/Passes/PassBuilderPipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2153,6 +2153,17 @@ PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
if (PGOOpt && PGOOpt->DebugInfoForProfiling)
MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));

if (PGOOpt && PGOOpt->Action == PGOOptions::SampleUse) {
// Explicitly disable sample loader inlining in O0 pipeline.
MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
PGOOpt->ProfileRemappingFile,
ThinOrFullLTOPhase::None, nullptr,
/*DisableSampleProfileInlining*/ true));
// Cache ProfileSummaryAnalysis once to avoid the potential need to insert
// RequireAnalysisPass for PSI before subsequent non-module passes.
MPM.addPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
}

invokePipelineEarlySimplificationEPCallbacks(MPM, Level);

// Build a minimal pipeline based on the semantics required by LLVM,
Expand Down
8 changes: 6 additions & 2 deletions llvm/lib/Transforms/IPO/SampleProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2305,9 +2305,10 @@ bool SampleProfileLoader::runOnFunction(Function &F, ModuleAnalysisManager *AM)
}
SampleProfileLoaderPass::SampleProfileLoaderPass(
std::string File, std::string RemappingFile, ThinOrFullLTOPhase LTOPhase,
IntrusiveRefCntPtr<vfs::FileSystem> FS)
IntrusiveRefCntPtr<vfs::FileSystem> FS, bool DisableSampleProfileInlining)
: ProfileFileName(File), ProfileRemappingFileName(RemappingFile),
LTOPhase(LTOPhase), FS(std::move(FS)) {}
LTOPhase(LTOPhase), FS(std::move(FS)),
DisableSampleProfileInlining(DisableSampleProfileInlining) {}

PreservedAnalyses SampleProfileLoaderPass::run(Module &M,
ModuleAnalysisManager &AM) {
Expand All @@ -2326,6 +2327,9 @@ PreservedAnalyses SampleProfileLoaderPass::run(Module &M,

if (!FS)
FS = vfs::getRealFileSystem();
if (!DisableSampleLoaderInlining.getNumOccurrences() &&
DisableSampleProfileInlining)
DisableSampleLoaderInlining = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this mixes up global variable and class field and may be good to allow setting true and false from command line?

Suggested change
if (!DisableSampleLoaderInlining.getNumOccurrences() &&
DisableSampleProfileInlining)
DisableSampleLoaderInlining = true;
if (!::DisableSampleLoaderInlining.getNumOccurrences())
this->DisableSampleLoaderInlining = ::DisableSampleLoaderInlining;

Copy link
Contributor

@MatzeB MatzeB Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I think I misread the variables names. This actually changes the cl::opt setting based on the class parameter... I think that is dangerous then. In a ThinLTO or similar setting we could have multiple threads / LLVMContexts using different settings so we shouldn't just change the global variables...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point, I was to avoid setting the global variable in PassBuilderPipelines.cpp, so just learned this can also happen in the pass class. OK, I will try setting a class field.

LazyCallGraph &CG = AM.getResult<LazyCallGraphAnalysis>(M);

SampleProfileLoader SampleLoader(
Expand Down
6 changes: 5 additions & 1 deletion llvm/test/Other/new-pm-pgo-O0.ll
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
; RUN: |FileCheck %s --check-prefixes=USE_POST_LINK,USE
; RUN: opt -debug-pass-manager -passes='lto<O0>' -pgo-kind=pgo-instr-use-pipeline -profile-file='%t.profdata' %s 2>&1 \
; RUN: |FileCheck %s --check-prefixes=USE_POST_LINK,USE
; 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 \
; RUN: |FileCheck %s --check-prefixes=SAMPLE_USE

;
; GEN: Running pass: PGOInstrumentationGen
; USE_DEFAULT: Running pass: PGOInstrumentationUse
; USE_PRE_LINK: Running pass: PGOInstrumentationUse
; USE_POST_LINK-NOT: Running pass: PGOInstrumentationUse
; USE-NOT: Running pass: PGOIndirectCallPromotion
; USE-NOT: Running pass: PGOMemOPSizeOpt

; SAMPLE_USE: Running pass: AddDiscriminatorsPass
; SAMPLE_USE: Running pass: SampleProfileLoaderPass

define void @foo() {
ret void
}
Loading