Skip to content

[Frontend][OpenMP] Allow implicit clauses to fail to apply #100460

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

Merged
merged 2 commits into from
Jul 25, 2024

Conversation

kparzysz
Copy link
Contributor

@kparzysz kparzysz commented Jul 24, 2024

The linear(x) clause implies firstprivate(x) on the compound construct if x is not an induction variable. With more construct combinations coming in OpenMP 6.0, the firstprivate clause may not be possible to apply, e.g. in "masked simd".
An additional benefit from this change is that it allows treating leaf constructs as combined constructs with a single constituent. Otherwise, a linear clause on a lone simd construct could imply a firstprivate clause that can't be applied.

The `linear(x)` clause implies `firstprivate(x)` on the compound construct
if `x` is not an induction variable. With more construct combinations
coming in OpenMP 6.0, the `firstprivate` clause may not be possible to
apply, e.g. in "masked simd".
An additional benefit from this change is that it allows treating leaf
constructs as combined constructs with a single constituent. Otherwise,
a `linear` clause on a `simd` construct could imply a `firstprivate`
clause that can't be applied.
@kparzysz kparzysz requested a review from skatrak July 24, 2024 20:12
@llvmbot llvmbot added flang:openmp clang:openmp OpenMP related changes to Clang labels Jul 24, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 24, 2024

@llvm/pr-subscribers-flang-openmp

Author: Krzysztof Parzyszek (kparzysz)

Changes

The linear(x) clause implies firstprivate(x) on the compound construct if x is not an induction variable. With more construct combinations coming in OpenMP 6.0, the firstprivate clause may not be possible to apply, e.g. in "masked simd".
An additional benefit from this change is that it allows treating leaf constructs as combined constructs with a single constituent. Otherwise, a linear clause on a simd construct could imply a firstprivate clause that can't be applied.


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

1 Files Affected:

  • (modified) llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h (+8-2)
diff --git a/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h b/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
index 349d862135d8c..b93bc594a82bf 100644
--- a/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
+++ b/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
@@ -1114,6 +1114,11 @@ bool ConstructDecompositionT<C, H>::applyClause(
 template <typename C, typename H> bool ConstructDecompositionT<C, H>::split() {
   bool success = true;
 
+  auto isImplicit = [this](const ClauseTy *node) {
+    return llvm::any_of(
+        implicit, [node](const ClauseTy &clause) { return &clause == node; });
+  };
+
   for (llvm::omp::Directive leaf :
        llvm::omp::getLeafConstructsOrSelf(construct))
     leafs.push_back(LeafReprInternal{leaf, /*clauses=*/{}});
@@ -1153,9 +1158,10 @@ template <typename C, typename H> bool ConstructDecompositionT<C, H>::split() {
   for (const ClauseTy *node : nodes) {
     if (skip(node))
       continue;
-    success =
-        success &&
+    bool result =
         std::visit([&](auto &&s) { return applyClause(s, node); }, node->u);
+    if (!isImplicit(node))
+      success = success && result;
   }
 
   // Apply "allocate".

Copy link
Member

@skatrak skatrak left a comment

Choose a reason for hiding this comment

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

It makes sense to me, but I think we should have a test to check it before merging.

Copy link
Member

@skatrak skatrak left a comment

Choose a reason for hiding this comment

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

Thank you, LGTM.

@kparzysz kparzysz merged commit a0c5907 into llvm:main Jul 25, 2024
7 checks passed
@kparzysz kparzysz deleted the users/kparzysz/implicit-fail branch July 25, 2024 14:20
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary:
The `linear(x)` clause implies `firstprivate(x)` on the compound
construct if `x` is not an induction variable. With more construct
combinations coming in OpenMP 6.0, the `firstprivate` clause may not be
possible to apply, e.g. in "masked simd".
An additional benefit from this change is that it allows treating leaf
constructs as combined constructs with a single constituent. Otherwise,
a `linear` clause on a lone `simd` construct could imply a
`firstprivate` clause that can't be applied.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250572
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:openmp OpenMP related changes to Clang flang:openmp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants