[Mlir-commits] [mlir] 918e93b - [MLIR] Add getter for the action handler of MLIR context (#197230)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed May 13 05:48:25 PDT 2026


Author: Kigyosi Alexandru
Date: 2026-05-13T12:48:20Z
New Revision: 918e93b4dbaa444ed6a6ed31881d76787e798a5c

URL: https://github.com/llvm/llvm-project/commit/918e93b4dbaa444ed6a6ed31881d76787e798a5c
DIFF: https://github.com/llvm/llvm-project/commit/918e93b4dbaa444ed6a6ed31881d76787e798a5c.diff

LOG: [MLIR] Add getter for the action handler of MLIR context (#197230)

Current implementation of MLIRContext's action handling, requires the
user to hold the stored memory for any observer or breakpoint manager
added to the execution context. Using a getter for the registered action
handler, permits the user to store the observers and breakpoints into
MLIRContext and modify their state later, by retrieving the action
handler and invoking the functor's target. Mainly for attaching new
observers later in the compilation pipeline, after the execution context
got registered.

Added: 
    

Modified: 
    mlir/include/mlir/IR/MLIRContext.h
    mlir/lib/IR/MLIRContext.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/MLIRContext.h b/mlir/include/mlir/IR/MLIRContext.h
index 9690029256474..ab121777a1296 100644
--- a/mlir/include/mlir/IR/MLIRContext.h
+++ b/mlir/include/mlir/IR/MLIRContext.h
@@ -267,6 +267,10 @@ class MLIRContext {
   /// context. A nullptr handler can be set to disable a previously set handler.
   void registerActionHandler(HandlerTy handler);
 
+  /// Return a reference to the currently registered action handler. Its target
+  /// can be used to gain access to the handler's state, if any.
+  const HandlerTy &getActionHandler();
+
   /// Return true if a valid ActionHandler is set.
   bool hasActionHandler();
 

diff  --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp
index 7b666d11a4a89..624121c2733ba 100644
--- a/mlir/lib/IR/MLIRContext.cpp
+++ b/mlir/lib/IR/MLIRContext.cpp
@@ -380,6 +380,10 @@ void MLIRContext::registerActionHandler(HandlerTy handler) {
   getImpl().actionHandler = std::move(handler);
 }
 
+const MLIRContext::HandlerTy &MLIRContext::getActionHandler() {
+  return getImpl().actionHandler;
+}
+
 /// Dispatch the provided action to the handler if any, or just execute it.
 void MLIRContext::executeActionInternal(function_ref<void()> actionFn,
                                         const tracing::Action &action) {


        


More information about the Mlir-commits mailing list