Skip to content

Commit c25a059

Browse files
Refactor avoiding checking the memory order
1 parent 35856c1 commit c25a059

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

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

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,8 +2780,6 @@ void OmpStructureChecker::Enter(const parser::OmpClause &x) {
27802780

27812781
// Following clauses do not have a separate node in parse-tree.h.
27822782
CHECK_SIMPLE_CLAUSE(Absent, OMPC_absent)
2783-
CHECK_SIMPLE_CLAUSE(AcqRel, OMPC_acq_rel)
2784-
CHECK_SIMPLE_CLAUSE(Acquire, OMPC_acquire)
27852783
CHECK_SIMPLE_CLAUSE(Affinity, OMPC_affinity)
27862784
CHECK_SIMPLE_CLAUSE(Capture, OMPC_capture)
27872785
CHECK_SIMPLE_CLAUSE(Contains, OMPC_contains)
@@ -2817,9 +2815,6 @@ CHECK_SIMPLE_CLAUSE(Nogroup, OMPC_nogroup)
28172815
CHECK_SIMPLE_CLAUSE(Notinbranch, OMPC_notinbranch)
28182816
CHECK_SIMPLE_CLAUSE(Partial, OMPC_partial)
28192817
CHECK_SIMPLE_CLAUSE(ProcBind, OMPC_proc_bind)
2820-
CHECK_SIMPLE_CLAUSE(Release, OMPC_release)
2821-
CHECK_SIMPLE_CLAUSE(Relaxed, OMPC_relaxed)
2822-
CHECK_SIMPLE_CLAUSE(SeqCst, OMPC_seq_cst)
28232818
CHECK_SIMPLE_CLAUSE(Simd, OMPC_simd)
28242819
CHECK_SIMPLE_CLAUSE(Sizes, OMPC_sizes)
28252820
CHECK_SIMPLE_CLAUSE(Permutation, OMPC_permutation)
@@ -2847,7 +2842,6 @@ CHECK_SIMPLE_CLAUSE(Compare, OMPC_compare)
28472842
CHECK_SIMPLE_CLAUSE(CancellationConstructType, OMPC_cancellation_construct_type)
28482843
CHECK_SIMPLE_CLAUSE(OmpxAttribute, OMPC_ompx_attribute)
28492844
CHECK_SIMPLE_CLAUSE(OmpxBare, OMPC_ompx_bare)
2850-
CHECK_SIMPLE_CLAUSE(Fail, OMPC_fail)
28512845
CHECK_SIMPLE_CLAUSE(Weak, OMPC_weak)
28522846

28532847
CHECK_REQ_SCALAR_INT_CLAUSE(NumTeams, OMPC_num_teams)
@@ -2860,6 +2854,53 @@ CHECK_REQ_CONSTANT_SCALAR_INT_CLAUSE(Collapse, OMPC_collapse)
28602854
CHECK_REQ_CONSTANT_SCALAR_INT_CLAUSE(Safelen, OMPC_safelen)
28612855
CHECK_REQ_CONSTANT_SCALAR_INT_CLAUSE(Simdlen, OMPC_simdlen)
28622856

2857+
void OmpStructureChecker::Enter(const parser::OmpClause::AcqRel &) {
2858+
if (!isFailClause)
2859+
CheckAllowedClause(llvm::omp::Clause::OMPC_acq_rel);
2860+
}
2861+
2862+
void OmpStructureChecker::Enter(const parser::OmpClause::Acquire &) {
2863+
if (!isFailClause)
2864+
CheckAllowedClause(llvm::omp::Clause::OMPC_acquire);
2865+
}
2866+
2867+
void OmpStructureChecker::Enter(const parser::OmpClause::Release &) {
2868+
if (!isFailClause)
2869+
CheckAllowedClause(llvm::omp::Clause::OMPC_release);
2870+
}
2871+
2872+
void OmpStructureChecker::Enter(const parser::OmpClause::Relaxed &) {
2873+
if (!isFailClause)
2874+
CheckAllowedClause(llvm::omp::Clause::OMPC_relaxed);
2875+
}
2876+
2877+
void OmpStructureChecker::Enter(const parser::OmpClause::SeqCst &) {
2878+
if (!isFailClause)
2879+
CheckAllowedClause(llvm::omp::Clause::OMPC_seq_cst);
2880+
}
2881+
2882+
void OmpStructureChecker::Enter(const parser::OmpClause::Fail &) {
2883+
assert(!isFailClause && "Unexpected FAIL clause inside a FAIL clause?");
2884+
isFailClause = true;
2885+
CheckAllowedClause(llvm::omp::Clause::OMPC_fail);
2886+
}
2887+
2888+
void OmpStructureChecker::Leave(const parser::OmpClause::Fail &) {
2889+
assert(isFailClause && "Expected to be inside a FAIL clause here");
2890+
isFailClause = false;
2891+
}
2892+
2893+
void OmpStructureChecker::Enter(const parser::OmpFailClause &) {
2894+
assert(!isFailClause && "Unexpected FAIL clause inside a FAIL clause?");
2895+
isFailClause = true;
2896+
CheckAllowedClause(llvm::omp::Clause::OMPC_fail);
2897+
}
2898+
2899+
void OmpStructureChecker::Leave(const parser::OmpFailClause &) {
2900+
assert(isFailClause && "Expected to be inside a FAIL clause here");
2901+
isFailClause = false;
2902+
}
2903+
28632904
// Restrictions specific to each clause are implemented apart from the
28642905
// generalized restrictions.
28652906

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

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

145+
void Leave(const parser::OmpClause::Fail &);
146+
void Enter(const parser::OmpFailClause &);
147+
void Leave(const parser::OmpFailClause &);
148+
145149
private:
146150
bool CheckAllowedClause(llvmOmpClause clause);
147151
bool IsVariableListItem(const Symbol &sym);
@@ -272,6 +276,7 @@ class OmpStructureChecker
272276
using LoopConstruct = std::variant<const parser::DoConstruct *,
273277
const parser::OpenMPLoopConstruct *>;
274278
std::vector<LoopConstruct> loopStack_;
279+
bool isFailClause{false};
275280
};
276281

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

flang/lib/Semantics/semantics.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ class SemanticsVisitor : public virtual BaseChecker, public virtual C... {
114114
context_.set_location(std::nullopt);
115115
}
116116

117-
// This is necessary to avoid "walking" into the Fail clause,
118-
// which confuses the CheckAllowed into thinking there's another
119-
// memoryorder, when it's actually the argument to the fail clause.
120-
bool Pre(const parser::OmpFailClause &) { return false; }
121-
122117
bool Walk(const parser::Program &program) {
123118
parser::Walk(program, *this);
124119
return !context_.AnyFatalError();

0 commit comments

Comments
 (0)