[mlir][openacc] Use new reduction design in acc.loop
authorValentin Clement <clementval@gmail.com>
Wed, 24 May 2023 17:44:40 +0000 (10:44 -0700)
committerValentin Clement <clementval@gmail.com>
Wed, 24 May 2023 17:51:39 +0000 (10:51 -0700)
Use the new reduction design in acc.loop operation.

Depends on D151146

Reviewed By: razvanlupusoru, jeanPerier

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

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

index a662ad9..097d01e 100644 (file)
@@ -1046,8 +1046,8 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
                        Variadic<IntOrIndex>:$tileOperands,
                        Variadic<OpenACC_PointerLikeTypeInterface>:$privateOperands,
                        OptionalAttr<SymbolRefArrayAttr>:$privatizations,
-                       OptionalAttr<OpenACC_ReductionOperatorAttr>:$reductionOp,
-                       Variadic<AnyType>:$reductionOperands);
+                       Variadic<AnyType>:$reductionOperands,
+                       OptionalAttr<SymbolRefArrayAttr>:$reductionRecipes);
 
   let results = (outs Variadic<AnyType>:$results);
 
@@ -1069,7 +1069,9 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
             $privateOperands, type($privateOperands), $privatizations)
         `)`
       | `tile` `(` $tileOperands `:` type($tileOperands) `)`
-      | `reduction` `(` $reductionOperands `:` type($reductionOperands) `)`
+      | `reduction` `(` custom<SymOperandList>(
+            $reductionOperands, type($reductionOperands), $reductionRecipes)
+        `)`
     )
     $region
     ( `(` type($results)^ `)` )?
index e5d7888..714bf26 100644 (file)
@@ -749,6 +749,11 @@ LogicalResult acc::LoopOp::verify() {
           "privatizations")))
     return failure();
 
+  if (failed(checkSymOperandList<mlir::acc::ReductionRecipeOp>(
+          *this, getReductionRecipes(), getReductionOperands(), "reduction",
+          "reductions")))
+    return failure();
+
   // Check non-empty body().
   if (getRegion().empty())
     return emitError("expected non-empty body.");
index fca5a5f..17a6cbd 100644 (file)
@@ -1412,13 +1412,13 @@ acc.private.recipe @privatization_struct_i32_i64 : !llvm.struct<(i32, i32)> init
 // -----
 
 acc.reduction.recipe @reduction_add_i64 : i64 reduction_operator<add> init {
-^bb0(%0: i64):
-  %1 = arith.constant 0 : i64
-  acc.yield %1 : i64
+^bb0(%arg0: i64):
+  %0 = arith.constant 0 : i64
+  acc.yield %0 : i64
 } combiner {
-^bb0(%0: i64, %1: i64):
-  %2 = arith.addi %0, %1 : i64
-  acc.yield %2 : i64
+^bb0(%arg0: i64, %arg1: i64):
+  %0 = arith.addi %arg0, %arg1 : i64
+  acc.yield %0 : i64
 }
 
 // CHECK-LABEL: acc.reduction.recipe @reduction_add_i64 : i64 reduction_operator <add> init {
@@ -1433,6 +1433,10 @@ acc.reduction.recipe @reduction_add_i64 : i64 reduction_operator<add> init {
 
 func.func @acc_reduc_test(%a : i64) -> () {
   acc.parallel reduction(@reduction_add_i64 -> %a : i64) {
+    acc.loop reduction(@reduction_add_i64 -> %a : i64) {
+      acc.yield
+    }
+    acc.yield
   }
   return
 }
@@ -1440,6 +1444,7 @@ func.func @acc_reduc_test(%a : i64) -> () {
 // CHECK-LABEL: func.func @acc_reduc_test(
 // CHECK-SAME:    %[[ARG0:.*]]: i64)
 // CHECK:         acc.parallel reduction(@reduction_add_i64 -> %[[ARG0]] : i64)
+// CHECK:           acc.loop reduction(@reduction_add_i64 -> %[[ARG0]] : i64)
 
 // -----