[Mlir-commits] [mlir] [MLIR][mlir-opt] move action debugger hook flag (PR #134842)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Apr 8 04:37:36 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Christopher McGirr (chrsmcgrr)

<details>
<summary>Changes</summary>

Currently if a developer uses the flag `--mlir-enable-debugger-hook` the debugger hook is not actually enabled. It seems the DebugConfig and the MainMLIROptConfig are not connected.

To fix this we can move the `enableDebuggerHook` CL Option to the DebugConfigCLOptions struct so that it can get registered and enabled along with the other debugger flags. AFAICS there are no other uses of the flag so this should be safe.

This also adds a small LIT test to check that the hook is enabled by checking the std::cerr output for the log message.

---
Full diff: https://github.com/llvm/llvm-project/pull/134842.diff


4 Files Affected:

- (modified) mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h (-3) 
- (modified) mlir/lib/Debug/CLOptionsSetup.cpp (+5) 
- (modified) mlir/lib/Tools/mlir-opt/MlirOptMain.cpp (-5) 
- (added) mlir/test/mlir-opt/debuggerhook.mlir (+9) 


``````````diff
diff --git a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
index 09bd86b9581df..af379797fe865 100644
--- a/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
+++ b/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h
@@ -238,9 +238,6 @@ class MlirOptMainConfig {
   /// Elide resources when generating bytecode.
   bool elideResourceDataFromBytecodeFlag = false;
 
-  /// Enable the Debugger action hook: Debugger can intercept MLIR Actions.
-  bool enableDebuggerActionHookFlag = false;
-
   /// IRDL file to register before processing the input.
   std::string irdlFileFlag = "";
 
diff --git a/mlir/lib/Debug/CLOptionsSetup.cpp b/mlir/lib/Debug/CLOptionsSetup.cpp
index 340055adf5aab..cb0b0e5c375e0 100644
--- a/mlir/lib/Debug/CLOptionsSetup.cpp
+++ b/mlir/lib/Debug/CLOptionsSetup.cpp
@@ -64,6 +64,11 @@ struct DebugConfigCLOptions : public DebugConfig {
           auto [file, line, col] = *locBreakpoint;
           locBreakpointManager.addBreakpoint(file, line, col);
         }));
+
+    static cl::opt<bool, /*ExternalStorage=*/true> enableDebuggerHook(
+        "mlir-enable-debugger-hook",
+        cl::desc("Enable Debugger hook for debugging MLIR Actions"),
+        cl::location(enableDebuggerActionHookFlag), cl::init(false));
   }
   tracing::FileLineColLocBreakpointManager locBreakpointManager;
 };
diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index 9bbf91de18305..2924a1205f574 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -126,11 +126,6 @@ struct MlirOptMainConfigCLOptions : public MlirOptMainConfig {
         "mlir-disable-diagnostic-notes", cl::desc("Disable diagnostic notes."),
         cl::location(disableDiagnosticNotesFlag), cl::init(false));
 
-    static cl::opt<bool, /*ExternalStorage=*/true> enableDebuggerHook(
-        "mlir-enable-debugger-hook",
-        cl::desc("Enable Debugger hook for debugging MLIR Actions"),
-        cl::location(enableDebuggerActionHookFlag), cl::init(false));
-
     static cl::opt<bool, /*ExternalStorage=*/true> explicitModule(
         "no-implicit-module",
         cl::desc("Disable implicit addition of a top-level module op during "
diff --git a/mlir/test/mlir-opt/debuggerhook.mlir b/mlir/test/mlir-opt/debuggerhook.mlir
new file mode 100644
index 0000000000000..54f1bf98d66df
--- /dev/null
+++ b/mlir/test/mlir-opt/debuggerhook.mlir
@@ -0,0 +1,9 @@
+// Checks that the debugger hook is enabled when called with the CLI option.
+// RUN: mlir-opt %s --mlir-enable-debugger-hook --pass-pipeline="builtin.module(func.func(canonicalize))" --mlir-disable-threading 2>&1 | FileCheck %s
+
+func.func @foo() {
+    return
+}
+
+// CHECK: ExecutionContext registered on the context
+// CHECK-SAME:  (with Debugger hook)

``````````

</details>


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


More information about the Mlir-commits mailing list