[llvm] [PassBuilder] Add a mechanism for adding passbuilder callbacks for static builds (PR #70171)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 25 00:27:38 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
Author: William Moses (wsmoses)
<details>
<summary>Changes</summary>
Adding passbuilder callbacks presently can be done one of two ways:
* a shared library plugin
* modifying the extensions list (and thus extensions.def)
This prevents the use of such functionality for static builds on build systems that cannot be modified, as well as prevents such functionality from being usable when using llvm/clang as a library.
This creates a third mechanism for adding these callbacks, an explicit list of said callbacks. It's otherwise identical to the plugin approach, except now instead of the list of plugins each being queried for the callback function, this just runs the callback function.
---
Full diff: https://github.com/llvm/llvm-project/pull/70171.diff
4 Files Affected:
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+3)
- (modified) llvm/include/llvm/Passes/PassBuilder.h (+5)
- (modified) llvm/lib/LTO/LTOBackend.cpp (+3)
- (modified) llvm/tools/opt/NewPMDriver.cpp (+6)
``````````diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 70accce456d3c07..8dbe4d942df278d 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -909,6 +909,9 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
#define HANDLE_EXTENSION(Ext) \
get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
#include "llvm/Support/Extension.def"
+ for (auto PassCallback : ListRegisterPassBuilderCallbacks) {
+ PassCallback(PB);
+ }
// Register the target library analysis directly and give it a customized
// preset TLI.
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 2c7ceda7998eda1..d018dd1e69166f0 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -739,6 +739,11 @@ bool parseAnalysisUtilityPasses(
return false;
}
+
+//! List of pass builder callbacks to be applied, in addition to those imported
+//! from plugins or LLVM extensions.
+extern SmallVector<std::function<void(PassBuilder &)>>
+ ListRegisterPassBuilderCallbacks;
}
#endif
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index ccc4276e36dacf0..28aabf8bdebb4d6 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -187,6 +187,9 @@ static void RegisterPassPlugins(ArrayRef<std::string> PassPlugins,
#define HANDLE_EXTENSION(Ext) \
get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
#include "llvm/Support/Extension.def"
+ for (auto PassCallback : ListRegisterPassBuilderCallbacks) {
+ PassCallback(PB);
+ }
// Load requested pass plugins and let them register pass builder callbacks
for (auto &PluginFN : PassPlugins) {
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index 6ae3f87099afd64..595bc4acddee6c4 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -431,6 +431,9 @@ bool llvm::runPassPipeline(
#define HANDLE_EXTENSION(Ext) \
get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
#include "llvm/Support/Extension.def"
+ for (auto PassCallback : ListRegisterPassBuilderCallbacks) {
+ PassCallback(PB);
+ }
// Specially handle the alias analysis manager so that we can register
// a custom pipeline of AA passes with it.
@@ -546,3 +549,6 @@ void llvm::printPasses(raw_ostream &OS) {
PassBuilder PB;
PB.printPassNames(OS);
}
+
+llvm::SmallVector<std::function<void(PassBuilder &)>>
+ ListRegisterPassBuilderCallbacks;
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/70171
More information about the llvm-commits
mailing list