Index: flang/include/flang/Parser/parse-tree.h =================================================================== --- flang/include/flang/Parser/parse-tree.h +++ flang/include/flang/Parser/parse-tree.h @@ -3346,8 +3346,9 @@ // 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 @@ std::tuple> t; }; - // 2.17.8 flush -> FLUSH [memory-order-clause] [(variable-name-list)] struct OpenMPFlushConstruct { TUPLE_CLASS_BOILERPLATE(OpenMPFlushConstruct); Index: flang/lib/Parser/openmp-parsers.cpp =================================================================== --- flang/lib/Parser/openmp-parsers.cpp +++ flang/lib/Parser/openmp-parsers.cpp @@ -55,9 +55,23 @@ // 2.15.5.2 defaultmap -> DEFAULTMAP (TOFROM:SCALAR) 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 Index: flang/test/Parser/omp-defaultmap-unparse.f90 =================================================================== --- /dev/null +++ flang/test/Parser/omp-defaultmap-unparse.f90 @@ -0,0 +1,279 @@ +! RUN: %flang_fc1 -fdebug-unparse-no-sema -fopenmp %s | FileCheck %s +! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp %s | FileCheck --check-prefix="PARSE-TREE" %s +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 + + + !$omp target defaultmap(tofrom:scalar) + do i = 1, N + a = 3.14 + enddo + !$omp end target + +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = Tofrom +!PARSE-TREE: VariableCategory = Scalar +!PARSE-TREE: Block +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> DoConstruct +!PARSE-TREE: NonLabelDoStmt +!PARSE-TREE: LoopControl -> LoopBounds +!PARSE-TREE: Scalar -> Name = 'i' +!PARSE-TREE: Scalar -> Expr -> LiteralConstant -> IntLiteralConstant = '1' +!PARSE-TREE: Scalar -> Expr -> Designator -> DataRef -> Name = 'n' +!PARSE-TREE: Block +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> Designator -> DataRef -> Name = 'a' +!PARSE-TREE: Expr -> LiteralConstant -> RealLiteralConstant +!PARSE-TREE: Real = '3.14' +!PARSE-TREE: EndDoStmt -> +!PARSE-TREE: OmpEndBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> + + !$omp target defaultmap(alloc:scalar) + a = 4.56 + !$omp end target + +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = Alloc +!PARSE-TREE: VariableCategory = Scalar +!PARSE-TREE: Block +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> Designator -> DataRef -> Name = 'a' +!PARSE-TREE: Expr -> LiteralConstant -> RealLiteralConstant +!PARSE-TREE: Real = '4.56' +!PARSE-TREE: OmpEndBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> + + !$omp target defaultmap(none) + a = 6.78 + !$omp end target + +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = None +!PARSE-TREE: Block +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> Designator -> DataRef -> Name = 'a' +!PARSE-TREE: Expr -> LiteralConstant -> RealLiteralConstant +!PARSE-TREE: Real = '6.78' +!PARSE-TREE: OmpEndBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> + + !$omp target defaultmap(none:scalar) + a = 4.78 + !$omp end target + +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = None +!PARSE-TREE: VariableCategory = Scalar +!PARSE-TREE: Block +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> Designator -> DataRef -> Name = 'a' +!PARSE-TREE: Expr -> LiteralConstant -> RealLiteralConstant +!PARSE-TREE: Real = '4.78' +!PARSE-TREE: OmpEndBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> + + !$omp target defaultmap(to:scalar) + a = 2.39 + !$omp end target + +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = To +!PARSE-TREE: VariableCategory = Scalar +!PARSE-TREE: Block +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> Designator -> DataRef -> Name = 'a' +!PARSE-TREE: Expr -> LiteralConstant -> RealLiteralConstant +!PARSE-TREE: Real = '2.39' +!PARSE-TREE: OmpEndBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> + + !$omp target defaultmap(firstprivate:scalar) + a = 9.45 + !$omp end target + +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = Firstprivate +!PARSE-TREE: VariableCategory = Scalar +!PARSE-TREE: Block +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> Designator -> DataRef -> Name = 'a' +!PARSE-TREE: Expr -> LiteralConstant -> RealLiteralConstant +!PARSE-TREE: Real = '9.45' +!PARSE-TREE: OmpEndBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> + + !$omp target defaultmap(tofrom:aggregate) + arrC(1) = 10 + data01_a%a = 11 + data01_a%arr(1) = 100 + data01_a%arr(2) = 245 + !$omp end target + +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = Tofrom +!PARSE-TREE: VariableCategory = Aggregate +!PARSE-TREE: Block +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> FunctionReference -> Call +!PARSE-TREE: ProcedureDesignator -> Name = 'arrc' +!PARSE-TREE: ActualArgSpec +!PARSE-TREE: ActualArg -> Expr -> LiteralConstant -> IntLiteralConstant = '1' +!PARSE-TREE: Expr -> LiteralConstant -> IntLiteralConstant = '10' +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> Designator -> DataRef -> StructureComponent +!PARSE-TREE: DataRef -> Name = 'data01_a' +!PARSE-TREE: Name = 'a' +!PARSE-TREE: Expr -> LiteralConstant -> IntLiteralConstant = '11' +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> FunctionReference -> Call +!PARSE-TREE: ProcedureDesignator -> ProcComponentRef -> Scalar -> StructureComponent +!PARSE-TREE: DataRef -> Name = 'data01_a' +!PARSE-TREE: Name = 'arr' +!PARSE-TREE: ActualArgSpec +!PARSE-TREE: ActualArg -> Expr -> LiteralConstant -> IntLiteralConstant = '1' +!PARSE-TREE: Expr -> LiteralConstant -> IntLiteralConstant = '100' +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> FunctionReference -> Call +!PARSE-TREE: ProcedureDesignator -> ProcComponentRef -> Scalar -> StructureComponent +!PARSE-TREE: DataRef -> Name = 'data01_a' +!PARSE-TREE: Name = 'arr' +!PARSE-TREE: ActualArgSpec +!PARSE-TREE: ActualArg -> Expr -> LiteralConstant -> IntLiteralConstant = '2' +!PARSE-TREE: Expr -> LiteralConstant -> IntLiteralConstant = '245' +!PARSE-TREE: OmpEndBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> + + !$omp target defaultmap(tofrom:allocatable) + alloc_arr(23) = 234 + !$omp end target + +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = Tofrom +!PARSE-TREE: VariableCategory = Allocatable +!PARSE-TREE: Block +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> FunctionReference -> Call +!PARSE-TREE: ProcedureDesignator -> Name = 'alloc_arr' +!PARSE-TREE: ActualArgSpec +!PARSE-TREE: ActualArg -> Expr -> LiteralConstant -> IntLiteralConstant = '23' +!PARSE-TREE: Expr -> LiteralConstant -> IntLiteralConstant = '234' +!PARSE-TREE: OmpEndBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> + + !$omp target defaultmap(default:pointer) + ptrArr=>arrC + ptrArr(2) = 5 + prtArr(200) = 34 + !$omp end target + +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> OmpClause -> Defaultmap -> OmpDefaultmapClause +!PARSE-TREE: ImplicitBehavior = Default +!PARSE-TREE: VariableCategory = Pointer +!PARSE-TREE: Block +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> PointerAssignmentStmt +!PARSE-TREE: DataRef -> Name = 'ptrarr' +!PARSE-TREE: Bounds -> +!PARSE-TREE: Expr -> Designator -> DataRef -> Name = 'arrc' +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> FunctionReference -> Call +!PARSE-TREE: ProcedureDesignator -> Name = 'ptrarr' +!PARSE-TREE: ActualArgSpec +!PARSE-TREE: ActualArg -> Expr -> LiteralConstant -> IntLiteralConstant = '2' +!PARSE-TREE: Expr -> LiteralConstant -> IntLiteralConstant = '5' +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt +!PARSE-TREE: Variable -> FunctionReference -> Call +!PARSE-TREE: ProcedureDesignator -> Name = 'prtarr' +!PARSE-TREE: ActualArgSpec +!PARSE-TREE: ActualArg -> Expr -> LiteralConstant -> IntLiteralConstant = '200' +!PARSE-TREE: Expr -> LiteralConstant -> IntLiteralConstant = '34' +!PARSE-TREE: OmpEndBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = target +!PARSE-TREE: OmpClauseList -> + +end program main +!CHECK-LABEL: PROGRAM main + +!CHECK: !$OMP TARGET DEFAULTMAP(TOFROM:SCALAR) +!CHECK: !$OMP END TARGET + +!CHECK: !$OMP TARGET DEFAULTMAP(ALLOC:SCALAR) +!CHECK: !$OMP END TARGET + +!CHECK: !$OMP TARGET DEFAULTMAP(NONE) +!CHECK: !$OMP END TARGET + +!CHECK: !$OMP TARGET DEFAULTMAP(NONE:SCALAR) +!CHECK: !$OMP END TARGET + +!CHECK: !$OMP TARGET DEFAULTMAP(TO:SCALAR) +!CHECK: !$OMP END TARGET + +!CHECK: !$OMP TARGET DEFAULTMAP(FIRSTPRIVATE:SCALAR) +!CHECK: !$OMP END TARGET + +!CHECK: !$OMP TARGET DEFAULTMAP(TOFROM:AGGREGATE) +!CHECK: !$OMP END TARGET + +!CHECK: !$OMP TARGET DEFAULTMAP(TOFROM:ALLOCATABLE) +!CHECK: !$OMP END TARGET + +!CHECK: !$OMP TARGET DEFAULTMAP(DEFAULT:POINTER) +!CHECK: !$OMP END TARGET