-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
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.
@llvm/pr-subscribers-flang-openmp Author: Krzysztof Parzyszek (kparzysz) ChangesThe Full diff: https://github.com/llvm/llvm-project/pull/100460.diff 1 Files Affected:
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".
|
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.
It makes sense to me, but I think we should have a test to check it before merging.
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.
Thank you, LGTM.
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
The
linear(x)
clause impliesfirstprivate(x)
on the compound construct ifx
is not an induction variable. With more construct combinations coming in OpenMP 6.0, thefirstprivate
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 lonesimd
construct could imply afirstprivate
clause that can't be applied.