Skip to content

Commit cfd67c2

Browse files
authored
[flang][OpenMP] Normalize clause modifiers that exist on their own (#116655)
This is the first part of the effort to make parsing of clause modifiers more uniform and robust. Currently, when multiple modifiers are allowed, the parser will expect them to appear in a hard-coded order. Additionally, modifier properties (such as "ultimate") are checked separately for each case. The overall plan is 1. Extract all modifiers into their own top-level classes, and then equip them with sets of common properties that will allow performing the property checks generically, without refering to the specific kind of the modifier. 2. Define a parser (as a separate class) for each modifier. 3. For each clause define a union (std::variant) of all allowable modifiers, and parse the modifiers as a list of these unions. The intent is also to isolate parts of the code that could eventually be auto-generated. OpenMP modifier overhaul: #1/3
1 parent b49c4af commit cfd67c2

19 files changed

+196
-167
lines changed

flang/examples/FeatureList/FeatureList.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,9 @@ struct NodeVisitor {
475475
READ_FEATURE(OmpDoacross::Source)
476476
READ_FEATURE(OmpDoacrossClause)
477477
READ_FEATURE(OmpDependenceType)
478-
READ_FEATURE(OmpDependenceType::Type)
478+
READ_FEATURE(OmpDependenceType::Value)
479479
READ_FEATURE(OmpTaskDependenceType)
480-
READ_FEATURE(OmpTaskDependenceType::Type)
480+
READ_FEATURE(OmpTaskDependenceType::Value)
481481
READ_FEATURE(OmpIteration)
482482
READ_FEATURE(OmpIterationOffset)
483483
READ_FEATURE(OmpIterationVector)
@@ -495,7 +495,7 @@ struct NodeVisitor {
495495
READ_FEATURE(OmpLinearClause::WithModifier)
496496
READ_FEATURE(OmpLinearClause::WithoutModifier)
497497
READ_FEATURE(OmpLinearModifier)
498-
READ_FEATURE(OmpLinearModifier::Type)
498+
READ_FEATURE(OmpLinearModifier::Value)
499499
READ_FEATURE(OmpLoopDirective)
500500
READ_FEATURE(OmpMapClause)
501501
READ_FEATURE(OmpMapClause::TypeModifier)
@@ -515,7 +515,7 @@ struct NodeVisitor {
515515
READ_FEATURE(OmpReductionCombiner)
516516
READ_FEATURE(OmpReductionCombiner::FunctionCombiner)
517517
READ_FEATURE(OmpReductionInitializerClause)
518-
READ_FEATURE(OmpReductionOperator)
518+
READ_FEATURE(OmpReductionIdentifier)
519519
READ_FEATURE(OmpAllocateClause)
520520
READ_FEATURE(OmpAllocateClause::AllocateModifier)
521521
READ_FEATURE(OmpAllocateClause::AllocateModifier::Allocator)

flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ void OpenMPCounterVisitor::Post(const OmpScheduleModifierType::ModType &c) {
218218
clauseDetails +=
219219
"modifier=" + std::string{OmpScheduleModifierType::EnumToString(c)} + ";";
220220
}
221-
void OpenMPCounterVisitor::Post(const OmpLinearModifier::Type &c) {
221+
void OpenMPCounterVisitor::Post(const OmpLinearModifier::Value &c) {
222222
clauseDetails +=
223223
"modifier=" + std::string{OmpLinearModifier::EnumToString(c)} + ";";
224224
}
225-
void OpenMPCounterVisitor::Post(const OmpTaskDependenceType::Type &c) {
225+
void OpenMPCounterVisitor::Post(const OmpTaskDependenceType::Value &c) {
226226
clauseDetails +=
227227
"type=" + std::string{OmpTaskDependenceType::EnumToString(c)} + ";";
228228
}

flang/examples/FlangOmpReport/FlangOmpReportVisitor.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ struct OpenMPCounterVisitor {
7272
void Post(const OmpDefaultmapClause::VariableCategory &c);
7373
void Post(const OmpDeviceTypeClause::Type &c);
7474
void Post(const OmpScheduleModifierType::ModType &c);
75-
void Post(const OmpLinearModifier::Type &c);
76-
void Post(const OmpTaskDependenceType::Type &c);
75+
void Post(const OmpLinearModifier::Value &c);
76+
void Post(const OmpTaskDependenceType::Value &c);
7777
void Post(const OmpMapClause::Type &c);
7878
void Post(const OmpScheduleClause::ScheduleType &c);
7979
void Post(const OmpIfClause::DirectiveNameModifier &c);

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ class ParseTreeDumper {
477477
NODE(parser, ObjectDecl)
478478
NODE(parser, OldParameterStmt)
479479
NODE(parser, OmpIteratorSpecifier)
480-
NODE(parser, OmpIteratorModifier)
480+
NODE(parser, OmpIterator)
481481
NODE(parser, OmpAffinityClause)
482482
NODE(parser, OmpAlignedClause)
483483
NODE(parser, OmpAtomic)
@@ -513,9 +513,9 @@ class ParseTreeDumper {
513513
NODE_ENUM(OmpDefaultmapClause, ImplicitBehavior)
514514
NODE_ENUM(OmpDefaultmapClause, VariableCategory)
515515
NODE(parser, OmpDependenceType)
516-
NODE_ENUM(OmpDependenceType, Type)
516+
NODE_ENUM(OmpDependenceType, Value)
517517
NODE(parser, OmpTaskDependenceType)
518-
NODE_ENUM(OmpTaskDependenceType, Type)
518+
NODE_ENUM(OmpTaskDependenceType, Value)
519519
NODE(parser, OmpIterationOffset)
520520
NODE(parser, OmpIteration)
521521
NODE(parser, OmpIterationVector)
@@ -543,7 +543,7 @@ class ParseTreeDumper {
543543
NODE(OmpLinearClause, WithModifier)
544544
NODE(OmpLinearClause, WithoutModifier)
545545
NODE(parser, OmpLinearModifier)
546-
NODE_ENUM(OmpLinearModifier, Type)
546+
NODE_ENUM(OmpLinearModifier, Value)
547547
NODE(parser, OmpLoopDirective)
548548
NODE(parser, OmpMapClause)
549549
NODE(parser, OmpMapperIdentifier)
@@ -574,7 +574,7 @@ class ParseTreeDumper {
574574
NODE(parser, OmpReductionCombiner)
575575
NODE(OmpReductionCombiner, FunctionCombiner)
576576
NODE(parser, OmpReductionInitializerClause)
577-
NODE(parser, OmpReductionOperator)
577+
NODE(parser, OmpReductionIdentifier)
578578
NODE(parser, OmpAllocateClause)
579579
NODE(OmpAllocateClause, AllocateModifier)
580580
NODE(OmpAllocateClause::AllocateModifier, Allocator)

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

+70-43
Original file line numberDiff line numberDiff line change
@@ -3440,13 +3440,33 @@ struct OmpObject {
34403440

34413441
WRAPPER_CLASS(OmpObjectList, std::list<OmpObject>);
34423442

3443+
inline namespace modifier {
3444+
// For uniformity, in all keyword modifiers the name of the type defined
3445+
// by ENUM_CLASS is "Value", e.g.
3446+
// struct Foo {
3447+
// ENUM_CLASS(Value, Keyword1, Keyword2);
3448+
// };
3449+
3450+
// Ref: [5.0:47-49], [5.1:49-51], [5.2:67-69]
3451+
//
3452+
// iterator-specifier ->
3453+
// [iterator-type] iterator-identifier
3454+
// = range-specification | // since 5.0
3455+
// [iterator-type ::] iterator-identifier
3456+
// = range-specification // since 5.2
3457+
struct OmpIteratorSpecifier {
3458+
TUPLE_CLASS_BOILERPLATE(OmpIteratorSpecifier);
3459+
CharBlock source;
3460+
std::tuple<TypeDeclarationStmt, SubscriptTriplet> t;
3461+
};
3462+
34433463
// Ref: [4.5:169-170], [5.0:255-256], [5.1:288-289]
34443464
//
34453465
// dependence-type ->
3446-
// SINK | SOURCE | // since 4.5
3447-
// IN | OUT | INOUT | // since 4.5, until 5.1
3448-
// MUTEXINOUTSET | DEPOBJ | // since 5.0, until 5.1
3449-
// INOUTSET // since 5.1, until 5.1
3466+
// SINK | SOURCE | // since 4.5
3467+
// IN | OUT | INOUT | // since 4.5, until 5.1
3468+
// MUTEXINOUTSET | DEPOBJ | // since 5.0, until 5.1
3469+
// INOUTSET // since 5.1, until 5.1
34503470
//
34513471
// All of these, except SINK and SOURCE became task-dependence-type in 5.2.
34523472
//
@@ -3457,45 +3477,59 @@ WRAPPER_CLASS(OmpObjectList, std::list<OmpObject>);
34573477
// vector). This would accept the vector "i, j, k" (although interpreted
34583478
// incorrectly), while flagging a syntax error for "i+1, j, k".
34593479
struct OmpDependenceType {
3460-
ENUM_CLASS(Type, Sink, Source);
3461-
WRAPPER_CLASS_BOILERPLATE(OmpDependenceType, Type);
3480+
ENUM_CLASS(Value, Sink, Source);
3481+
WRAPPER_CLASS_BOILERPLATE(OmpDependenceType, Value);
34623482
};
34633483

3464-
// Ref: [4.5:169-170], [5.0:254-256], [5.1:287-289], [5.2:321]
3484+
// Ref: [5.0:47-49], [5.1:49-51], [5.2:67-69]
34653485
//
3466-
// task-dependence-type -> // "dependence-type" in 5.1 and before
3467-
// IN | OUT | INOUT | // since 4.5
3468-
// MUTEXINOUTSET | DEPOBJ | // since 5.0
3469-
// INOUTSET // since 5.2
3470-
struct OmpTaskDependenceType {
3471-
ENUM_CLASS(Type, In, Out, Inout, Inoutset, Mutexinoutset, Depobj)
3472-
WRAPPER_CLASS_BOILERPLATE(OmpTaskDependenceType, Type);
3486+
// iterator-modifier ->
3487+
// ITERATOR(iterator-specifier [, ...]) // since 5.0
3488+
struct OmpIterator {
3489+
WRAPPER_CLASS_BOILERPLATE(OmpIterator, std::list<OmpIteratorSpecifier>);
34733490
};
34743491

3475-
// [5.0] 2.1.6 iterator-specifier -> type-declaration-stmt = subscript-triple
3476-
// iterator-modifier -> iterator-specifier-list
3477-
struct OmpIteratorSpecifier {
3478-
TUPLE_CLASS_BOILERPLATE(OmpIteratorSpecifier);
3479-
CharBlock source;
3480-
std::tuple<TypeDeclarationStmt, SubscriptTriplet> t;
3492+
// Ref: [4.5:207-210], [5.0:290-293], [5.1:323-325], [5.2:117-120]
3493+
//
3494+
// linear-modifier ->
3495+
// REF | UVAL | VAL // since 4.5
3496+
struct OmpLinearModifier {
3497+
ENUM_CLASS(Value, Ref, Uval, Val);
3498+
WRAPPER_CLASS_BOILERPLATE(OmpLinearModifier, Value);
34813499
};
34823500

3483-
WRAPPER_CLASS(OmpIteratorModifier, std::list<OmpIteratorSpecifier>);
3484-
3485-
// 2.15.3.6 reduction-identifier -> + | - | * | .AND. | .OR. | .EQV. | .NEQV. |
3486-
// MAX | MIN | IAND | IOR | IEOR
3487-
struct OmpReductionOperator {
3488-
UNION_CLASS_BOILERPLATE(OmpReductionOperator);
3501+
// Ref: [4.5:201-207], [5.0:293-299], [5.1:325-331], [5.2:124]
3502+
//
3503+
// reduction-identifier ->
3504+
// base-language-identifier | // since 4.5
3505+
// - | // since 4.5, until 5.2
3506+
// + | * | .AND. | .OR. | .EQV. | .NEQV. | // since 4.5
3507+
// MIN | MAX | IAND | IOR | IEOR // since 4.5
3508+
//
3509+
struct OmpReductionIdentifier {
3510+
UNION_CLASS_BOILERPLATE(OmpReductionIdentifier);
34893511
std::variant<DefinedOperator, ProcedureDesignator> u;
34903512
};
34913513

3514+
// Ref: [4.5:169-170], [5.0:254-256], [5.1:287-289], [5.2:321]
3515+
//
3516+
// task-dependence-type -> // "dependence-type" in 5.1 and before
3517+
// IN | OUT | INOUT | // since 4.5
3518+
// MUTEXINOUTSET | DEPOBJ | // since 5.0
3519+
// INOUTSET // since 5.2
3520+
struct OmpTaskDependenceType {
3521+
ENUM_CLASS(Value, In, Out, Inout, Inoutset, Mutexinoutset, Depobj)
3522+
WRAPPER_CLASS_BOILERPLATE(OmpTaskDependenceType, Value);
3523+
};
3524+
} // namespace modifier
3525+
34923526
// --- Clauses
34933527

34943528
// OMP 5.0 2.10.1 affinity([aff-modifier:] locator-list)
34953529
// aff-modifier: interator-modifier
34963530
struct OmpAffinityClause {
34973531
TUPLE_CLASS_BOILERPLATE(OmpAffinityClause);
3498-
std::tuple<std::optional<OmpIteratorModifier>, OmpObjectList> t;
3532+
std::tuple<std::optional<OmpIterator>, OmpObjectList> t;
34993533
};
35003534

35013535
// 2.8.1 aligned-clause -> ALIGNED (variable-name-list[ : scalar-constant])
@@ -3566,7 +3600,7 @@ WRAPPER_CLASS(OmpIterationVector, std::list<OmpIteration>);
35663600
// OmpDoacrossClause), so that the context in TYPE_CONTEXT_PARSER can be set
35673601
// separately for OmpDependClause and OmpDoacrossClause.
35683602
struct OmpDoacross {
3569-
OmpDependenceType::Type GetDepType() const;
3603+
OmpDependenceType::Value GetDepType() const;
35703604

35713605
WRAPPER_CLASS(Sink, OmpIterationVector);
35723606
EMPTY_CLASS(Source);
@@ -3586,10 +3620,9 @@ struct OmpDoacross {
35863620
struct OmpDependClause {
35873621
UNION_CLASS_BOILERPLATE(OmpDependClause);
35883622
struct TaskDep {
3589-
OmpTaskDependenceType::Type GetTaskDepType() const;
3623+
OmpTaskDependenceType::Value GetTaskDepType() const;
35903624
TUPLE_CLASS_BOILERPLATE(TaskDep);
3591-
std::tuple<std::optional<OmpIteratorModifier>, OmpTaskDependenceType,
3592-
OmpObjectList>
3625+
std::tuple<std::optional<OmpIterator>, OmpTaskDependenceType, OmpObjectList>
35933626
t;
35943627
};
35953628
std::variant<TaskDep, OmpDoacross> u;
@@ -3632,7 +3665,7 @@ struct OmpFromClause {
36323665
// As in the case of MAP, modifiers are parsed as lists, even if they
36333666
// are unique. These restrictions will be checked in semantic checks.
36343667
std::tuple<std::optional<std::list<Expectation>>,
3635-
std::optional<std::list<OmpIteratorModifier>>, OmpObjectList,
3668+
std::optional<std::list<OmpIterator>>, OmpObjectList,
36363669
bool> // were the modifiers comma-separated?
36373670
t;
36383671
};
@@ -3661,7 +3694,7 @@ struct OmpDetachClause {
36613694
// variable-name-list)
36623695
struct OmpInReductionClause {
36633696
TUPLE_CLASS_BOILERPLATE(OmpInReductionClause);
3664-
std::tuple<OmpReductionOperator, OmpObjectList> t;
3697+
std::tuple<OmpReductionIdentifier, OmpObjectList> t;
36653698
};
36663699

36673700
// OMP 5.0 2.19.4.5 lastprivate-clause ->
@@ -3673,12 +3706,6 @@ struct OmpLastprivateClause {
36733706
std::tuple<std::optional<LastprivateModifier>, OmpObjectList> t;
36743707
};
36753708

3676-
// 2.15.3.7 linear-modifier -> REF | VAL | UVAL
3677-
struct OmpLinearModifier {
3678-
ENUM_CLASS(Type, Ref, Val, Uval)
3679-
WRAPPER_CLASS_BOILERPLATE(OmpLinearModifier, Type);
3680-
};
3681-
36823709
// 2.15.3.7 linear-clause -> LINEAR (linear-list[ : linear-step])
36833710
// linear-list -> list | linear-modifier(list)
36843711
struct OmpLinearClause {
@@ -3723,7 +3750,7 @@ struct OmpMapClause {
37233750
// information about separator presence to emit a diagnostic if needed.
37243751
std::tuple<OmpMapperIdentifier, // Mapper name
37253752
std::optional<std::list<TypeModifier>>,
3726-
std::optional<std::list<OmpIteratorModifier>>, // unique
3753+
std::optional<std::list<OmpIterator>>, // unique
37273754
std::optional<std::list<Type>>, // unique
37283755
OmpObjectList,
37293756
bool> // were the modifiers comma-separated?
@@ -3753,7 +3780,7 @@ struct OmpProcBindClause {
37533780
struct OmpReductionClause {
37543781
TUPLE_CLASS_BOILERPLATE(OmpReductionClause);
37553782
ENUM_CLASS(ReductionModifier, Inscan, Task, Default)
3756-
std::tuple<std::optional<ReductionModifier>, OmpReductionOperator,
3783+
std::tuple<std::optional<ReductionModifier>, OmpReductionIdentifier,
37573784
OmpObjectList>
37583785
t;
37593786
};
@@ -3798,7 +3825,7 @@ struct OmpToClause {
37983825
// As in the case of MAP, modifiers are parsed as lists, even if they
37993826
// are unique. These restrictions will be checked in semantic checks.
38003827
std::tuple<std::optional<std::list<Expectation>>,
3801-
std::optional<std::list<OmpIteratorModifier>>, OmpObjectList,
3828+
std::optional<std::list<OmpIterator>>, OmpObjectList,
38023829
bool> // were the modifiers comma-separated?
38033830
t;
38043831
};
@@ -3946,7 +3973,7 @@ WRAPPER_CLASS(OmpReductionInitializerClause, Expr);
39463973
struct OpenMPDeclareReductionConstruct {
39473974
TUPLE_CLASS_BOILERPLATE(OpenMPDeclareReductionConstruct);
39483975
CharBlock source;
3949-
std::tuple<Verbatim, OmpReductionOperator, std::list<DeclarationTypeSpec>,
3976+
std::tuple<Verbatim, OmpReductionIdentifier, std::list<DeclarationTypeSpec>,
39503977
OmpReductionCombiner, std::optional<OmpReductionInitializerClause>>
39513978
t;
39523979
};

0 commit comments

Comments
 (0)