[flang-commits] [flang] [flang][OpenMP] Enable lastprivate with collapse (PR #93778)

via flang-commits flang-commits at lists.llvm.org
Thu May 30 00:46:12 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: None (NimishMishra)

<details>
<summary>Changes</summary>

This PR enables the lowering of lastprivate in presence of collapse clause. 

---
Full diff: https://github.com/llvm/llvm-project/pull/93778.diff


2 Files Affected:

- (modified) flang/lib/Lower/OpenMP/DataSharingProcessor.cpp (+1-6) 
- (modified) flang/test/Lower/OpenMP/wsloop-collapse.f90 (+33) 


``````````diff
diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
index 557a9685024c5..8aa37035ddee5 100644
--- a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
@@ -143,7 +143,7 @@ void DataSharingProcessor::collectOmpObjectListSymbol(
 }
 
 void DataSharingProcessor::collectSymbolsForPrivatization() {
-  bool hasCollapse = false;
+
   for (const omp::Clause &clause : clauses) {
     if (const auto &privateClause =
             std::get_if<omp::clause::Private>(&clause.u)) {
@@ -157,16 +157,11 @@ void DataSharingProcessor::collectSymbolsForPrivatization() {
       const ObjectList &objects = std::get<ObjectList>(lastPrivateClause->t);
       collectOmpObjectListSymbol(objects, explicitlyPrivatizedSymbols);
       hasLastPrivateOp = true;
-    } else if (std::get_if<omp::clause::Collapse>(&clause.u)) {
-      hasCollapse = true;
     }
   }
 
   for (auto *sym : explicitlyPrivatizedSymbols)
     allPrivatizedSymbols.insert(sym);
-
-  if (hasCollapse && hasLastPrivateOp)
-    TODO(converter.getCurrentLocation(), "Collapse clause with lastprivate");
 }
 
 bool DataSharingProcessor::needBarrier() {
diff --git a/flang/test/Lower/OpenMP/wsloop-collapse.f90 b/flang/test/Lower/OpenMP/wsloop-collapse.f90
index 67351ca275efb..3e862c25a8089 100644
--- a/flang/test/Lower/OpenMP/wsloop-collapse.f90
+++ b/flang/test/Lower/OpenMP/wsloop-collapse.f90
@@ -94,3 +94,36 @@ program wsloop_collapse
 !CHECK:         return
 !CHECK:       }
 end program wsloop_collapse
+
+subroutine collapse_with_lastprivate
+!CHECK: %[[VAL_I:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFcollapse_with_lastprivateEi"}
+!CHECK: %[[VAL_I_DECLARE:.*]]:2 = hlfir.declare %[[VAL_I]] {{.*}}
+!CHECK: %[[VAL_J:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFcollapse_with_lastprivateEj"}
+!CHECK: %[[VAL_J_DECLARE:.*]]:2 = hlfir.declare %[[VAL_J]] {{.*}}
+!CHECK: %[[VAL_K:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFcollapse_with_lastprivateEk"}
+!CHECK: %[[VAL_K_DECLARE:.*]]:2 = hlfir.declare %[[VAL_K]] {{.}}
+!CHECK: %[[VAL_X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFcollapse_with_lastprivateEx"}
+!CHECK: %[[VAL_X_DECLARE:.*]]:2 = hlfir.declare %[[VAL_X]] {{.*}}
+
+        integer :: x, i, j, k
+
+!CHECK: omp.parallel {
+!CHECK: %[[INNER_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFcollapse_with_lastprivateEx"}
+!CHECK: %[[INNER_X_DECLARE:.*]]:2 = hlfir.declare %[[INNER_X]] {{.*}}
+        !$omp parallel do lastprivate(x) collapse(2)
+!CHECK: omp.wsloop {
+!CHECK: omp.loop_nest (%[[ARG0:.*]], %[[ARG1:.*]]) : i32 = (%[[LB1:.*]], %[[LB2:.*]]) to (%[[UB1:.*]], %[[UB2:.*]]) inclusive step (%[[STEP1:.*]], %[[STEP2:.*]]) {
+           do i = 1, 10
+             do j = 1, 20
+!CHECK: %[[LOOP_CONTROL:.*]]:2 = fir.do_loop %[[ARG2:.*]] = {{.*}}
+               do k = 1, 30
+                 x = x + 1
+               end do
+             end do
+           end do
+!CHECK: fir.if {{.*}} {
+!CHECK: %[[LOADED_X:.*]] = fir.load %[[INNER_X_DECLARE]]#0 : !fir.ref<i32>
+!CHECK: hlfir.assign %[[LOADED_X]] to %[[VAL_X_DECLARE]]#0 temporary_lhs : i32, !fir.ref<i32>
+!CHECK: }
+        !$omp end parallel do
+end subroutine

``````````

</details>


https://github.com/llvm/llvm-project/pull/93778


More information about the flang-commits mailing list