[mlir][openacc] Relax verifier for the acc.reduction.recipe
authorValentin Clement <clementval@gmail.com>
Wed, 19 Jul 2023 17:30:42 +0000 (10:30 -0700)
committerValentin Clement <clementval@gmail.com>
Wed, 19 Jul 2023 17:31:37 +0000 (10:31 -0700)
Allow the init and combiner regions to have more
arguments to pass information.

Reviewed By: razvanlupusoru

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

mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
mlir/test/Dialect/OpenACC/invalid.mlir

index a40ae06..6c8fa85 100644 (file)
@@ -615,12 +615,14 @@ def OpenACC_ReductionRecipeOp : OpenACC_Op<"reduction.recipe",
     mandatory regions.
 
       1. The initializer region specifies how to initialize the local reduction
-         value. The region has an argument that contains the value of the
+         value. The region has a first argument that contains the value of the
          reduction accumulator at the start of the reduction. It is expected to
-         `acc.yield` the new value.
+         `acc.yield` the new value. Extra arguments can be added to deal with
+         dynamic arrays.
       2. The reduction region contains a sequences of operations to combine two
-         values of the reduction type into one. It has two arguments and it is
-         expected to `acc.yield` the combined value.
+         values of the reduction type into one. It has at least two arguments
+         and it is expected to `acc.yield` the combined value. Extra arguments
+         can be added to deal with dynamic arrays.
 
     Example:
 
index f5d5149..c571cae 100644 (file)
@@ -387,10 +387,10 @@ static LogicalResult verifyInitLikeSingleArgRegion(
   if (region.empty())
     return op->emitOpError() << "expects non-empty " << regionName << " region";
   Block &firstBlock = region.front();
-  if (firstBlock.getNumArguments() != 1 ||
+  if (firstBlock.getNumArguments() < 1 ||
       firstBlock.getArgument(0).getType() != type)
     return op->emitOpError() << "expects " << regionName
-                             << " region with one "
+                             << " region first "
                                 "argument of the "
                              << regionType << " type";
 
@@ -463,11 +463,11 @@ LogicalResult acc::ReductionRecipeOp::verifyRegions() {
     return emitOpError() << "expects non-empty combiner region";
 
   Block &reductionBlock = getCombinerRegion().front();
-  if (reductionBlock.getNumArguments() != 2 ||
+  if (reductionBlock.getNumArguments() < 2 ||
       reductionBlock.getArgument(0).getType() != getType() ||
       reductionBlock.getArgument(1).getType() != getType())
-    return emitOpError() << "expects combiner region with two arguments of "
-                         << "the reduction type";
+    return emitOpError() << "expects combiner region with the first two "
+                         << "arguments of the reduction type";
 
   for (YieldOp yieldOp : getCombinerRegion().getOps<YieldOp>()) {
     if (yieldOp.getOperands().size() != 1 ||
index 2a36cca..1a7e1d8 100644 (file)
@@ -267,7 +267,7 @@ acc.private.recipe @privatization_i32 : !llvm.ptr<i32> init {
 
 // -----
 
-// expected-error@+1 {{expects init region with one argument of the privatization type}}
+// expected-error@+1 {{expects init region first argument of the privatization type}}
 acc.private.recipe @privatization_i32 : !llvm.ptr<i32> init {
 ^bb0(%arg0 : !llvm.ptr<f32>):
   %c1 = arith.constant 1 : i32
@@ -291,7 +291,7 @@ acc.private.recipe @privatization_i32 : !llvm.ptr<f32> init {
 
 // -----
 
-// expected-error@+1 {{expects destroy region with one argument of the privatization type}}
+// expected-error@+1 {{expects destroy region first argument of the privatization type}}
 acc.private.recipe @privatization_i32 : !llvm.ptr<i32> init {
 ^bb0(%arg0 : !llvm.ptr<i32>):
   %c1 = arith.constant 1 : i32
@@ -312,7 +312,7 @@ acc.firstprivate.recipe @privatization_i32 : !llvm.ptr<i32> init {
 
 // -----
 
-// expected-error@+1 {{expects init region with one argument of the privatization type}}
+// expected-error@+1 {{expects init region first argument of the privatization type}}
 acc.firstprivate.recipe @privatization_i32 : !llvm.ptr<i32> init {
 ^bb0(%arg0 : !llvm.ptr<f32>):
   %c1 = arith.constant 1 : i32
@@ -379,7 +379,7 @@ acc.firstprivate.recipe @privatization_i32 : !llvm.ptr<i32> init {
 
 // -----
 
-// expected-error@+1 {{destroy region with one argument of the privatization type}}
+// expected-error@+1 {{expects destroy region first argument of the privatization type}}
 acc.firstprivate.recipe @privatization_i32 : i32 init {
 ^bb0(%arg0 : i32):
   %0 = arith.constant 1 : i32
@@ -409,7 +409,7 @@ acc.reduction.recipe @reduction_i64 : i64 reduction_operator<add> init {
 
 // -----
 
-// expected-error@+1 {{expects init region with one argument of the reduction type}}
+// expected-error@+1 {{expects init region first argument of the reduction type}}
 acc.reduction.recipe @reduction_i64 : i64 reduction_operator<add> init {
 ^bb0(%0: i32):
   %1 = arith.constant 0 : i64
@@ -427,7 +427,7 @@ acc.reduction.recipe @reduction_i64 : i64 reduction_operator<add> init {
 
 // -----
 
-// expected-error@+1 {{expects combiner region with two arguments of the reduction type}}
+// expected-error@+1 {{expects combiner region with the first two arguments of the reduction type}}
 acc.reduction.recipe @reduction_i64 : i64 reduction_operator<add> init {
 ^bb0(%0: i64):
   %1 = arith.constant 0 : i64
@@ -439,7 +439,7 @@ acc.reduction.recipe @reduction_i64 : i64 reduction_operator<add> init {
 
 // -----
 
-// expected-error@+1 {{expects combiner region with two arguments of the reduction type}}
+// expected-error@+1 {{expects combiner region with the first two arguments of the reduction type}}
 acc.reduction.recipe @reduction_i64 : i64 reduction_operator<add> init {
 ^bb0(%0: i64):
   %1 = arith.constant 0 : i64