Skip to content

Commit 386ff11

Browse files
authored
[flang][OpenMP] Use OmpMemoryOrderType enumeration in FAIL clause (#136313)
Make the FAIL clause contain OmpMemoryOrderType enumeration instead of OmpClause. This simplifies the semantic checks of the FAIL clause.
1 parent a1f369e commit 386ff11

File tree

6 files changed

+42
-73
lines changed

6 files changed

+42
-73
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4242,9 +4242,8 @@ struct OmpDeviceTypeClause {
42424242
// OMP 5.2 15.8.3 extended-atomic, fail-clause ->
42434243
// FAIL(memory-order)
42444244
struct OmpFailClause {
4245-
WRAPPER_CLASS_BOILERPLATE(
4246-
OmpFailClause, common::Indirection<OmpMemoryOrderClause>);
4247-
CharBlock source;
4245+
using MemoryOrder = common::OmpMemoryOrderType;
4246+
WRAPPER_CLASS_BOILERPLATE(OmpFailClause, MemoryOrder);
42484247
};
42494248

42504249
// Ref: [4.5:107-109], [5.0:176-180], [5.1:205-210], [5.2:167-168]

flang/lib/Lower/OpenMP/Clauses.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,19 @@ Exclusive make(const parser::OmpClause::Exclusive &inp,
785785

786786
Fail make(const parser::OmpClause::Fail &inp,
787787
semantics::SemanticsContext &semaCtx) {
788-
// inp -> empty
789-
llvm_unreachable("Empty: fail");
788+
// inp.v -> parser::OmpFalClause
789+
CLAUSET_ENUM_CONVERT( //
790+
convert, common::OmpMemoryOrderType, Fail::MemoryOrder,
791+
// clang-format off
792+
MS(Acq_Rel, AcqRel)
793+
MS(Acquire, Acquire)
794+
MS(Relaxed, Relaxed)
795+
MS(Release, Release)
796+
MS(Seq_Cst, SeqCst)
797+
// clang-format on
798+
);
799+
800+
return Fail{/*MemoryOrder=*/convert(inp.v.v)};
790801
}
791802

792803
Filter make(const parser::OmpClause::Filter &inp,

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,13 @@ TYPE_PARSER(construct<OmpDefaultClause>(
666666
Parser<OmpDefaultClause::DataSharingAttribute>{}) ||
667667
construct<OmpDefaultClause>(indirect(Parser<OmpDirectiveSpecification>{}))))
668668

669+
TYPE_PARSER(construct<OmpFailClause>(
670+
"ACQ_REL" >> pure(common::OmpMemoryOrderType::Acq_Rel) ||
671+
"ACQUIRE" >> pure(common::OmpMemoryOrderType::Acquire) ||
672+
"RELAXED" >> pure(common::OmpMemoryOrderType::Relaxed) ||
673+
"RELEASE" >> pure(common::OmpMemoryOrderType::Release) ||
674+
"SEQ_CST" >> pure(common::OmpMemoryOrderType::Seq_Cst)))
675+
669676
// 2.5 PROC_BIND (MASTER | CLOSE | PRIMARY | SPREAD)
670677
TYPE_PARSER(construct<OmpProcBindClause>(
671678
"CLOSE" >> pure(OmpProcBindClause::AffinityPolicy::Close) ||
@@ -943,6 +950,8 @@ TYPE_PARSER( //
943950
parenthesized(Parser<OmpObjectList>{}))) ||
944951
"EXCLUSIVE" >> construct<OmpClause>(construct<OmpClause::Exclusive>(
945952
parenthesized(Parser<OmpObjectList>{}))) ||
953+
"FAIL" >> construct<OmpClause>(construct<OmpClause::Fail>(
954+
parenthesized(Parser<OmpFailClause>{}))) ||
946955
"FILTER" >> construct<OmpClause>(construct<OmpClause::Filter>(
947956
parenthesized(scalarIntExpr))) ||
948957
"FINAL" >> construct<OmpClause>(construct<OmpClause::Final>(
@@ -1201,9 +1210,6 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
12011210
TYPE_PARSER(sourced(construct<OmpBeginLoopDirective>(
12021211
sourced(Parser<OmpLoopDirective>{}), Parser<OmpClauseList>{})))
12031212

1204-
TYPE_PARSER(sourced(construct<OmpFailClause>(
1205-
parenthesized(indirect(Parser<OmpMemoryOrderClause>{})))))
1206-
12071213
// 2.17.7 Atomic construct/2.17.8 Flush construct [OpenMP 5.0]
12081214
// memory-order-clause ->
12091215
// acq_rel
@@ -1222,7 +1228,8 @@ TYPE_PARSER(sourced(construct<OmpMemoryOrderClause>(
12221228
// atomic-clause -> memory-order-clause | HINT(hint-expression)
12231229
TYPE_PARSER(sourced(construct<OmpAtomicClause>(
12241230
construct<OmpAtomicClause>(Parser<OmpMemoryOrderClause>{}) ||
1225-
construct<OmpAtomicClause>("FAIL" >> Parser<OmpFailClause>{}) ||
1231+
construct<OmpAtomicClause>(
1232+
"FAIL" >> parenthesized(Parser<OmpFailClause>{})) ||
12261233
construct<OmpAtomicClause>(
12271234
"HINT" >> parenthesized(Parser<OmpHintClause>{})))))
12281235

flang/lib/Parser/unparse.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,22 +2889,20 @@ class UnparseVisitor {
28892889
Put("\n");
28902890
EndOpenMP();
28912891
}
2892-
void Unparse(const OmpFailClause &x) {
2893-
Word("FAIL(");
2894-
Walk(x.v);
2895-
Put(")");
2896-
}
2897-
void Unparse(const OmpHintClause &x) {
2898-
Word("HINT(");
2899-
Walk(x.v);
2900-
Put(")");
2901-
}
29022892
void Unparse(const OmpMemoryOrderClause &x) { Walk(x.v); }
29032893
void Unparse(const OmpAtomicClause &x) {
29042894
common::visit(common::visitors{
29052895
[&](const OmpMemoryOrderClause &y) { Walk(y); },
2906-
[&](const OmpFailClause &y) { Walk(y); },
2907-
[&](const OmpHintClause &y) { Walk(y); },
2896+
[&](const OmpFailClause &y) {
2897+
Word("FAIL(");
2898+
Walk(y.v);
2899+
Put(")");
2900+
},
2901+
[&](const OmpHintClause &y) {
2902+
Word("HINT(");
2903+
Walk(y.v);
2904+
Put(")");
2905+
},
29082906
},
29092907
x.u);
29102908
}

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

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,12 @@ CHECK_SIMPLE_CLAUSE(Align, OMPC_align)
32623262
CHECK_SIMPLE_CLAUSE(Compare, OMPC_compare)
32633263
CHECK_SIMPLE_CLAUSE(OmpxAttribute, OMPC_ompx_attribute)
32643264
CHECK_SIMPLE_CLAUSE(Weak, OMPC_weak)
3265+
CHECK_SIMPLE_CLAUSE(AcqRel, OMPC_acq_rel)
3266+
CHECK_SIMPLE_CLAUSE(Acquire, OMPC_acquire)
3267+
CHECK_SIMPLE_CLAUSE(Relaxed, OMPC_relaxed)
3268+
CHECK_SIMPLE_CLAUSE(Release, OMPC_release)
3269+
CHECK_SIMPLE_CLAUSE(SeqCst, OMPC_seq_cst)
3270+
CHECK_SIMPLE_CLAUSE(Fail, OMPC_fail)
32653271

32663272
CHECK_REQ_SCALAR_INT_CLAUSE(NumTeams, OMPC_num_teams)
32673273
CHECK_REQ_SCALAR_INT_CLAUSE(NumThreads, OMPC_num_threads)
@@ -3273,53 +3279,6 @@ CHECK_REQ_CONSTANT_SCALAR_INT_CLAUSE(Collapse, OMPC_collapse)
32733279
CHECK_REQ_CONSTANT_SCALAR_INT_CLAUSE(Safelen, OMPC_safelen)
32743280
CHECK_REQ_CONSTANT_SCALAR_INT_CLAUSE(Simdlen, OMPC_simdlen)
32753281

3276-
void OmpStructureChecker::Enter(const parser::OmpClause::AcqRel &) {
3277-
if (!isFailClause)
3278-
CheckAllowedClause(llvm::omp::Clause::OMPC_acq_rel);
3279-
}
3280-
3281-
void OmpStructureChecker::Enter(const parser::OmpClause::Acquire &) {
3282-
if (!isFailClause)
3283-
CheckAllowedClause(llvm::omp::Clause::OMPC_acquire);
3284-
}
3285-
3286-
void OmpStructureChecker::Enter(const parser::OmpClause::Release &) {
3287-
if (!isFailClause)
3288-
CheckAllowedClause(llvm::omp::Clause::OMPC_release);
3289-
}
3290-
3291-
void OmpStructureChecker::Enter(const parser::OmpClause::Relaxed &) {
3292-
if (!isFailClause)
3293-
CheckAllowedClause(llvm::omp::Clause::OMPC_relaxed);
3294-
}
3295-
3296-
void OmpStructureChecker::Enter(const parser::OmpClause::SeqCst &) {
3297-
if (!isFailClause)
3298-
CheckAllowedClause(llvm::omp::Clause::OMPC_seq_cst);
3299-
}
3300-
3301-
void OmpStructureChecker::Enter(const parser::OmpClause::Fail &) {
3302-
assert(!isFailClause && "Unexpected FAIL clause inside a FAIL clause?");
3303-
isFailClause = true;
3304-
CheckAllowedClause(llvm::omp::Clause::OMPC_fail);
3305-
}
3306-
3307-
void OmpStructureChecker::Leave(const parser::OmpClause::Fail &) {
3308-
assert(isFailClause && "Expected to be inside a FAIL clause here");
3309-
isFailClause = false;
3310-
}
3311-
3312-
void OmpStructureChecker::Enter(const parser::OmpFailClause &) {
3313-
assert(!isFailClause && "Unexpected FAIL clause inside a FAIL clause?");
3314-
isFailClause = true;
3315-
CheckAllowedClause(llvm::omp::Clause::OMPC_fail);
3316-
}
3317-
3318-
void OmpStructureChecker::Leave(const parser::OmpFailClause &) {
3319-
assert(isFailClause && "Expected to be inside a FAIL clause here");
3320-
isFailClause = false;
3321-
}
3322-
33233282
// Restrictions specific to each clause are implemented apart from the
33243283
// generalized restrictions.
33253284

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ class OmpStructureChecker
166166
#define GEN_FLANG_CLAUSE_CHECK_ENTER
167167
#include "llvm/Frontend/OpenMP/OMP.inc"
168168

169-
void Leave(const parser::OmpClause::Fail &);
170-
void Enter(const parser::OmpFailClause &);
171-
void Leave(const parser::OmpFailClause &);
172-
173169
private:
174170
bool CheckAllowedClause(llvmOmpClause clause);
175171
bool IsVariableListItem(const Symbol &sym);
@@ -345,7 +341,6 @@ class OmpStructureChecker
345341
using LoopConstruct = std::variant<const parser::DoConstruct *,
346342
const parser::OpenMPLoopConstruct *>;
347343
std::vector<LoopConstruct> loopStack_;
348-
bool isFailClause{false};
349344
};
350345

351346
/// Find a duplicate entry in the range, and return an iterator to it.

0 commit comments

Comments
 (0)