Skip to content

Commit

Permalink
[Frontend][OpenMP] Allow implicit clauses to fail to apply (llvm#100460)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kparzysz authored Jul 25, 2024
1 parent daf9d7f commit a0c5907
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 8 additions & 2 deletions llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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=*/{}});
Expand Down Expand Up @@ -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".
Expand Down
17 changes: 17 additions & 0 deletions llvm/unittests/Frontend/OpenMPDecompositionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,4 +1100,21 @@ TEST_F(OpenMPDecompositionTest, Nowait1) {
ASSERT_EQ(Dir1, "parallel"); // (23)
ASSERT_EQ(Dir2, "for"); // (23)
}

// ---

// Check that "simd linear(x)" does not fail despite the implied "firstprivate"
// (which "simd" does not allow).
TEST_F(OpenMPDecompositionTest, Misc1) {
omp::Object x{"x"};
omp::List<omp::Clause> Clauses{
{OMPC_linear,
omp::clause::Linear{{std::nullopt, std::nullopt, std::nullopt, {x}}}},
};

omp::ConstructDecomposition Dec(AnyVersion, Helper, OMPD_simd, Clauses);
ASSERT_EQ(Dec.output.size(), 1u);
std::string Dir0 = stringify(Dec.output[0]);
ASSERT_EQ(Dir0, "simd linear(, , , (x)) lastprivate(, (x))");
}
} // namespace

0 comments on commit a0c5907

Please sign in to comment.