This PR adds two extension points to the default LTO pipeline in PassBuilder, one at the beginning and one at the end. These two extension points already existed in the old pass manager, the aim is to replicate the same functionality in the new one.
Reviewed By: aeubanks
Differential Revision: https://reviews.llvm.org/D120491
OptimizerLastEPCallbacks.push_back(C);
}
+ /// Register a callback for a default optimizer pipeline extension point
+ ///
+ /// This extension point allows adding optimizations at the start of the full
+ /// LTO pipeline.
+ void registerFullLinkTimeOptimizationEarlyEPCallback(
+ const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
+ FullLinkTimeOptimizationEarlyEPCallbacks.push_back(C);
+ }
+
+ /// Register a callback for a default optimizer pipeline extension point
+ ///
+ /// This extension point allows adding optimizations at the end of the full
+ /// LTO pipeline.
+ void registerFullLinkTimeOptimizationLastEPCallback(
+ const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
+ FullLinkTimeOptimizationLastEPCallbacks.push_back(C);
+ }
+
/// Register a callback for parsing an AliasAnalysis Name to populate
/// the given AAManager \p AA
void registerParseAACallback(
VectorizerStartEPCallbacks;
SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
OptimizerLastEPCallbacks;
+ SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
+ FullLinkTimeOptimizationEarlyEPCallbacks;
+ SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
+ FullLinkTimeOptimizationLastEPCallbacks;
// Module callbacks
SmallVector<std::function<void(ModulePassManager &, OptimizationLevel)>, 2>
PipelineStartEPCallbacks;
// Convert @llvm.global.annotations to !annotation metadata.
MPM.addPass(Annotation2MetadataPass());
+ for (auto &C : FullLinkTimeOptimizationEarlyEPCallbacks)
+ C(MPM, Level);
+
// Create a function that performs CFI checks for cross-DSO calls with targets
// in the current module.
MPM.addPass(CrossDSOCFIPass());
// in ICP.
MPM.addPass(LowerTypeTestsPass(nullptr, nullptr, true));
+ for (auto &C : FullLinkTimeOptimizationLastEPCallbacks)
+ C(MPM, Level);
+
// Emit annotation remarks.
addAnnotationRemarksPass(MPM);
// pipeline).
MPM.addPass(LowerTypeTestsPass(nullptr, nullptr, true));
+ for (auto &C : FullLinkTimeOptimizationLastEPCallbacks)
+ C(MPM, Level);
+
// Emit annotation remarks.
addAnnotationRemarksPass(MPM);
if (PTO.MergeFunctions)
MPM.addPass(MergeFunctionsPass());
+ for (auto &C : FullLinkTimeOptimizationLastEPCallbacks)
+ C(MPM, Level);
+
// Emit annotation remarks.
addAnnotationRemarksPass(MPM);
; RUN: opt -disable-output -debug-pass-manager -passes-ep-pipeline-start=no-op-module -passes='default<O0>' 2>&1 < %s | FileCheck %s
; RUN: opt -disable-output -debug-pass-manager -passes-ep-pipeline-early-simplification=no-op-module -passes='default<O0>' 2>&1 < %s | FileCheck %s
; RUN: opt -disable-output -debug-pass-manager -passes-ep-optimizer-last=no-op-function -passes='default<O0>' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-full-link-time-optimization-early=no-op-module -passes='lto<O0>' 2>&1 < %s | FileCheck %s
+; RUN: opt -disable-output -debug-pass-manager -passes-ep-full-link-time-optimization-last=no-op-module -passes='lto<O0>' 2>&1 < %s | FileCheck %s
; CHECK: Running pass: NoOp
; RUN: -passes='lto<O1>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK-O1
; RUN: opt -disable-verify -verify-cfg-preserved=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
+; RUN: -passes='lto<O1>' -S %s -passes-ep-full-link-time-optimization-early=no-op-module \
+; RUN: -passes-ep-full-link-time-optimization-last=no-op-module 2>&1 \
+; RUN: | FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK-O1 --check-prefix=CHECK-EP
+; RUN: opt -disable-verify -verify-cfg-preserved=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
; RUN: -passes='lto<O2>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK-O23SZ \
; RUN: --check-prefix=CHECK-O2
; RUN: opt -disable-verify -verify-cfg-preserved=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
+; RUN: -passes='lto<O2>' -S %s -passes-ep-full-link-time-optimization-early=no-op-module \
+; RUN: -passes-ep-full-link-time-optimization-last=no-op-module 2>&1 \
+; RUN: | FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK-O23SZ \
+; RUN: --check-prefix=CHECK-O2 --check-prefix=CHECK-EP
+; RUN: opt -disable-verify -verify-cfg-preserved=0 -eagerly-invalidate-analyses=0 -debug-pass-manager \
; RUN: -passes='lto<O3>' -S %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=CHECK-O --check-prefix=CHECK-O23SZ \
; RUN: --check-prefix=CHECK-O3
; RUN: --check-prefix=CHECK-O3 --check-prefix=CHECK-EP-Peephole
; CHECK-O: Running pass: Annotation2Metadata
+; CHECK-EP-NEXT: Running pass: NoOpModulePass
; CHECK-O-NEXT: Running pass: CrossDSOCFIPass
; CHECK-O-NEXT: Running pass: OpenMPOptPass
; CHECK-O-NEXT: Running pass: GlobalDCEPass
; CHECK-O23SZ-NEXT: Running pass: SimplifyCFGPass
; CHECK-O23SZ-NEXT: Running pass: EliminateAvailableExternallyPass
; CHECK-O23SZ-NEXT: Running pass: GlobalDCEPass
+; CHECK-EP-NEXT: Running pass: NoOpModulePass
; CHECK-O-NEXT: Running pass: AnnotationRemarksPass on foo
; CHECK-O-NEXT: Running pass: PrintModulePass
cl::desc("A textual description of the module pass pipeline inserted at "
"the OptimizerLast extension point into default pipelines"),
cl::Hidden);
+static cl::opt<std::string> FullLinkTimeOptimizationEarlyEPPipeline(
+ "passes-ep-full-link-time-optimization-early",
+ cl::desc("A textual description of the module pass pipeline inserted at "
+ "the FullLinkTimeOptimizationEarly extension point into default "
+ "pipelines"),
+ cl::Hidden);
+static cl::opt<std::string> FullLinkTimeOptimizationLastEPPipeline(
+ "passes-ep-full-link-time-optimization-last",
+ cl::desc("A textual description of the module pass pipeline inserted at "
+ "the FullLinkTimeOptimizationLast extension point into default "
+ "pipelines"),
+ cl::Hidden);
// Individual pipeline tuning options.
extern cl::opt<bool> DisableLoopUnrolling;
ExitOnError Err("Unable to parse OptimizerLastEP pipeline: ");
Err(PB.parsePassPipeline(PM, OptimizerLastEPPipeline));
});
+ if (tryParsePipelineText<ModulePassManager>(
+ PB, FullLinkTimeOptimizationEarlyEPPipeline))
+ PB.registerFullLinkTimeOptimizationEarlyEPCallback(
+ [&PB](ModulePassManager &PM, OptimizationLevel) {
+ ExitOnError Err(
+ "Unable to parse FullLinkTimeOptimizationEarlyEP pipeline: ");
+ Err(PB.parsePassPipeline(PM,
+ FullLinkTimeOptimizationEarlyEPPipeline));
+ });
+ if (tryParsePipelineText<ModulePassManager>(
+ PB, FullLinkTimeOptimizationLastEPPipeline))
+ PB.registerFullLinkTimeOptimizationLastEPCallback(
+ [&PB](ModulePassManager &PM, OptimizationLevel) {
+ ExitOnError Err(
+ "Unable to parse FullLinkTimeOptimizationLastEP pipeline: ");
+ Err(PB.parsePassPipeline(PM, FullLinkTimeOptimizationLastEPPipeline));
+ });
}
#define HANDLE_EXTENSION(Ext) \