[llvm] d311a62 - [ctx_profile] Decouple ctx instrumentation from PGOOpt (#92445)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 16 13:41:40 PDT 2024


Author: Mircea Trofin
Date: 2024-05-16T13:41:36-07:00
New Revision: d311a62e2f1ae34a0329c3812f2969cedac93561

URL: https://github.com/llvm/llvm-project/commit/d311a62e2f1ae34a0329c3812f2969cedac93561
DIFF: https://github.com/llvm/llvm-project/commit/d311a62e2f1ae34a0329c3812f2969cedac93561.diff

LOG: [ctx_profile] Decouple ctx  instrumentation from PGOOpt (#92445)

We currently don't support passing files and don't need frontend involvement either.

Added: 
    

Modified: 
    llvm/lib/Passes/PassBuilderPipelines.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 682bdefbd5243..1892e16a06528 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -839,10 +839,6 @@ void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM,
   MPM.addPass(PGOInstrumentationGen(IsCS));
 
   addPostPGOLoopRotation(MPM, Level);
-  if (PGOCtxProfLoweringPass::isContextualIRPGOEnabled()) {
-    MPM.addPass(PGOCtxProfLoweringPass());
-    return;
-  }
   // Add the profile lowering pass.
   InstrProfOptions Options;
   if (!ProfileFile.empty())
@@ -1157,8 +1153,17 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   const bool IsPGOInstrUse =
       IsPGOPreLink && PGOOpt->Action == PGOOptions::IRUse;
   const bool IsMemprofUse = IsPGOPreLink && !PGOOpt->MemoryProfile.empty();
-
-  if (IsPGOInstrGen || IsPGOInstrUse || IsMemprofUse)
+  // We don't want to mix pgo ctx gen and pgo gen; we also don't currently
+  // enable ctx profiling from the frontend.
+  assert(
+      !(IsPGOInstrGen && PGOCtxProfLoweringPass::isContextualIRPGOEnabled()) &&
+      "Enabling both instrumented FDO and contextual instrumentation is not "
+      "supported.");
+  // Enable contextual profiling instrumentation.
+  const bool IsCtxProfGen = !IsPGOInstrGen && IsPreLink &&
+                            PGOCtxProfLoweringPass::isContextualIRPGOEnabled();
+
+  if (IsPGOInstrGen || IsPGOInstrUse || IsMemprofUse || IsCtxProfGen)
     addPreInlinerPasses(MPM, Level, Phase);
 
   // Add all the requested passes for instrumentation PGO, if requested.
@@ -1168,9 +1173,13 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
                       /*IsCS=*/false, PGOOpt->AtomicCounterUpdate,
                       PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile,
                       PGOOpt->FS);
+  } else if (IsCtxProfGen) {
+    MPM.addPass(PGOInstrumentationGen(false));
+    addPostPGOLoopRotation(MPM, Level);
+    MPM.addPass(PGOCtxProfLoweringPass());
   }
 
-  if (IsPGOInstrGen || IsPGOInstrUse)
+  if (IsPGOInstrGen || IsPGOInstrUse || IsCtxProfGen)
     MPM.addPass(PGOIndirectCallPromotion(false, false));
 
   if (IsPGOPreLink && PGOOpt->CSAction == PGOOptions::CSIRInstr)


        


More information about the llvm-commits mailing list