[Mlir-commits] [mlir] [MLIR][Python] Add a DSL for defining IRDL dialects in Python bindings (PR #169045)
Sasha Lopoukhine
llvmlistbot at llvm.org
Sat Dec 6 00:36:42 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)
----------------
superlopuh wrote:
We added this inheritance mechanism for convenience of op definitions, it allows one to use the natural way of extending operations by implementing the interface's abstract methods. One of the reasons not to modify the mro of a class is that it would mess with method resolution in ways that are hard to reason about. It would also not be a good idea from the perspective of trying to make xDSL approachable.
https://github.com/llvm/llvm-project/pull/169045
More information about the Mlir-commits
mailing list