Skip to content

Commit

Permalink
[flang][openacc] Support array slices when creating firstprivate recipe
Browse files Browse the repository at this point in the history
The return type of the recipe must match the array slice provided by
the user. This patch enhance the recipe creation to take into account
the constant slices.

Depends on D154657

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D154727
  • Loading branch information
clementval committed Jul 12, 2023
1 parent 67c8110 commit a48445f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
8 changes: 4 additions & 4 deletions flang/lib/Lower/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ genPrivatizations(const Fortran::parser::AccObjectList &objectList,
operandLocation, asFortran, bounds);

RecipeOp recipe;
mlir::Type retTy = getTypeFromBounds(bounds, baseAddr.getType());
if constexpr (std::is_same_v<RecipeOp, mlir::acc::PrivateRecipeOp>) {
mlir::Type retTy = getTypeFromBounds(bounds, baseAddr.getType());
std::string recipeName =
fir::getTypeAsString(retTy, converter.getKindMap(), "privatization");
recipe = Fortran::lower::createOrGetPrivateRecipe(builder, recipeName,
Expand All @@ -586,12 +586,12 @@ genPrivatizations(const Fortran::parser::AccObjectList &objectList,
dataOperands.push_back(op.getAccPtr());
} else {
std::string recipeName = fir::getTypeAsString(
baseAddr.getType(), converter.getKindMap(), "firstprivatization");
retTy, converter.getKindMap(), "firstprivatization");
recipe = Fortran::lower::createOrGetFirstprivateRecipe(
builder, recipeName, operandLocation, baseAddr.getType());
builder, recipeName, operandLocation, retTy);
auto op = createDataEntryOp<mlir::acc::FirstprivateOp>(
builder, operandLocation, baseAddr, asFortran, bounds, true,
mlir::acc::DataClause::acc_firstprivate, baseAddr.getType());
mlir::acc::DataClause::acc_firstprivate, retTy);
dataOperands.push_back(op.getAccPtr());
}
privatizations.push_back(mlir::SymbolRefAttr::get(
Expand Down
32 changes: 32 additions & 0 deletions flang/test/Lower/OpenACC/acc-private.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s

! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_50xf32 : !fir.ref<!fir.array<50xf32>> init {
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<50xf32>>):
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<50xf32>
! CHECK: acc.yield %[[ALLOCA]] : !fir.ref<!fir.array<50xf32>>
! CHECK: } copy {
! CHECK: ^bb0(%[[SRC:.*]]: !fir.ref<!fir.array<50xf32>>, %[[DST:.*]]: !fir.ref<!fir.array<50xf32>>):
! CHECK: %[[LB0:.*]] = arith.constant 0 : index
! CHECK: %[[UB0:.*]] = arith.constant 49 : index
! CHECK: %[[STEP0:.*]] = arith.constant 1 : index
! CHECK: fir.do_loop %[[IV0:.*]] = %[[LB0]] to %[[UB0]] step %[[STEP0]] {
! CHECK: %[[COORD0:.*]] = fir.coordinate_of %[[SRC]], %[[IV0]] : (!fir.ref<!fir.array<50xf32>>, index) -> !fir.ref<f32>
! CHECK: %[[COORD1:.*]] = fir.coordinate_of %[[DST]], %[[IV0]] : (!fir.ref<!fir.array<50xf32>>, index) -> !fir.ref<f32>
! CHECK: %[[VALUE:.*]] = fir.load %[[COORD0]] : !fir.ref<f32>
! CHECK: fir.store %[[VALUE]] to %[[COORD1]] : !fir.ref<f32>
! CHECK: }
! CHECK: acc.terminator
! CHECK: }

! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_100xf32 : !fir.ref<!fir.array<100xf32>> init {
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<100xf32>>):
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32>
Expand Down Expand Up @@ -116,5 +134,19 @@ program acc_private
! CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[C1]] : index) startIdx(%[[C1]] : index)
! CHECK: %[[FP_B:.*]] = acc.firstprivate varPtr(%[[B]] : !fir.ref<!fir.array<100xf32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<100xf32>> {name = "b"}
! CHECK: acc.parallel firstprivate(@firstprivatization_ref_100xf32 -> %[[FP_B]] : !fir.ref<!fir.array<100xf32>>)
! CHECK: acc.yield

!$acc parallel loop firstprivate(b(51:100))
DO i = 1, n
c = i
a(i) = b(i) + c
END DO

! CHECK: %[[C1:.*]] = arith.constant 1 : index
! CHECK: %[[LB:.*]] = arith.constant 50 : index
! CHECK: %[[UB:.*]] = arith.constant 99 : index
! CHECK: %[[BOUND:.*]] = acc.bounds lowerbound(%[[LB]] : index) upperbound(%[[UB]] : index) stride(%[[C1]] : index) startIdx(%[[C1]] : index)
! CHECK: %[[FP_B:.*]] = acc.firstprivate varPtr(%[[B]] : !fir.ref<!fir.array<100xf32>>) bounds(%[[BOUND]]) -> !fir.ref<!fir.array<50xf32>> {name = "b(51:100)"}
! CHECK: acc.parallel firstprivate(@firstprivatization_ref_50xf32 -> %[[FP_B]] : !fir.ref<!fir.array<50xf32>>)

end program

0 comments on commit a48445f

Please sign in to comment.