diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h --- a/flang/include/flang/Parser/dump-parse-tree.h +++ b/flang/include/flang/Parser/dump-parse-tree.h @@ -549,6 +549,7 @@ NODE(parser, OpenMPCancellationPointConstruct) NODE(parser, OpenMPConstruct) NODE(parser, OpenMPCriticalConstruct) + NODE(parser, OpenMPDeclarativeAllocate) NODE(parser, OpenMPDeclarativeConstruct) NODE(parser, OpenMPDeclareReductionConstruct) NODE(parser, OpenMPDeclareSimdConstruct) @@ -556,6 +557,7 @@ NODE(parser, OmpFlushMemoryClause) NODE(parser, OpenMPFlushConstruct) NODE(parser, OpenMPLoopConstruct) + NODE(parser, OpenMPExecutableAllocate) NODE(parser, OpenMPSimpleStandaloneConstruct) NODE(parser, OpenMPStandaloneConstruct) NODE(parser, OpenMPSectionsConstruct) diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -3583,11 +3583,19 @@ std::tuple t; }; +// 2.11.3 allocate -> ALLOCATE (variable-name-list) [clause] +struct OpenMPDeclarativeAllocate { + TUPLE_CLASS_BOILERPLATE(OpenMPDeclarativeAllocate); + CharBlock source; + std::tuple t; +}; + struct OpenMPDeclarativeConstruct { UNION_CLASS_BOILERPLATE(OpenMPDeclarativeConstruct); CharBlock source; - std::variant + std::variant u; }; @@ -3610,6 +3618,14 @@ std::tuple t; }; +// 2.11.3 allocate -> ALLOCATE (variable-name-list) [clause] allocate-statement +// clause -> allocator-clause +struct OpenMPExecutableAllocate { + TUPLE_CLASS_BOILERPLATE(OpenMPExecutableAllocate); + CharBlock source; + std::tuple> t; +}; + // 2.17.7 atomic -> ATOMIC [clause[,]] atomic-clause [[,]clause] | // ATOMIC [clause] // clause -> memory-order-clause | HINT(hint-expression) @@ -3796,7 +3812,7 @@ UNION_CLASS_BOILERPLATE(OpenMPConstruct); std::variant + OpenMPExecutableAllocate, OpenMPCriticalConstruct> u; }; diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp --- a/flang/lib/Lower/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP.cpp @@ -138,6 +138,8 @@ [&](const Fortran::parser::OpenMPLoopConstruct &loopConstruct) { TODO(); }, + [&](const Fortran::parser::OpenMPExecutableAllocate + &execAllocConstruct) { TODO(); }, [&](const Fortran::parser::OpenMPBlockConstruct &blockConstruct) { genOMP(converter, eval, blockConstruct); }, diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -473,6 +473,12 @@ TYPE_PARSER(construct( Parser{}, block, Parser{})) +// 2.11.3 Executable Allocate directive +TYPE_PARSER( + sourced(construct(verbatim("ALLOCATE"_tok), + parenthesized(Parser{}) / endOmpLine, + statement(allocateStmt)))) + // 2.8.2 Declare Simd construct TYPE_PARSER( sourced(construct(verbatim("DECLARE SIMD"_tok), @@ -482,6 +488,12 @@ TYPE_PARSER(sourced(construct( verbatim("THREADPRIVATE"_tok), parenthesized(Parser{})))) +// 2.11.3 Declarative Allocate directive +TYPE_PARSER( + sourced(construct( + verbatim("ALLOCATE"_tok), parenthesized(Parser{}))) / + lookAhead(endOmpLine / !statement(allocateStmt))) + // Declarative constructs TYPE_PARSER(startOmpLine >> sourced(construct( @@ -490,6 +502,8 @@ Parser{}) || construct( Parser{}) || + construct( + Parser{}) || construct(Parser{})) / endOmpLine) @@ -530,6 +544,7 @@ // OpenMPStandaloneConstruct to resolve !$OMP ORDERED construct(Parser{}), construct(Parser{}), + construct(Parser{}), construct(Parser{}))) // END OMP Block directives diff --git a/flang/lib/Parser/type-parsers.h b/flang/lib/Parser/type-parsers.h --- a/flang/lib/Parser/type-parsers.h +++ b/flang/lib/Parser/type-parsers.h @@ -91,6 +91,7 @@ constexpr Parser expr; // R1022 constexpr Parser specificationExpr; // R1028 constexpr Parser assignmentStmt; // R1032 +constexpr Parser allocateStmt; constexpr Parser pointerAssignmentStmt; // R1033 constexpr Parser whereStmt; // R1041, R1045, R1046 constexpr Parser whereConstruct; // R1042 diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -2313,6 +2313,14 @@ Walk(std::get>(x.t), "!$OMP END ATOMIC\n"); EndOpenMP(); } + void Unparse(const OpenMPExecutableAllocate &x) { + BeginOpenMP(); + Word("!$OMP ALLOCATE ("); + Walk(std::get(x.t)); + Put(")\n"); + EndOpenMP(); + Walk(std::get>(x.t)); + } void Unparse(const OmpCriticalDirective &x) { BeginOpenMP(); Word("!$OMP CRITICAL"); @@ -2365,6 +2373,10 @@ BeginOpenMP(); Word("!$OMP "); return std::visit(common::visitors{ + [&](const OpenMPDeclarativeAllocate &) { + Word("ALLOCATE ("); + return true; + }, [&](const OpenMPDeclareReductionConstruct &) { Word("DECLARE REDUCTION "); return true; @@ -2392,6 +2404,10 @@ Put("\n"); EndOpenMP(); } + void Post(const OpenMPDeclarativeAllocate &) { + Put(")\n"); + EndOpenMP(); + } void Post(const OpenMPThreadprivate &) { Put(")\n"); EndOpenMP(); diff --git a/flang/test/Semantics/omp-declarative-directive.f90 b/flang/test/Semantics/omp-declarative-directive.f90 --- a/flang/test/Semantics/omp-declarative-directive.f90 +++ b/flang/test/Semantics/omp-declarative-directive.f90 @@ -41,6 +41,7 @@ end subroutine sub1 ! 2.10.6 declare-target +! 2.11.3 declarative allocate ! 2.15.2 threadprivate module m2 @@ -54,6 +55,7 @@ integer, parameter :: N=10000, M=1024 integer :: i real :: Q(N, N), R(N,M), S(M,M) + !$omp allocate(i) !$omp threadprivate(i) end subroutine foo end module m2