diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp index b77ab6248c4d5..d6f9cadfc9638 100644 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -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) { - mlir::Type retTy = getTypeFromBounds(bounds, baseAddr.getType()); std::string recipeName = fir::getTypeAsString(retTy, converter.getKindMap(), "privatization"); recipe = Fortran::lower::createOrGetPrivateRecipe(builder, recipeName, @@ -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( 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( diff --git a/flang/test/Lower/OpenACC/acc-private.f90 b/flang/test/Lower/OpenACC/acc-private.f90 index f3162d14763ec..8cd4c74548c17 100644 --- a/flang/test/Lower/OpenACC/acc-private.f90 +++ b/flang/test/Lower/OpenACC/acc-private.f90 @@ -2,6 +2,24 @@ ! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s +! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_50xf32 : !fir.ref> init { +! CHECK: ^bb0(%{{.*}}: !fir.ref>): +! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<50xf32> +! CHECK: acc.yield %[[ALLOCA]] : !fir.ref> +! CHECK: } copy { +! CHECK: ^bb0(%[[SRC:.*]]: !fir.ref>, %[[DST:.*]]: !fir.ref>): +! 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>, index) -> !fir.ref +! CHECK: %[[COORD1:.*]] = fir.coordinate_of %[[DST]], %[[IV0]] : (!fir.ref>, index) -> !fir.ref +! CHECK: %[[VALUE:.*]] = fir.load %[[COORD0]] : !fir.ref +! CHECK: fir.store %[[VALUE]] to %[[COORD1]] : !fir.ref +! CHECK: } +! CHECK: acc.terminator +! CHECK: } + ! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_100xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<100xf32> @@ -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>) bounds(%[[BOUND]]) -> !fir.ref> {name = "b"} ! CHECK: acc.parallel firstprivate(@firstprivatization_ref_100xf32 -> %[[FP_B]] : !fir.ref>) +! 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>) bounds(%[[BOUND]]) -> !fir.ref> {name = "b(51:100)"} +! CHECK: acc.parallel firstprivate(@firstprivatization_ref_50xf32 -> %[[FP_B]] : !fir.ref>) end program