[Mlir-commits] [mlir] [MLIR][Transform][Python] expose transform.debug extension in Python (PR #145550)
Maksim Levental
llvmlistbot at llvm.org
Tue Jun 24 10:57:08 PDT 2025
================
@@ -0,0 +1,86 @@
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+from typing import Optional
+
+from ...ir import Attribute, Operation, Value, StringAttr
+from .._transform_debug_extension_ops_gen import *
+from .._transform_pdl_extension_ops_gen import _Dialect
+
+try:
+ from .._ods_common import _cext as _ods_cext
+except ImportError as e:
+ raise RuntimeError("Error loading imports from extension module") from e
+
+from typing import Union
+
+
+ at _ods_cext.register_operation(_Dialect, replace=True)
+class DebugEmitParamAsRemarkOp(DebugEmitParamAsRemarkOp):
+ def __init__(
+ self,
+ param: Attribute,
+ *,
+ anchor: Optional[Operation] = None,
+ message: Optional[Union[StringAttr, str]] = None,
+ loc=None,
+ ip=None,
+ ):
+ if isinstance(message, str):
+ message = StringAttr.get(message)
+
+ super().__init__(
+ param,
+ anchor=anchor,
+ message=message,
+ loc=loc,
+ ip=ip,
+ )
+
+
+def emit_param_as_remark(
+ param: Attribute,
+ *,
+ anchor: Optional[Operation] = None,
+ message: Optional[Union[StringAttr, str]] = None,
+ loc=None,
+ ip=None,
+):
+ return DebugEmitParamAsRemarkOp(
+ param, anchor=anchor, message=message, loc=loc, ip=ip
+ )
+
+del debug_emit_param_as_remark
----------------
makslevental wrote:
if you really want to do this the solution is to use [`__all__`](https://realpython.com/python-all-attribute/#preparing-your-packages-for-wildcard-imports-with-__all__) to control what's exported from this module (`del`ing the function is not the "right" way).
IMHO it's not worth the effort and I would just opt to leave as-is (with the `debug_` prefix). But it's up to you.
Though, I admit that in my downstream stuff related to `transform` I do something even more ["cursed"](https://github.com/makslevental/mlir-python-extras/blob/main/mlir/extras/dialects/ext/transform.py#L24-L64) (I rewrite the namespaces themselves so that you can do [automatically get your desired namespacing for all the transform extensions](https://github.com/makslevental/mlir-python-extras/blob/main/tests/test_transform.py#L937-L940)).
https://github.com/llvm/llvm-project/pull/145550
More information about the Mlir-commits
mailing list