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

Steven Varoumas llvmlistbot at llvm.org
Tue Mar 19 10:23:36 PDT 2024


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

>From 6eba9fd6e3ba161aa44e2fd2ff9d09a0c1a08ae7 Mon Sep 17 00:00:00 2001
From: Steven Varoumas <steven.varoumas1 at huawei.com>
Date: Wed, 20 Mar 2024 00:55:12 +0800
Subject: [PATCH 1/2] [mlir][python] Enable python bindings for Index dialect

---
 mlir/python/CMakeLists.txt                 |   9 +
 mlir/python/mlir/dialects/IndexOps.td      |  14 +
 mlir/python/mlir/dialects/index.py         |   6 +
 mlir/test/python/dialects/index_dialect.py | 335 +++++++++++++++++++++
 4 files changed, 364 insertions(+)
 create mode 100644 mlir/python/mlir/dialects/IndexOps.td
 create mode 100644 mlir/python/mlir/dialects/index.py
 create mode 100644 mlir/test/python/dialects/index_dialect.py

diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt
index 563d035f155267..c27ee688a04087 100644
--- a/mlir/python/CMakeLists.txt
+++ b/mlir/python/CMakeLists.txt
@@ -108,6 +108,15 @@ declare_mlir_dialect_python_bindings(
     dialects/complex.py
   DIALECT_NAME complex)
 
