[llvm] [LTO] Add a hook to customize the optimization pipeline (PR #71268)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 3 20:32:42 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lto
Author: Igor Kudrin (igorkudrin)
<details>
<summary>Changes</summary>
The hook allows the calling code to register instrumentation callbacks for the LTO optimization pipeline. In particular, a custom pass filter can be added to skip certain passes from the default pipeline.
---
Full diff: https://github.com/llvm/llvm-project/pull/71268.diff
2 Files Affected:
- (modified) llvm/include/llvm/LTO/Config.h (+5)
- (modified) llvm/lib/LTO/LTOBackend.cpp (+2)
``````````diff
diff --git a/llvm/include/llvm/LTO/Config.h b/llvm/include/llvm/LTO/Config.h
index 6fb55f1cf1686a5..fd22c17bc12a38c 100644
--- a/llvm/include/llvm/LTO/Config.h
+++ b/llvm/include/llvm/LTO/Config.h
@@ -257,6 +257,11 @@ struct Config {
const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols)>;
CombinedIndexHookFn CombinedIndexHook;
+ /// This hook is called when the optimization pipeline is being built.
+ using CustomizeOptPipelineHookFn =
+ std::function<void(PassInstrumentationCallbacks &)>;
+ CustomizeOptPipelineHookFn CustomizeOptPipeline;
+
/// This is a convenience function that configures this Config object to write
/// temporary files named after the given OutputFileName for each of the LTO
/// phases to disk. A client can use this function to implement -save-temps.
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index ccc4276e36dacf0..7e1b35319a71d59 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -265,6 +265,8 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
ModuleAnalysisManager MAM;
PassInstrumentationCallbacks PIC;
+ if (Conf.CustomizeOptPipeline)
+ Conf.CustomizeOptPipeline(PIC);
StandardInstrumentations SI(Mod.getContext(), Conf.DebugPassManager,
Conf.VerifyEach);
SI.registerCallbacks(PIC, &MAM);
``````````
</details>
https://github.com/llvm/llvm-project/pull/71268
More information about the llvm-commits
mailing list