-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[flang][OpenMP] Make static duration variables default to shared DSA #142783
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] Make static duration variables default to shared DSA #142783
Conversation
@llvm/pr-subscribers-flang-semantics @llvm/pr-subscribers-flang-openmp Author: Kajetan Puchalski (mrkajetanp) ChangesAccording to the OpenMP standard, variables with static storage duration are predetermined as shared. Fixes llvm#140732. Full diff: https://github.com/llvm/llvm-project/pull/142783.diff 2 Files Affected:
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index ec385b7baf8bd..d1495e7b3b7f2 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -2310,6 +2310,8 @@ void OmpAttributeVisitor::CreateImplicitSymbols(const Symbol *symbol) {
bool targetDir = llvm::omp::allTargetSet.test(dirContext.directive);
bool parallelDir = llvm::omp::allParallelSet.test(dirContext.directive);
bool teamsDir = llvm::omp::allTeamsSet.test(dirContext.directive);
+ bool isStaticStorageDuration =
+ symbol->flags().test(Symbol::Flag::InDataStmt);
if (dsa.any()) {
if (parallelDir || taskGenDir || teamsDir) {
@@ -2367,7 +2369,8 @@ void OmpAttributeVisitor::CreateImplicitSymbols(const Symbol *symbol) {
dsa = prevDSA;
} else if (taskGenDir) {
// TODO 5) dummy arg in orphaned taskgen construct -> firstprivate
- if (prevDSA.test(Symbol::Flag::OmpShared)) {
+ // variables with static storage duration are predetermined as shared
+ if (prevDSA.test(Symbol::Flag::OmpShared) || isStaticStorageDuration) {
// 6) shared in enclosing context -> shared
dsa = {Symbol::Flag::OmpShared};
makeSymbol(dsa);
diff --git a/flang/test/Semantics/OpenMP/implicit-dsa.f90 b/flang/test/Semantics/OpenMP/implicit-dsa.f90
index 7e38435274b7b..9e48dd2a83257 100644
--- a/flang/test/Semantics/OpenMP/implicit-dsa.f90
+++ b/flang/test/Semantics/OpenMP/implicit-dsa.f90
@@ -169,3 +169,23 @@ subroutine implicit_dsa_test8
end do
!$omp end task
end subroutine
+
+! Test static storage duration variables default to shared DSA
+!DEF: /implicit_dsa_test9_mod Module
+module implicit_dsa_test9_mod
+ !DEF: /implicit_dsa_test9_mod/tm3a PUBLIC (InDataStmt) ObjectEntity COMPLEX(4)
+ complex tm3a/(0,0)/
+contains
+ !DEF: /implicit_dsa_test9_mod/implict_dsa_test9 PUBLIC (Subroutine) Subprogram
+ subroutine implict_dsa_test9
+ !$omp task
+ !$omp task
+ !DEF: /implicit_dsa_test9_mod/implict_dsa_test9/OtherConstruct1/OtherConstruct1/tm3a (OmpShared) HostAssoc COMPLEX(4)
+ tm3a = (1, 2)
+ !$omp end task
+ !$omp end task
+ !$omp taskwait
+ !REF: /implicit_dsa_test9_mod/tm3a
+ print *,tm3a
+ end subroutine
+end module
|
The OpenMP standard says the following for static storage duration:
Could you comment on whether all these cases (variable with SAVE, common block object, variables in module) are handled in this patch? |
The patch checks for the InDataStmt flag, which I think should be set in all of these cases. I'll add tests for those alongside the changes Tom asked for to make sure. |
I've checked the other cases. Variables with SAVE and common block objects do not actually have any Symbol flags set on them as things stand, so with the patch as-is they will not be shared. Should the approach then be to always determine whether the symbol has static storage duration and if so make it shared? I think that'd require adding some more plumbing to get the right information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM but please don't merge without approval from @luporl.
I'm a bit surprised there wasn't already a flag for common blocks but it seems like you are right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Note that I'm assuming the reason for static storage variables defaulting to shared DSA is:
- Implicit rule that says that in a task generating construct, with no default clause, a variable that is shared in the enclosing context is determined to be shared.
- When the enclosing context is not an OpenMP directive, a variable is shared if it has static storage duration.
According to the OpenMP standard, variables with static storage duration are predetermined as shared. Add a check when creating implicit symbols for OpenMP to fix them erroneously getting set to firstprivate. Fixes llvm#140732. Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
6a2676f
to
037a68e
Compare
Hello, this PR caused regression in the following Fujitsu tests:
"NG" (probably means "not good") should not appear in the output. When I compile flang with the commit just before the one in this PR, the tests pass. Now, it's possible that these tests are incorrect or perhaps not everything needed by these tests is implemented. Could someone please take a look? I could file a new issue for flang/OpenMP, if it's easier. Thanks! |
Very interesting, you're right, though I'm quite surprised it's hitting that code path. |
The issue is that the current implementation checks the ultimate symbol rather than the 'enclosing' symbol. In this case because there are multiple nesting levels, the enclosing symbol is actually an implicitly created one rather than the ultimate one.
|
It looks like we're not handling the DSA of the enclosing symbol correctly in implicit rule "6". If the flags of the enclosing context symbol have any DSA set, we should not consider whether the ultimate symbol has static storage duration or not. Replacing
by
should fix it. |
Good suggestion, thanks! This makes it work for me. PR here: #143601 |
…lvm#142783) According to the OpenMP standard, variables with static storage duration are predetermined as shared. Add a check when creating implicit symbols for OpenMP to fix them erroneously getting set to firstprivate. Fixes llvm#140732. --------- Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
…lvm#142783) According to the OpenMP standard, variables with static storage duration are predetermined as shared. Add a check when creating implicit symbols for OpenMP to fix them erroneously getting set to firstprivate. Fixes llvm#140732. --------- Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
…lvm#142783) According to the OpenMP standard, variables with static storage duration are predetermined as shared. Add a check when creating implicit symbols for OpenMP to fix them erroneously getting set to firstprivate. Fixes llvm#140732. --------- Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
According to the OpenMP standard, variables with static storage duration are predetermined as shared.
Add a check when creating implicit symbols for OpenMP to fix them erroneously getting set to firstprivate.
Fixes #140732.