[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
Sun Dec 21 23:32:14 PST 2025


================
@@ -0,0 +1,300 @@
+# 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.Is(IntegerType.get_signless(32))
+
+    class ConstantOp(myint.Operation, name="constant"):
----------------
PragmaTwice wrote:

Now this problem is solved.

TLDR:
```python
i32 = irdsl.Is[IntegerType.get_signless](32)
f32 = irdsl.Is[F32Type]
```

Now we lazily construct Attributes or Types. We introduce a function via `Is[callable]`, and optionally pre-fill some arguments via `Is[callable](optional args)`, then we defer construction until the `Context` is available. Note that `Is[F32Type]` works because `.get` can be omitted.


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


More information about the Mlir-commits mailing list