Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit 7442670

Browse files
authored
[MLIR][Transform] expose transform.debug extension in Python (#145550)
Removes the Debug... prefix on the ops in tablegen, in line with pretty much all other Transform-dialect extension ops. This means that the ops in Python look like `debug.EmitParamAsRemarkOp`/`debug.emit_param_as_remark` instead of `debug.DebugEmitParamAsRemarkOp`/`debug.debug_emit_param_as_remark`.
1 parent 78fbf0c commit 7442670

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

mlir/python/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
171171
DIALECT_NAME transform
172172
EXTENSION_NAME transform_pdl_extension)
173173

174+
declare_mlir_dialect_extension_python_bindings(
175+
ADD_TO_PARENT MLIRPythonSources.Dialects
176+
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
177+
TD_FILE dialects/TransformDebugExtensionOps.td
178+
SOURCES
179+
dialects/transform/debug.py
180+
DIALECT_NAME transform
181+
EXTENSION_NAME transform_debug_extension)
182+
174183
declare_mlir_dialect_python_bindings(
175184
ADD_TO_PARENT MLIRPythonSources.Dialects
176185
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- TransformDebugExtensionOps.td - Binding entry point *- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Entry point of the generated Python bindings for the Debug extension of the
10+
// Transform dialect.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef PYTHON_BINDINGS_TRANSFORM_DEBUG_EXTENSION_OPS
15+
#define PYTHON_BINDINGS_TRANSFORM_DEBUG_EXTENSION_OPS
16+
17+
include "mlir/Dialect/Transform/DebugExtension/DebugExtensionOps.td"
18+
19+
#endif // PYTHON_BINDINGS_TRANSFORM_DEBUG_EXTENSION_OPS
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
from typing import Optional
6+
7+
from ...ir import Attribute, Operation, Value, StringAttr
8+
from .._transform_debug_extension_ops_gen import *
9+
from .._transform_pdl_extension_ops_gen import _Dialect
10+
11+
try:
12+
from .._ods_common import _cext as _ods_cext
13+
except ImportError as e:
14+
raise RuntimeError("Error loading imports from extension module") from e
15+
16+
from typing import Union
17+
18+
19+
@_ods_cext.register_operation(_Dialect, replace=True)
20+
class EmitParamAsRemarkOp(EmitParamAsRemarkOp):
21+
def __init__(
22+
self,
23+
param: Attribute,
24+
*,
25+
anchor: Optional[Operation] = None,
26+
message: Optional[Union[StringAttr, str]] = None,
27+
loc=None,
28+
ip=None,
29+
):
30+
if isinstance(message, str):
31+
message = StringAttr.get(message)
32+
33+
super().__init__(
34+
param,
35+
anchor=anchor,
36+
message=message,
37+
loc=loc,
38+
ip=ip,
39+
)
40+
41+
42+
def emit_param_as_remark(
43+
param: Attribute,
44+
*,
45+
anchor: Optional[Operation] = None,
46+
message: Optional[Union[StringAttr, str]] = None,
47+
loc=None,
48+
ip=None,
49+
):
50+
return EmitParamAsRemarkOp(param, anchor=anchor, message=message, loc=loc, ip=ip)
51+
52+
53+
@_ods_cext.register_operation(_Dialect, replace=True)
54+
class EmitRemarkAtOp(EmitRemarkAtOp):
55+
def __init__(
56+
self,
57+
at: Union[Operation, Value],
58+
message: Optional[Union[StringAttr, str]] = None,
59+
*,
60+
loc=None,
61+
ip=None,
62+
):
63+
if isinstance(message, str):
64+
message = StringAttr.get(message)
65+
66+
super().__init__(
67+
at,
68+
message,
69+
loc=loc,
70+
ip=ip,
71+
)
72+
73+
74+
def emit_remark_at(
75+
at: Union[Operation, Value],
76+
message: Optional[Union[StringAttr, str]] = None,
77+
*,
78+
loc=None,
79+
ip=None,
80+
):
81+
return EmitRemarkAtOp(at, message, loc=loc, ip=ip)

0 commit comments

Comments
 (0)