diff options
author | Philip Pfaffe <philip.pfaffe@gmail.com> | 2018-11-12 11:17:07 +0000 |
---|---|---|
committer | Philip Pfaffe <philip.pfaffe@gmail.com> | 2018-11-12 11:17:07 +0000 |
commit | 0c20a4d744a4d0b35ce0d768a9449516c07b1d77 (patch) | |
tree | 779177fcd4ccafd57cbb114d5ff11496dd301e18 | |
parent | 8e59cd19150eefbb0777cd8be1d470e093cdbb68 (diff) |
Add an OptimizerLast EP
Summary:
It turns out that we need an OptimizerLast PassBuilder extension point
after all. I missed the relevance of this EP the first time. By legacy PM magic,
function passes added at this EP get added to the last _Function_ PM, which is a
feature we lost when dropping this EP for the new PM.
A key difference between this and the legacy PassManager's OptimizerLast
callback is that this extension point is not triggered at O0. Extensions
to the O0 pipeline should append their passes to the end of the overall
pipeline.
Differential Revision: https://reviews.llvm.org/D54374
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346645 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Passes/PassBuilder.h | 14 | ||||
-rw-r--r-- | lib/Passes/PassBuilder.cpp | 3 | ||||
-rw-r--r-- | test/Other/new-pm-defaults.ll | 6 | ||||
-rw-r--r-- | tools/opt/NewPMDriver.cpp | 13 |
4 files changed, 36 insertions, 0 deletions
diff --git a/include/llvm/Passes/PassBuilder.h b/include/llvm/Passes/PassBuilder.h index 22e5eb0caa0..fa59345a02c 100644 --- a/include/llvm/Passes/PassBuilder.h +++ b/include/llvm/Passes/PassBuilder.h @@ -501,6 +501,18 @@ public: PipelineStartEPCallbacks.push_back(C); } + /// Register a callback for a default optimizer pipeline extension point + /// + /// This extension point allows adding optimizations at the very end of the + /// function optimization pipeline. A key difference between this and the + /// legacy PassManager's OptimizerLast callback is that this extension point + /// is not triggered at O0. Extensions to the O0 pipeline should append their + /// passes to the end of the overall pipeline. + void registerOptimizerLastEPCallback( + const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) { + OptimizerLastEPCallbacks.push_back(C); + } + /// Register a callback for parsing an AliasAnalysis Name to populate /// the given AAManager \p AA void registerParseAACallback( @@ -614,6 +626,8 @@ private: CGSCCOptimizerLateEPCallbacks; SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2> VectorizerStartEPCallbacks; + SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2> + OptimizerLastEPCallbacks; // Module callbacks SmallVector<std::function<void(ModulePassManager &)>, 2> PipelineStartEPCallbacks; diff --git a/lib/Passes/PassBuilder.cpp b/lib/Passes/PassBuilder.cpp index 0c6dfff06f1..33f74cfd9ed 100644 --- a/lib/Passes/PassBuilder.cpp +++ b/lib/Passes/PassBuilder.cpp @@ -862,6 +862,9 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level, // inserting redudnancies into the progrem. This even includes SimplifyCFG. OptimizePM.addPass(SpeculateAroundPHIsPass()); + for (auto &C : OptimizerLastEPCallbacks) + C(OptimizePM, Level); + // Add the core optimizing pipeline. MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM))); diff --git a/test/Other/new-pm-defaults.ll b/test/Other/new-pm-defaults.ll index f86257b406a..d58794132b0 100644 --- a/test/Other/new-pm-defaults.ll +++ b/test/Other/new-pm-defaults.ll @@ -66,6 +66,11 @@ ; RUN: -passes='lto-pre-link<O3>' -S %s 2>&1 \ ; RUN: | FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK-O3 \ ; RUN: --check-prefix=CHECK-EP-PIPELINE-START +; RUN: opt -disable-verify -debug-pass-manager \ +; RUN: -passes-ep-optimizer-last='no-op-function' \ +; RUN: -passes='default<O3>' -S %s 2>&1 \ +; RUN: | FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK-O3 \ +; RUN: --check-prefix=CHECK-EP-OPTIMIZER-LAST ; CHECK-O: Running analysis: PassInstrumentationAnalysis ; CHECK-O-NEXT: Starting llvm::Module pass manager run. @@ -254,6 +259,7 @@ ; CHECK-O-NEXT: Running pass: DivRemPairsPass ; CHECK-O-NEXT: Running pass: SimplifyCFGPass ; CHECK-O-NEXT: Running pass: SpeculateAroundPHIsPass +; CHECK-EP-OPTIMIZER-LAST: Running pass: NoOpFunctionPass ; CHECK-O-NEXT: Finished llvm::Function pass manager run. ; CHECK-O-NEXT: Running pass: CGProfilePass ; CHECK-O-NEXT: Running pass: GlobalDCEPass diff --git a/tools/opt/NewPMDriver.cpp b/tools/opt/NewPMDriver.cpp index e2f9a06523a..e68645fd0f4 100644 --- a/tools/opt/NewPMDriver.cpp +++ b/tools/opt/NewPMDriver.cpp @@ -95,6 +95,12 @@ static cl::opt<std::string> PipelineStartEPPipeline( cl::desc("A textual description of the function pass pipeline inserted at " "the PipelineStart extension point into default pipelines"), cl::Hidden); +static cl::opt<std::string> OptimizerLastEPPipeline( + "passes-ep-optimizer-last", + cl::desc("A textual description of the function pass pipeline inserted at " + "the OptimizerLast extension point into default pipelines"), + cl::Hidden); + enum PGOKind { NoPGO, InstrGen, InstrUse, SampleUse }; static cl::opt<PGOKind> PGOKindFlag( "pgo-kind", cl::init(NoPGO), cl::Hidden, @@ -195,6 +201,13 @@ static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass, Err(PB.parsePassPipeline(PM, PipelineStartEPPipeline, VerifyEachPass, DebugLogging)); }); + if (tryParsePipelineText<FunctionPassManager>(PB, OptimizerLastEPPipeline)) + PB.registerOptimizerLastEPCallback( + [&PB, VerifyEachPass, DebugLogging](FunctionPassManager &PM, + PassBuilder::OptimizationLevel) { + PB.parsePassPipeline(PM, OptimizerLastEPPipeline, VerifyEachPass, + DebugLogging); + }); } #ifdef LINK_POLLY_INTO_TOOLS |