Skip to content

Commit 88b71e2

Browse files
authored
[flang][OpenMP] Replace OpenMPBlockConstruct with OmpBlockConstruct (#155872)
OpenMPBlockConstruct, somewhat confusingly, represents most but not all block-associated constructs. It's derived from OmpBlockConstruct, as are all the remaining block-associated constructs. It does not correspond to any well-defined group of constructs. It's the collection of constructs that don't have their own types (and those that do have their own types do so for their own reasons). Using the broader OmpBlockConstruct in type-based visitors won't cause issues, because the specific overloads (for classes derived from it) will always be preferred.
1 parent 3b150fb commit 88b71e2

20 files changed

+65
-72
lines changed

flang/examples/FeatureList/FeatureList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ struct NodeVisitor {
448448
READ_FEATURE(OmpBeginDirective)
449449
READ_FEATURE(OmpBeginLoopDirective)
450450
READ_FEATURE(OmpBeginSectionsDirective)
451+
READ_FEATURE(OmpBlockConstruct)
451452
READ_FEATURE(OmpClause)
452453
READ_FEATURE(OmpClauseList)
453454
READ_FEATURE(OmpDeclareTargetSpecifier)
@@ -541,7 +542,6 @@ struct NodeVisitor {
541542
READ_FEATURE(OpenACCStandaloneConstruct)
542543
READ_FEATURE(OpenACCWaitConstruct)
543544
READ_FEATURE(OpenMPAtomicConstruct)
544-
READ_FEATURE(OpenMPBlockConstruct)
545545
READ_FEATURE(OpenMPCancelConstruct)
546546
READ_FEATURE(OpenMPCancellationPointConstruct)
547547
READ_FEATURE(OpenMPConstruct)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ class ParseTreeDumper {
527527
NODE(parser, OmpBeginSectionsDirective)
528528
NODE(parser, OmpBindClause)
529529
NODE_ENUM(OmpBindClause, Binding)
530+
NODE(parser, OmpBlockConstruct)
530531
NODE(parser, OmpCancellationConstructTypeClause)
531532
NODE(parser, OmpChunkModifier)
532533
NODE_ENUM(OmpChunkModifier, Value)
@@ -714,7 +715,6 @@ class ParseTreeDumper {
714715
NODE(parser, OpenMPAllocatorsConstruct)
715716
NODE(parser, OpenMPAssumeConstruct)
716717
NODE(parser, OpenMPAtomicConstruct)
717-
NODE(parser, OpenMPBlockConstruct)
718718
NODE(parser, OpenMPCancelConstruct)
719719
NODE(parser, OpenMPCancellationPointConstruct)
720720
NODE(parser, OpenMPConstruct)

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5138,10 +5138,6 @@ struct OmpEndLoopDirective {
51385138
CharBlock source;
51395139
};
51405140

5141-
struct OpenMPBlockConstruct : public OmpBlockConstruct {
5142-
INHERITED_TUPLE_CLASS_BOILERPLATE(OpenMPBlockConstruct, OmpBlockConstruct);
5143-
};
5144-
51455141
// OpenMP directives enclosing do loop
51465142
using NestedConstruct =
51475143
std::variant<DoConstruct, common::Indirection<OpenMPLoopConstruct>>;
@@ -5164,7 +5160,7 @@ struct OpenMPExecDirective {
51645160
struct OpenMPConstruct {
51655161
UNION_CLASS_BOILERPLATE(OpenMPConstruct);
51665162
std::variant<OpenMPStandaloneConstruct, OpenMPSectionsConstruct,
5167-
OpenMPSectionConstruct, OpenMPLoopConstruct, OpenMPBlockConstruct,
5163+
OpenMPSectionConstruct, OpenMPLoopConstruct, OmpBlockConstruct,
51685164
OpenMPAtomicConstruct, OpenMPDeclarativeAllocate, OpenMPDispatchConstruct,
51695165
OpenMPUtilityConstruct, OpenMPExecutableAllocate,
51705166
OpenMPAllocatorsConstruct, OpenMPAssumeConstruct, OpenMPCriticalConstruct>

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ static void processHostEvalClauses(lower::AbstractConverter &converter,
409409
const parser::OmpClauseList *endClauseList = nullptr;
410410
common::visit(
411411
common::visitors{
412-
[&](const parser::OpenMPBlockConstruct &ompConstruct) {
412+
[&](const parser::OmpBlockConstruct &ompConstruct) {
413413
beginClauseList = &ompConstruct.BeginDir().Clauses();
414414
if (auto &endSpec = ompConstruct.EndDir())
415415
endClauseList = &endSpec->Clauses();
@@ -3789,7 +3789,7 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
37893789
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
37903790
semantics::SemanticsContext &semaCtx,
37913791
lower::pft::Evaluation &eval,
3792-
const parser::OpenMPBlockConstruct &blockConstruct) {
3792+
const parser::OmpBlockConstruct &blockConstruct) {
37933793
const parser::OmpDirectiveSpecification &beginSpec =
37943794
blockConstruct.BeginDir();
37953795
List<Clause> clauses = makeClauses(beginSpec.Clauses(), semaCtx);
@@ -4150,7 +4150,7 @@ void Fortran::lower::genDeclareTargetIntGlobal(
41504150
bool Fortran::lower::isOpenMPTargetConstruct(
41514151
const parser::OpenMPConstruct &omp) {
41524152
llvm::omp::Directive dir = llvm::omp::Directive::OMPD_unknown;
4153-
if (const auto *block = std::get_if<parser::OpenMPBlockConstruct>(&omp.u)) {
4153+
if (const auto *block = std::get_if<parser::OmpBlockConstruct>(&omp.u)) {
41544154
dir = block->BeginDir().DirId();
41554155
} else if (const auto *loop =
41564156
std::get_if<parser::OpenMPLoopConstruct>(&omp.u)) {

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,7 +1862,7 @@ TYPE_PARSER(construct<OpenMPAssumeConstruct>(
18621862

18631863
// Block Construct
18641864
#define MakeBlockConstruct(dir) \
1865-
construct<OpenMPBlockConstruct>(OmpBlockConstructParser{dir})
1865+
construct<OmpBlockConstruct>(OmpBlockConstructParser{dir})
18661866
TYPE_PARSER( //
18671867
MakeBlockConstruct(llvm::omp::Directive::OMPD_masked) ||
18681868
MakeBlockConstruct(llvm::omp::Directive::OMPD_master) ||
@@ -1927,8 +1927,8 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
19271927
withMessage("expected OpenMP construct"_err_en_US,
19281928
first(construct<OpenMPConstruct>(Parser<OpenMPSectionsConstruct>{}),
19291929
construct<OpenMPConstruct>(Parser<OpenMPLoopConstruct>{}),
1930-
construct<OpenMPConstruct>(Parser<OpenMPBlockConstruct>{}),
1931-
// OpenMPBlockConstruct is attempted before
1930+
construct<OpenMPConstruct>(Parser<OmpBlockConstruct>{}),
1931+
// OmpBlockConstruct is attempted before
19321932
// OpenMPStandaloneConstruct to resolve !$OMP ORDERED
19331933
construct<OpenMPConstruct>(Parser<OpenMPStandaloneConstruct>{}),
19341934
construct<OpenMPConstruct>(Parser<OpenMPAtomicConstruct>{}),

flang/lib/Parser/unparse.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,9 +2833,6 @@ class UnparseVisitor {
28332833
Put("\n");
28342834
EndOpenMP();
28352835
}
2836-
void Unparse(const OpenMPBlockConstruct &x) {
2837-
Unparse(static_cast<const OmpBlockConstruct &>(x));
2838-
}
28392836
void Unparse(const OpenMPLoopConstruct &x) {
28402837
BeginOpenMP();
28412838
Word("!$OMP ");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void OmpStructureChecker::CheckSIMDNest(const parser::OpenMPConstruct &c) {
196196
common::visit(
197197
common::visitors{
198198
// Allow `!$OMP ORDERED SIMD`
199-
[&](const parser::OpenMPBlockConstruct &c) {
199+
[&](const parser::OmpBlockConstruct &c) {
200200
const parser::OmpDirectiveSpecification &beginSpec{c.BeginDir()};
201201
if (beginSpec.DirId() == llvm::omp::Directive::OMPD_ordered) {
202202
for (const auto &clause : beginSpec.Clauses().v) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) {
814814
parser::CharBlock source;
815815
common::visit(
816816
common::visitors{
817-
[&](const parser::OpenMPBlockConstruct &c) {
817+
[&](const parser::OmpBlockConstruct &c) {
818818
const parser::OmpDirectiveSpecification &beginSpec{c.BeginDir()};
819819
source = beginSpec.DirName().source;
820820
if (beginSpec.DirId() == llvm::omp::Directive::OMPD_target_data) {
@@ -864,7 +864,7 @@ void OmpStructureChecker::CheckTargetNest(const parser::OpenMPConstruct &c) {
864864
}
865865
}
866866

867-
void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
867+
void OmpStructureChecker::Enter(const parser::OmpBlockConstruct &x) {
868868
const parser::OmpDirectiveSpecification &beginSpec{x.BeginDir()};
869869
const std::optional<parser::OmpEndDirective> &endSpec{x.EndDir()};
870870
const parser::Block &block{std::get<parser::Block>(x.t)};
@@ -1045,7 +1045,7 @@ void OmpStructureChecker::Enter(const parser::OpenMPBlockConstruct &x) {
10451045
}
10461046

10471047
void OmpStructureChecker::CheckMasterNesting(
1048-
const parser::OpenMPBlockConstruct &x) {
1048+
const parser::OmpBlockConstruct &x) {
10491049
// A MASTER region may not be `closely nested` inside a worksharing, loop,
10501050
// task, taskloop, or atomic region.
10511051
// TODO: Expand the check to include `LOOP` construct as well when it is
@@ -1074,7 +1074,7 @@ void OmpStructureChecker::Leave(const parser::OpenMPDeclarativeAssumes &) {
10741074
dirContext_.pop_back();
10751075
}
10761076

1077-
void OmpStructureChecker::Leave(const parser::OpenMPBlockConstruct &) {
1077+
void OmpStructureChecker::Leave(const parser::OmpBlockConstruct &) {
10781078
if (GetDirectiveNest(TargetBlockOnlyTeams)) {
10791079
ExitDirectiveNest(TargetBlockOnlyTeams);
10801080
}
@@ -4605,7 +4605,7 @@ bool OmpStructureChecker::CheckTargetBlockOnlyTeams(
46054605
if (const auto *ompConstruct{
46064606
parser::Unwrap<parser::OpenMPConstruct>(*it)}) {
46074607
if (const auto *ompBlockConstruct{
4608-
std::get_if<parser::OpenMPBlockConstruct>(&ompConstruct->u)}) {
4608+
std::get_if<parser::OmpBlockConstruct>(&ompConstruct->u)}) {
46094609
llvm::omp::Directive dirId{ompBlockConstruct->BeginDir().DirId()};
46104610
if (dirId == llvm::omp::Directive::OMPD_teams) {
46114611
nestedTeams = true;
@@ -4652,7 +4652,7 @@ void OmpStructureChecker::CheckWorkshareBlockStmts(
46524652
// 'Parallel' constructs
46534653
auto currentDir{llvm::omp::Directive::OMPD_unknown};
46544654
if (const auto *ompBlockConstruct{
4655-
std::get_if<parser::OpenMPBlockConstruct>(&ompConstruct->u)}) {
4655+
std::get_if<parser::OmpBlockConstruct>(&ompConstruct->u)}) {
46564656
currentDir = ompBlockConstruct->BeginDir().DirId();
46574657
} else if (const auto *ompLoopConstruct{
46584658
std::get_if<parser::OpenMPLoopConstruct>(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class OmpStructureChecker
8888
void Leave(const parser::OpenMPAssumeConstruct &);
8989
void Enter(const parser::OpenMPDeclarativeAssumes &);
9090
void Leave(const parser::OpenMPDeclarativeAssumes &);
91-
void Enter(const parser::OpenMPBlockConstruct &);
92-
void Leave(const parser::OpenMPBlockConstruct &);
91+
void Enter(const parser::OmpBlockConstruct &);
92+
void Leave(const parser::OmpBlockConstruct &);
9393
void Leave(const parser::OmpBeginDirective &);
9494
void Enter(const parser::OmpEndDirective &);
9595
void Leave(const parser::OmpEndDirective &);
@@ -315,7 +315,7 @@ class OmpStructureChecker
315315
const parser::OmpReductionIdentifier &ident);
316316
void CheckReductionModifier(const parser::OmpReductionModifier &);
317317
void CheckLastprivateModifier(const parser::OmpLastprivateModifier &);
318-
void CheckMasterNesting(const parser::OpenMPBlockConstruct &x);
318+
void CheckMasterNesting(const parser::OmpBlockConstruct &x);
319319
void ChecksOnOrderedAsBlock();
320320
void CheckBarrierNesting(const parser::OpenMPSimpleStandaloneConstruct &x);
321321
void CheckScan(const parser::OpenMPSimpleStandaloneConstruct &x);

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
411411
}
412412
void Post(const parser::OmpMetadirectiveDirective &) { PopContext(); }
413413

414-
bool Pre(const parser::OpenMPBlockConstruct &);
415-
void Post(const parser::OpenMPBlockConstruct &);
414+
bool Pre(const parser::OmpBlockConstruct &);
415+
void Post(const parser::OmpBlockConstruct &);
416416

417417
void Post(const parser::OmpBeginDirective &x) {
418418
GetContext().withinConstruct = true;
@@ -1753,7 +1753,7 @@ static std::string ScopeSourcePos(const Fortran::semantics::Scope &scope);
17531753

17541754
#endif
17551755

1756-
bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
1756+
bool OmpAttributeVisitor::Pre(const parser::OmpBlockConstruct &x) {
17571757
const parser::OmpDirectiveSpecification &dirSpec{x.BeginDir()};
17581758
llvm::omp::Directive dirId{dirSpec.DirId()};
17591759
switch (dirId) {
@@ -1792,7 +1792,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
17921792
return true;
17931793
}
17941794

1795-
void OmpAttributeVisitor::Post(const parser::OpenMPBlockConstruct &x) {
1795+
void OmpAttributeVisitor::Post(const parser::OmpBlockConstruct &x) {
17961796
const parser::OmpDirectiveSpecification &dirSpec{x.BeginDir()};
17971797
llvm::omp::Directive dirId{dirSpec.DirId()};
17981798
switch (dirId) {

0 commit comments

Comments
 (0)