Skip to content

Commit 3f526f3

Browse files
kparzyszIanWood1
authored andcommitted
[flang][OpenMP] Allow UPDATE clause to not have any arguments (llvm#137521)
The UPDATE clause can be specified on both ATOMIC and DEPOBJ directives. Currently, the ATOMIC directive has its own handling of it, and the definition of the UPDATE clause only supports its use in the DEPOBJ directive, where it takes a dependence-type as an argument. The UPDATE clause on the ATOMIC directive may not have any arguments. Since the implementation of the ATOMIC construct will be modified to use the standard handling of clauses, the definition of UPDATE should reflect that.
1 parent 8e39e16 commit 3f526f3

File tree

5 files changed

+53
-29
lines changed

5 files changed

+53
-29
lines changed

flang/include/flang/Parser/parse-tree.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4501,6 +4501,11 @@ struct OmpToClause {
45014501

45024502
// Ref: [5.0:254-255], [5.1:287-288], [5.2:321-322]
45034503
//
4504+
// In ATOMIC construct
4505+
// update-clause ->
4506+
// UPDATE // Since 4.5
4507+
//
4508+
// In DEPOBJ construct
45044509
// update-clause ->
45054510
// UPDATE(dependence-type) // since 5.0, until 5.1
45064511
// update-clause ->

flang/lib/Lower/OpenMP/Clauses.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,9 +1400,13 @@ Uniform make(const parser::OmpClause::Uniform &inp,
14001400
Update make(const parser::OmpClause::Update &inp,
14011401
semantics::SemanticsContext &semaCtx) {
14021402
// inp.v -> parser::OmpUpdateClause
1403-
auto depType =
1404-
common::visit([](auto &&s) { return makeDepType(s); }, inp.v.u);
1405-
return Update{/*DependenceType=*/depType};
1403+
if (inp.v) {
1404+
return common::visit(
1405+
[](auto &&s) { return Update{/*DependenceType=*/makeDepType(s)}; },
1406+
inp.v->u);
1407+
} else {
1408+
return Update{/*DependenceType=*/std::nullopt};
1409+
}
14061410
}
14071411

14081412
Use make(const parser::OmpClause::Use &inp,

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,9 @@ TYPE_PARSER(construct<OmpInitClause>(
836836
TYPE_PARSER(construct<OmpAlignedClause>(Parser<OmpObjectList>{},
837837
maybe(":" >> nonemptyList(Parser<OmpAlignedClause::Modifier>{}))))
838838

839-
TYPE_PARSER(construct<OmpUpdateClause>(
840-
construct<OmpUpdateClause>(Parser<OmpDependenceType>{}) ||
841-
construct<OmpUpdateClause>(Parser<OmpTaskDependenceType>{})))
839+
TYPE_PARSER( //
840+
construct<OmpUpdateClause>(parenthesized(Parser<OmpDependenceType>{})) ||
841+
construct<OmpUpdateClause>(parenthesized(Parser<OmpTaskDependenceType>{})))
842842

843843
TYPE_PARSER(construct<OmpOrderClause>(
844844
maybe(nonemptyList(Parser<OmpOrderClause::Modifier>{}) / ":"),
@@ -1079,7 +1079,7 @@ TYPE_PARSER( //
10791079
parenthesized(nonemptyList(name)))) ||
10801080
"UNTIED" >> construct<OmpClause>(construct<OmpClause::Untied>()) ||
10811081
"UPDATE" >> construct<OmpClause>(construct<OmpClause::Update>(
1082-
parenthesized(Parser<OmpUpdateClause>{}))) ||
1082+
maybe(Parser<OmpUpdateClause>{}))) ||
10831083
"WHEN" >> construct<OmpClause>(construct<OmpClause::When>(
10841084
parenthesized(Parser<OmpWhenClause>{}))) ||
10851085
// Cancellable constructs
@@ -1313,24 +1313,30 @@ TYPE_PARSER(
13131313
endOfLine)
13141314

13151315
// Directives enclosing structured-block
1316-
TYPE_PARSER(construct<OmpBlockDirective>(first(
1317-
"MASKED" >> pure(llvm::omp::Directive::OMPD_masked),
1318-
"MASTER" >> pure(llvm::omp::Directive::OMPD_master),
1319-
"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered),
1320-
"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked),
1321-
"PARALLEL MASTER" >> pure(llvm::omp::Directive::OMPD_parallel_master),
1322-
"PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare),
1323-
"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel),
1324-
"SCOPE" >> pure(llvm::omp::Directive::OMPD_scope),
1325-
"SINGLE" >> pure(llvm::omp::Directive::OMPD_single),
1326-
"TARGET DATA" >> pure(llvm::omp::Directive::OMPD_target_data),
1327-
"TARGET PARALLEL" >> pure(llvm::omp::Directive::OMPD_target_parallel),
1328-
"TARGET TEAMS" >> pure(llvm::omp::Directive::OMPD_target_teams),
1329-
"TARGET" >> pure(llvm::omp::Directive::OMPD_target),
1330-
"TASK"_id >> pure(llvm::omp::Directive::OMPD_task),
1331-
"TASKGROUP" >> pure(llvm::omp::Directive::OMPD_taskgroup),
1332-
"TEAMS" >> pure(llvm::omp::Directive::OMPD_teams),
1333-
"WORKSHARE" >> pure(llvm::omp::Directive::OMPD_workshare))))
1316+
TYPE_PARSER(
1317+
// In this context "TARGET UPDATE" can be parsed as a TARGET directive
1318+
// followed by an UPDATE clause. This is the only combination at the
1319+
// moment, exclude it explicitly.
1320+
(!"TARGET UPDATE"_sptok) >=
1321+
construct<OmpBlockDirective>(first(
1322+
"MASKED" >> pure(llvm::omp::Directive::OMPD_masked),
1323+
"MASTER" >> pure(llvm::omp::Directive::OMPD_master),
1324+
"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered),
1325+
"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked),
1326+
"PARALLEL MASTER" >> pure(llvm::omp::Directive::OMPD_parallel_master),
1327+
"PARALLEL WORKSHARE" >>
1328+
pure(llvm::omp::Directive::OMPD_parallel_workshare),
1329+
"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel),
1330+
"SCOPE" >> pure(llvm::omp::Directive::OMPD_scope),
1331+
"SINGLE" >> pure(llvm::omp::Directive::OMPD_single),
1332+
"TARGET DATA" >> pure(llvm::omp::Directive::OMPD_target_data),
1333+
"TARGET PARALLEL" >> pure(llvm::omp::Directive::OMPD_target_parallel),
1334+
"TARGET TEAMS" >> pure(llvm::omp::Directive::OMPD_target_teams),
1335+
"TARGET" >> pure(llvm::omp::Directive::OMPD_target),
1336+
"TASK"_id >> pure(llvm::omp::Directive::OMPD_task),
1337+
"TASKGROUP" >> pure(llvm::omp::Directive::OMPD_taskgroup),
1338+
"TEAMS" >> pure(llvm::omp::Directive::OMPD_teams),
1339+
"WORKSHARE" >> pure(llvm::omp::Directive::OMPD_workshare))))
13341340

13351341
TYPE_PARSER(sourced(construct<OmpBeginBlockDirective>(
13361342
sourced(Parser<OmpBlockDirective>{}), Parser<OmpClauseList>{})))

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4571,10 +4571,18 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Update &x) {
45714571
llvm::omp::Directive dir{GetContext().directive};
45724572
unsigned version{context_.langOptions().OpenMPVersion};
45734573

4574-
auto *depType{std::get_if<parser::OmpDependenceType>(&x.v.u)};
4575-
auto *taskType{std::get_if<parser::OmpTaskDependenceType>(&x.v.u)};
4576-
assert(((depType == nullptr) != (taskType == nullptr)) &&
4577-
"Unexpected alternative in update clause");
4574+
const parser::OmpDependenceType *depType{nullptr};
4575+
const parser::OmpTaskDependenceType *taskType{nullptr};
4576+
if (auto &maybeUpdate{x.v}) {
4577+
depType = std::get_if<parser::OmpDependenceType>(&maybeUpdate->u);
4578+
taskType = std::get_if<parser::OmpTaskDependenceType>(&maybeUpdate->u);
4579+
}
4580+
4581+
if (!depType && !taskType) {
4582+
assert(dir == llvm::omp::Directive::OMPD_atomic &&
4583+
"Unexpected alternative in update clause");
4584+
return;
4585+
}
45784586

45794587
if (depType) {
45804588
CheckDependenceType(depType->v);

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ def OMPC_Untied : Clause<"untied"> {
525525
def OMPC_Update : Clause<"update"> {
526526
let clangClass = "OMPUpdateClause";
527527
let flangClass = "OmpUpdateClause";
528+
let isValueOptional = true;
528529
}
529530
def OMPC_Use : Clause<"use"> {
530531
let clangClass = "OMPUseClause";

0 commit comments

Comments
 (0)