Skip to content

Commit c075fee

Browse files
authored
[flang][OpenMP] Use OmpDirectiveSpecification in utility directives (#159585)
1 parent e361c0f commit c075fee

File tree

6 files changed

+35
-34
lines changed

6 files changed

+35
-34
lines changed

flang/include/flang/Parser/openmp-utils.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ struct ConstructId {
3939
}
4040

4141
MAKE_CONSTR_ID(OmpDeclareVariantDirective, D::OMPD_declare_variant);
42-
MAKE_CONSTR_ID(OmpErrorDirective, D::OMPD_error);
4342
MAKE_CONSTR_ID(OpenMPDeclarativeAllocate, D::OMPD_allocate);
4443
MAKE_CONSTR_ID(OpenMPDeclarativeAssumes, D::OMPD_assumes);
4544
MAKE_CONSTR_ID(OpenMPDeclareMapperConstruct, D::OMPD_declare_mapper);
@@ -60,10 +59,6 @@ struct DirectiveNameScope {
6059
return name;
6160
}
6261

63-
static OmpDirectiveName GetOmpDirectiveName(const OmpNothingDirective &x) {
64-
return MakeName(x.source, llvm::omp::Directive::OMPD_nothing);
65-
}
66-
6762
static OmpDirectiveName GetOmpDirectiveName(const OmpBeginLoopDirective &x) {
6863
return x.DirName();
6964
}
@@ -99,7 +94,6 @@ struct DirectiveNameScope {
9994
if constexpr (std::is_base_of_v<OmpBlockConstruct, T>) {
10095
return std::get<OmpBeginDirective>(x.t).DirName();
10196
} else if constexpr (std::is_same_v<T, OmpDeclareVariantDirective> ||
102-
std::is_same_v<T, OmpErrorDirective> ||
10397
std::is_same_v<T, OpenMPDeclarativeAllocate> ||
10498
std::is_same_v<T, OpenMPDeclarativeAssumes> ||
10599
std::is_same_v<T, OpenMPDeclareMapperConstruct> ||

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4843,17 +4843,13 @@ struct OmpMetadirectiveDirective {
48434843
// nothing-directive ->
48444844
// NOTHING // since 5.1
48454845
struct OmpNothingDirective {
4846-
using EmptyTrait = std::true_type;
4847-
COPY_AND_ASSIGN_BOILERPLATE(OmpNothingDirective);
4848-
CharBlock source;
4846+
WRAPPER_CLASS_BOILERPLATE(OmpNothingDirective, OmpDirectiveSpecification);
48494847
};
48504848

48514849
// Ref: OpenMP [5.2:216-218]
48524850
// ERROR AT(compilation|execution) SEVERITY(fatal|warning) MESSAGE("msg-str)
48534851
struct OmpErrorDirective {
4854-
TUPLE_CLASS_BOILERPLATE(OmpErrorDirective);
4855-
CharBlock source;
4856-
std::tuple<Verbatim, OmpClauseList> t;
4852+
WRAPPER_CLASS_BOILERPLATE(OmpErrorDirective, OmpDirectiveSpecification);
48574853
};
48584854

48594855
struct OpenMPUtilityConstruct {

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,9 +1279,6 @@ TYPE_PARSER(sourced(construct<OmpClauseList>(
12791279
// 2.1 (variable | /common-block/ | array-sections)
12801280
TYPE_PARSER(construct<OmpObjectList>(nonemptyList(Parser<OmpObject>{})))
12811281

1282-
TYPE_PARSER(sourced(construct<OmpErrorDirective>(
1283-
verbatim("ERROR"_tok), Parser<OmpClauseList>{})))
1284-
12851282
// --- Parsers for directives and constructs --------------------------
12861283

12871284
static inline constexpr auto IsDirective(llvm::omp::Directive dir) {
@@ -1368,13 +1365,19 @@ struct LooselyStructuredBlockParser {
13681365
}
13691366
};
13701367

1371-
TYPE_PARSER(sourced(construct<OmpNothingDirective>("NOTHING" >> ok)))
1368+
TYPE_PARSER(construct<OmpErrorDirective>(
1369+
predicated(Parser<OmpDirectiveName>{},
1370+
IsDirective(llvm::omp::Directive::OMPD_error)) >=
1371+
Parser<OmpDirectiveSpecification>{}))
13721372

1373-
TYPE_PARSER(sourced(construct<OpenMPUtilityConstruct>(
1374-
sourced(construct<OpenMPUtilityConstruct>(
1375-
sourced(Parser<OmpErrorDirective>{}))) ||
1376-
sourced(construct<OpenMPUtilityConstruct>(
1377-
sourced(Parser<OmpNothingDirective>{}))))))
1373+
TYPE_PARSER(construct<OmpNothingDirective>(
1374+
predicated(Parser<OmpDirectiveName>{},
1375+
IsDirective(llvm::omp::Directive::OMPD_nothing)) >=
1376+
Parser<OmpDirectiveSpecification>{}))
1377+
1378+
TYPE_PARSER( //
1379+
sourced(construct<OpenMPUtilityConstruct>(Parser<OmpErrorDirective>{})) ||
1380+
sourced(construct<OpenMPUtilityConstruct>(Parser<OmpNothingDirective>{})))
13781381

13791382
TYPE_PARSER(construct<OmpMetadirectiveDirective>(
13801383
predicated(Parser<OmpDirectiveName>{},

flang/lib/Parser/unparse.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,13 +2621,18 @@ class UnparseVisitor {
26212621
return false;
26222622
}
26232623
void Unparse(const OmpErrorDirective &x) {
2624-
Word("!$OMP ERROR ");
2625-
Walk(x.t);
2624+
BeginOpenMP();
2625+
Word("!$OMP ");
2626+
Walk(x.v);
26262627
Put("\n");
2628+
EndOpenMP();
26272629
}
26282630
void Unparse(const OmpNothingDirective &x) {
2629-
Word("!$OMP NOTHING");
2631+
BeginOpenMP();
2632+
Word("!$OMP ");
2633+
Walk(x.v);
26302634
Put("\n");
2635+
EndOpenMP();
26312636
}
26322637
void Unparse(const OpenMPSectionConstruct &x) {
26332638
if (auto &&dirSpec{

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -611,14 +611,6 @@ template <typename Checker> struct DirectiveSpellingVisitor {
611611
checker_(GetDirName(x.t).source, Directive::OMPD_dispatch);
612612
return false;
613613
}
614-
bool Pre(const parser::OmpErrorDirective &x) {
615-
checker_(std::get<parser::Verbatim>(x.t).source, Directive::OMPD_error);
616-
return false;
617-
}
618-
bool Pre(const parser::OmpNothingDirective &x) {
619-
checker_(x.source, Directive::OMPD_nothing);
620-
return false;
621-
}
622614
bool Pre(const parser::OpenMPExecutableAllocate &x) {
623615
checker_(std::get<parser::Verbatim>(x.t).source, Directive::OMPD_allocate);
624616
return false;
@@ -1761,8 +1753,17 @@ void OmpStructureChecker::Leave(const parser::OpenMPDeclareTargetConstruct &x) {
17611753
}
17621754

17631755
void OmpStructureChecker::Enter(const parser::OmpErrorDirective &x) {
1764-
const auto &dir{std::get<parser::Verbatim>(x.t)};
1765-
PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_error);
1756+
const parser::OmpDirectiveName &dirName{x.v.DirName()};
1757+
PushContextAndClauseSets(dirName.source, dirName.v);
1758+
}
1759+
1760+
void OmpStructureChecker::Enter(const parser::OmpNothingDirective &x) {
1761+
const parser::OmpDirectiveName &dirName{x.v.DirName()};
1762+
PushContextAndClauseSets(dirName.source, dirName.v);
1763+
}
1764+
1765+
void OmpStructureChecker::Leave(const parser::OmpNothingDirective &x) {
1766+
dirContext_.pop_back();
17661767
}
17671768

17681769
void OmpStructureChecker::Enter(const parser::OpenMPDispatchConstruct &x) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ class OmpStructureChecker
120120
void Leave(const parser::OpenMPDispatchConstruct &);
121121
void Enter(const parser::OmpErrorDirective &);
122122
void Leave(const parser::OmpErrorDirective &);
123+
void Enter(const parser::OmpNothingDirective &);
124+
void Leave(const parser::OmpNothingDirective &);
123125
void Enter(const parser::OpenMPExecutableAllocate &);
124126
void Leave(const parser::OpenMPExecutableAllocate &);
125127
void Enter(const parser::OpenMPAllocatorsConstruct &);

0 commit comments

Comments
 (0)