Skip to content

[flang][OpenMP] Parse WHEN, OTHERWISE, MATCH clauses plus METADIRECTIVE #121817

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

Merged
merged 12 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 7 additions & 1 deletion flang/include/flang/Parser/dump-parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,16 @@ class ParseTreeDumper {
NODE(parser, NullInit)
NODE(parser, ObjectDecl)
NODE(parser, OldParameterStmt)
NODE(parser, OmpMetadirectiveDirective)
NODE(parser, OmpMatchClause)
NODE(parser, OmpOtherwiseClause)
NODE(parser, OmpWhenClause)
NODE(OmpWhenClause, Modifier)
NODE(parser, OmpDirectiveSpecification)
NODE(parser, OmpTraitPropertyName)
NODE(parser, OmpTraitScore)
NODE(parser, OmpTraitPropertyExtension)
NODE(OmpTraitPropertyExtension, ExtensionValue)
NODE(OmpTraitPropertyExtension, Complex)
NODE(parser, OmpTraitProperty)
NODE(parser, OmpTraitSelectorName)
NODE_ENUM(OmpTraitSelectorName, Value)
Expand Down
89 changes: 61 additions & 28 deletions flang/include/flang/Parser/parse-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3456,6 +3456,14 @@ WRAPPER_CLASS(PauseStmt, std::optional<StopCode>);
struct OmpClause;
struct OmpClauseList;

struct OmpDirectiveSpecification {
TUPLE_CLASS_BOILERPLATE(OmpDirectiveSpecification);
std::tuple<llvm::omp::Directive,
std::optional<common::Indirection<OmpClauseList>>>
t;
CharBlock source;
};

// 2.1 Directives or clauses may accept a list or extended-list.
// A list item is a variable, array section or common block name (enclosed
// in slashes). An extended list item is a list item or a procedure Name.
Expand Down Expand Up @@ -3505,37 +3513,22 @@ struct OmpTraitScore {
};

// trait-property-extension ->
// trait-property-name (trait-property-value, ...)
// trait-property-value ->
// trait-property-name |
// scalar-integer-expression |
// trait-property-extension
//
// The grammar in OpenMP 5.2+ spec is ambiguous, the above is a different
// version (but equivalent) that doesn't have ambiguities.
// The ambiguity is in
// trait-property:
// trait-property-name <- (a)
// trait-property-clause
// trait-property-expression <- (b)
// trait-property-extension <- this conflicts with (a) and (b)
// trait-property-extension:
// trait-property-name <- conflict with (a)
// identifier(trait-property-extension[, trait-property-extension[, ...]])
// constant integer expression <- conflict with (b)
// scalar-expr |
// trait-property-name (trait-property-extension, ...)
//
struct OmpTraitPropertyExtension {
CharBlock source;
TUPLE_CLASS_BOILERPLATE(OmpTraitPropertyExtension);
struct ExtensionValue {
UNION_CLASS_BOILERPLATE(OmpTraitPropertyExtension);
struct Complex { // name (prop-ext, prop-ext, ...)
CharBlock source;
UNION_CLASS_BOILERPLATE(ExtensionValue);
std::variant<OmpTraitPropertyName, ScalarExpr,
common::Indirection<OmpTraitPropertyExtension>>
u;
TUPLE_CLASS_BOILERPLATE(Complex);
std::tuple<OmpTraitPropertyName,
std::list<common::Indirection<OmpTraitPropertyExtension>>>
t;
};
using ExtensionList = std::list<ExtensionValue>;
std::tuple<OmpTraitPropertyName, ExtensionList> t;

std::variant<OmpTraitPropertyName, ScalarExpr, Complex> u;
};

// trait-property ->
Expand Down Expand Up @@ -3568,9 +3561,10 @@ struct OmpTraitProperty {
// UID | T // unique-string-id /impl-defined
// VENDOR | I // name-list (vendor-id /add-def-doc)
// EXTENSION | I // name-list (ext_name /impl-defined)
// ATOMIC_DEFAULT_MEM_ORDER I | // value of admo
// ATOMIC_DEFAULT_MEM_ORDER I | // clause-list (value of admo)
// REQUIRES | I // clause-list (from requires)
// CONDITION U // logical-expr
// <other name> I // treated as extension
//
// Trait-set-selectors:
// [D]evice, [T]arget_device, [C]onstruct, [I]mplementation, [U]ser.
Expand All @@ -3579,7 +3573,7 @@ struct OmpTraitSelectorName {
UNION_CLASS_BOILERPLATE(OmpTraitSelectorName);
ENUM_CLASS(Value, Arch, Atomic_Default_Mem_Order, Condition, Device_Num,
Extension, Isa, Kind, Requires, Simd, Uid, Vendor)
std::variant<Value, llvm::omp::Directive> u;
std::variant<Value, llvm::omp::Directive, std::string> u;
};

// trait-selector ->
Expand Down Expand Up @@ -3978,6 +3972,7 @@ struct OmpBindClause {
// data-sharing-attribute ->
// SHARED | NONE | // since 4.5
// PRIVATE | FIRSTPRIVATE // since 5.0
// See also otherwise-clause.
struct OmpDefaultClause {
ENUM_CLASS(DataSharingAttribute, Private, Firstprivate, Shared, None)
WRAPPER_CLASS_BOILERPLATE(OmpDefaultClause, DataSharingAttribute);
Expand Down Expand Up @@ -4198,6 +4193,16 @@ struct OmpMapClause {
std::tuple<MODIFIERS(), OmpObjectList, /*CommaSeparated=*/bool> t;
};

// Ref: [5.0:58-60], [5.1:63-68], [5.2:194-195]
//
// match-clause ->
// MATCH (context-selector-specification) // since 5.0
struct OmpMatchClause {
// The context-selector is an argument.
WRAPPER_CLASS_BOILERPLATE(
OmpMatchClause, traits::OmpContextSelectorSpecification);
};

// Ref: [5.2:217-218]
// message-clause ->
// MESSAGE("message-text")
Expand Down Expand Up @@ -4228,6 +4233,17 @@ struct OmpOrderClause {
std::tuple<MODIFIERS(), Ordering> t;
};

// Ref: [5.0:56-57], [5.1:60-62], [5.2:191]
//
// otherwise-clause ->
// DEFAULT ([directive-specification]) // since 5.0, until 5.1
// otherwise-clause ->
// OTHERWISE ([directive-specification])] // since 5.2
struct OmpOtherwiseClause {
WRAPPER_CLASS_BOILERPLATE(
OmpOtherwiseClause, std::optional<OmpDirectiveSpecification>);
};

// Ref: [4.5:46-50], [5.0:74-78], [5.1:92-96], [5.2:229-230]
//
// proc-bind-clause ->
Expand Down Expand Up @@ -4313,6 +4329,17 @@ struct OmpUpdateClause {
std::variant<OmpDependenceType, OmpTaskDependenceType> u;
};

// Ref: [5.0:56-57], [5.1:60-62], [5.2:190-191]
//
// when-clause ->
// WHEN (context-selector :
// [directive-specification]) // since 5.0
struct OmpWhenClause {
TUPLE_CLASS_BOILERPLATE(OmpWhenClause);
MODIFIER_BOILERPLATE(OmpContextSelector);
std::tuple<MODIFIERS(), std::optional<OmpDirectiveSpecification>> t;
};

// OpenMP Clauses
struct OmpClause {
UNION_CLASS_BOILERPLATE(OmpClause);
Expand All @@ -4337,6 +4364,12 @@ struct OmpClauseList {

// --- Directives and constructs

struct OmpMetadirectiveDirective {
TUPLE_CLASS_BOILERPLATE(OmpMetadirectiveDirective);
std::tuple<OmpClauseList> t;
CharBlock source;
};

// Ref: [5.1:89-90], [5.2:216]
//
// nothing-directive ->
Expand Down Expand Up @@ -4710,7 +4743,7 @@ struct OpenMPStandaloneConstruct {
CharBlock source;
std::variant<OpenMPSimpleStandaloneConstruct, OpenMPFlushConstruct,
OpenMPCancelConstruct, OpenMPCancellationPointConstruct,
OpenMPDepobjConstruct>
OpenMPDepobjConstruct, OmpMetadirectiveDirective>
u;
};

Expand Down
21 changes: 17 additions & 4 deletions flang/lib/Lower/OpenMP/Clauses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ MAKE_EMPTY_CLASS(Threadprivate, Threadprivate);

MAKE_INCOMPLETE_CLASS(AdjustArgs, AdjustArgs);
MAKE_INCOMPLETE_CLASS(AppendArgs, AppendArgs);
MAKE_INCOMPLETE_CLASS(Match, Match);
// MAKE_INCOMPLETE_CLASS(Match, Match);
// MAKE_INCOMPLETE_CLASS(Otherwise, ); // missing-in-parser
MAKE_INCOMPLETE_CLASS(When, When);
// MAKE_INCOMPLETE_CLASS(When, When);

List<IteratorSpecifier>
makeIteratorSpecifiers(const parser::OmpIteratorSpecifier &inp,
Expand Down Expand Up @@ -997,7 +997,11 @@ Map make(const parser::OmpClause::Map &inp,
/*LocatorList=*/makeObjects(t4, semaCtx)}};
}

// Match: incomplete
Match make(const parser::OmpClause::Match &inp,
semantics::SemanticsContext &semaCtx) {
return Match{};
}

// MemoryOrder: empty
// Mergeable: empty

Expand Down Expand Up @@ -1102,6 +1106,10 @@ Ordered make(const parser::OmpClause::Ordered &inp,
}

// Otherwise: incomplete, missing-in-parser
Otherwise make(const parser::OmpClause::Otherwise &inp,
semantics::SemanticsContext &semaCtx) {
return Otherwise{};
}

Partial make(const parser::OmpClause::Partial &inp,
semantics::SemanticsContext &semaCtx) {
Expand Down Expand Up @@ -1356,7 +1364,12 @@ UsesAllocators make(const parser::OmpClause::UsesAllocators &inp,
}

// Weak: empty
// When: incomplete

When make(const parser::OmpClause::When &inp,
semantics::SemanticsContext &semaCtx) {
return When{};
}

// Write: empty
} // namespace clause

Expand Down
1 change: 1 addition & 0 deletions flang/lib/Lower/OpenMP/Clauses.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ using OmpxBare = tomp::clause::OmpxBareT<TypeTy, IdTy, ExprTy>;
using OmpxDynCgroupMem = tomp::clause::OmpxDynCgroupMemT<TypeTy, IdTy, ExprTy>;
using Ordered = tomp::clause::OrderedT<TypeTy, IdTy, ExprTy>;
using Order = tomp::clause::OrderT<TypeTy, IdTy, ExprTy>;
using Otherwise = tomp::clause::OtherwiseT<TypeTy, IdTy, ExprTy>;
using Partial = tomp::clause::PartialT<TypeTy, IdTy, ExprTy>;
using Priority = tomp::clause::PriorityT<TypeTy, IdTy, ExprTy>;
using Private = tomp::clause::PrivateT<TypeTy, IdTy, ExprTy>;
Expand Down
5 changes: 5 additions & 0 deletions flang/lib/Lower/OpenMP/OpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,11 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
TODO(converter.getCurrentLocation(), "OpenMPDepobjConstruct");
}

static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx,
lower::pft::Evaluation &eval,
const parser::OmpMetadirectiveDirective &construct) {}

static void
genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
semantics::SemanticsContext &semaCtx, lower::pft::Evaluation &eval,
Expand Down
Loading
Loading