Skip to content

Commit db510b8

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 db510b8

25 files changed

+676
-657
lines changed

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: 39 additions & 32 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,24 @@ struct OmpLinearModifier {
35193534
WRAPPER_CLASS_BOILERPLATE(OmpLinearModifier, Value);
35203535
};
35213536

3537+
// [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+
struct OmpMapType {
3546+
ENUM_CLASS(Value, Alloc, Delete, From, Release, To, Tofrom);
3547+
WRAPPER_CLASS_BOILERPLATE(OmpMapType, Value);
3548+
};
3549+
3550+
struct OmpMapTypeModifier {
3551+
ENUM_CLASS(Value, Always, Close, Present, Ompx_Hold)
3552+
WRAPPER_CLASS_BOILERPLATE(OmpMapTypeModifier, Value);
3553+
};
3554+
35223555
// Ref: [4.5:56-63], [5.0:101-109], [5.1:126-133], [5.2:252-254]
35233556
//
35243557
// modifier ->
@@ -3723,15 +3756,9 @@ struct OmpDeviceTypeClause {
37233756
// motion-modifier ->
37243757
// PRESENT | mapper-modifier | iterator-modifier
37253758
struct OmpFromClause {
3726-
ENUM_CLASS(Expectation, Present);
37273759
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;
3760+
MODIFIER_BOILERPLATE(OmpExpectation, OmpIterator, OmpMapper);
3761+
std::tuple<MODIFIERS(), OmpObjectList, bool> t;
37353762
};
37363763

37373764
// OMP 5.2 12.6.1 grainsize-clause -> grainsize ([prescriptiveness :] value)
@@ -3794,8 +3821,6 @@ struct OmpLinearClause {
37943821
std::variant<WithModifier, WithoutModifier> u;
37953822
};
37963823

3797-
WRAPPER_CLASS(OmpMapperIdentifier, std::optional<Name>);
3798-
37993824
// 2.15.5.1 map ->
38003825
// MAP ([MAPPER(mapper-identifier)] [[map-type-modifier-list [,]]
38013826
// [iterator-modifier [,]] map-type : ]
@@ -3804,21 +3829,9 @@ WRAPPER_CLASS(OmpMapperIdentifier, std::optional<Name>);
38043829
// map-type-modifier -> ALWAYS | CLOSE | PRESENT | OMPX_HOLD
38053830
// map-type -> TO | FROM | TOFROM | ALLOC | RELEASE | DELETE
38063831
struct OmpMapClause {
3807-
ENUM_CLASS(TypeModifier, Always, Close, Present, Ompx_Hold);
3808-
ENUM_CLASS(Type, To, From, Tofrom, Alloc, Release, Delete)
38093832
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;
3833+
MODIFIER_BOILERPLATE(OmpMapTypeModifier, OmpMapper, OmpIterator, OmpMapType);
3834+
std::tuple<MODIFIERS(), OmpObjectList, bool> t;
38223835
};
38233836

38243837
// Ref: [5.0:101-109], [5.1:126-134], [5.2:233-234]
@@ -3877,15 +3890,9 @@ struct OmpScheduleClause {
38773890
// motion-modifier ->
38783891
// PRESENT | mapper-modifier | iterator-modifier
38793892
struct OmpToClause {
3880-
using Expectation = OmpFromClause::Expectation;
38813893
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;
3894+
MODIFIER_BOILERPLATE(OmpExpectation, OmpIterator, OmpMapper);
3895+
std::tuple<MODIFIERS(), OmpObjectList, bool> t;
38893896
};
38903897

38913898
// OMP 5.2 12.6.2 num_tasks-clause -> num_tasks ([prescriptiveness :] value)

0 commit comments

Comments
 (0)