diff options
| author | Philip Pfaffe <philip.pfaffe@gmail.com> | 2017-07-10 10:57:55 +0000 |
|---|---|---|
| committer | Philip Pfaffe <philip.pfaffe@gmail.com> | 2017-07-10 10:57:55 +0000 |
| commit | 730f2f9bb622a4b72231628239fe607d26224a07 (patch) | |
| tree | a7c21e1550bda5b1293f5454daca7ac2d321fd37 /llvm/tools/opt/NewPMDriver.cpp | |
| parent | fb3210aa057fb3f396289fdb110b9f80625c9eef (diff) | |
| download | bcm5719-llvm-730f2f9bb622a4b72231628239fe607d26224a07.tar.gz bcm5719-llvm-730f2f9bb622a4b72231628239fe607d26224a07.zip | |
[PM] Enable registration of out-of-tree passes with PassBuilder
Summary:
This patch adds a callback registration API to the PassBuilder,
enabling registering out-of-tree passes with it.
Through the Callback API, callers may register callbacks with the
various stages at which passes are added into pass managers, including
parsing of a pass pipeline as well as at extension points within the
default -O pipelines.
Registering utilities like `require<>` and `invalidate<>` needs to be
handled manually by the caller, but a helper is provided.
Additionally, adding passes at pipeline extension points is exposed
through the opt tool. This patch adds a `-passes-ep-X` commandline
option for every extension point X, which opt parses into pipelines
inserted into that extension point.
Reviewers: chandlerc
Reviewed By: chandlerc
Subscribers: lksbhm, grosser, davide, mehdi_amini, llvm-commits, mgorny
Differential Revision: https://reviews.llvm.org/D33464
llvm-svn: 307532
Diffstat (limited to 'llvm/tools/opt/NewPMDriver.cpp')
| -rw-r--r-- | llvm/tools/opt/NewPMDriver.cpp | 82 |
1 files changed, 80 insertions, 2 deletions
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp index 58e9caeff0f..9672ce7d177 100644 --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/tools/opt/NewPMDriver.cpp @@ -48,6 +48,83 @@ static cl::opt<std::string> "pipeline for handling managed aliasing queries"), cl::Hidden); +/// {{@ These options accept textual pipeline descriptions which will be +/// inserted into default pipelines at the respective extension points +static cl::opt<std::string> PeepholeEPPipeline( + "passes-ep-peephole", + cl::desc("A textual description of the function pass pipeline inserted at " + "the Peephole extension points into default pipelines"), + cl::Hidden); +static cl::opt<std::string> LateLoopOptimizationsEPPipeline( + "passes-ep-late-loop-optimizations", + cl::desc( + "A textual description of the loop pass pipeline inserted at " + "the LateLoopOptimizations extension point into default pipelines"), + cl::Hidden); +static cl::opt<std::string> LoopOptimizerEndEPPipeline( + "passes-ep-loop-optimizer-end", + cl::desc("A textual description of the loop pass pipeline inserted at " + "the LoopOptimizerEnd extension point into default pipelines"), + cl::Hidden); +static cl::opt<std::string> ScalarOptimizerLateEPPipeline( + "passes-ep-scalar-optimizer-late", + cl::desc("A textual description of the function pass pipeline inserted at " + "the ScalarOptimizerLate extension point into default pipelines"), + cl::Hidden); +static cl::opt<std::string> CGSCCOptimizerLateEPPipeline( + "passes-ep-cgscc-optimizer-late", + cl::desc("A textual description of the cgscc pass pipeline inserted at " + "the CGSCCOptimizerLate extension point into default pipelines"), + cl::Hidden); +static cl::opt<std::string> VectorizerStartEPPipeline( + "passes-ep-vectorizer-start", + cl::desc("A textual description of the function pass pipeline inserted at " + "the VectorizerStart extension point into default pipelines"), + cl::Hidden); +/// @}} + +/// If one of the EPPipeline command line options was given, register callbacks +/// for parsing and inserting the given pipeline +static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass, + bool DebugLogging) { + if (!PeepholeEPPipeline.empty()) + PB.registerPeepholeEPCallback( + [&](FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { + return PB.parsePassPipeline(PM, PeepholeEPPipeline, VerifyEachPass, + DebugPM); + }); + if (!LateLoopOptimizationsEPPipeline.empty()) + PB.registerLateLoopOptimizationsEPCallback( + [&](LoopPassManager &PM, PassBuilder::OptimizationLevel Level) { + return PB.parsePassPipeline(PM, LateLoopOptimizationsEPPipeline, + VerifyEachPass, DebugPM); + }); + if (!LoopOptimizerEndEPPipeline.empty()) + PB.registerLoopOptimizerEndEPCallback( + [&](LoopPassManager &PM, PassBuilder::OptimizationLevel Level) { + return PB.parsePassPipeline(PM, LoopOptimizerEndEPPipeline, + VerifyEachPass, DebugPM); + }); + if (!ScalarOptimizerLateEPPipeline.empty()) + PB.registerScalarOptimizerLateEPCallback( + [&](FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { + return PB.parsePassPipeline(PM, ScalarOptimizerLateEPPipeline, + VerifyEachPass, DebugPM); + }); + if (!CGSCCOptimizerLateEPPipeline.empty()) + PB.registerCGSCCOptimizerLateEPCallback( + [&](CGSCCPassManager &PM, PassBuilder::OptimizationLevel Level) { + return PB.parsePassPipeline(PM, CGSCCOptimizerLateEPPipeline, + VerifyEachPass, DebugPM); + }); + if (!VectorizerStartEPPipeline.empty()) + PB.registerVectorizerStartEPCallback( + [&](FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { + return PB.parsePassPipeline(PM, VectorizerStartEPPipeline, + VerifyEachPass, DebugPM); + }); +} + bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, tool_output_file *Out, tool_output_file *ThinLTOLinkOut, @@ -56,7 +133,9 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveBitcodeUseListOrder, bool EmitSummaryIndex, bool EmitModuleHash) { + bool VerifyEachPass = VK == VK_VerifyEachPass; PassBuilder PB(TM); + registerEPCallbacks(PB, VerifyEachPass, DebugPM); // Specially handle the alias analysis manager so that we can register // a custom pipeline of AA passes with it. @@ -85,8 +164,7 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, if (VK > VK_NoVerifier) MPM.addPass(VerifierPass()); - if (!PB.parsePassPipeline(MPM, PassPipeline, VK == VK_VerifyEachPass, - DebugPM)) { + if (!PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) { errs() << Arg0 << ": unable to parse pass pipeline description.\n"; return false; } |

