[flang] Complete source provenance on OMP constructs (except ATOMIC)

Original-commit: flang-compiler/f18@8f6e93d579
Reviewed-on: https://github.com/flang-compiler/f18/pull/569
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2019-07-12 16:16:40 -07:00
parent 521a9770af
commit 5557fff6e8
4 changed files with 48 additions and 34 deletions

View file

@ -1,5 +1,5 @@
<!--
Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
-->
## Concept

View file

@ -675,6 +675,7 @@ public:
NODE(parser, Value)
NODE(parser, ValueStmt)
NODE(parser, Variable)
NODE(parser, Verbatim)
NODE(parser, Volatile)
NODE(parser, VolatileStmt)
NODE(parser, WaitSpec)

View file

@ -46,6 +46,10 @@ template<typename A> constexpr decltype(auto) OmpConstructDirective(A keyword) {
return sourced(keyword >> Parser<OmpClauseList>{}) / endOmpLine;
}
template<typename A> constexpr decltype(auto) verbatim(A x) {
return sourced(construct<Verbatim>(x));
}
// OpenMP Clauses
// DEFAULT (PRIVATE | FIRSTPRIVATE | SHARED | NONE )
TYPE_PARSER(construct<OmpDefaultClause>(
@ -290,26 +294,24 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
pure(OmpLoopDirective::Directive::TeamsDistributeSimd),
"TEAMS DISTRIBUTE" >> pure(OmpLoopDirective::Directive::TeamsDistribute)))))
TYPE_PARSER(sourced(construct<OmpCancelType>(
first("PARALLEL" >> pure(OmpCancelType::Type::Parallel),
"SECTIONS" >> pure(OmpCancelType::Type::Sections),
"DO" >> pure(OmpCancelType::Type::Do),
"TASKGROUP" >> pure(OmpCancelType::Type::Taskgroup)))))
// Cancellation Point construct
TYPE_PARSER("CANCELLATION POINT" >>
construct<OpenMPCancellationPointConstruct>(
"PARALLEL" >> pure(OmpCancelType::Type::Parallel) ||
"SECTIONS" >> pure(OmpCancelType::Type::Sections) ||
"DO" >> pure(OmpCancelType::Type::Do) ||
"TASKGROUP" >> pure(OmpCancelType::Type::Taskgroup)))
TYPE_PARSER(construct<OpenMPCancellationPointConstruct>(
sourced("CANCELLATION POINT" >> Parser<OmpCancelType>{})))
// Cancel construct
TYPE_PARSER(
"CANCEL" >> construct<OpenMPCancelConstruct>(
("PARALLEL" >> pure(OmpCancelType::Type::Parallel) ||
"SECTIONS" >> pure(OmpCancelType::Type::Sections) ||
"DO" >> pure(OmpCancelType::Type::Do) ||
"TASKGROUP" >> pure(OmpCancelType::Type::Taskgroup)),
maybe("IF" >> parenthesized(scalarLogicalExpr))))
TYPE_PARSER(construct<OpenMPCancelConstruct>(
sourced("CANCEL" >> Parser<OmpCancelType>{}),
maybe("IF" >> parenthesized(scalarLogicalExpr))))
// Flush construct
TYPE_PARSER("FLUSH" >> construct<OpenMPFlushConstruct>(
maybe(parenthesized(Parser<OmpObjectList>{}))))
TYPE_PARSER(sourced(construct<OpenMPFlushConstruct>(
"FLUSH" >> maybe(parenthesized(Parser<OmpObjectList>{})))))
// Standalone directives
TYPE_PARSER(sourced(construct<OmpStandaloneDirective>(first(
@ -472,13 +474,11 @@ TYPE_PARSER("SINGLE" >>
construct<OpenMPSingleConstruct>(
OmpConstructDirective("SINGLE"_tok), block, Parser<OmpEndSingle>{}))
TYPE_PARSER(startOmpLine >> "END"_tok >>
construct<OmpEndWorkshare>("WORKSHARE"_tok) / endOmpLine)
// OMP WORKSHARE
TYPE_PARSER("WORKSHARE" >>
construct<OpenMPWorkshareConstruct>(endOmpLine >> block,
Parser<OmpEndWorkshare>{} >> maybe(construct<OmpNowait>("NOWAIT"_tok))))
TYPE_PARSER(construct<OpenMPWorkshareConstruct>(
verbatim("WORKSHARE"_tok) / endOmpLine, block,
startOmpLine >> "END WORKSHARE"_tok >>
maybe(construct<OmpNowait>("NOWAIT"_tok) / endOmpLine)))
// OMP END DO SIMD [NOWAIT]
TYPE_PARSER(construct<OmpEndDoSimd>(maybe(construct<OmpNowait>("NOWAIT"_tok))))
@ -505,6 +505,8 @@ TYPE_PARSER(construct<OpenMPParallelSectionsConstruct>(
OmpConstructDirective("PARALLEL SECTIONS"_tok), block,
Parser<OmpEndParallelSections>{}))
TYPE_PARSER(construct<OmpSection>(verbatim("SECTION"_tok) / endOmpLine))
TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
startOmpLine >>
first(construct<OpenMPConstruct>(Parser<OpenMPStandaloneConstruct>{}),
@ -522,8 +524,7 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
construct<OpenMPConstruct>(
Parser<OpenMPCancellationPointConstruct>{}),
construct<OpenMPConstruct>(Parser<OpenMPFlushConstruct>{}),
"SECTION" >> endOmpLine >>
construct<OpenMPConstruct>(construct<OmpSection>())))
construct<OpenMPConstruct>(Parser<OmpSection>{})))
// END OMP Block directives
TYPE_PARSER(startOmpLine >> "END"_tok >>

View file

@ -88,14 +88,17 @@ struct GenericExprWrapper; // forward definition, wraps Expr<SomeType>
// Empty classes are often used below as alternatives in std::variant<>
// discriminated unions.
#define EMPTY_CLASS_BOILERPLATE(classname) \
classname() {} \
classname(const classname &) {} \
classname(classname &&) {} \
classname &operator=(const classname &) { return *this; }; \
classname &operator=(classname &&) { return *this; }; \
using EmptyTrait = std::true_type
#define EMPTY_CLASS(classname) \
struct classname { \
classname() {} \
classname(const classname &) {} \
classname(classname &&) {} \
classname &operator=(const classname &) { return *this; }; \
classname &operator=(classname &&) { return *this; }; \
using EmptyTrait = std::true_type; \
EMPTY_CLASS_BOILERPLATE(classname); \
}
// Many classes below simply wrap a std::variant<> discriminated union,
@ -266,6 +269,12 @@ struct OpenMPEndLoopDirective;
// Cooked character stream locations
using Location = const char *;
// A parse tree node with provenance only
struct Verbatim {
EMPTY_CLASS_BOILERPLATE(Verbatim);
CharBlock source;
};
// Implicit definitions of the Standard
// R403 scalar-xyz -> xyz
@ -3464,7 +3473,7 @@ struct OmpClauseList {
// SECTIONS, PARALLEL SECTIONS
WRAPPER_CLASS(OmpEndSections, std::optional<OmpNowait>);
WRAPPER_CLASS(OmpEndParallelSections, std::optional<OmpNowait>);
EMPTY_CLASS(OmpSection);
WRAPPER_CLASS(OmpSection, Verbatim);
struct OpenMPSectionsConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPSectionsConstruct);
@ -3477,10 +3486,9 @@ struct OpenMPParallelSectionsConstruct {
};
// WORKSHARE
EMPTY_CLASS(OmpEndWorkshare);
struct OpenMPWorkshareConstruct {
TUPLE_CLASS_BOILERPLATE(OpenMPWorkshareConstruct);
std::tuple<Block, std::optional<OmpNowait>> t;
std::tuple<Verbatim, Block, std::optional<OmpNowait>> t;
};
// SINGLE
@ -3642,6 +3650,7 @@ struct OmpLoopDirective {
struct OmpCancelType {
ENUM_CLASS(Type, Parallel, Sections, Do, Taskgroup)
WRAPPER_CLASS_BOILERPLATE(OmpCancelType, Type);
CharBlock source;
};
// CANCELLATION POINT
@ -3655,7 +3664,10 @@ struct OpenMPCancelConstruct {
};
// FLUSH
WRAPPER_CLASS(OpenMPFlushConstruct, std::optional<OmpObjectList>);
struct OpenMPFlushConstruct {
WRAPPER_CLASS_BOILERPLATE(OpenMPFlushConstruct, std::optional<OmpObjectList>);
CharBlock source;
};
// These simple constructs do not have clauses.
struct OpenMPSimpleConstruct {