Skip to content

Commit e184c0b

Browse files
committed
[flang][OpenMP] Use new modifier infrastructure for MAP/FROM/TO clauses
This removes the specialized parsers and helper classes for these clauses, namely ConcatSeparated, MapModifiers, and MotionModifiers. Map and the motion clauses are now handled in the same way as all other clauses with modifiers, with one exception: the commas separating their modifiers are optional. This syntax is deprecated in OpenMP 5.2. Implement version checks for modifiers: for a given modifier on a given clause, check if that modifier is allowed on this clause in the specified OpenMP version. This replaced several individual checks. Add a testcase for handling map modifiers in a different order, and for diagnosing an ultimate modifier out of position.
1 parent 5f9db08 commit e184c0b

28 files changed

+716
-684
lines changed

flang/examples/FeatureList/FeatureList.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ struct NodeVisitor {
498498
READ_FEATURE(OmpLinearModifier::Value)
499499
READ_FEATURE(OmpLoopDirective)
500500
READ_FEATURE(OmpMapClause)
501-
READ_FEATURE(OmpMapClause::TypeModifier)
502-
READ_FEATURE(OmpMapClause::Type)
501+
READ_FEATURE(OmpMapClause::Modifier)
503502
READ_FEATURE(OmpNumTasksClause)
504503
READ_FEATURE(OmpNumTasksClause::Prescriptiveness)
505504
READ_FEATURE(OmpObject)

flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ void OpenMPCounterVisitor::Post(const OmpTaskDependenceType::Value &c) {
229229
clauseDetails +=
230230
"type=" + std::string{OmpTaskDependenceType::EnumToString(c)} + ";";
231231
}
232-
void OpenMPCounterVisitor::Post(const OmpMapClause::Type &c) {
233-
clauseDetails += "type=" + std::string{OmpMapClause::EnumToString(c)} + ";";
232+
void OpenMPCounterVisitor::Post(const OmpMapType::Value &c) {
233+
clauseDetails += "type=" + std::string{OmpMapType::EnumToString(c)} + ";";
234234
}
235235
void OpenMPCounterVisitor::Post(const OmpScheduleClause::Kind &c) {
236236
clauseDetails +=

flang/examples/FlangOmpReport/FlangOmpReportVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct OpenMPCounterVisitor {
7575
void Post(const OmpLinearModifier::Value &c);
7676
void Post(const OmpOrderingModifier::Value &c);
7777
void Post(const OmpTaskDependenceType::Value &c);
78-
void Post(const OmpMapClause::Type &c);
78+
void Post(const OmpMapType::Value &c);
7979
void Post(const OmpScheduleClause::Kind &c);
8080
void Post(const OmpIfClause::DirectiveNameModifier &c);
8181
void Post(const OmpCancelType::Type &c);

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,11 @@ class ParseTreeDumper {
476476
NODE(parser, NullInit)
477477
NODE(parser, ObjectDecl)
478478
NODE(parser, OldParameterStmt)
479+
NODE(parser, OmpMapper)
480+
NODE(parser, OmpMapType)
481+
NODE_ENUM(OmpMapType, Value)
482+
NODE(parser, OmpMapTypeModifier)
483+
NODE_ENUM(OmpMapTypeModifier, Value)
479484
NODE(parser, OmpIteratorSpecifier)
480485
NODE(parser, OmpIterator)
481486
NODE(parser, OmpAffinityClause)
@@ -536,7 +541,9 @@ class ParseTreeDumper {
536541
NODE(parser, OmpEndLoopDirective)
537542
NODE(parser, OmpEndSectionsDirective)
538543
NODE(parser, OmpFromClause)
539-
NODE_ENUM(OmpFromClause, Expectation)
544+
NODE(OmpFromClause, Modifier)
545+
NODE(parser, OmpExpectation)
546+
NODE_ENUM(OmpExpectation, Value)
540547
NODE(parser, OmpIfClause)
541548
NODE_ENUM(OmpIfClause, DirectiveNameModifier)
542549
NODE_ENUM(OmpLastprivateClause, LastprivateModifier)
@@ -548,9 +555,7 @@ class ParseTreeDumper {
548555
NODE_ENUM(OmpLinearModifier, Value)
549556
NODE(parser, OmpLoopDirective)
550557
NODE(parser, OmpMapClause)
551-
NODE(parser, OmpMapperIdentifier)
552-
NODE_ENUM(OmpMapClause, TypeModifier)
553-
NODE_ENUM(OmpMapClause, Type)
558+
NODE(OmpMapClause, Modifier)
554559
static std::string GetNodeName(const llvm::omp::Clause &x) {
555560
return llvm::Twine(
556561
"llvm::omp::Clause = ", llvm::omp::getOpenMPClauseName(x))
@@ -601,8 +606,7 @@ class ParseTreeDumper {
601606
NODE(parser, OmpSectionsDirective)
602607
NODE(parser, OmpSimpleStandaloneDirective)
603608
NODE(parser, OmpToClause)
604-
// No NODE_ENUM for OmpToClause::Expectation, because it's an alias
605-
// for OmpFromClause::Expectation.
609+
NODE(OmpToClause, Modifier)
606610
NODE(parser, Only)
607611
NODE(parser, OpenACCAtomicConstruct)
608612
NODE(parser, OpenACCBlockConstruct)

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

Lines changed: 74 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3502,6 +3502,21 @@ struct OmpDependenceType {
35023502
WRAPPER_CLASS_BOILERPLATE(OmpDependenceType, Value);
35033503
};
35043504

3505+
// Ref: [5.1:205-209], [5.2:166-168]
3506+
//
3507+
// motion-modifier ->
3508+
// PRESENT | // since 5.0, until 5.0
3509+
// mapper | iterator
3510+
// expectation ->
3511+
// PRESENT // since 5.1
3512+
//
3513+
// The PRESENT value was a part of motion-modifier in 5.1, and became a
3514+
// value of expectation in 5.2.
3515+
struct OmpExpectation {
3516+
ENUM_CLASS(Value, Present);
3517+
WRAPPER_CLASS_BOILERPLATE(OmpExpectation, Value);
3518+
};
3519+
35053520
// Ref: [5.0:47-49], [5.1:49-51], [5.2:67-69]
35063521
//
35073522
// iterator-modifier ->
@@ -3519,6 +3534,34 @@ struct OmpLinearModifier {
35193534
WRAPPER_CLASS_BOILERPLATE(OmpLinearModifier, Value);
35203535
};
35213536

3537+
// Ref: [5.0:176-180], [5.1:205-210], [5.2:149-150]
3538+
//
3539+
// mapper ->
3540+
// identifier // since 4.5
3541+
struct OmpMapper {
3542+
WRAPPER_CLASS_BOILERPLATE(OmpMapper, Name);
3543+
};
3544+
3545+
// Ref: [4.5:216-219], [5.0:315-324], [5.1:347-355], [5.2:150-158]
3546+
//
3547+
// map-type ->
3548+
// ALLOC | DELETE | FROM | RELEASE | TO | TOFROM // since 4.5
3549+
struct OmpMapType {
3550+
ENUM_CLASS(Value, Alloc, Delete, From, Release, To, Tofrom);
3551+
WRAPPER_CLASS_BOILERPLATE(OmpMapType, Value);
3552+
};
3553+
3554+
// Ref: [4.5:216-219], [5.0:315-324], [5.1:347-355], [5.2:150-158]
3555+
//
3556+
// map-type-modifier ->
3557+
// ALWAYS | // since 4.5
3558+
// CLOSE | // since 5.0
3559+
// PRESENT // since 5.1
3560+
struct OmpMapTypeModifier {
3561+
ENUM_CLASS(Value, Always, Close, Present, Ompx_Hold)
3562+
WRAPPER_CLASS_BOILERPLATE(OmpMapTypeModifier, Value);
3563+
};
3564+
35223565
// Ref: [4.5:56-63], [5.0:101-109], [5.1:126-133], [5.2:252-254]
35233566
//
35243567
// modifier ->
@@ -3546,10 +3589,10 @@ struct OmpOrderModifier {
35463589
// Ref: [4.5:201-207], [5.0:293-299], [5.1:325-331], [5.2:124]
35473590
//
35483591
// reduction-identifier ->
3549-
// base-language-identifier | // since 4.5
3550-
// - | // since 4.5, until 5.2
3551-
// + | * | .AND. | .OR. | .EQV. | .NEQV. | // since 4.5
3552-
// MIN | MAX | IAND | IOR | IEOR // since 4.5
3592+
// base-language-identifier | // since 4.5
3593+
// - | // since 4.5, until 5.2
3594+
// + | * | .AND. | .OR. | .EQV. | .NEQV. | // since 4.5
3595+
// MIN | MAX | IAND | IOR | IEOR // since 4.5
35533596
struct OmpReductionIdentifier {
35543597
UNION_CLASS_BOILERPLATE(OmpReductionIdentifier);
35553598
std::variant<DefinedOperator, ProcedureDesignator> u;
@@ -3558,7 +3601,7 @@ struct OmpReductionIdentifier {
35583601
// Ref: [5.0:300-302], [5.1:332-334], [5.2:134-137]
35593602
//
35603603
// reduction-modifier ->
3561-
// DEFAULT | INSCAN | TASK // since 5.0
3604+
// DEFAULT | INSCAN | TASK // since 5.0
35623605
struct OmpReductionModifier {
35633606
ENUM_CLASS(Value, Default, Inscan, Task);
35643607
WRAPPER_CLASS_BOILERPLATE(OmpReductionModifier, Value);
@@ -3578,9 +3621,9 @@ struct OmpTaskDependenceType {
35783621
// Ref: [4.5:229-230], [5.0:324-325], [5.1:357-358], [5.2:161-162]
35793622
//
35803623
// variable-category ->
3581-
// SCALAR | // since 4.5
3582-
// AGGREGATE | ALLOCATABLE | POINTER | // since 5.0
3583-
// ALL // since 5.2
3624+
// SCALAR | // since 4.5
3625+
// AGGREGATE | ALLOCATABLE | POINTER | // since 5.0
3626+
// ALL // since 5.2
35843627
struct OmpVariableCategory {
35853628
ENUM_CLASS(Value, Aggregate, All, Allocatable, Pointer, Scalar)
35863629
WRAPPER_CLASS_BOILERPLATE(OmpVariableCategory, Value);
@@ -3723,15 +3766,9 @@ struct OmpDeviceTypeClause {
37233766
// motion-modifier ->
37243767
// PRESENT | mapper-modifier | iterator-modifier
37253768
struct OmpFromClause {
3726-
ENUM_CLASS(Expectation, Present);
37273769
TUPLE_CLASS_BOILERPLATE(OmpFromClause);
3728-
3729-
// As in the case of MAP, modifiers are parsed as lists, even if they
3730-
// are unique. These restrictions will be checked in semantic checks.
3731-
std::tuple<std::optional<std::list<Expectation>>,
3732-
std::optional<std::list<OmpIterator>>, OmpObjectList,
3733-
bool> // were the modifiers comma-separated?
3734-
t;
3770+
MODIFIER_BOILERPLATE(OmpExpectation, OmpIterator, OmpMapper);
3771+
std::tuple<MODIFIERS(), OmpObjectList, bool> t;
37353772
};
37363773

37373774
// OMP 5.2 12.6.1 grainsize-clause -> grainsize ([prescriptiveness :] value)
@@ -3794,31 +3831,19 @@ struct OmpLinearClause {
37943831
std::variant<WithModifier, WithoutModifier> u;
37953832
};
37963833

3797-
WRAPPER_CLASS(OmpMapperIdentifier, std::optional<Name>);
3798-
3799-
// 2.15.5.1 map ->
3800-
// MAP ([MAPPER(mapper-identifier)] [[map-type-modifier-list [,]]
3801-
// [iterator-modifier [,]] map-type : ]
3802-
// variable-name-list)
3803-
// map-type-modifier-list -> map-type-modifier [,] [...]
3804-
// map-type-modifier -> ALWAYS | CLOSE | PRESENT | OMPX_HOLD
3805-
// map-type -> TO | FROM | TOFROM | ALLOC | RELEASE | DELETE
3834+
// Ref: [4.5:216-219], [5.0:315-324], [5.1:347-355], [5.2:150-158]
3835+
//
3836+
// map-clause ->
3837+
// MAP([modifier...:] locator-list) // since 4.5
3838+
// modifier ->
3839+
// map-type-modifier | // since 4.5
3840+
// mapper | // since 5.0
3841+
// iterator | // since 5.1
3842+
// map-type // since 4.5
38063843
struct OmpMapClause {
3807-
ENUM_CLASS(TypeModifier, Always, Close, Present, Ompx_Hold);
3808-
ENUM_CLASS(Type, To, From, Tofrom, Alloc, Release, Delete)
38093844
TUPLE_CLASS_BOILERPLATE(OmpMapClause);
3810-
3811-
// All modifiers are parsed into optional lists, even if they are unique.
3812-
// The checks for satisfying those constraints are deferred to semantics.
3813-
// In OpenMP 5.2 the non-comma syntax has been deprecated: keep the
3814-
// information about separator presence to emit a diagnostic if needed.
3815-
std::tuple<OmpMapperIdentifier, // Mapper name
3816-
std::optional<std::list<TypeModifier>>,
3817-
std::optional<std::list<OmpIterator>>, // unique
3818-
std::optional<std::list<Type>>, // unique
3819-
OmpObjectList,
3820-
bool> // were the modifiers comma-separated?
3821-
t;
3845+
MODIFIER_BOILERPLATE(OmpMapTypeModifier, OmpMapper, OmpIterator, OmpMapType);
3846+
std::tuple<MODIFIERS(), OmpObjectList, bool> t;
38223847
};
38233848

38243849
// Ref: [5.0:101-109], [5.1:126-134], [5.2:233-234]
@@ -3869,23 +3894,17 @@ struct OmpScheduleClause {
38693894
// Ref: [4.5:107-109], [5.0:176-180], [5.1:205-210], [5.2:167-168]
38703895
//
38713896
// to-clause (in DECLARE TARGET) ->
3872-
// TO(extended-list) | // until 5.1
3897+
// TO(extended-list) | // until 5.1
38733898
// to-clause (in TARGET UPDATE) ->
38743899
// TO(locator-list) |
3875-
// TO(mapper-modifier: locator-list) | // since 5.0
3876-
// TO(motion-modifier[,] ...: locator-list) // since 5.1
3877-
// motion-modifier ->
3900+
// TO(mapper-modifier: locator-list) | // since 5.0
3901+
// TO(motion-modifier[,] ...: locator-list) // since 5.1
3902+
// motion-modifier ->
38783903
// PRESENT | mapper-modifier | iterator-modifier
38793904
struct OmpToClause {
3880-
using Expectation = OmpFromClause::Expectation;
38813905
TUPLE_CLASS_BOILERPLATE(OmpToClause);
3882-
3883-
// As in the case of MAP, modifiers are parsed as lists, even if they
3884-
// are unique. These restrictions will be checked in semantic checks.
3885-
std::tuple<std::optional<std::list<Expectation>>,
3886-
std::optional<std::list<OmpIterator>>, OmpObjectList,
3887-
bool> // were the modifiers comma-separated?
3888-
t;
3906+
MODIFIER_BOILERPLATE(OmpExpectation, OmpIterator, OmpMapper);
3907+
std::tuple<MODIFIERS(), OmpObjectList, bool> t;
38893908
};
38903909

38913910
// OMP 5.2 12.6.2 num_tasks-clause -> num_tasks ([prescriptiveness :] value)
@@ -3897,8 +3916,10 @@ struct OmpNumTasksClause {
38973916

38983917
// Ref: [5.0:254-255], [5.1:287-288], [5.2:321-322]
38993918
//
3900-
// update-clause -> UPDATE(dependence-type) // since 5.0, until 5.1
3901-
// update-clause -> UPDATE(task-dependence-type) // since 5.2
3919+
// update-clause ->
3920+
// UPDATE(dependence-type) // since 5.0, until 5.1
3921+
// update-clause ->
3922+
// UPDATE(task-dependence-type) // since 5.2
39023923
struct OmpUpdateClause {
39033924
UNION_CLASS_BOILERPLATE(OmpUpdateClause);
39043925
std::variant<OmpDependenceType, OmpTaskDependenceType> u;

0 commit comments

Comments
 (0)