[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:44:59 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:
----------------
superlopuh wrote:
Just for some context, it would be relatively straightforward to synthesize an init per class, but I don't know of a way to make Pyright aware of it. I'm not sure if you've come across it, but we've also implemented a rudimentary way to import IRDL in Python directly, as if it were defined in Python. We generate type stubs for Pyright, which is where such an auto-generated constructor could be typed. I do see people routinely write bugs in the op inits, it would be quite nice to have a better mechanism to do some checks here.
https://github.com/llvm/llvm-project/pull/169045
More information about the Mlir-commits
mailing list