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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading