[Mlir-commits] [mlir] [mlir][python] Enable python bindings for Index dialect (PR #85827)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Tue Mar 19 10:23:18 PDT 2024


================
@@ -0,0 +1,335 @@
+# RUN: %PYTHON %s | FileCheck %s
+
+from mlir.ir import *
+from mlir.dialects import index, arith
+
+
+def run(f):
+  print("\nTEST:", f.__name__)
+  f()
+
+
+# CHECK-LABEL: TEST: testConstantOp
+ at run
+def testConstantOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+    # CHECK: %[[A:.*]] = index.constant 42
+    print(module)
+
+
+# CHECK-LABEL: TEST: testBoolConstantOp
+ at run
+def testBoolConstantOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.BoolConstantOp(value=True)
+    # CHECK: %[[A:.*]] = index.bool.constant true
+    print(module)
+
+
+# CHECK-LABEL: TEST: testAndOp
+ at run
+def testAndOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      r = index.AndOp(a, a)
+    # CHECK: %[[R:.*]] = index.and {{.*}}, {{.*}}
----------------
ftynse wrote:

Nit: prefer the `%{{.*}}` form as it makes tests slightly more understandable.

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


More information about the Mlir-commits mailing list