[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:26:36 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:
----------------
PragmaTwice wrote:
The custom builder looks like a nice feature. However, since Python doesn’t support overloading, this might not be very intuitive. I’m thinking we could generate two classes: first a `class MyOp(OpView)`, and then a `class CustomMyOp(MyOp)` to attach any custom methods, such as `__init__` or others.
https://github.com/llvm/llvm-project/pull/169045
More information about the Mlir-commits
mailing list