[flang-commits] [flang] a05ed47 - [flang][openacc] Populate the init region for acc.private.recipe for simple type
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Jul 6 13:55:59 PDT 2023
Author: Valentin Clement
Date: 2023-07-06T13:55:54-07:00
New Revision: a05ed478c8f54131f9cafc20f15847dd745f5116
URL: https://github.com/llvm/llvm-project/commit/a05ed478c8f54131f9cafc20f15847dd745f5116
DIFF: https://github.com/llvm/llvm-project/commit/a05ed478c8f54131f9cafc20f15847dd745f5116.diff
LOG: [flang][openacc] Populate the init region for acc.private.recipe for simple type
Generate code to allocate privates for trivial scalars and arrays.
Reviewed By: razvanlupusoru
Differential Revision: https://reviews.llvm.org/D154259
Added:
flang/test/Lower/OpenACC/acc-private.f90
Modified:
flang/lib/Lower/OpenACC.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 3d19ac82d2fa3c..f6cef04e8445e9 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -427,8 +427,20 @@ Fortran::lower::createOrGetPrivateRecipe(mlir::OpBuilder &builder,
builder.createBlock(&recipe.getInitRegion(), recipe.getInitRegion().end(),
{ty}, {loc});
builder.setInsertionPointToEnd(&recipe.getInitRegion().back());
- builder.create<mlir::acc::YieldOp>(
- loc, recipe.getInitRegion().front().getArgument(0));
+
+ mlir::Value retVal = recipe.getInitRegion().front().getArgument(0);
+ if (auto refTy = mlir::dyn_cast_or_null<fir::ReferenceType>(ty)) {
+ if (fir::isa_trivial(refTy.getEleTy()))
+ retVal = builder.create<fir::AllocaOp>(loc, refTy.getEleTy());
+ else if (auto seqTy =
+ mlir::dyn_cast_or_null<fir::SequenceType>(refTy.getEleTy())) {
+ if (seqTy.hasDynamicExtents())
+ TODO(loc, "private recipe of array with dynamic extents");
+ if (fir::isa_trivial(seqTy.getEleTy()))
+ retVal = builder.create<fir::AllocaOp>(loc, seqTy);
+ }
+ }
+ builder.create<mlir::acc::YieldOp>(loc, retVal);
builder.restoreInsertionPoint(crtPos);
return recipe;
}
diff --git a/flang/test/Lower/OpenACC/acc-private.f90 b/flang/test/Lower/OpenACC/acc-private.f90
new file mode 100644
index 00000000000000..fc806a26c8562b
--- /dev/null
+++ b/flang/test/Lower/OpenACC/acc-private.f90
@@ -0,0 +1,48 @@
+! This test checks lowering of OpenACC loop directive.
+
+! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
+
+! CHECK-LABEL: acc.private.recipe @privatization_ref_100xf32 : !fir.ref<!fir.array<100xf32>> init {
+! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xf32>>):
+! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32>
+! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.array<100xf32>>
+! CHECK: }
+
+! CHECK-LABEL: acc.private.recipe @privatization_ref_i32 : !fir.ref<i32> init {
+! CHECK: ^bb0(%{{.*}}: !fir.ref<i32>):
+! CHECK: %[[ALLOCA:.*]] = fir.alloca i32
+! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<i32>
+! CHECK: }
+
+program acc_private
+ integer :: i, c
+ integer, parameter :: n = 100
+ real, dimension(n) :: a, b
+
+! CHECK: %[[B:.*]] = fir.address_of(@_QFEb) : !fir.ref<!fir.array<100xf32>>
+! CHECK: %[[C:.*]] = fir.alloca i32 {bindc_name = "c", uniq_name = "_QFEc"}
+
+ !$acc loop private(c)
+ DO i = 1, n
+ c = i
+ a(i) = b(i) + c
+ END DO
+
+! CHECK: %[[C_PRIVATE:.*]] = acc.private varPtr(%[[C]] : !fir.ref<i32>) -> !fir.ref<i32> {name = "c"}
+! CHECK: acc.loop private(@privatization_ref_i32 -> %[[C_PRIVATE]] : !fir.ref<i32>)
+! CHECK: acc.yield
+
+ !$acc loop private(b)
+ DO i = 1, n
+ c = i
+ a(i) = b(i) + c
+ END DO
+
+! CHECK: %[[C1:.*]] = arith.constant 1 : index
+! CHECK: %[[LB:.*]] = arith.constant 0 : index
+! CHECK: %[[UB:.*]] = arith.subi %{{.*}}, %[[C1]] : index
+! CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[C1]] : index) startIdx(%[[C1]] : index)
+! CHECK: %[[B_PRIVATE:.*]] = acc.private varPtr(%[[B]] : !fir.ref<!fir.array<100xf32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<100xf32>> {name = "b"}
+! CHECK: acc.loop private(@privatization_ref_100xf32 -> %[[B_PRIVATE]] : !fir.ref<!fir.array<100xf32>>) {
+
+end program
More information about the flang-commits
mailing list