diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h --- a/llvm/include/llvm/Passes/PassBuilder.h +++ b/llvm/include/llvm/Passes/PassBuilder.h @@ -470,6 +470,15 @@ const std::function &C) { FullLinkTimeOptimizationEarlyEPCallbacks.push_back(C); } + + /// Register a callback for a default optimizer pipeline extension point + /// + /// This extension point allows adding optimizations at the module level before + /// any loop optimizations are run. + void registerFullLinkTimeOptimizatioBeforeLoopEPCallback( + const std::function &C) { + FullLinkTimeOptimizationBeforeLoopEPCallbacks.push_back(C); + } /// Register a callback for a default optimizer pipeline extension point /// @@ -576,6 +585,8 @@ OptimizationLevel Level); void invokeFullLinkTimeOptimizationEarlyEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level); + void invokeFullLinkTimeOptimizationBeforeLoopEPCallbacks(ModulePassManager &MPM, + OptimizationLevel Level); void invokeFullLinkTimeOptimizationLastEPCallbacks(ModulePassManager &MPM, OptimizationLevel Level); void invokePipelineStartEPCallbacks(ModulePassManager &MPM, @@ -638,6 +649,8 @@ OptimizerLastEPCallbacks; SmallVector, 2> FullLinkTimeOptimizationEarlyEPCallbacks; + SmallVector, 2> + FullLinkTimeOptimizationBeforeLoopEPCallbacks; SmallVector, 2> FullLinkTimeOptimizationLastEPCallbacks; SmallVector, 2> diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -340,6 +340,11 @@ for (auto &C : FullLinkTimeOptimizationEarlyEPCallbacks) C(MPM, Level); } +void PassBuilder::invokeFullLinkTimeOptimizationBeforeLoopEPCallbacks( + ModulePassManager &MPM, OptimizationLevel Level) { + for (auto &C : FullLinkTimeOptimizationBeforeLoopEPCallbacks) + C(MPM, Level); +} void PassBuilder::invokeFullLinkTimeOptimizationLastEPCallbacks( ModulePassManager &MPM, OptimizationLevel Level) { for (auto &C : FullLinkTimeOptimizationLastEPCallbacks) @@ -1794,6 +1799,9 @@ // Require the GlobalsAA analysis for the module so we can query it within // MainFPM. MPM.addPass(RequireAnalysisPass()); + + invokeFullLinkTimeOptimizationBeforeLoopEPCallbacks(MPM, Level); + // Invalidate AAManager so it can be recreated and pick up the newly available // GlobalsAA. MPM.addPass(