[Mlir-commits] [mlir] [MLIR][Python] Add a DSL for defining IRDL dialects in Python bindings (PR #169045)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Dec 6 19:22:31 PST 2025


================
@@ -0,0 +1,308 @@
+# RUN: %PYTHON %s 2>&1 | FileCheck %s
+
+from mlir.ir import *
+from mlir.dialects.irdl import dsl as irdsl
+from mlir.dialects import arith
+import sys
+
+
+def run(f):
+    print("\nTEST:", f.__name__, file=sys.stderr)
+    with Context():
+        f()
+
+
+# CHECK: TEST: testMyInt
+ at run
+def testMyInt():
+    myint = irdsl.Dialect("myint")
+    iattr = irdsl.BaseName("#builtin.integer")
+    i32 = irdsl.IsType(IntegerType.get_signless(32))
+
+    @myint.op("constant")
+    class ConstantOp:
+        value = irdsl.Attribute(iattr)
+        cst = irdsl.Result(i32)
----------------
PragmaTwice wrote:

This seems to involve two things:

1. Making the op name a class member. I don’t have any strong opinion on this; it’s probably better to stay as consistent with xdsl as possible.
2. Inheritance: at the moment, the generated classes all inherit from `OpView`. If they’re supposed to inherit from `irdsl.Operation`, I’m not sure what is actually expected to live there. Also, if the user forgets to inherit from this class or inherits from some other class, how should the decorator handle that?


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


More information about the Mlir-commits mailing list