Skip to content

Commit 49f1232

Browse files
authored
[flang][openacc] Support assumed shape arrays in private recipe (#67701)
This patch adds correct support for the assumed shape arrays in the privatization recipes. This follows the same IR generation than in #67610.
1 parent 35ec6ea commit 49f1232

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,13 @@ static void genPrivateLikeInitRegion(mlir::OpBuilder &builder, RecipeOp recipe,
380380
retVal = declareOp.getBase();
381381
}
382382
}
383+
} else if (auto boxTy = mlir::dyn_cast_or_null<fir::BaseBoxType>(ty)) {
384+
if (!mlir::isa<fir::SequenceType>(boxTy.getEleTy()))
385+
TODO(loc, "Unsupported boxed type in OpenACC privatization");
386+
fir::FirOpBuilder firBuilder{builder, recipe.getOperation()};
387+
hlfir::Entity source = hlfir::Entity{retVal};
388+
auto [temp, cleanup] = hlfir::createTempFromMold(loc, firBuilder, source);
389+
retVal = temp;
383390
}
384391
builder.create<mlir::acc::YieldOp>(loc, retVal);
385392
}

flang/test/Lower/OpenACC/acc-private.f90

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s --check-prefixes=CHECK,FIR
44
! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s --check-prefixes=CHECK,HLFIR
55

6+
! CHECK-LABEL: acc.private.recipe @"privatization_box_?xi32" : !fir.box<!fir.array<?xi32>> init {
7+
! CHECK: ^bb0(%[[ARG0:.*]]: !fir.box<!fir.array<?xi32>>):
8+
! HLFIR: %[[C0:.*]] = arith.constant 0 : index
9+
! HLFIR: %[[BOX_DIMS:.*]]:3 = fir.box_dims %[[ARG0]], %[[C0]] : (!fir.box<!fir.array<?xi32>>, index) -> (index, index, index)
10+
! HLFIR: %[[SHAPE:.*]] = fir.shape %[[BOX_DIMS]]#1 : (index) -> !fir.shape<1>
11+
! HLFIR: %[[TEMP:.*]] = fir.allocmem !fir.array<?xi32>, %0#1 {bindc_name = ".tmp", uniq_name = ""}
12+
! HLFIR: %[[DECLARE:.*]]:2 = hlfir.declare %[[TEMP]](%[[SHAPE]]) {uniq_name = ".tmp"} : (!fir.heap<!fir.array<?xi32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.heap<!fir.array<?xi32>>)
13+
! HLFIR: acc.yield %[[DECLARE:.*]]#0 : !fir.box<!fir.array<?xi32>>
14+
! CHECK: }
15+
616
! CHECK-LABEL: acc.firstprivate.recipe @firstprivatization_ref_50xf32 : !fir.ref<!fir.array<50xf32>> init {
717
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<50xf32>>):
818
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.array<50xf32>
@@ -169,3 +179,19 @@ program acc_private
169179
! CHECK: acc.parallel firstprivate(@firstprivatization_ref_50xf32 -> %[[FP_B]] : !fir.ref<!fir.array<50xf32>>)
170180

171181
end program
182+
183+
subroutine acc_private_assumed_shape(a, n)
184+
integer :: a(:), i, n
185+
186+
!$acc parallel loop private(a)
187+
do i = 1, n
188+
a(i) = i
189+
end do
190+
end subroutine
191+
192+
! CHECK-LABEL: func.func @_QPacc_private_assumed_shape(
193+
! CHECK-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "a"}
194+
! HLFIR: %[[DECL_A:.*]]:2 = hlfir.declare %arg0 {uniq_name = "_QFacc_private_assumed_shapeEa"} : (!fir.box<!fir.array<?xi32>>) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>)
195+
! HLFIR: %[[ADDR:.*]] = fir.box_addr %[[DECL_A]]#1 : (!fir.box<!fir.array<?xi32>>) -> !fir.ref<!fir.array<?xi32>>
196+
! HLFIR: %[[PRIVATE:.*]] = acc.private varPtr(%[[ADDR]] : !fir.ref<!fir.array<?xi32>>) bounds(%{{.*}}) -> !fir.ref<!fir.array<?xi32>> {name = "a"}
197+
! HLFIR: acc.parallel private(@"privatization_box_?xi32" -> %[[PRIVATE]] : !fir.ref<!fir.array<?xi32>>) {

mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ Value ParallelOp::getDataOperand(unsigned i) {
619619
LogicalResult acc::ParallelOp::verify() {
620620
if (failed(checkSymOperandList<mlir::acc::PrivateRecipeOp>(
621621
*this, getPrivatizations(), getGangPrivateOperands(), "private",
622-
"privatizations")))
622+
"privatizations", false)))
623623
return failure();
624624
if (failed(checkSymOperandList<mlir::acc::ReductionRecipeOp>(
625625
*this, getReductionRecipes(), getReductionOperands(), "reduction",
@@ -860,7 +860,7 @@ LogicalResult acc::LoopOp::verify() {
860860

861861
if (failed(checkSymOperandList<mlir::acc::PrivateRecipeOp>(
862862
*this, getPrivatizations(), getPrivateOperands(), "private",
863-
"privatizations")))
863+
"privatizations", false)))
864864
return failure();
865865

866866
if (failed(checkSymOperandList<mlir::acc::ReductionRecipeOp>(

0 commit comments

Comments
 (0)