From e72f5738488766e61dec55d4bd93bb542825eca5 Mon Sep 17 00:00:00 2001 From: Dossay Oryspayev Date: Tue, 31 May 2022 22:39:59 +0530 Subject: [PATCH] [flang][OpenMP] Added parser support for defaultmap (OpenMP 5.0) This patch adds parser support for defaultmap clause [OpenMP 5.0]. Reviewed By: kiranchandramohan, peixin, shraiysh Differential Revision: https://reviews.llvm.org/D124190 --- flang/include/flang/Parser/parse-tree.h | 6 +- flang/lib/Parser/openmp-parsers.cpp | 26 ++++- flang/test/Parser/omp-defaultmap-unparse.f90 | 144 +++++++++++++++++++++++++++ 3 files changed, 169 insertions(+), 7 deletions(-) create mode 100644 flang/test/Parser/omp-defaultmap-unparse.f90 diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 23c572c..4824e4a 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -3346,8 +3346,9 @@ struct OmpMapClause { // 2.15.5.2 defaultmap -> DEFAULTMAP (implicit-behavior[:variable-category]) struct OmpDefaultmapClause { TUPLE_CLASS_BOILERPLATE(OmpDefaultmapClause); - ENUM_CLASS(ImplicitBehavior, Tofrom) - ENUM_CLASS(VariableCategory, Scalar) + ENUM_CLASS( + ImplicitBehavior, Alloc, To, From, Tofrom, Firstprivate, None, Default) + ENUM_CLASS(VariableCategory, Scalar, Aggregate, Allocatable, Pointer) std::tuple> t; }; @@ -3754,7 +3755,6 @@ struct OpenMPCancelConstruct { std::tuple> t; }; - // 2.17.8 flush -> FLUSH [memory-order-clause] [(variable-name-list)] struct OpenMPFlushConstruct { TUPLE_CLASS_BOILERPLATE(OpenMPFlushConstruct); diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index 9a4f4bb..8d298f0 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -52,12 +52,30 @@ TYPE_PARSER(construct( TYPE_PARSER(construct( maybe(Parser{}), Parser{})) -// 2.15.5.2 defaultmap -> DEFAULTMAP (TOFROM:SCALAR) +// [OpenMP 5.0] +// 2.19.7.2 defaultmap(implicit-behavior[:variable-category]) +// implicit-behavior -> ALLOC | TO | FROM | TOFROM | FIRSRTPRIVATE | NONE | +// DEFAULT +// variable-category -> SCALAR | AGGREGATE | ALLOCATABLE | POINTER TYPE_PARSER(construct( construct( - "TOFROM" >> pure(OmpDefaultmapClause::ImplicitBehavior::Tofrom)), - maybe(":" >> construct("SCALAR" >> - pure(OmpDefaultmapClause::VariableCategory::Scalar))))) + "ALLOC" >> pure(OmpDefaultmapClause::ImplicitBehavior::Alloc) || + "TO"_id >> pure(OmpDefaultmapClause::ImplicitBehavior::To) || + "FROM" >> pure(OmpDefaultmapClause::ImplicitBehavior::From) || + "TOFROM" >> pure(OmpDefaultmapClause::ImplicitBehavior::Tofrom) || + "FIRSTPRIVATE" >> + pure(OmpDefaultmapClause::ImplicitBehavior::Firstprivate) || + "NONE" >> pure(OmpDefaultmapClause::ImplicitBehavior::None) || + "DEFAULT" >> pure(OmpDefaultmapClause::ImplicitBehavior::Default)), + maybe(":" >> + construct( + "SCALAR" >> pure(OmpDefaultmapClause::VariableCategory::Scalar) || + "AGGREGATE" >> + pure(OmpDefaultmapClause::VariableCategory::Aggregate) || + "ALLOCATABLE" >> + pure(OmpDefaultmapClause::VariableCategory::Allocatable) || + "POINTER" >> + pure(OmpDefaultmapClause::VariableCategory::Pointer))))) // 2.7.1 SCHEDULE ([modifier1 [, modifier2]:]kind[, chunk_size]) // Modifier -> MONITONIC | NONMONOTONIC | SIMD diff --git a/flang/test/Parser/omp-defaultmap-unparse.f90 b/flang/test/Parser/omp-defaultmap-unparse.f90 new file mode 100644 index 0000000..e7333b0 --- /dev/null +++ b/flang/test/Parser/omp-defaultmap-unparse.f90 @@ -0,0 +1,144 @@ +! RUN: %flang_fc1 -fdebug-unparse-no-sema -fopenmp %s | FileCheck --ignore-case %s +! RUN: %flang_fc1 -fdebug-dump-parse-tree-no-sema -fopenmp %s | FileCheck --check-prefix="PARSE-TREE" %s +program main +!CHECK-LABEL: program main + implicit none + + integer, parameter :: N = 256 + + type data01 + integer :: a + integer :: arr(N) + end type + + real :: arrA(N), arrB(N) + integer, target :: arrC(N) + type(data01) :: data01_a + integer, allocatable :: alloc_arr(:) + integer, pointer :: ptrArr(:) + + arrA = 1.414 + arrB = 3.14 + arrC = -1 + data01_a%a = -1 + data01_arr = -1 + allocate(alloc_arr(N)) + alloc_arr = -1 + + +!CHECK: !$omp target defaultmap(tofrom:scalar) + !$omp target defaultmap(tofrom:scalar) + do i = 1, N + a = 3.14 + enddo +!CHECK: !$omp end target + !$omp end target + +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = Tofrom +!PARSE-TREE: VariableCategory = Scalar + +!CHECK: !$omp target defaultmap(alloc:scalar) + !$omp target defaultmap(alloc:scalar) + a = 4.56 +!CHECK: !$omp end target + !$omp end target + +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = Alloc +!PARSE-TREE: VariableCategory = Scalar + +!CHECK: !$omp target defaultmap(none) + !$omp target defaultmap(none) + a = 6.78 +!CHECK: !$omp end target + !$omp end target + +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = None + +!CHECK: !$omp target defaultmap(none:scalar) + !$omp target defaultmap(none:scalar) + a = 4.78 +!CHECK: !$omp end target + !$omp end target + +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = None +!PARSE-TREE: VariableCategory = Scalar + +!CHECK: !$omp target defaultmap(to:scalar) + !$omp target defaultmap(to:scalar) + a = 2.39 +!CHECK: !$omp end target + !$omp end target + +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = To +!PARSE-TREE: VariableCategory = Scalar + +!CHECK: !$omp target defaultmap(firstprivate:scalar) + !$omp target defaultmap(firstprivate:scalar) + a = 9.45 +!CHECK: !$omp end target + !$omp end target + +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = Firstprivate +!PARSE-TREE: VariableCategory = Scalar + +!CHECK: !$omp target defaultmap(tofrom:aggregate) + !$omp target defaultmap(tofrom:aggregate) + arrC(1) = 10 + data01_a%a = 11 + data01_a%arr(1) = 100 + data01_a%arr(2) = 245 +!CHECK: !$omp end target + !$omp end target + +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = Tofrom +!PARSE-TREE: VariableCategory = Aggregate + +!CHECK: !$omp target defaultmap(tofrom:allocatable) + !$omp target defaultmap(tofrom:allocatable) + alloc_arr(23) = 234 +!CHECK: !$omp end target + !$omp end target + +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = Tofrom +!PARSE-TREE: VariableCategory = Allocatable + +!CHECK: !$omp target defaultmap(default:pointer) + !$omp target defaultmap(default:pointer) + ptrArr=>arrC + ptrArr(2) = 5 + prtArr(200) = 34 +!CHECK: !$omp end target + !$omp end target + +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = Default +!PARSE-TREE: VariableCategory = Pointer + +end program main +!CHECK-LABEL: end program main -- 2.7.4