From 14a695874d9204a1a5680df42d47e80ba3971d8a Mon Sep 17 00:00:00 2001 From: Mircea Trofin Date: Wed, 26 Feb 2025 12:05:45 -0800 Subject: [PATCH] [ctxprof] Override type of instrumentation if `-profile-context-root` is specified --- llvm/lib/Passes/PassBuilderPipelines.cpp | 8 ++++---- .../PGOProfile/ctx-instrumentation-optin.ll | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 llvm/test/Transforms/PGOProfile/ctx-instrumentation-optin.ll diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index d4c3fe9562f9e..546a5eb1ec283 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -1206,7 +1206,10 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, // We already asserted this happens in non-FullLTOPostLink earlier. const bool IsPreLink = Phase != ThinOrFullLTOPhase::ThinLTOPostLink; - const bool IsPGOPreLink = PGOOpt && IsPreLink; + // Enable contextual profiling instrumentation. + const bool IsCtxProfGen = + IsPreLink && PGOCtxProfLoweringPass::isCtxIRPGOInstrEnabled(); + const bool IsPGOPreLink = !IsCtxProfGen && PGOOpt && IsPreLink; const bool IsPGOInstrGen = IsPGOPreLink && PGOOpt->Action == PGOOptions::IRInstr; const bool IsPGOInstrUse = @@ -1217,9 +1220,6 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level, assert(!(IsPGOInstrGen && PGOCtxProfLoweringPass::isCtxIRPGOInstrEnabled()) && "Enabling both instrumented PGO and contextual instrumentation is not " "supported."); - // Enable contextual profiling instrumentation. - const bool IsCtxProfGen = !IsPGOInstrGen && IsPreLink && - PGOCtxProfLoweringPass::isCtxIRPGOInstrEnabled(); const bool IsCtxProfUse = !UseCtxProfile.empty() && Phase == ThinOrFullLTOPhase::ThinLTOPreLink; diff --git a/llvm/test/Transforms/PGOProfile/ctx-instrumentation-optin.ll b/llvm/test/Transforms/PGOProfile/ctx-instrumentation-optin.ll new file mode 100644 index 0000000000000..f749e3e526b9d --- /dev/null +++ b/llvm/test/Transforms/PGOProfile/ctx-instrumentation-optin.ll @@ -0,0 +1,16 @@ +; REQUIRES: linux +; +; RUN: opt -O2 -debug-pass-manager -S -pgo-kind=pgo-instr-gen-pipeline -profile-file='temp' \ +; RUN: < %s 2>&1 | FileCheck %s --check-prefixes=COMMON,PGO +; RUN: opt -O2 -debug-pass-manager -S -pgo-kind=pgo-instr-gen-pipeline -profile-file='temp' \ +; RUN: -profile-context-root=something < %s 2>&1 | FileCheck %s --check-prefixes=COMMON,CTXPROF + +; COMMON: Running pass: PGOInstrumentationGen +; COMMON: Invalidating analysis: InnerAnalysisManagerProxy +; COMMON: Invalidating analysis: LazyCallGraphAnalysis +; COMMON: Invalidating analysis: InnerAnalysisManagerProxy +; CTXPROF: Running pass: AssignGUIDPass +; CTXPROF: Running pass: NoinlineNonPrevailing +; COMMON: Running analysis: InnerAnalysisManagerProxy +; PGO: Running pass: InstrProfilingLoweringPass +; CTXPROF: Running pass: PGOCtxProfLoweringPass