Skip to content

Commit 135529a

Browse files
authoredFeb 20, 2024
[flang][openacc] Use the same iv privatized value in the loop region (#81821)
IV variable are privatized during acc loop lowering. An hlfir.declare operation is added when mapping the symbol to the new private value. In order to avoid using multiple value in the acc.loop region, we map the symbol to the result of the hlfir.declare operation inserted.
1 parent d7a73c9 commit 135529a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
 

‎flang/lib/Lower/OpenACC.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -1658,10 +1658,18 @@ static void privatizeIv(Fortran::lower::AbstractConverter &converter,
16581658
mlir::acc::DataClause::acc_private, ivValue.getType());
16591659

16601660
privateOperands.push_back(op.getAccPtr());
1661-
ivPrivate.push_back(op.getAccPtr());
16621661
privatizations.push_back(mlir::SymbolRefAttr::get(builder.getContext(),
16631662
recipe.getSymName().str()));
1663+
1664+
// Map the new private iv to its symbol for the scope of the loop. bindSymbol
1665+
// might create a hlfir.declare op, if so, we map its result in order to
1666+
// use the sym value in the scope.
16641667
converter.bindSymbol(sym, op.getAccPtr());
1668+
auto privateValue = converter.getSymbolAddress(sym);
1669+
if (auto declareOp =
1670+
mlir::dyn_cast<hlfir::DeclareOp>(privateValue.getDefiningOp()))
1671+
privateValue = declareOp.getResults()[0];
1672+
ivPrivate.push_back(privateValue);
16651673
}
16661674

16671675
static mlir::acc::LoopOp

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

+19
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,22 @@ subroutine sub1()
382382
end module
383383

384384
! CHECK: acc.parallel private(@privatization_ref_10xf32 -> %{{.*}} : !fir.ref<!fir.array<10xf32>>)
385+
386+
subroutine acc_private_use()
387+
integer :: i, j
388+
389+
!$acc parallel loop
390+
do i = 1, 10
391+
j = i
392+
end do
393+
end
394+
395+
! CHECK-LABEL: func.func @_QPacc_private_use()
396+
! CHECK: %[[I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFacc_private_useEi"}
397+
! CHECK: %[[DECL_I:.*]]:2 = hlfir.declare %0 {uniq_name = "_QFacc_private_useEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
398+
! CHECK: acc.parallel
399+
! CHECK: %[[PRIV_I:.*]] = acc.private varPtr(%[[DECL_I]]#1 : !fir.ref<i32>) -> !fir.ref<i32> {implicit = true, name = ""}
400+
! CHECK: %[[DECL_PRIV_I:.*]]:2 = hlfir.declare %[[PRIV_I]] {uniq_name = "_QFacc_private_useEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
401+
! CHECK: acc.loop private(@privatization_ref_i32 -> %[[PRIV_I]] : !fir.ref<i32>) control(%[[IV0:.*]] : i32) = (%c1{{.*}} : i32) to (%c10{{.*}} : i32) step (%c1{{.*}} : i32)
402+
! CHECK: fir.store %[[IV0]] to %[[DECL_PRIV_I]]#0 : !fir.ref<i32>
403+
! CHECK: %{{.*}} = fir.load %[[DECL_PRIV_I]]#0 : !fir.ref<i32>

0 commit comments

Comments
 (0)