diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td --- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td +++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td @@ -1043,8 +1043,8 @@ Variadic:$tileOperands, Variadic:$privateOperands, OptionalAttr:$privatizations, - OptionalAttr:$reductionOp, - Variadic:$reductionOperands); + Variadic:$reductionOperands, + OptionalAttr:$reductions); let results = (outs Variadic:$results); @@ -1066,7 +1066,9 @@ $privateOperands, type($privateOperands), $privatizations) `)` | `tile` `(` $tileOperands `:` type($tileOperands) `)` - | `reduction` `(` $reductionOperands `:` type($reductionOperands) `)` + | `reduction` `(` custom( + $reductionOperands, type($reductionOperands), $reductions) + `)` ) $region ( `(` type($results)^ `)` )? diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp --- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp +++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp @@ -739,6 +739,11 @@ "privatizations"))) return failure(); + if (failed(checkSymOperandList( + *this, getReductions(), getReductionOperands(), "reduction", + "reductions"))) + return failure(); + // Check non-empty body(). if (getRegion().empty()) return emitError("expected non-empty body."); diff --git a/mlir/test/Dialect/OpenACC/ops.mlir b/mlir/test/Dialect/OpenACC/ops.mlir --- a/mlir/test/Dialect/OpenACC/ops.mlir +++ b/mlir/test/Dialect/OpenACC/ops.mlir @@ -1387,13 +1387,13 @@ // ----- acc.reduction.recipe @reduction_add_i64 : i64 reduction_operator 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 init { @@ -1408,6 +1408,10 @@ 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 } @@ -1415,3 +1419,4 @@ // 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)