Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][OpenMP] Allow loop iteration variables in DSA clauses #86194

Merged
merged 3 commits into from
Mar 25, 2024

Conversation

luporl
Copy link
Contributor

@luporl luporl commented Mar 21, 2024

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

Fixes #78938

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

Fixes llvm#78938
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:openmp flang:semantics labels Mar 21, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 21, 2024

@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-openmp

Author: Leandro Lupori (luporl)

Changes

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

Fixes #78938


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

2 Files Affected:

  • (modified) flang/lib/Semantics/resolve-directives.cpp (+6)
  • (added) flang/test/Semantics/OpenMP/do20.f90 (+18)
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

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please wait for @mjklemm

Comment on lines 1654 to 1657
if (const Symbol *symbol = iv.symbol)
for (auto symMap : targetIt->objectWithDSA)
if (symMap.first->name() == symbol->name())
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Frontend style uses curly braces.

Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link

github-actions bot commented Mar 22, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@luporl
Copy link
Contributor Author

luporl commented Mar 22, 2024

Thanks for the quick reviews!

@luporl luporl merged commit edcf65d into llvm:main Mar 25, 2024
4 checks passed
@luporl luporl deleted the luporl-fix-omp-shared-iv branch March 25, 2024 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:openmp flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Flang][OpenMP] Incorrect execution result of a do-variable defined as shared in parallel construct
4 participants