+declare_mlir_dialect_python_bindings(
+  ADD_TO_PARENT MLIRPythonSources.Dialects
+  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
+  TD_FILE dialects/IndexOps.td
+  SOURCES
+    dialects/index.py
+  DIALECT_NAME index
+  GEN_ENUM_BINDINGS)
+
 declare_mlir_dialect_python_bindings(
   ADD_TO_PARENT MLIRPythonSources.Dialects
   ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
diff --git a/mlir/python/mlir/dialects/IndexOps.td b/mlir/python/mlir/dialects/IndexOps.td
new file mode 100644
index 00000000000000..f98e4698f22e12
--- /dev/null
+++ b/mlir/python/mlir/dialects/IndexOps.td
@@ -0,0 +1,14 @@
+//===-- IndexOps.td - Entry point for Index bindings -----*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef PYTHON_BINDINGS_INDEX_OPS
+#define PYTHON_BINDINGS_INDEX_OPS
+
+include "mlir/Dialect/Index/IR/IndexOps.td"
+
+#endif
diff --git a/mlir/python/mlir/dialects/index.py b/mlir/python/mlir/dialects/index.py
new file mode 100644
index 00000000000000..73708c7d71a8c8
--- /dev/null
+++ b/mlir/python/mlir/dialects/index.py
@@ -0,0 +1,6 @@
+#  Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+#  See https://llvm.org/LICENSE.txt for license information.
+#  SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+from ._index_ops_gen import *
+from ._index_enum_gen import *
diff --git a/mlir/test/python/dialects/index_dialect.py b/mlir/test/python/dialects/index_dialect.py
new file mode 100644
index 00000000000000..f2e7071a53f04f
--- /dev/null
+++ b/mlir/test/python/dialects/index_dialect.py
@@ -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 {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testOrOp
+ at run
+def testOrOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      r = index.OrOp(a, a)
+    # CHECK: %[[R:.*]] = index.or {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testXOrOp
+ at run
+def testXOrOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      r = index.XOrOp(a, a)
+    # CHECK: %[[R:.*]] = index.xor {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testCastSOp
+ at run
+def testCastSOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      b = arith.ConstantOp(value=23, result=IntegerType.get_signless(64))
+      c = index.CastSOp(input=a, output=IntegerType.get_signless(32))
+      d = index.CastSOp(input=b, output=IndexType.get())
+    # CHECK: %[[C:.*]] = index.casts {{.*}} : index to i32
+    # CHECK: %[[D:.*]] = index.casts {{.*}} : i64 to index
+    print(module)
+
+
+# CHECK-LABEL: TEST: testCastUOp
+ at run
+def testCastUOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      b = arith.ConstantOp(value=23, result=IntegerType.get_signless(64))
+      c = index.CastUOp(input=a, output=IntegerType.get_signless(32))
+      d = index.CastUOp(input=b, output=IndexType.get())
+    # CHECK: %[[C:.*]] = index.castu {{.*}} : index to i32
+    # CHECK: %[[D:.*]] = index.castu {{.*}} : i64 to index
+    print(module)
+
+
+# CHECK-LABEL: TEST: testCeilDivSOp
+ at run
+def testCeilDivSOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      r = index.CeilDivSOp(a, a)
+    # CHECK: %[[R:.*]] = index.ceildivs {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testCeilDivUOp
+ at run
+def testCeilDivUOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      r = index.CeilDivUOp(a, a)
+    # CHECK: %[[R:.*]] = index.ceildivu {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testCmpOp
+ at run
+def testCmpOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      b = index.ConstantOp(value=23)
+      pred = AttrBuilder.get('IndexCmpPredicateAttr')("slt", context=ctx)
+      r = index.CmpOp(pred, lhs=a, rhs=b)
+    # CHECK: %[[R:.*]] = index.cmp slt({{.*}}, {{.*}})
+    print(module)
+
+
+# CHECK-LABEL: TEST: testAddOp
+ at run
+def testAddOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      r = index.AddOp(a, a)
+    # CHECK: %[[R:.*]] = index.add {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testSubOp
+ at run
+def testSubOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      r = index.SubOp(a, a)
+    # CHECK: %[[R:.*]] = index.sub {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testMulOp
+ at run
+def testMulOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      r = index.MulOp(a, a)
+    # CHECK: %[[R:.*]] = index.mul {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testDivSOp
+ at run
+def testDivSOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      r = index.DivSOp(a, a)
+    # CHECK: %[[R:.*]] = index.divs {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testDivUOp
+ at run
+def testDivUOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      r = index.DivUOp(a, a)
+    # CHECK: %[[R:.*]] = index.divu {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testFloorDivSOp
+ at run
+def testFloorDivSOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      r = index.FloorDivSOp(a, a)
+    # CHECK: %[[R:.*]] = index.floordivs {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testMaxSOp
+ at run
+def testMaxSOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      b = index.ConstantOp(value=23)
+      r = index.MaxSOp(a, b)
+    # CHECK: %[[R:.*]] = index.maxs {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testMaxUOp
+ at run
+def testMaxUOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      b = index.ConstantOp(value=23)
+      r = index.MaxUOp(a, b)
+    # CHECK: %[[R:.*]] = index.maxu {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testMinSOp
+ at run
+def testMinSOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      b = index.ConstantOp(value=23)
+      r = index.MinSOp(a, b)
+    # CHECK: %[[R:.*]] = index.mins {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testMinUOp
+ at run
+def testMinUOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      b = index.ConstantOp(value=23)
+      r = index.MinUOp(a, b)
+    # CHECK: %[[R:.*]] = index.minu {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testRemSOp
+ at run
+def testRemSOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      b = index.ConstantOp(value=23)
+      r = index.RemSOp(a, b)
+    # CHECK: %[[R:.*]] = index.rems {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testRemUOp
+ at run
+def testRemUOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      b = index.ConstantOp(value=23)
+      r = index.RemUOp(a, b)
+    # CHECK: %[[R:.*]] = index.remu {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testShlOp
+ at run
+def testShlOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      b = index.ConstantOp(value=3)
+      r = index.ShlOp(a, b)
+    # CHECK: %[[R:.*]] = index.shl {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testShrSOp
+ at run
+def testShrSOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      b = index.ConstantOp(value=3)
+      r = index.ShrSOp(a, b)
+    # CHECK: %[[R:.*]] = index.shrs {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testShrUOp
+ at run
+def testShrUOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      a = index.ConstantOp(value=42)
+      b = index.ConstantOp(value=3)
+      r = index.ShrUOp(a, b)
+    # CHECK: %[[R:.*]] = index.shru {{.*}}, {{.*}}
+    print(module)
+
+
+# CHECK-LABEL: TEST: testSizeOfOp
+ at run
+def testSizeOfOp():
+  with Context() as ctx, Location.unknown():
+    module = Module.create()
+    with InsertionPoint(module.body):
+      r = index.SizeOfOp()
+    # CHECK: %[[R:.*]] = index.sizeof
+    print(module)

>From 4b82d707a7e67a0cfa1ed9e99fefd7c2fc978453 Mon Sep 17 00:00:00 2001
From: Steven Varoumas <steven.varoumas1 at huawei.com>
Date: Wed, 20 Mar 2024 01:23:05 +0800
Subject: [PATCH 2/2] Formatting

---
 mlir/test/python/dialects/index_dialect.py | 396 ++++++++++-----------
 1 file changed, 198 insertions(+), 198 deletions(-)

diff --git a/mlir/test/python/dialects/index_dialect.py b/mlir/test/python/dialects/index_dialect.py
index f2e7071a53f04f..c0e460d5dcbc6a 100644
--- a/mlir/test/python/dialects/index_dialect.py
+++ b/mlir/test/python/dialects/index_dialect.py
@@ -5,331 +5,331 @@
 
 
 def run(f):
-  print("\nTEST:", f.__name__)
-  f()
+    print("\nTEST:", f.__name__)
+    f()
 
 
 # CHECK-LABEL: TEST: testConstantOp
 @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)
+    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
 @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)
