[flang-commits] [flang] e355f85 - [flang] Add parser support for OpenMP allocate clause
Andrzej Warzynski via flang-commits
flang-commits at lists.llvm.org
Thu Aug 6 02:45:48 PDT 2020
Author: Irina Dobrescu
Date: 2020-08-06T10:45:34+01:00
New Revision: e355f85bdf9e36a0f17428b281b7879051ed2867
URL: https://github.com/llvm/llvm-project/commit/e355f85bdf9e36a0f17428b281b7879051ed2867
DIFF: https://github.com/llvm/llvm-project/commit/e355f85bdf9e36a0f17428b281b7879051ed2867.diff
LOG: [flang] Add parser support for OpenMP allocate clause
Differential Revision: https://reviews.llvm.org/D85212
Added:
Modified:
flang/include/flang/Parser/dump-parse-tree.h
flang/include/flang/Parser/parse-tree.h
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/test/Semantics/omp-clause-validity01.f90
Removed:
################################################################################
diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h
index 02da3f53b44e..e3986b754f83 100644
--- a/flang/include/flang/Parser/dump-parse-tree.h
+++ b/flang/include/flang/Parser/dump-parse-tree.h
@@ -582,6 +582,8 @@ class ParseTreeDumper {
NODE(OmpReductionCombiner, FunctionCombiner)
NODE(parser, OmpReductionInitializerClause)
NODE(parser, OmpReductionOperator)
+ NODE(parser, OmpAllocateClause)
+ NODE(OmpAllocateClause, Allocator)
NODE(parser, OmpScheduleClause)
NODE_ENUM(OmpScheduleClause, ScheduleType)
NODE(parser, OmpScheduleModifier)
diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h
index 4b34d2cd674c..c0a1a385801b 100644
--- a/flang/include/flang/Parser/parse-tree.h
+++ b/flang/include/flang/Parser/parse-tree.h
@@ -3415,6 +3415,13 @@ struct OmpReductionClause {
std::tuple<OmpReductionOperator, std::list<Designator>> t;
};
+// OMP 5.0 2.11.4 allocate-clause -> ALLOCATE ([allocator:] variable-name-list)
+struct OmpAllocateClause {
+ TUPLE_CLASS_BOILERPLATE(OmpAllocateClause);
+ WRAPPER_CLASS(Allocator, ScalarIntExpr);
+ std::tuple<std::optional<Allocator>, OmpObjectList> t;
+};
+
// 2.13.9 depend-vec-length -> +/- non-negative-constant
struct OmpDependSinkVecLength {
TUPLE_CLASS_BOILERPLATE(OmpDependSinkVecLength);
@@ -3490,9 +3497,9 @@ struct OmpClause {
Firstprivate, From, Grainsize, Lastprivate, NumTasks, NumTeams,
NumThreads, Ordered, Priority, Private, Safelen, Shared, Simdlen,
ThreadLimit, To, Link, Uniform, UseDevicePtr, IsDevicePtr,
- OmpAlignedClause, OmpDefaultClause, OmpDefaultmapClause, OmpDependClause,
- OmpIfClause, OmpLinearClause, OmpMapClause, OmpProcBindClause,
- OmpReductionClause, OmpScheduleClause>
+ OmpAlignedClause, OmpAllocateClause, OmpDefaultClause,
+ OmpDefaultmapClause, OmpDependClause, OmpIfClause, OmpLinearClause,
+ OmpMapClause, OmpProcBindClause, OmpReductionClause, OmpScheduleClause>
u;
};
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index a09a5554116f..2f0765617077 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -104,6 +104,11 @@ TYPE_PARSER(construct<OmpReductionOperator>(Parser<DefinedOperator>{}) ||
TYPE_PARSER(construct<OmpReductionClause>(
Parser<OmpReductionOperator>{} / ":", nonemptyList(designator)))
+// OMP 5.0 2.11.4 ALLOCATE ([allocator:] variable-name-list)
+TYPE_PARSER(construct<OmpAllocateClause>(
+ maybe(construct<OmpAllocateClause::Allocator>(scalarIntExpr) / ":"),
+ Parser<OmpObjectList>{}))
+
// 2.13.9 DEPEND (SOURCE | SINK : vec | (IN | OUT | INOUT) : list
TYPE_PARSER(construct<OmpDependSinkVecLength>(
Parser<DefinedOperator>{}, scalarIntConstantExpr))
@@ -206,6 +211,8 @@ TYPE_PARSER("ALIGNED" >>
construct<OmpClause>(parenthesized(Parser<OmpProcBindClause>{})) ||
"REDUCTION" >>
construct<OmpClause>(parenthesized(Parser<OmpReductionClause>{})) ||
+ "ALLOCATE" >>
+ construct<OmpClause>(parenthesized(Parser<OmpAllocateClause>{})) ||
"SAFELEN" >> construct<OmpClause>(construct<OmpClause::Safelen>(
parenthesized(scalarIntConstantExpr))) ||
"SCHEDULE" >>
diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 3b95636fc3e5..ab18d026e74e 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2207,6 +2207,12 @@ class UnparseVisitor {
Walk(std::get<std::list<Designator>>(x.t), ",");
Put(")");
}
+ void Unparse(const OmpAllocateClause &x) {
+ Word("ALLOCATE(");
+ Walk(std::get<std::optional<OmpAllocateClause::Allocator>>(x.t), ":");
+ Walk(std::get<OmpObjectList>(x.t));
+ Put(")");
+ }
void Unparse(const OmpDependSinkVecLength &x) {
Walk(std::get<DefinedOperator>(x.t));
Walk(std::get<ScalarIntConstantExpr>(x.t));
diff --git a/flang/test/Semantics/omp-clause-validity01.f90 b/flang/test/Semantics/omp-clause-validity01.f90
index d1889979527b..d3f77a432de8 100644
--- a/flang/test/Semantics/omp-clause-validity01.f90
+++ b/flang/test/Semantics/omp-clause-validity01.f90
@@ -1,5 +1,5 @@
! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
-
+use omp_lib
! Check OpenMP clause validity for the following directives:
!
! 2.5 PARALLEL construct
@@ -13,6 +13,11 @@
integer, parameter :: num = 16
real(8) :: arrayA(256), arrayB(512)
+ integer(omp_memspace_handle_kind) :: xy_memspace = omp_default_mem_space
+ type(omp_alloctrait) :: xy_traits(1) = [omp_alloctrait(omp_atk_alignment,64)]
+ integer(omp_allocator_handle_kind) :: xy_alloc
+ xy_alloc = omp_init_allocator(xy_memspace, 1, xy_traits)
+
arrayA = 1.414
arrayB = 3.14
N = 1024
@@ -25,7 +30,8 @@
! shared-clause |
! copyin-clause |
! reduction-clause |
-! proc-bind-clause
+! proc-bind-clause |
+! allocate-clause
!$omp parallel
do i = 1, N
@@ -33,6 +39,30 @@
enddo
!$omp end parallel
+ !$omp parallel allocate(b)
+ do i = 1, N
+ a = 3.14
+ enddo
+ !$omp end parallel
+
+ !$omp parallel allocate(omp_default_mem_space : b, c)
+ do i = 1, N
+ a = 3.14
+ enddo
+ !$omp end parallel
+
+ !$omp parallel allocate(b) allocate(c)
+ do i = 1, N
+ a = 3.14
+ enddo
+ !$omp end parallel
+
+ !$omp parallel allocate(xy_alloc :b)
+ do i = 1, N
+ a = 3.14
+ enddo
+ !$omp end parallel
+
!ERROR: SCHEDULE clause is not allowed on the PARALLEL directive
!$omp parallel schedule(static)
do i = 1, N
More information about the flang-commits
mailing list