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 @@ -481,7 +481,8 @@ created private value. It takes the initial value and the privatized value as arguments. 3. The destroy region specifies how to destruct the value when it reaches - its end of life. It takes the privatized value as argument. + its end of life. It takes the privatized value as argument. It is + optional. A single privatization recipe can be used for multiple operand if they have the same type and do not require a specific default initialization. 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 @@ -398,6 +398,9 @@ return emitOpError() << "expects copy region with two arguments of the " "privatization type"; + if (getDestroyRegion().empty()) + return success(); + if (failed(verifyInitLikeSingleArgRegion(*this, getDestroyRegion(), "privatization", "destroy", getType(), /*verifyYield=*/false))) 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 @@ -510,6 +510,31 @@ acc.terminator } +acc.firstprivate.recipe @privatization_memref_10xf32 : memref<10xf32> init { +^bb0(%arg0: memref<10xf32>): + %0 = memref.alloc() : memref<10xf32> + acc.yield %0 : memref<10xf32> +} copy { +^bb0(%arg0: memref<10xf32>, %arg1: memref<10xf32>): + acc.terminator +} destroy { +^bb0(%arg0: memref<10xf32>): + memref.dealloc %arg0 : memref<10xf32> + acc.terminator +} + +// Test optional destroy region +acc.firstprivate.recipe @privatization_memref_20xf32 : memref<20xf32> init { +^bb0(%arg0: memref<20xf32>): + %0 = memref.alloc() : memref<20xf32> + acc.yield %0 : memref<20xf32> +} copy { +^bb0(%arg0: memref<20xf32>, %arg1: memref<20xf32>): + acc.terminator +} + +// CHECK-LABEL: acc.firstprivate.recipe @privatization_memref_20xf32 : memref<20xf32> init + func.func @testserialop(%a: memref<10xf32>, %b: memref<10xf32>, %c: memref<10x10xf32>) -> () { %i64value = arith.constant 1 : i64 %i32value = arith.constant 1 : i32