[flang-commits] [flang] [flang][OpenMP] Allow loop iteration variables in DSA clauses (PR #86194)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Fri Mar 22 09:51:55 PDT 2024


https://github.com/luporl updated https://github.com/llvm/llvm-project/pull/86194

>From 3dfc430277045c7c20a2f6ecf84f7469d91ba648 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Thu, 21 Mar 2024 17:24:04 -0300
Subject: [PATCH 1/3] [flang][OpenMP] Allow loop iteration variables in DSA
 clauses

Iteration variables of non-associated loops may be listed in DSA
clauses.

Fixes https://github.com/llvm/llvm-project/issues/78938
---
 flang/lib/Semantics/resolve-directives.cpp |  6 ++++++
 flang/test/Semantics/OpenMP/do20.f90       | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+)
 create mode 100644 flang/test/Semantics/OpenMP/do20.f90

diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 6d58013b87d298..95dea05d9a760d 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1649,6 +1649,12 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
       break;
     }
   }
+  // If this symbol already has a data-sharing attribute then there is nothing
+  // to do here.
+  if (const Symbol *symbol = iv.symbol)
+    for (auto symMap : targetIt->objectWithDSA)
+      if (symMap.first->name() == symbol->name())
+        return;
   // If this symbol is already Private or Firstprivate in the enclosing
   // OpenMP parallel or task then there is nothing to do here.
   if (auto *symbol{targetIt->scope.FindSymbol(iv.source)}) {
diff --git a/flang/test/Semantics/OpenMP/do20.f90 b/flang/test/Semantics/OpenMP/do20.f90
new file mode 100644
index 00000000000000..915d01e69edd74
--- /dev/null
+++ b/flang/test/Semantics/OpenMP/do20.f90
@@ -0,0 +1,18 @@
+! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp
+
+! OpenMP 5.2 5.1.1
+! Iteration variables of non-associated loops may be listed in DSA clauses.
+
+!DEF: /shared_iv (Subroutine)Subprogram
+subroutine shared_iv
+  !DEF: /shared_iv/i ObjectEntity INTEGER(4)
+  integer i
+
+  !$omp parallel shared(i)
+    !$omp single
+      !REF: /shared_iv/i
+      do i = 0, 1
+      end do
+    !$omp end single
+  !$omp end parallel
+end subroutine

>From ddce6d5b5266915aa48a60501bc17571bd09f485 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Fri, 22 Mar 2024 13:40:01 -0300
Subject: [PATCH 2/3] Fix style

---
 flang/lib/Semantics/resolve-directives.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 95dea05d9a760d..8bbe4117975740 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1651,10 +1651,13 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
   }
   // If this symbol already has a data-sharing attribute then there is nothing
   // to do here.
-  if (const Symbol *symbol = iv.symbol)
-    for (auto symMap : targetIt->objectWithDSA)
-      if (symMap.first->name() == symbol->name())
+  if (const Symbol *symbol{iv.symbol}) {
+    for (auto symMap : targetIt->objectWithDSA) {
+      if (symMap.first->name() == symbol->name()) {
         return;
+      }
+    }
+  }
   // If this symbol is already Private or Firstprivate in the enclosing
   // OpenMP parallel or task then there is nothing to do here.
   if (auto *symbol{targetIt->scope.FindSymbol(iv.source)}) {

>From 8e76367a067620c7261fe5f143fd563641c6d9bf Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Fri, 22 Mar 2024 13:51:27 -0300
Subject: [PATCH 3/3] clang-format

---
 flang/lib/Semantics/resolve-directives.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 8bbe4117975740..27af192f606be9 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1651,7 +1651,7 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
   }
   // If this symbol already has a data-sharing attribute then there is nothing
   // to do here.
-  if (const Symbol *symbol{iv.symbol}) {
+  if (const Symbol * symbol{iv.symbol}) {
     for (auto symMap : targetIt->objectWithDSA) {
       if (symMap.first->name() == symbol->name()) {
         return;



More information about the flang-commits mailing list