[mlir][openacc] Relax the single block constraint on acc.loop
authorValentin Clement <clementval@gmail.com>
Tue, 11 Apr 2023 17:42:44 +0000 (10:42 -0700)
committerValentin Clement <clementval@gmail.com>
Tue, 11 Apr 2023 17:43:09 +0000 (10:43 -0700)
The acc.loop operation was constrained by the SingleBlockImplicitTerminator.
This patch relax this constraint to allow multiple block in the loop.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D148025

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
mlir/test/Dialect/OpenACC/ops.mlir

index 9203e8b..9a6e942 100644 (file)
@@ -343,9 +343,7 @@ def OpenACC_ExitDataOp : OpenACC_Op<"exit_data", [AttrSizedOperandSegments]> {
 // 2.9 loop Construct
 //===----------------------------------------------------------------------===//
 
-def OpenACC_LoopOp : OpenACC_Op<"loop",
-      [AttrSizedOperandSegments,
-       SingleBlockImplicitTerminator<"acc::YieldOp">]> {
+def OpenACC_LoopOp : OpenACC_Op<"loop", [AttrSizedOperandSegments]> {
   let summary = "loop construct";
 
   let description = [{
@@ -367,7 +365,6 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
     ```
   }];
 
-
   let arguments = (ins OptionalAttr<I64Attr>:$collapse,
                        Optional<IntOrIndex>:$gangNum,
                        Optional<IntOrIndex>:$gangStatic,
index 48d343b..de5c3b4 100644 (file)
@@ -323,6 +323,37 @@ func.func @testloopop() -> () {
 
 // -----
 
+func.func @acc_loop_multiple_block() {
+  acc.parallel {
+    acc.loop {
+      %c1 = arith.constant 1 : index
+      cf.br ^bb1(%c1 : index)
+    ^bb1(%9: index):
+      %c0 = arith.constant 0 : index
+      %12 = arith.cmpi sgt, %9, %c0 : index
+      cf.cond_br %12, ^bb2, ^bb3
+    ^bb2:
+      %c1_0 = arith.constant 1 : index
+      %c10 = arith.constant 10 : index
+      %22 = arith.subi %c10, %c1_0 : index
+      cf.br ^bb1(%22 : index)
+    ^bb3:
+      acc.yield
+    }
+    acc.yield
+  }
+  return
+}
+
+// CHECK-LABEL: func.func @acc_loop_multiple_block()
+// CHECK: acc.parallel
+// CHECK: acc.loop
+// CHECK-3: ^bb{{.*}}
+// CHECK: acc.yield
+// CHECK: acc.yield
+
+// -----
+
 func.func @testparallelop(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) -> () {
   %i64value = arith.constant 1 : i64
   %i32value = arith.constant 1 : i32