[llvm] [CodeGen] Expose the extensibility of PassConfig to plugins (PR #139059)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 2 10:06:26 PDT 2025


================
@@ -119,6 +125,9 @@ class TargetMachine {
   std::optional<PGOOptions> PGOOption;
 
 public:
+  static ManagedStatic<SmallVector<PassConfigCallback, 1>>
+      TargetPassConfigCallbacks;
----------------
Tcc100 wrote:

I didn't use `ManagedStatic` to move the vector within the class but to solve the lifetime issue. The callbacks from the plugin must be unregistered before the shared object is unloaded. `ManagedStatic` was the straightforward way to solve this as `ManagedStatic`s are cleared right after LLVM finished.

I now adopted the cleaner way of other LLVM registries that bind the lifetime of the registration to the plugin using an object created in the plugin. This introduces the `RegisterTargetPassConfigCallback` class that automatically unregisters the callback when the plugin is unloaded.
I also created an invoke method and updated the examples accordingly. Please let me know if this fits your intent.


https://github.com/llvm/llvm-project/pull/139059


More information about the llvm-commits mailing list