Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][OpenMP] Use new modifier infrastructure for MAP/FROM/TO clauses #117447

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions flang/examples/FeatureList/FeatureList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,7 @@ struct NodeVisitor {
READ_FEATURE(OmpLinearModifier::Value)
READ_FEATURE(OmpLoopDirective)
READ_FEATURE(OmpMapClause)
READ_FEATURE(OmpMapClause::TypeModifier)
READ_FEATURE(OmpMapClause::Type)
READ_FEATURE(OmpMapClause::Modifier)
READ_FEATURE(OmpNumTasksClause)
READ_FEATURE(OmpNumTasksClause::Prescriptiveness)
READ_FEATURE(OmpObject)
Expand Down
4 changes: 2 additions & 2 deletions flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ void OpenMPCounterVisitor::Post(const OmpTaskDependenceType::Value &c) {
clauseDetails +=
"type=" + std::string{OmpTaskDependenceType::EnumToString(c)} + ";";
}
void OpenMPCounterVisitor::Post(const OmpMapClause::Type &c) {
clauseDetails += "type=" + std::string{OmpMapClause::EnumToString(c)} + ";";
void OpenMPCounterVisitor::Post(const OmpMapType::Value &c) {
clauseDetails += "type=" + std::string{OmpMapType::EnumToString(c)} + ";";
}
void OpenMPCounterVisitor::Post(const OmpScheduleClause::Kind &c) {
clauseDetails +=
Expand Down
2 changes: 1 addition & 1 deletion flang/examples/FlangOmpReport/FlangOmpReportVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct OpenMPCounterVisitor {
void Post(const OmpLinearModifier::Value &c);
void Post(const OmpOrderingModifier::Value &c);
void Post(const OmpTaskDependenceType::Value &c);
void Post(const OmpMapClause::Type &c);
void Post(const OmpMapType::Value &c);
void Post(const OmpScheduleClause::Kind &c);
void Post(const OmpIfClause::DirectiveNameModifier &c);
void Post(const OmpCancelType::Type &c);
Expand Down
16 changes: 10 additions & 6 deletions flang/include/flang/Parser/dump-parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ class ParseTreeDumper {
NODE(parser, NullInit)
NODE(parser, ObjectDecl)
NODE(parser, OldParameterStmt)
NODE(parser, OmpMapper)
NODE(parser, OmpMapType)
NODE_ENUM(OmpMapType, Value)
NODE(parser, OmpMapTypeModifier)
NODE_ENUM(OmpMapTypeModifier, Value)
NODE(parser, OmpIteratorSpecifier)
NODE(parser, OmpIterator)
NODE(parser, OmpAffinityClause)
Expand Down Expand Up @@ -536,7 +541,9 @@ class ParseTreeDumper {
NODE(parser, OmpEndLoopDirective)
NODE(parser, OmpEndSectionsDirective)
NODE(parser, OmpFromClause)
NODE_ENUM(OmpFromClause, Expectation)
NODE(OmpFromClause, Modifier)
NODE(parser, OmpExpectation)
NODE_ENUM(OmpExpectation, Value)
NODE(parser, OmpIfClause)
NODE_ENUM(OmpIfClause, DirectiveNameModifier)
NODE_ENUM(OmpLastprivateClause, LastprivateModifier)
Expand All @@ -548,9 +555,7 @@ class ParseTreeDumper {
NODE_ENUM(OmpLinearModifier, Value)
NODE(parser, OmpLoopDirective)
NODE(parser, OmpMapClause)
NODE(parser, OmpMapperIdentifier)
NODE_ENUM(OmpMapClause, TypeModifier)
NODE_ENUM(OmpMapClause, Type)
NODE(OmpMapClause, Modifier)
static std::string GetNodeName(const llvm::omp::Clause &x) {
return llvm::Twine(
"llvm::omp::Clause = ", llvm::omp::getOpenMPClauseName(x))
Expand Down Expand Up @@ -601,8 +606,7 @@ class ParseTreeDumper {
NODE(parser, OmpSectionsDirective)
NODE(parser, OmpSimpleStandaloneDirective)
NODE(parser, OmpToClause)
// No NODE_ENUM for OmpToClause::Expectation, because it's an alias
// for OmpFromClause::Expectation.
NODE(OmpToClause, Modifier)
NODE(parser, Only)
NODE(parser, OpenACCAtomicConstruct)
NODE(parser, OpenACCBlockConstruct)
Expand Down
127 changes: 74 additions & 53 deletions flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3502,6 +3502,21 @@ struct OmpDependenceType {
WRAPPER_CLASS_BOILERPLATE(OmpDependenceType, Value);
};

// Ref: [5.1:205-209], [5.2:166-168]
//
// motion-modifier ->
// PRESENT | // since 5.0, until 5.0
// mapper | iterator
// expectation ->
// PRESENT // since 5.1
//
// The PRESENT value was a part of motion-modifier in 5.1, and became a
// value of expectation in 5.2.
struct OmpExpectation {
ENUM_CLASS(Value, Present);
WRAPPER_CLASS_BOILERPLATE(OmpExpectation, Value);
};

// Ref: [5.0:47-49], [5.1:49-51], [5.2:67-69]
//
// iterator-modifier ->
Expand All @@ -3519,6 +3534,34 @@ struct OmpLinearModifier {
WRAPPER_CLASS_BOILERPLATE(OmpLinearModifier, Value);
};

// Ref: [5.0:176-180], [5.1:205-210], [5.2:149-150]
//
// mapper ->
// identifier // since 4.5
struct OmpMapper {
WRAPPER_CLASS_BOILERPLATE(OmpMapper, Name);
};

// Ref: [4.5:216-219], [5.0:315-324], [5.1:347-355], [5.2:150-158]
//
// map-type ->
// ALLOC | DELETE | FROM | RELEASE | TO | TOFROM // since 4.5
struct OmpMapType {
ENUM_CLASS(Value, Alloc, Delete, From, Release, To, Tofrom);
WRAPPER_CLASS_BOILERPLATE(OmpMapType, Value);
};

// Ref: [4.5:216-219], [5.0:315-324], [5.1:347-355], [5.2:150-158]
//
// map-type-modifier ->
// ALWAYS | // since 4.5
// CLOSE | // since 5.0
// PRESENT // since 5.1
struct OmpMapTypeModifier {
ENUM_CLASS(Value, Always, Close, Present, Ompx_Hold)
WRAPPER_CLASS_BOILERPLATE(OmpMapTypeModifier, Value);
};

// Ref: [4.5:56-63], [5.0:101-109], [5.1:126-133], [5.2:252-254]
//
// modifier ->
Expand Down Expand Up @@ -3546,10 +3589,10 @@ struct OmpOrderModifier {
// Ref: [4.5:201-207], [5.0:293-299], [5.1:325-331], [5.2:124]
//
// reduction-identifier ->
// base-language-identifier | // since 4.5
// - | // since 4.5, until 5.2
// + | * | .AND. | .OR. | .EQV. | .NEQV. | // since 4.5
// MIN | MAX | IAND | IOR | IEOR // since 4.5
// base-language-identifier | // since 4.5
// - | // since 4.5, until 5.2
// + | * | .AND. | .OR. | .EQV. | .NEQV. | // since 4.5
// MIN | MAX | IAND | IOR | IEOR // since 4.5
struct OmpReductionIdentifier {
UNION_CLASS_BOILERPLATE(OmpReductionIdentifier);
std::variant<DefinedOperator, ProcedureDesignator> u;
Expand All @@ -3558,7 +3601,7 @@ struct OmpReductionIdentifier {
// Ref: [5.0:300-302], [5.1:332-334], [5.2:134-137]
//
// reduction-modifier ->
// DEFAULT | INSCAN | TASK // since 5.0
// DEFAULT | INSCAN | TASK // since 5.0
struct OmpReductionModifier {
ENUM_CLASS(Value, Default, Inscan, Task);
WRAPPER_CLASS_BOILERPLATE(OmpReductionModifier, Value);
Expand All @@ -3578,9 +3621,9 @@ struct OmpTaskDependenceType {
// Ref: [4.5:229-230], [5.0:324-325], [5.1:357-358], [5.2:161-162]
//
// variable-category ->
// SCALAR | // since 4.5
// AGGREGATE | ALLOCATABLE | POINTER | // since 5.0
// ALL // since 5.2
// SCALAR | // since 4.5
// AGGREGATE | ALLOCATABLE | POINTER | // since 5.0
// ALL // since 5.2
struct OmpVariableCategory {
ENUM_CLASS(Value, Aggregate, All, Allocatable, Pointer, Scalar)
WRAPPER_CLASS_BOILERPLATE(OmpVariableCategory, Value);
Expand Down Expand Up @@ -3723,15 +3766,9 @@ struct OmpDeviceTypeClause {
// motion-modifier ->
// PRESENT | mapper-modifier | iterator-modifier
struct OmpFromClause {
ENUM_CLASS(Expectation, Present);
TUPLE_CLASS_BOILERPLATE(OmpFromClause);

// As in the case of MAP, modifiers are parsed as lists, even if they
// are unique. These restrictions will be checked in semantic checks.
std::tuple<std::optional<std::list<Expectation>>,
std::optional<std::list<OmpIterator>>, OmpObjectList,
bool> // were the modifiers comma-separated?
t;
MODIFIER_BOILERPLATE(OmpExpectation, OmpIterator, OmpMapper);
std::tuple<MODIFIERS(), OmpObjectList, bool> t;
};

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

WRAPPER_CLASS(OmpMapperIdentifier, std::optional<Name>);

// 2.15.5.1 map ->
// MAP ([MAPPER(mapper-identifier)] [[map-type-modifier-list [,]]
// [iterator-modifier [,]] map-type : ]
// variable-name-list)
// map-type-modifier-list -> map-type-modifier [,] [...]
// map-type-modifier -> ALWAYS | CLOSE | PRESENT | OMPX_HOLD
// map-type -> TO | FROM | TOFROM | ALLOC | RELEASE | DELETE
// Ref: [4.5:216-219], [5.0:315-324], [5.1:347-355], [5.2:150-158]
//
// map-clause ->
// MAP([modifier...:] locator-list) // since 4.5
// modifier ->
// map-type-modifier | // since 4.5
// mapper | // since 5.0
// iterator | // since 5.1
// map-type // since 4.5
struct OmpMapClause {
ENUM_CLASS(TypeModifier, Always, Close, Present, Ompx_Hold);
ENUM_CLASS(Type, To, From, Tofrom, Alloc, Release, Delete)
TUPLE_CLASS_BOILERPLATE(OmpMapClause);

// All modifiers are parsed into optional lists, even if they are unique.
// The checks for satisfying those constraints are deferred to semantics.
// In OpenMP 5.2 the non-comma syntax has been deprecated: keep the
// information about separator presence to emit a diagnostic if needed.
std::tuple<OmpMapperIdentifier, // Mapper name
std::optional<std::list<TypeModifier>>,
std::optional<std::list<OmpIterator>>, // unique
std::optional<std::list<Type>>, // unique
OmpObjectList,
bool> // were the modifiers comma-separated?
t;
MODIFIER_BOILERPLATE(OmpMapTypeModifier, OmpMapper, OmpIterator, OmpMapType);
std::tuple<MODIFIERS(), OmpObjectList, bool> t;
};

// Ref: [5.0:101-109], [5.1:126-134], [5.2:233-234]
Expand Down Expand Up @@ -3869,23 +3894,17 @@ struct OmpScheduleClause {
// Ref: [4.5:107-109], [5.0:176-180], [5.1:205-210], [5.2:167-168]
//
// to-clause (in DECLARE TARGET) ->
// TO(extended-list) | // until 5.1
// TO(extended-list) | // until 5.1
// to-clause (in TARGET UPDATE) ->
// TO(locator-list) |
// TO(mapper-modifier: locator-list) | // since 5.0
// TO(motion-modifier[,] ...: locator-list) // since 5.1
// motion-modifier ->
// TO(mapper-modifier: locator-list) | // since 5.0
// TO(motion-modifier[,] ...: locator-list) // since 5.1
// motion-modifier ->
// PRESENT | mapper-modifier | iterator-modifier
struct OmpToClause {
using Expectation = OmpFromClause::Expectation;
TUPLE_CLASS_BOILERPLATE(OmpToClause);

// As in the case of MAP, modifiers are parsed as lists, even if they
// are unique. These restrictions will be checked in semantic checks.
std::tuple<std::optional<std::list<Expectation>>,
std::optional<std::list<OmpIterator>>, OmpObjectList,
bool> // were the modifiers comma-separated?
t;
MODIFIER_BOILERPLATE(OmpExpectation, OmpIterator, OmpMapper);
std::tuple<MODIFIERS(), OmpObjectList, bool> t;
};

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

// Ref: [5.0:254-255], [5.1:287-288], [5.2:321-322]
//
// update-clause -> UPDATE(dependence-type) // since 5.0, until 5.1
// update-clause -> UPDATE(task-dependence-type) // since 5.2
// update-clause ->
// UPDATE(dependence-type) // since 5.0, until 5.1
// update-clause ->
// UPDATE(task-dependence-type) // since 5.2
struct OmpUpdateClause {
UNION_CLASS_BOILERPLATE(OmpUpdateClause);
std::variant<OmpDependenceType, OmpTaskDependenceType> u;
Expand Down
Loading
Loading