[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 13 20:46:47 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:

Yes. If we consider that we may want to do some customization and extensions for dialects in the future, then defining it as a class does seem like a good idea. But at least for now, we don’t seem to have a concrete use case, so I’m a bit inclined to keep things simpler.

> where `IntegerType.get_signless(32)` does (implicitly) require a `mlir.ir.Context` to be active.

Ah, thanks for pointing that out—I hadn’t thought of it either. Yes, it does indeed require a ctx. I was thinking: if we pass a ctx when loading the dialect and then propagate it down step by step, maybe we could make it so that when defining `Is` constraints we can do something like `Is(lambda ctx: IntegerType.get(..., ctx))`. But I’m not sure whether that’s intuitive or pleasant to use.


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


More information about the Mlir-commits mailing list