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

Rolf Morel llvmlistbot at llvm.org
Fri Dec 5 11:49:00 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)
----------------
rolfmorel wrote:

Had a look just now: in xDSL one can add traits as a member of the op definition: https://github.com/xdslproject/xdsl/blob/56e89d375e4bdf2a4e8301996c2fc2639668b792/xdsl/dialects/builtin.py#L2267-L2272

At the same time, xDSL (though not IRDL) also has the notion of interfaces: https://github.com/xdslproject/xdsl/blob/main/xdsl/interfaces.py which can be inherited: https://github.com/xdslproject/xdsl/blob/56e89d375e4bdf2a4e8301996c2fc2639668b792/xdsl/dialects/arith.py#L140

I believe @superlopuh was making the argument that the list of traits mechanism allows for late-binding of traits in a more natural way than modifying the classes an op subclasses _after_ the op ('s class) has been defined.

Could someone from the xDSL side comment on the value of inheritance? @superlopuh @math-fehr @Moxinilian 

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


More information about the Mlir-commits mailing list