[clang] [PassBuilder] Add a mechanism for adding passbuilder callbacks for static builds (PR #70171)
William Moses via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 25 01:11:26 PDT 2023
https://github.com/wsmoses updated https://github.com/llvm/llvm-project/pull/70171
>From 8b0e0939ea51768b9e1257e816556d245c91134b Mon Sep 17 00:00:00 2001
From: "William S. Moses" <gh at wsmoses.com>
Date: Wed, 25 Oct 2023 02:10:32 -0500
Subject: [PATCH] [PassBuilder] Add a mechanism for adding passbuilder
callbacks without an extension mechanism or dlopen of plugin
---
clang/lib/CodeGen/BackendUtil.cpp | 3 +++
llvm/include/llvm/Passes/PassBuilder.h | 5 +++++
llvm/lib/LTO/LTOBackend.cpp | 3 +++
llvm/lib/Passes/PassBuilder.cpp | 3 +++
llvm/tools/opt/NewPMDriver.cpp | 3 +++
5 files changed, 17 insertions(+)
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/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index fde759026e5d780..ff63988566b8649 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -2099,3 +2099,6 @@ void PassBuilder::registerParseTopLevelPipelineCallback(
&C) {
TopLevelPipelineParsingCallbacks.push_back(C);
}
+
+llvm::SmallVector<std::function<void(PassBuilder &)>>
+ ListRegisterPassBuilderCallbacks;
\ No newline at end of file
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index 6ae3f87099afd64..f072120d7461d4e 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.
More information about the cfe-commits
mailing list