[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
This commit is contained in:
Arthur Eubanks 2020-11-04 10:14:37 -08:00
parent c29c24be63
commit 7a83aa0520
4 changed files with 16 additions and 14 deletions

View File

@ -587,7 +587,7 @@ public:
/// 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 @@ private:
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;

View File

@ -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

View File

@ -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)));

View File

@ -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) {