diff options
author | David Blaikie <dblaikie@gmail.com> | 2018-01-23 01:25:20 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2018-01-23 01:25:20 +0000 |
commit | 0c64f5a2eba6ed11c1e04cfbb19ab8dcf0a469ed (patch) | |
tree | bd5b7b020667dfe8e148f8acb3b974090c3bbb4e | |
parent | 60ec30340ff0c9b51fd1da4b7173dc087e2a96ae (diff) | |
download | bcm5719-llvm-0c64f5a2eba6ed11c1e04cfbb19ab8dcf0a469ed.tar.gz bcm5719-llvm-0c64f5a2eba6ed11c1e04cfbb19ab8dcf0a469ed.zip |
NewPM: Add an extension point for the start of the pipeline.
This applies to most pipelines except the LTO and ThinLTO backend
actions - it is for use at the beginning of the overall pipeline.
This extension point will be used to add the GCOV pass when enabled in
Clang.
llvm-svn: 323166
-rw-r--r-- | llvm/include/llvm/Passes/PassBuilder.h | 13 | ||||
-rw-r--r-- | llvm/lib/Passes/PassBuilder.cpp | 9 | ||||
-rw-r--r-- | llvm/test/Other/new-pm-defaults.ll | 11 | ||||
-rw-r--r-- | llvm/test/Other/new-pm-thinlto-defaults.ll | 7 | ||||
-rw-r--r-- | llvm/tools/opt/NewPMDriver.cpp | 11 |
5 files changed, 47 insertions, 4 deletions
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h index b6998882625..5efcda0a1b4 100644 --- a/llvm/include/llvm/Passes/PassBuilder.h +++ b/llvm/include/llvm/Passes/PassBuilder.h @@ -19,6 +19,7 @@ #include "llvm/ADT/Optional.h" #include "llvm/Analysis/CGSCCPassManager.h" #include "llvm/IR/PassManager.h" +#include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/Scalar/LoopPassManager.h" #include <vector> @@ -476,6 +477,16 @@ public: VectorizerStartEPCallbacks.push_back(C); } + /// Register a callback for a default optimizer pipeline extension point. + /// + /// This extension point allows adding optimization once at the start of the + /// pipeline. This does not apply to 'backend' compiles (LTO and ThinLTO + /// link-time pipelines). + void registerPipelineStartEPCallback( + const std::function<void(ModulePassManager &)> &C) { + PipelineStartEPCallbacks.push_back(C); + } + /// \brief Register a callback for parsing an AliasAnalysis Name to populate /// the given AAManager \p AA void registerParseAACallback( @@ -589,6 +600,8 @@ private: SmallVector<std::function<void(FunctionPassManager &, OptimizationLevel)>, 2> VectorizerStartEPCallbacks; // Module callbacks + SmallVector<std::function<void(ModulePassManager &)>, 2> + PipelineStartEPCallbacks; SmallVector<std::function<void(ModuleAnalysisManager &)>, 2> ModuleAnalysisRegistrationCallbacks; SmallVector<std::function<bool(StringRef, ModulePassManager &, diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index c344a3165a0..07c6f55afd6 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -150,7 +150,6 @@ #include "llvm/Transforms/Vectorize/LoopVectorize.h" #include "llvm/Transforms/Vectorize/SLPVectorizer.h" - using namespace llvm; static cl::opt<unsigned> MaxDevirtIterations("pm-max-devirt-iterations", @@ -841,6 +840,10 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level, // Force any function attributes we want the rest of the pipeline to observe. MPM.addPass(ForceFunctionAttrsPass()); + // Apply module pipeline start EP callback. + for (auto &C : PipelineStartEPCallbacks) + C(MPM); + if (PGOOpt && PGOOpt->SamplePGOSupport) MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass())); @@ -867,6 +870,10 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level, if (PGOOpt && PGOOpt->SamplePGOSupport) MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass())); + // Apply module pipeline start EP callback. + for (auto &C : PipelineStartEPCallbacks) + C(MPM); + // If we are planning to perform ThinLTO later, we don't bloat the code with // unrolling/vectorization/... now. Just simplify the module as much as we // can. diff --git a/llvm/test/Other/new-pm-defaults.ll b/llvm/test/Other/new-pm-defaults.ll index 96b925f9d69..2be8fdeb06f 100644 --- a/llvm/test/Other/new-pm-defaults.ll +++ b/llvm/test/Other/new-pm-defaults.ll @@ -56,11 +56,22 @@ ; RUN: -passes='default<O3>' -S %s 2>&1 \ ; RUN: | FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK-O3 \ ; RUN: --check-prefix=CHECK-EP-VECTORIZER-START +; RUN: opt -disable-verify -debug-pass-manager \ +; RUN: -passes-ep-pipeline-start='no-op-module' \ +; RUN: -passes='default<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-pipeline-start='no-op-module' \ +; 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 ; CHECK-O: Starting llvm::Module pass manager run. ; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}> ; CHECK-O-NEXT: Starting llvm::Module pass manager run. ; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass +; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass ; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}> ; CHECK-O-NEXT: Starting llvm::Module pass manager run. ; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass diff --git a/llvm/test/Other/new-pm-thinlto-defaults.ll b/llvm/test/Other/new-pm-thinlto-defaults.ll index 077d48bb6ae..c40e46aee6e 100644 --- a/llvm/test/Other/new-pm-thinlto-defaults.ll +++ b/llvm/test/Other/new-pm-thinlto-defaults.ll @@ -15,8 +15,8 @@ ; RUN: -passes='thinlto-pre-link<O2>,name-anon-globals' -S %s 2>&1 \ ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-O2 ; RUN: opt -disable-verify -debug-pass-manager \ -; RUN: -passes='thinlto-pre-link<O3>,name-anon-globals' -S %s 2>&1 \ -; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-O3 +; RUN: -passes='thinlto-pre-link<O3>,name-anon-globals' -S -passes-ep-pipeline-start='no-op-module' %s 2>&1 \ +; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-O3,CHECK-EP-PIPELINE-START ; RUN: opt -disable-verify -debug-pass-manager \ ; RUN: -passes='thinlto-pre-link<Os>,name-anon-globals' -S %s 2>&1 \ ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-Os,CHECK-PRELINK-O,CHECK-PRELINK-O-NODIS,CHECK-PRELINK-Os @@ -34,7 +34,7 @@ ; RUN: opt -disable-verify -debug-pass-manager \ ; RUN: -passes='thinlto<O2>' -S %s 2>&1 \ ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O2,CHECK-POSTLINK-O,CHECK-POSTLINK-O2 -; RUN: opt -disable-verify -debug-pass-manager \ +; RUN: opt -disable-verify -debug-pass-manager -passes-ep-pipeline-start='no-op-module' \ ; RUN: -passes='thinlto<O3>' -S %s 2>&1 \ ; RUN: | FileCheck %s --check-prefixes=CHECK-O,CHECK-O3,CHECK-POSTLINK-O,CHECK-POSTLINK-O3 ; RUN: opt -disable-verify -debug-pass-manager \ @@ -51,6 +51,7 @@ ; CHECK-O-NEXT: Running pass: PassManager<{{.*}}Module{{.*}}> ; CHECK-O-NEXT: Starting llvm::Module pass manager run. ; CHECK-O-NEXT: Running pass: ForceFunctionAttrsPass +; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass ; CHECK-DIS-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}> ; CHECK-DIS-NEXT: Running analysis: InnerAnalysisManagerProxy ; CHECK-POSTLINK-O-NEXT: Running pass: PGOIndirectCallPromotion diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp index a3f16f2538c..bf512e0db84 100644 --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/tools/opt/NewPMDriver.cpp @@ -82,6 +82,11 @@ static cl::opt<std::string> VectorizerStartEPPipeline( cl::desc("A textual description of the function pass pipeline inserted at " "the VectorizerStart extension point into default pipelines"), cl::Hidden); +static cl::opt<std::string> PipelineStartEPPipeline( + "passes-ep-pipeline-start", + cl::desc("A textual description of the function pass pipeline inserted at " + "the PipelineStart 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, @@ -159,6 +164,12 @@ static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass, PB.parsePassPipeline(PM, VectorizerStartEPPipeline, VerifyEachPass, DebugLogging); }); + if (tryParsePipelineText<ModulePassManager>(PB, PipelineStartEPPipeline)) + PB.registerPipelineStartEPCallback( + [&PB, VerifyEachPass, DebugLogging](ModulePassManager &PM) { + PB.parsePassPipeline(PM, PipelineStartEPPipeline, VerifyEachPass, + DebugLogging); + }); } #ifdef LINK_POLLY_INTO_TOOLS |