aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Parser
diff options
context:
space:
mode:
Diffstat (limited to 'flang/lib/Parser')
-rw-r--r--flang/lib/Parser/openmp-parsers.cpp44
-rw-r--r--flang/lib/Parser/openmp-utils.cpp39
-rw-r--r--flang/lib/Parser/unparse.cpp28
3 files changed, 69 insertions, 42 deletions
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index 4159d2e..4374acb 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -1778,6 +1778,31 @@ private:
llvm::omp::Directive dir_;
};
+struct OmpDeclarativeAllocateParser {
+ using resultType = OmpAllocateDirective;
+
+ std::optional<resultType> Parse(ParseState &state) const {
+ constexpr llvm::omp::Directive dir{llvm::omp::Directive::OMPD_allocate};
+ if (auto &&begin{attempt(OmpBeginDirectiveParser(dir)).Parse(state)}) {
+ Block empty;
+ auto end{maybe(OmpEndDirectiveParser{dir}).Parse(state)};
+ return OmpAllocateDirective{std::move(*begin), std::move(empty),
+ llvm::transformOptional(std::move(*end),
+ [](auto &&s) { return OmpEndDirective(std::move(s)); })};
+ }
+ return std::nullopt;
+ }
+};
+
+struct OmpExecutableAllocateParser {
+ using resultType = OmpAllocateDirective;
+
+ std::optional<resultType> Parse(ParseState &state) const {
+ OmpStatementConstructParser p{llvm::omp::Directive::OMPD_allocate};
+ return construct<OmpAllocateDirective>(p).Parse(state);
+ }
+};
+
TYPE_PARSER(sourced(construct<OpenMPAllocatorsConstruct>(
OmpStatementConstructParser{llvm::omp::Directive::OMPD_allocators})))
@@ -2044,13 +2069,6 @@ TYPE_PARSER(construct<OmpInitializerExpression>(OmpStylizedExpressionParser{}))
TYPE_PARSER(sourced(construct<OpenMPCriticalConstruct>(
OmpBlockConstructParser{llvm::omp::Directive::OMPD_critical})))
-// 2.11.3 Executable Allocate directive
-TYPE_PARSER(
- sourced(construct<OpenMPExecutableAllocate>(verbatim("ALLOCATE"_tok),
- maybe(parenthesized(Parser<OmpObjectList>{})), Parser<OmpClauseList>{},
- maybe(nonemptyList(Parser<OpenMPDeclarativeAllocate>{})) / endOmpLine,
- statement(allocateStmt))))
-
// 2.8.2 Declare Simd construct
TYPE_PARSER(sourced(construct<OpenMPDeclareSimdConstruct>(
predicated(Parser<OmpDirectiveName>{},
@@ -2076,12 +2094,6 @@ TYPE_PARSER(sourced( //
IsDirective(llvm::omp::Directive::OMPD_threadprivate)) >=
Parser<OmpDirectiveSpecification>{})))
-// 2.11.3 Declarative Allocate directive
-TYPE_PARSER(
- sourced(construct<OpenMPDeclarativeAllocate>(verbatim("ALLOCATE"_tok),
- parenthesized(Parser<OmpObjectList>{}), Parser<OmpClauseList>{})) /
- lookAhead(endOmpLine / !statement(allocateStmt)))
-
// Assumes Construct
TYPE_PARSER(sourced(construct<OpenMPDeclarativeAssumes>(
predicated(OmpDirectiveNameParser{},
@@ -2104,7 +2116,7 @@ TYPE_PARSER(
construct<OpenMPDeclarativeConstruct>(
Parser<OmpDeclareVariantDirective>{}) ||
construct<OpenMPDeclarativeConstruct>(
- Parser<OpenMPDeclarativeAllocate>{}) ||
+ sourced(OmpDeclarativeAllocateParser{})) ||
construct<OpenMPDeclarativeConstruct>(
Parser<OpenMPGroupprivate>{}) ||
construct<OpenMPDeclarativeConstruct>(
@@ -2192,6 +2204,8 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
withMessage("expected OpenMP construct"_err_en_US,
first(construct<OpenMPConstruct>(Parser<OpenMPSectionsConstruct>{}),
construct<OpenMPConstruct>(Parser<OpenMPLoopConstruct>{}),
+ construct<OpenMPConstruct>(
+ sourced(OmpExecutableAllocateParser{})),
construct<OpenMPConstruct>(Parser<OmpBlockConstruct>{}),
// OmpBlockConstruct is attempted before
// OpenMPStandaloneConstruct to resolve !$OMP ORDERED
@@ -2199,9 +2213,7 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
construct<OpenMPConstruct>(Parser<OpenMPAtomicConstruct>{}),
construct<OpenMPConstruct>(Parser<OpenMPUtilityConstruct>{}),
construct<OpenMPConstruct>(Parser<OpenMPDispatchConstruct>{}),
- construct<OpenMPConstruct>(Parser<OpenMPExecutableAllocate>{}),
construct<OpenMPConstruct>(Parser<OpenMPAllocatorsConstruct>{}),
- construct<OpenMPConstruct>(Parser<OpenMPDeclarativeAllocate>{}),
construct<OpenMPConstruct>(Parser<OpenMPAssumeConstruct>{}),
construct<OpenMPConstruct>(Parser<OpenMPCriticalConstruct>{}))))
diff --git a/flang/lib/Parser/openmp-utils.cpp b/flang/lib/Parser/openmp-utils.cpp
index 95ad3f6..b9d3763c 100644
--- a/flang/lib/Parser/openmp-utils.cpp
+++ b/flang/lib/Parser/openmp-utils.cpp
@@ -22,6 +22,25 @@
namespace Fortran::parser::omp {
+const OpenMPDeclarativeConstruct *GetOmp(const DeclarationConstruct &x) {
+ if (auto *y = std::get_if<SpecificationConstruct>(&x.u)) {
+ if (auto *z{std::get_if<common::Indirection<OpenMPDeclarativeConstruct>>(
+ &y->u)}) {
+ return &z->value();
+ }
+ }
+ return nullptr;
+}
+
+const OpenMPConstruct *GetOmp(const ExecutionPartConstruct &x) {
+ if (auto *y{std::get_if<ExecutableConstruct>(&x.u)}) {
+ if (auto *z{std::get_if<common::Indirection<OpenMPConstruct>>(&y->u)}) {
+ return &z->value();
+ }
+ }
+ return nullptr;
+}
+
const OmpObjectList *GetOmpObjectList(const OmpClause &clause) {
// Clauses with OmpObjectList as its data member
using MemberObjectListClauses = std::tuple<OmpClause::Copyin,
@@ -86,4 +105,24 @@ const OmpInitializerExpression *GetInitializerExpr(const OmpClause &init) {
return nullptr;
}
+static void SplitOmpAllocateHelper(
+ OmpAllocateInfo &n, const OmpAllocateDirective &x) {
+ n.dirs.push_back(&x);
+ const Block &body{std::get<Block>(x.t)};
+ if (!body.empty()) {
+ if (auto *omp{GetOmp(body.front())}) {
+ if (auto *ad{std::get_if<OmpAllocateDirective>(&omp->u)}) {
+ return SplitOmpAllocateHelper(n, *ad);
+ }
+ }
+ n.body = &body.front();
+ }
+}
+
+OmpAllocateInfo SplitOmpAllocate(const OmpAllocateDirective &x) {
+ OmpAllocateInfo info;
+ SplitOmpAllocateHelper(info, x);
+ return info;
+}
+
} // namespace Fortran::parser::omp
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 9b38cfc..8412303 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2482,32 +2482,8 @@ public:
Unparse(static_cast<const OmpBlockConstruct &>(x));
}
- void Unparse(const OpenMPExecutableAllocate &x) {
- const auto &fields =
- std::get<std::optional<std::list<parser::OpenMPDeclarativeAllocate>>>(
- x.t);
- if (fields) {
- for (const auto &decl : *fields) {
- Walk(decl);
- }
- }
- BeginOpenMP();
- Word("!$OMP ALLOCATE");
- Walk(" (", std::get<std::optional<OmpObjectList>>(x.t), ")");
- Walk(std::get<OmpClauseList>(x.t));
- Put("\n");
- EndOpenMP();
- Walk(std::get<Statement<AllocateStmt>>(x.t));
- }
- void Unparse(const OpenMPDeclarativeAllocate &x) {
- BeginOpenMP();
- Word("!$OMP ALLOCATE");
- Put(" (");
- Walk(std::get<OmpObjectList>(x.t));
- Put(")");
- Walk(std::get<OmpClauseList>(x.t));
- Put("\n");
- EndOpenMP();
+ void Unparse(const OmpAllocateDirective &x) {
+ Unparse(static_cast<const OmpBlockConstruct &>(x));
}
void Unparse(const OpenMPAllocatorsConstruct &x) {
Unparse(static_cast<const OmpBlockConstruct &>(x));