[llvm] [CodeGen] Expose the extensibility of PassConfig to plugins (PR #139059)
Stefan Gränitz via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 3 03:47:03 PDT 2025
================
@@ -531,6 +532,39 @@ class LLVM_ABI TargetMachine {
}
};
+using PassConfigCallback =
+ std::function<void(TargetMachine &, PassManagerBase &, TargetPassConfig *)>;
+
+class TargetPassConfigCallbackRegistry : public PassConfigCallback {
+protected:
+ static SmallVector<PassConfigCallback *, 1> Callbacks;
+
+ explicit TargetPassConfigCallbackRegistry(PassConfigCallback &&C)
+ : PassConfigCallback(std::move(C)) {}
+
+public:
+ static void invokeCallbacks(TargetMachine &TM, PassManagerBase &PM,
+ TargetPassConfig *PassConfig) {
+ for (const PassConfigCallback *C : Callbacks)
+ (*C)(TM, PM, PassConfig);
+ }
----------------
weliveindetail wrote:
Do we need a registry? IIUC this could a simple freestanding function that is declared here and defined in the cpp (where you have the static member init right now). Maybe let the name express it, like `invokeGlobalTargetPassConfigCallbacks(...)`? We don't need the callbacks vector here in the header. It should be a global `ManagedStatic` then (instead of the static member init).
https://github.com/llvm/llvm-project/pull/139059
More information about the llvm-commits
mailing list