[llvm] [SampleFDO] Support enabling sample loader pass in O0 mode (PR #113985)
Lei Wang via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 28 17:15:41 PDT 2024
https://github.com/wlei-llvm created https://github.com/llvm/llvm-project/pull/113985
Add support for enabling sample loader pass in O0 mode(under `-fsample-profile-use`). This can help verify PGO raw profile count quality or provide a more accurate performance proxy(predictor), as O0 mode has minimal or no compiler optimizations that might otherwise impact profile count accuracy.
- Explicitly disable the sample loader inlining to ensure it only emits sampling annotation.
- Add the pass after `AddDiscriminatorsPass` pass to work with `-fdebug-info-for-profiling`.
>From e877d833af6a1d65d389d62b3a743f48af3fd513 Mon Sep 17 00:00:00 2001
From: wlei <wlei at fb.com>
Date: Mon, 28 Oct 2024 16:34:17 -0700
Subject: [PATCH] [SampleFDO] Support running sample loader in O0 mode
---
llvm/lib/Passes/PassBuilderPipelines.cpp | 13 +++++++++++++
llvm/lib/Transforms/IPO/SampleProfile.cpp | 2 +-
llvm/test/Other/new-pm-pgo-O0.ll | 6 +++++-
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 488554c84c1c43..abd4afb0f2c30f 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -302,6 +302,7 @@ static cl::opt<std::string> InstrumentColdFuncOnlyPath(
extern cl::opt<std::string> UseCtxProfile;
extern cl::opt<bool> PGOInstrumentColdFunctionOnly;
+extern cl::opt<bool> DisableSampleLoaderInlining;
namespace llvm {
extern cl::opt<bool> EnableMemProfContextDisambiguation;
@@ -2138,6 +2139,18 @@ ModulePassManager 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.
+ if (!DisableSampleLoaderInlining.getNumOccurrences())
+ DisableSampleLoaderInlining = true;
+ MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
+ PGOOpt->ProfileRemappingFile,
+ ThinOrFullLTOPhase::None));
+ // 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,
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 5d1ec7248ae679..3a2966320d54d5 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -192,7 +192,7 @@ static cl::opt<bool> ProfileSizeInline(
// Since profiles are consumed by many passes, turning on this option has
// side effects. For instance, pre-link SCC inliner would see merged profiles
// and inline the hot functions (that are skipped in this pass).
-static cl::opt<bool> DisableSampleLoaderInlining(
+cl::opt<bool> DisableSampleLoaderInlining(
"disable-sample-loader-inlining", cl::Hidden, cl::init(false),
cl::desc("If true, artifically skip inline transformation in sample-loader "
"pass, and merge (or scale) profiles (as configured by "
diff --git a/llvm/test/Other/new-pm-pgo-O0.ll b/llvm/test/Other/new-pm-pgo-O0.ll
index d7a6a03b8e44e3..d4f662fb25ace7 100644
--- a/llvm/test/Other/new-pm-pgo-O0.ll
+++ b/llvm/test/Other/new-pm-pgo-O0.ll
@@ -9,8 +9,9 @@
; 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
@@ -18,6 +19,9 @@
; 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
}
More information about the llvm-commits
mailing list