Skip to content

Commit 8ad7614

Browse files
committed
Revert "[flang][OpenMP] Make all block constructs share the same structure (llvm#150956)"
This reverts commit 6533ad0.
1 parent 4aa2178 commit 8ad7614

38 files changed

+557
-460
lines changed

flang/examples/FeatureList/FeatureList.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,10 @@ struct NodeVisitor {
445445
READ_FEATURE(ObjectDecl)
446446
READ_FEATURE(OldParameterStmt)
447447
READ_FEATURE(OmpAlignedClause)
448-
READ_FEATURE(OmpBeginDirective)
448+
READ_FEATURE(OmpBeginBlockDirective)
449449
READ_FEATURE(OmpBeginLoopDirective)
450450
READ_FEATURE(OmpBeginSectionsDirective)
451+
READ_FEATURE(OmpBlockDirective)
451452
READ_FEATURE(OmpClause)
452453
READ_FEATURE(OmpClauseList)
453454
READ_FEATURE(OmpCriticalDirective)
@@ -471,7 +472,7 @@ struct NodeVisitor {
471472
READ_FEATURE(OmpIteration)
472473
READ_FEATURE(OmpIterationOffset)
473474
READ_FEATURE(OmpIterationVector)
474-
READ_FEATURE(OmpEndDirective)
475+
READ_FEATURE(OmpEndBlockDirective)
475476
READ_FEATURE(OmpEndCriticalDirective)
476477
READ_FEATURE(OmpEndLoopDirective)
477478
READ_FEATURE(OmpEndSectionsDirective)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,10 @@ class ParseTreeDumper {
534534
NODE(parser, OmpAtClause)
535535
NODE_ENUM(OmpAtClause, ActionTime)
536536
NODE_ENUM(OmpSeverityClause, Severity)
537+
NODE(parser, OmpBeginBlockDirective)
537538
NODE(parser, OmpBeginLoopDirective)
538539
NODE(parser, OmpBeginSectionsDirective)
540+
NODE(parser, OmpBlockDirective)
539541
static std::string GetNodeName(const llvm::omp::Directive &x) {
540542
return llvm::Twine("llvm::omp::Directive = ",
541543
llvm::omp::getOpenMPDirectiveName(x, llvm::omp::FallbackVersion))
@@ -584,6 +586,7 @@ class ParseTreeDumper {
584586
NODE(parser, OmpDetachClause)
585587
NODE(parser, OmpDoacrossClause)
586588
NODE(parser, OmpDestroyClause)
589+
NODE(parser, OmpEndBlockDirective)
587590
NODE(parser, OmpEndCriticalDirective)
588591
NODE(parser, OmpEndLoopDirective)
589592
NODE(parser, OmpEndSectionsDirective)
@@ -705,8 +708,6 @@ class ParseTreeDumper {
705708
NODE(parser, OpenMPDeclarativeAssumes)
706709
NODE(parser, OmpAssumeDirective)
707710
NODE(parser, OmpEndAssumeDirective)
708-
NODE(parser, OmpBeginDirective)
709-
NODE(parser, OmpEndDirective)
710711
NODE(parser, OpenMPAtomicConstruct)
711712
NODE(parser, OpenMPBlockConstruct)
712713
NODE(parser, OpenMPCancelConstruct)

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ struct DirectiveNameScope {
6868
return MakeName(x.source, llvm::omp::Directive::OMPD_nothing);
6969
}
7070

71+
static OmpDirectiveName GetOmpDirectiveName(const OmpBeginBlockDirective &x) {
72+
auto &dir{std::get<OmpBlockDirective>(x.t)};
73+
return MakeName(dir.source, dir.v);
74+
}
75+
7176
static OmpDirectiveName GetOmpDirectiveName(const OmpBeginLoopDirective &x) {
7277
auto &dir{std::get<OmpLoopDirective>(x.t)};
7378
return MakeName(dir.source, dir.v);
@@ -101,8 +106,10 @@ struct DirectiveNameScope {
101106
return GetOmpDirectiveName(x.v);
102107
}
103108
} else if constexpr (TupleTrait<T>) {
104-
if constexpr (std::is_base_of_v<OmpBlockConstruct, T>) {
105-
return std::get<OmpBeginDirective>(x.t).DirName();
109+
if constexpr (std::is_same_v<T, OpenMPAllocatorsConstruct> ||
110+
std::is_same_v<T, OpenMPAtomicConstruct> ||
111+
std::is_same_v<T, OpenMPDispatchConstruct>) {
112+
return std::get<OmpDirectiveSpecification>(x.t).DirName();
106113
} else if constexpr (std::is_same_v<T, OmpAssumeDirective> ||
107114
std::is_same_v<T, OmpCriticalDirective> ||
108115
std::is_same_v<T, OmpDeclareVariantDirective> ||

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

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,12 +3469,6 @@ WRAPPER_CLASS(PauseStmt, std::optional<StopCode>);
34693469

34703470
// --- Common definitions
34713471

3472-
#define INHERITED_TUPLE_CLASS_BOILERPLATE(classname, basename) \
3473-
using basename::basename; \
3474-
classname(basename &&b) : basename(std::move(b)) {} \
3475-
using TupleTrait = std::true_type; \
3476-
BOILERPLATE(classname)
3477-
34783472
#define INHERITED_WRAPPER_CLASS_BOILERPLATE(classname, basename) \
34793473
BOILERPLATE(classname); \
34803474
using basename::basename; \
@@ -4756,33 +4750,6 @@ struct OmpDirectiveSpecification {
47564750
t;
47574751
};
47584752

4759-
// OmpBeginDirective and OmpEndDirective are needed for semantic analysis,
4760-
// where some checks are done specifically for either the begin or the end
4761-
// directive. The structure of both is identical, but the diffent types
4762-
// allow to distinguish them in the type-based parse-tree visitor.
4763-
struct OmpBeginDirective : public OmpDirectiveSpecification {
4764-
INHERITED_TUPLE_CLASS_BOILERPLATE(
4765-
OmpBeginDirective, OmpDirectiveSpecification);
4766-
};
4767-
4768-
struct OmpEndDirective : public OmpDirectiveSpecification {
4769-
INHERITED_TUPLE_CLASS_BOILERPLATE(OmpEndDirective, OmpDirectiveSpecification);
4770-
};
4771-
4772-
// Common base class for block-associated constructs.
4773-
struct OmpBlockConstruct {
4774-
TUPLE_CLASS_BOILERPLATE(OmpBlockConstruct);
4775-
const OmpBeginDirective &BeginDir() const {
4776-
return std::get<OmpBeginDirective>(t);
4777-
}
4778-
const std::optional<OmpEndDirective> &EndDir() const {
4779-
return std::get<std::optional<OmpEndDirective>>(t);
4780-
}
4781-
4782-
CharBlock source;
4783-
std::tuple<OmpBeginDirective, Block, std::optional<OmpEndDirective>> t;
4784-
};
4785-
47864753
struct OmpMetadirectiveDirective {
47874754
TUPLE_CLASS_BOILERPLATE(OmpMetadirectiveDirective);
47884755
std::tuple<Verbatim, OmpClauseList> t;
@@ -4887,6 +4854,12 @@ struct OpenMPSectionsConstruct {
48874854
t;
48884855
};
48894856

4857+
// OpenMP directive beginning or ending a block
4858+
struct OmpBlockDirective {
4859+
WRAPPER_CLASS_BOILERPLATE(OmpBlockDirective, llvm::omp::Directive);
4860+
CharBlock source;
4861+
};
4862+
48904863
struct OmpDeclareVariantDirective {
48914864
TUPLE_CLASS_BOILERPLATE(OmpDeclareVariantDirective);
48924865
CharBlock source;
@@ -5011,9 +4984,12 @@ struct OpenMPExecutableAllocate {
50114984
// ALLOCATORS [allocate-clause...]
50124985
// block
50134986
// [END ALLOCATORS]
5014-
struct OpenMPAllocatorsConstruct : public OmpBlockConstruct {
5015-
INHERITED_TUPLE_CLASS_BOILERPLATE(
5016-
OpenMPAllocatorsConstruct, OmpBlockConstruct);
4987+
struct OpenMPAllocatorsConstruct {
4988+
TUPLE_CLASS_BOILERPLATE(OpenMPAllocatorsConstruct);
4989+
CharBlock source;
4990+
std::tuple<OmpDirectiveSpecification, Block,
4991+
std::optional<OmpDirectiveSpecification>>
4992+
t;
50174993
};
50184994

50194995
// 2.17.7 Atomic construct/2.17.8 Flush construct [OpenMP 5.0]
@@ -5027,11 +5003,15 @@ struct OmpMemoryOrderClause {
50275003
CharBlock source;
50285004
};
50295005

5030-
struct OpenMPAtomicConstruct : public OmpBlockConstruct {
5006+
struct OpenMPAtomicConstruct {
50315007
llvm::omp::Clause GetKind() const;
50325008
bool IsCapture() const;
50335009
bool IsCompare() const;
5034-
INHERITED_TUPLE_CLASS_BOILERPLATE(OpenMPAtomicConstruct, OmpBlockConstruct);
5010+
TUPLE_CLASS_BOILERPLATE(OpenMPAtomicConstruct);
5011+
CharBlock source;
5012+
std::tuple<OmpDirectiveSpecification, Block,
5013+
std::optional<OmpDirectiveSpecification>>
5014+
t;
50355015

50365016
// Information filled out during semantic checks to avoid duplication
50375017
// of analyses.
@@ -5095,8 +5075,12 @@ struct OpenMPDepobjConstruct {
50955075
// nocontext-clause |
50965076
// novariants-clause |
50975077
// nowait-clause
5098-
struct OpenMPDispatchConstruct : public OmpBlockConstruct {
5099-
INHERITED_TUPLE_CLASS_BOILERPLATE(OpenMPDispatchConstruct, OmpBlockConstruct);
5078+
struct OpenMPDispatchConstruct {
5079+
TUPLE_CLASS_BOILERPLATE(OpenMPDispatchConstruct);
5080+
CharBlock source;
5081+
std::tuple<OmpDirectiveSpecification, Block,
5082+
std::optional<OmpDirectiveSpecification>>
5083+
t;
51005084
};
51015085

51025086
// [4.5:162-165], [5.0:242-246], [5.1:275-279], [5.2:315-316], [6.0:498-500]
@@ -5151,8 +5135,22 @@ struct OmpEndLoopDirective {
51515135
CharBlock source;
51525136
};
51535137

5154-
struct OpenMPBlockConstruct : public OmpBlockConstruct {
5155-
INHERITED_TUPLE_CLASS_BOILERPLATE(OpenMPBlockConstruct, OmpBlockConstruct);
5138+
struct OmpBeginBlockDirective {
5139+
TUPLE_CLASS_BOILERPLATE(OmpBeginBlockDirective);
5140+
std::tuple<OmpBlockDirective, OmpClauseList> t;
5141+
CharBlock source;
5142+
};
5143+
5144+
struct OmpEndBlockDirective {
5145+
TUPLE_CLASS_BOILERPLATE(OmpEndBlockDirective);
5146+
std::tuple<OmpBlockDirective, OmpClauseList> t;
5147+
CharBlock source;
5148+
};
5149+
5150+
struct OpenMPBlockConstruct {
5151+
TUPLE_CLASS_BOILERPLATE(OpenMPBlockConstruct);
5152+
std::tuple<OmpBeginBlockDirective, Block, std::optional<OmpEndBlockDirective>>
5153+
t;
51565154
};
51575155

51585156
// OpenMP directives enclosing do loop

flang/lib/Lower/OpenMP/Atomic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ void Fortran::lower::omp::lowerAtomic(
707707
};
708708

709709
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
710-
const parser::OmpDirectiveSpecification &dirSpec = construct.BeginDir();
710+
auto &dirSpec = std::get<parser::OmpDirectiveSpecification>(construct.t);
711711
omp::List<omp::Clause> clauses = makeClauses(dirSpec.Clauses(), semaCtx);
712712
lower::StatementContext stmtCtx;
713713

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,16 @@ static void processHostEvalClauses(lower::AbstractConverter &converter,
407407
common::visit(
408408
common::visitors{
409409
[&](const parser::OpenMPBlockConstruct &ompConstruct) {
410-
beginClauseList = &ompConstruct.BeginDir().Clauses();
411-
if (auto &endSpec = ompConstruct.EndDir())
412-
endClauseList = &endSpec->Clauses();
410+
const auto &beginDirective =
411+
std::get<parser::OmpBeginBlockDirective>(ompConstruct.t);
412+
beginClauseList =
413+
&std::get<parser::OmpClauseList>(beginDirective.t);
414+
if (auto &endDirective =
415+
std::get<std::optional<parser::OmpEndBlockDirective>>(
416+
ompConstruct.t)) {
417+
endClauseList =
418+
&std::get<parser::OmpClauseList>(endDirective->t);
419+
}
413420
},
414421
[&](const parser::OpenMPLoopConstruct &ompConstruct) {
415422
const auto &beginDirective =
@@ -3660,16 +3667,25 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
36603667
semantics::SemanticsContext &semaCtx,
36613668
lower::pft::Evaluation &eval,
36623669
const parser::OpenMPBlockConstruct &blockConstruct) {
3663-
const parser::OmpDirectiveSpecification &beginSpec =
3664-
blockConstruct.BeginDir();
3665-
List<Clause> clauses = makeClauses(beginSpec.Clauses(), semaCtx);
3666-
if (auto &endSpec = blockConstruct.EndDir())
3667-
clauses.append(makeClauses(endSpec->Clauses(), semaCtx));
3668-
3669-
llvm::omp::Directive directive = beginSpec.DirId();
3670-
assert(llvm::omp::blockConstructSet.test(directive) &&
3670+
const auto &beginBlockDirective =
3671+
std::get<parser::OmpBeginBlockDirective>(blockConstruct.t);
3672+
mlir::Location currentLocation =
3673+
converter.genLocation(beginBlockDirective.source);
3674+
const auto origDirective =
3675+
std::get<parser::OmpBlockDirective>(beginBlockDirective.t).v;
3676+
List<Clause> clauses = makeClauses(
3677+
std::get<parser::OmpClauseList>(beginBlockDirective.t), semaCtx);
3678+
3679+
if (const auto &endBlockDirective =
3680+
std::get<std::optional<parser::OmpEndBlockDirective>>(
3681+
blockConstruct.t)) {
3682+
clauses.append(makeClauses(
3683+
std::get<parser::OmpClauseList>(endBlockDirective->t), semaCtx));
3684+
}
3685+
3686+
assert(llvm::omp::blockConstructSet.test(origDirective) &&
36713687
"Expected block construct");
3672-
mlir::Location currentLocation = converter.genLocation(beginSpec.source);
3688+
(void)origDirective;
36733689

36743690
for (const Clause &clause : clauses) {
36753691
mlir::Location clauseLocation = converter.genLocation(clause.source);
@@ -3712,9 +3728,13 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
37123728
}
37133729
}
37143730

3731+
llvm::omp::Directive directive =
3732+
std::get<parser::OmpBlockDirective>(beginBlockDirective.t).v;
3733+
const parser::CharBlock &source =
3734+
std::get<parser::OmpBlockDirective>(beginBlockDirective.t).source;
37153735
ConstructQueue queue{
37163736
buildConstructQueue(converter.getFirOpBuilder().getModule(), semaCtx,
3717-
eval, beginSpec.source, directive, clauses)};
3737+
eval, source, directive, clauses)};
37183738
genOMPDispatch(converter, symTable, semaCtx, eval, currentLocation, queue,
37193739
queue.begin());
37203740
}
@@ -4002,7 +4022,8 @@ bool Fortran::lower::isOpenMPTargetConstruct(
40024022
const parser::OpenMPConstruct &omp) {
40034023
llvm::omp::Directive dir = llvm::omp::Directive::OMPD_unknown;
40044024
if (const auto *block = std::get_if<parser::OpenMPBlockConstruct>(&omp.u)) {
4005-
dir = block->BeginDir().DirId();
4025+
const auto &begin = std::get<parser::OmpBeginBlockDirective>(block->t);
4026+
dir = std::get<parser::OmpBlockDirective>(begin.t).v;
40064027
} else if (const auto *loop =
40074028
std::get_if<parser::OpenMPLoopConstruct>(&omp.u)) {
40084029
const auto &begin = std::get<parser::OmpBeginLoopDirective>(loop->t);

0 commit comments

Comments
 (0)