[clang] ab0ddbc - Reland [NewPM] Add OptimizationLevel param to registerPipelineStartEPCallback
Arthur Eubanks via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 4 13:13:09 PST 2020
Author: Arthur Eubanks
Date: 2020-11-04T13:11:40-08:00
New Revision: ab0ddbc38af9508ee0f753fb897d9050025a0763
URL: https://github.com/llvm/llvm-project/commit/ab0ddbc38af9508ee0f753fb897d9050025a0763
DIFF: https://github.com/llvm/llvm-project/commit/ab0ddbc38af9508ee0f753fb897d9050025a0763.diff
LOG: Reland [NewPM] Add OptimizationLevel param to registerPipelineStartEPCallback
This allows targets to skip optional optimization passes at -O0.
Reviewed By: ychen
Differential Revision: https://reviews.llvm.org/D90777
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/Passes/PassBuilder.h
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Target/BPF/BPFTargetMachine.cpp
llvm/tools/opt/NewPMDriver.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 1c1068135bb2..81ae79482d90 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1302,16 +1302,18 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
// test assume sequences inserted for whole program vtables so that
// codegen doesn't complain.
if (!CodeGenOpts.ThinLTOIndexFile.empty())
- PB.registerPipelineStartEPCallback([](ModulePassManager &MPM) {
- MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr,
- /*ImportSummary=*/nullptr,
- /*DropTypeTests=*/true));
- });
-
- PB.registerPipelineStartEPCallback([](ModulePassManager &MPM) {
- MPM.addPass(createModuleToFunctionPassAdaptor(
- EntryExitInstrumenterPass(/*PostInlining=*/false)));
- });
+ PB.registerPipelineStartEPCallback(
+ [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
+ MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr,
+ /*ImportSummary=*/nullptr,
+ /*DropTypeTests=*/true));
+ });
+
+ PB.registerPipelineStartEPCallback(
+ [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
+ MPM.addPass(createModuleToFunctionPassAdaptor(
+ EntryExitInstrumenterPass(/*PostInlining=*/false)));
+ });
// Register callbacks to schedule sanitizer passes at the appropriate part of
// the pipeline.
@@ -1394,14 +1396,18 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
}
if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts, LangOpts))
- PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
- MPM.addPass(GCOVProfilerPass(*Options));
- });
+ PB.registerPipelineStartEPCallback(
+ [Options](ModulePassManager &MPM,
+ PassBuilder::OptimizationLevel Level) {
+ MPM.addPass(GCOVProfilerPass(*Options));
+ });
if (Optional<InstrProfOptions> Options =
getInstrProfOptions(CodeGenOpts, LangOpts))
- PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
- MPM.addPass(InstrProfiling(*Options, false));
- });
+ PB.registerPipelineStartEPCallback(
+ [Options](ModulePassManager &MPM,
+ PassBuilder::OptimizationLevel Level) {
+ MPM.addPass(InstrProfiling(*Options, false));
+ });
if (IsThinLTO) {
MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level);
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 356b70d368bb..31c4782eaba3 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -587,7 +587,7 @@ class PassBuilder {
/// pipeline. This does not apply to 'backend' compiles (LTO and ThinLTO
/// link-time pipelines).
void registerPipelineStartEPCallback(
- const std::function<void(ModulePassManager &)> &C) {
+ const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
PipelineStartEPCallbacks.push_back(C);
}
@@ -722,7 +722,7 @@ class PassBuilder {
SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
OptimizerLastEPCallbacks;
// Module callbacks
- SmallVector<std::function<void(ModulePassManager &)>, 2>
+ SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
PipelineStartEPCallbacks;
SmallVector<std::function<void(ModuleAnalysisManager &)>, 2>
ModuleAnalysisRegistrationCallbacks;
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index fd16bedc70aa..68bbb01d1fda 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -1319,7 +1319,7 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
// Apply module pipeline start EP callback.
for (auto &C : PipelineStartEPCallbacks)
- C(MPM);
+ C(MPM, Level);
if (PGOOpt && PGOOpt->SamplePGOSupport)
MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
@@ -1348,7 +1348,7 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
// Apply module pipeline start EP callback.
for (auto &C : PipelineStartEPCallbacks)
- C(MPM);
+ C(MPM, Level);
// 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
diff --git a/llvm/lib/Target/BPF/BPFTargetMachine.cpp b/llvm/lib/Target/BPF/BPFTargetMachine.cpp
index 7ef35105083f..25fccea256f1 100644
--- a/llvm/lib/Target/BPF/BPFTargetMachine.cpp
+++ b/llvm/lib/Target/BPF/BPFTargetMachine.cpp
@@ -125,12 +125,13 @@ void BPFTargetMachine::adjustPassManager(PassManagerBuilder &Builder) {
void BPFTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB,
bool DebugPassManager) {
- PB.registerPipelineStartEPCallback([=](ModulePassManager &MPM) {
- FunctionPassManager FPM(DebugPassManager);
- FPM.addPass(BPFAbstractMemberAccessPass(this));
- FPM.addPass(BPFPreserveDITypePass());
- MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
- });
+ PB.registerPipelineStartEPCallback(
+ [=](ModulePassManager &MPM, PassBuilder::OptimizationLevel) {
+ FunctionPassManager FPM(DebugPassManager);
+ FPM.addPass(BPFAbstractMemberAccessPass(this));
+ FPM.addPass(BPFPreserveDITypePass());
+ MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
+ });
PB.registerPeepholeEPCallback([=](FunctionPassManager &FPM,
PassBuilder::OptimizationLevel Level) {
FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions().hoistCommonInsts(true)));
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index 609f64ca76b7..6d134afc96c3 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -190,10 +190,11 @@ static void registerEPCallbacks(PassBuilder &PB) {
Err(PB.parsePassPipeline(PM, VectorizerStartEPPipeline));
});
if (tryParsePipelineText<ModulePassManager>(PB, PipelineStartEPPipeline))
- PB.registerPipelineStartEPCallback([&PB](ModulePassManager &PM) {
- ExitOnError Err("Unable to parse PipelineStartEP pipeline: ");
- Err(PB.parsePassPipeline(PM, PipelineStartEPPipeline));
- });
+ PB.registerPipelineStartEPCallback(
+ [&PB](ModulePassManager &PM, PassBuilder::OptimizationLevel) {
+ ExitOnError Err("Unable to parse PipelineStartEP pipeline: ");
+ Err(PB.parsePassPipeline(PM, PipelineStartEPPipeline));
+ });
if (tryParsePipelineText<FunctionPassManager>(PB, OptimizerLastEPPipeline))
PB.registerOptimizerLastEPCallback(
[&PB](ModulePassManager &PM, PassBuilder::OptimizationLevel) {
More information about the cfe-commits
mailing list