[flang-commits] [flang] [flang][openacc] Use the same iv privatize value in the loop region (PR #81821)
via flang-commits
flang-commits at lists.llvm.org
Wed Feb 14 21:01:44 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-openacc
Author: Valentin Clement (バレンタイン クレメン) (clementval)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/81821.diff
2 Files Affected:
- (modified) flang/lib/Lower/OpenACC.cpp (+9-1)
- (modified) flang/test/Lower/OpenACC/acc-private.f90 (+19)
``````````diff
diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
index 6ae270f63f5cf4..446b1529ca0088 100644
--- a/flang/lib/Lower/OpenACC.cpp
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -1658,10 +1658,18 @@ static void privatizeIv(Fortran::lower::AbstractConverter &converter,
mlir::acc::DataClause::acc_private, ivValue.getType());
privateOperands.push_back(op.getAccPtr());
- ivPrivate.push_back(op.getAccPtr());
privatizations.push_back(mlir::SymbolRefAttr::get(builder.getContext(),
recipe.getSymName().str()));
+
+ // Map the new private iv to its symbol for the scope of the loop. bindSymbol
+ // might create a hlfir.declare op, if so, we map its result in order to
+ // use the sym value in the scope.
converter.bindSymbol(sym, op.getAccPtr());
+ auto privateValue = converter.getSymbolAddress(sym);
+ if (auto declareOp =
+ mlir::dyn_cast<hlfir::DeclareOp>(privateValue.getDefiningOp()))
+ privateValue = declareOp.getResults()[0];
+ ivPrivate.push_back(privateValue);
}
static mlir::acc::LoopOp
diff --git a/flang/test/Lower/OpenACC/acc-private.f90 b/flang/test/Lower/OpenACC/acc-private.f90
index 29074cbaedc910..ba582d40f0f512 100644
--- a/flang/test/Lower/OpenACC/acc-private.f90
+++ b/flang/test/Lower/OpenACC/acc-private.f90
@@ -382,3 +382,22 @@ subroutine sub1()
end module
! CHECK: acc.parallel private(@privatization_ref_10xf32 -> %{{.*}} : !fir.ref<!fir.array<10xf32>>)
+
+subroutine acc_private_use()
+ integer :: i, j
+
+ !$acc parallel loop
+ do i = 1, 10
+ j = i
+ end do
+end
+
+! CHECK-LABEL: func.func @_QPacc_private_use()
+! CHECK: %[[I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFacc_private_useEi"}
+! CHECK: %[[DECL_I:.*]]:2 = hlfir.declare %0 {uniq_name = "_QFacc_private_useEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! CHECK: acc.parallel
+! CHECK: %[[PRIV_I:.*]] = acc.private varPtr(%[[DECL_I]]#1 : !fir.ref<i32>) -> !fir.ref<i32> {implicit = true, name = ""}
+! CHECK: %[[DECL_PRIV_I:.*]]:2 = hlfir.declare %[[PRIV_I]] {uniq_name = "_QFacc_private_useEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+! CHECK: acc.loop private(@privatization_ref_i32 -> %[[PRIV_I]] : !fir.ref<i32>) control(%[[IV0:.*]] : i32) = (%c1{{.*}} : i32) to (%c10{{.*}} : i32) step (%c1{{.*}} : i32)
+! CHECK: fir.store %[[IV0]] to %[[DECL_PRIV_I]]#0 : !fir.ref<i32>
+! CHECK: %{{.*}} = fir.load %[[DECL_PRIV_I]]#0 : !fir.ref<i32>
``````````
</details>
https://github.com/llvm/llvm-project/pull/81821
More information about the flang-commits
mailing list