+    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
 @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 {{.*}}, {{.*}}
-    print(module)
+    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 {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testOrOp
 @run
 def testOrOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      r = index.OrOp(a, a)
-    # CHECK: %[[R:.*]] = index.or {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            r = index.OrOp(a, a)
+        # CHECK: %[[R:.*]] = index.or {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testXOrOp
 @run
 def testXOrOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      r = index.XOrOp(a, a)
-    # CHECK: %[[R:.*]] = index.xor {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            r = index.XOrOp(a, a)
+        # CHECK: %[[R:.*]] = index.xor {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testCastSOp
 @run
 def testCastSOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      b = arith.ConstantOp(value=23, result=IntegerType.get_signless(64))
-      c = index.CastSOp(input=a, output=IntegerType.get_signless(32))
-      d = index.CastSOp(input=b, output=IndexType.get())
-    # CHECK: %[[C:.*]] = index.casts {{.*}} : index to i32
-    # CHECK: %[[D:.*]] = index.casts {{.*}} : i64 to index
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            b = arith.ConstantOp(value=23, result=IntegerType.get_signless(64))
+            c = index.CastSOp(input=a, output=IntegerType.get_signless(32))
+            d = index.CastSOp(input=b, output=IndexType.get())
+        # CHECK: %[[C:.*]] = index.casts {{.*}} : index to i32
+        # CHECK: %[[D:.*]] = index.casts {{.*}} : i64 to index
+        print(module)
 
 
 # CHECK-LABEL: TEST: testCastUOp
 @run
 def testCastUOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      b = arith.ConstantOp(value=23, result=IntegerType.get_signless(64))
-      c = index.CastUOp(input=a, output=IntegerType.get_signless(32))
-      d = index.CastUOp(input=b, output=IndexType.get())
-    # CHECK: %[[C:.*]] = index.castu {{.*}} : index to i32
-    # CHECK: %[[D:.*]] = index.castu {{.*}} : i64 to index
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            b = arith.ConstantOp(value=23, result=IntegerType.get_signless(64))
+            c = index.CastUOp(input=a, output=IntegerType.get_signless(32))
+            d = index.CastUOp(input=b, output=IndexType.get())
+        # CHECK: %[[C:.*]] = index.castu {{.*}} : index to i32
+        # CHECK: %[[D:.*]] = index.castu {{.*}} : i64 to index
+        print(module)
 
 
 # CHECK-LABEL: TEST: testCeilDivSOp
 @run
 def testCeilDivSOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      r = index.CeilDivSOp(a, a)
-    # CHECK: %[[R:.*]] = index.ceildivs {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            r = index.CeilDivSOp(a, a)
+        # CHECK: %[[R:.*]] = index.ceildivs {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testCeilDivUOp
 @run
 def testCeilDivUOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      r = index.CeilDivUOp(a, a)
-    # CHECK: %[[R:.*]] = index.ceildivu {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            r = index.CeilDivUOp(a, a)
+        # CHECK: %[[R:.*]] = index.ceildivu {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testCmpOp
 @run
 def testCmpOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      b = index.ConstantOp(value=23)
-      pred = AttrBuilder.get('IndexCmpPredicateAttr')("slt", context=ctx)
-      r = index.CmpOp(pred, lhs=a, rhs=b)
-    # CHECK: %[[R:.*]] = index.cmp slt({{.*}}, {{.*}})
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            b = index.ConstantOp(value=23)
+            pred = AttrBuilder.get("IndexCmpPredicateAttr")("slt", context=ctx)
+            r = index.CmpOp(pred, lhs=a, rhs=b)
+        # CHECK: %[[R:.*]] = index.cmp slt({{.*}}, {{.*}})
+        print(module)
 
 
 # CHECK-LABEL: TEST: testAddOp
 @run
 def testAddOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      r = index.AddOp(a, a)
-    # CHECK: %[[R:.*]] = index.add {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            r = index.AddOp(a, a)
+        # CHECK: %[[R:.*]] = index.add {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testSubOp
 @run
 def testSubOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      r = index.SubOp(a, a)
-    # CHECK: %[[R:.*]] = index.sub {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            r = index.SubOp(a, a)
+        # CHECK: %[[R:.*]] = index.sub {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testMulOp
 @run
 def testMulOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      r = index.MulOp(a, a)
-    # CHECK: %[[R:.*]] = index.mul {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            r = index.MulOp(a, a)
+        # CHECK: %[[R:.*]] = index.mul {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testDivSOp
 @run
 def testDivSOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      r = index.DivSOp(a, a)
-    # CHECK: %[[R:.*]] = index.divs {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            r = index.DivSOp(a, a)
+        # CHECK: %[[R:.*]] = index.divs {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testDivUOp
 @run
 def testDivUOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      r = index.DivUOp(a, a)
-    # CHECK: %[[R:.*]] = index.divu {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            r = index.DivUOp(a, a)
+        # CHECK: %[[R:.*]] = index.divu {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testFloorDivSOp
 @run
 def testFloorDivSOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      r = index.FloorDivSOp(a, a)
-    # CHECK: %[[R:.*]] = index.floordivs {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            r = index.FloorDivSOp(a, a)
+        # CHECK: %[[R:.*]] = index.floordivs {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testMaxSOp
 @run
 def testMaxSOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      b = index.ConstantOp(value=23)
-      r = index.MaxSOp(a, b)
-    # CHECK: %[[R:.*]] = index.maxs {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            b = index.ConstantOp(value=23)
+            r = index.MaxSOp(a, b)
+        # CHECK: %[[R:.*]] = index.maxs {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testMaxUOp
 @run
 def testMaxUOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      b = index.ConstantOp(value=23)
-      r = index.MaxUOp(a, b)
-    # CHECK: %[[R:.*]] = index.maxu {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            b = index.ConstantOp(value=23)
+            r = index.MaxUOp(a, b)
+        # CHECK: %[[R:.*]] = index.maxu {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testMinSOp
 @run
 def testMinSOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      b = index.ConstantOp(value=23)
-      r = index.MinSOp(a, b)
-    # CHECK: %[[R:.*]] = index.mins {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            b = index.ConstantOp(value=23)
+            r = index.MinSOp(a, b)
+        # CHECK: %[[R:.*]] = index.mins {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testMinUOp
 @run
 def testMinUOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      b = index.ConstantOp(value=23)
-      r = index.MinUOp(a, b)
-    # CHECK: %[[R:.*]] = index.minu {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            b = index.ConstantOp(value=23)
+            r = index.MinUOp(a, b)
+        # CHECK: %[[R:.*]] = index.minu {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testRemSOp
 @run
 def testRemSOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      b = index.ConstantOp(value=23)
-      r = index.RemSOp(a, b)
-    # CHECK: %[[R:.*]] = index.rems {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            b = index.ConstantOp(value=23)
+            r = index.RemSOp(a, b)
+        # CHECK: %[[R:.*]] = index.rems {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testRemUOp
 @run
 def testRemUOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      b = index.ConstantOp(value=23)
-      r = index.RemUOp(a, b)
-    # CHECK: %[[R:.*]] = index.remu {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            b = index.ConstantOp(value=23)
+            r = index.RemUOp(a, b)
+        # CHECK: %[[R:.*]] = index.remu {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testShlOp
 @run
 def testShlOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      b = index.ConstantOp(value=3)
-      r = index.ShlOp(a, b)
-    # CHECK: %[[R:.*]] = index.shl {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            b = index.ConstantOp(value=3)
+            r = index.ShlOp(a, b)
+        # CHECK: %[[R:.*]] = index.shl {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testShrSOp
 @run
 def testShrSOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      b = index.ConstantOp(value=3)
-      r = index.ShrSOp(a, b)
-    # CHECK: %[[R:.*]] = index.shrs {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            b = index.ConstantOp(value=3)
+            r = index.ShrSOp(a, b)
+        # CHECK: %[[R:.*]] = index.shrs {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testShrUOp
 @run
 def testShrUOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      a = index.ConstantOp(value=42)
-      b = index.ConstantOp(value=3)
-      r = index.ShrUOp(a, b)
-    # CHECK: %[[R:.*]] = index.shru {{.*}}, {{.*}}
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            a = index.ConstantOp(value=42)
+            b = index.ConstantOp(value=3)
+            r = index.ShrUOp(a, b)
+        # CHECK: %[[R:.*]] = index.shru {{.*}}, {{.*}}
+        print(module)
 
 
 # CHECK-LABEL: TEST: testSizeOfOp
 @run
 def testSizeOfOp():
-  with Context() as ctx, Location.unknown():
-    module = Module.create()
-    with InsertionPoint(module.body):
-      r = index.SizeOfOp()
-    # CHECK: %[[R:.*]] = index.sizeof
-    print(module)
+    with Context() as ctx, Location.unknown():
+        module = Module.create()
+        with InsertionPoint(module.body):
+            r = index.SizeOfOp()
+        # CHECK: %[[R:.*]] = index.sizeof
+        print(module)



More information about the Mlir-commits mailing list