Skip to content

Commit a0c5907

Browse files
authored
[Frontend][OpenMP] Allow implicit clauses to fail to apply (#100460)
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.
1 parent daf9d7f commit a0c5907

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,11 @@ bool ConstructDecompositionT<C, H>::applyClause(
11141114
template <typename C, typename H> bool ConstructDecompositionT<C, H>::split() {
11151115
bool success = true;
11161116

1117+
auto isImplicit = [this](const ClauseTy *node) {
1118+
return llvm::any_of(
1119+
implicit, [node](const ClauseTy &clause) { return &clause == node; });
1120+
};
1121+
11171122
for (llvm::omp::Directive leaf :
11181123
llvm::omp::getLeafConstructsOrSelf(construct))
11191124
leafs.push_back(LeafReprInternal{leaf, /*clauses=*/{}});
@@ -1153,9 +1158,10 @@ template <typename C, typename H> bool ConstructDecompositionT<C, H>::split() {
11531158
for (const ClauseTy *node : nodes) {
11541159
if (skip(node))
11551160
continue;
1156-
success =
1157-
success &&
1161+
bool result =
11581162
std::visit([&](auto &&s) { return applyClause(s, node); }, node->u);
1163+
if (!isImplicit(node))
1164+
success = success && result;
11591165
}
11601166

11611167
// Apply "allocate".

llvm/unittests/Frontend/OpenMPDecompositionTest.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,4 +1100,21 @@ TEST_F(OpenMPDecompositionTest, Nowait1) {
11001100
ASSERT_EQ(Dir1, "parallel"); // (23)
11011101
ASSERT_EQ(Dir2, "for"); // (23)
11021102
}
1103+
1104+
// ---
1105+
1106+
// Check that "simd linear(x)" does not fail despite the implied "firstprivate"
1107+
// (which "simd" does not allow).
1108+
TEST_F(OpenMPDecompositionTest, Misc1) {
1109+
omp::Object x{"x"};
1110+
omp::List<omp::Clause> Clauses{
1111+
{OMPC_linear,
1112+
omp::clause::Linear{{std::nullopt, std::nullopt, std::nullopt, {x}}}},
1113+
};
1114+
1115+
omp::ConstructDecomposition Dec(AnyVersion, Helper, OMPD_simd, Clauses);
1116+
ASSERT_EQ(Dec.output.size(), 1u);
1117+
std::string Dir0 = stringify(Dec.output[0]);
1118+
ASSERT_EQ(Dir0, "simd linear(, , , (x)) lastprivate(, (x))");
1119+
}
11031120
} // namespace

0 commit comments

Comments
 (0)