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 @@ -514,6 +514,7 @@ NODE(parser, OmpProcBindClause) NODE_ENUM(OmpProcBindClause, Type) NODE(parser, OmpReductionClause) + NODE(parser, OmpInReductionClause) NODE(parser, OmpReductionCombiner) NODE(OmpReductionCombiner, FunctionCombiner) NODE(parser, OmpReductionInitializerClause) 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 @@ -3433,6 +3433,13 @@ std::tuple t; }; +// OMP 5.0 2.19.5.6 in_reduction-clause -> IN_REDUCTION (reduction-identifier: +// variable-name-list) +struct OmpInReductionClause { + TUPLE_CLASS_BOILERPLATE(OmpInReductionClause); + std::tuple t; +}; + // OMP 5.0 2.11.4 allocate-clause -> ALLOCATE ([allocator:] variable-name-list) struct OmpAllocateClause { TUPLE_CLASS_BOILERPLATE(OmpAllocateClause); 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 @@ -104,6 +104,10 @@ TYPE_PARSER(construct( Parser{} / ":", Parser{})) +// OMP 5.0 2.19.5.6 IN_REDUCTION (reduction-identifier: variable-name-list) +TYPE_PARSER(construct( + Parser{} / ":", Parser{})) + // OMP 5.0 2.11.4 ALLOCATE ([allocator:] variable-name-list) TYPE_PARSER(construct( maybe(construct(scalarIntExpr) / ":"), @@ -224,6 +228,8 @@ parenthesized(Parser{}))) || "REDUCTION" >> construct(construct( parenthesized(Parser{}))) || + "IN_REDUCTION" >> construct(construct( + parenthesized(Parser{}))) || "TASK_REDUCTION" >> construct(construct( parenthesized(Parser{}))) || 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 @@ -2025,6 +2025,11 @@ Put(":"); Walk(std::get(x.t)); } + void Unparse(const OmpInReductionClause &x) { + Walk(std::get(x.t)); + Put(":"); + Walk(std::get(x.t)); + } void Unparse(const OmpAllocateClause &x) { Walk(std::get>(x.t)); Put(":"); diff --git a/flang/test/Parser/omp-task-unparse.f90 b/flang/test/Parser/omp-task-unparse.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Parser/omp-task-unparse.f90 @@ -0,0 +1,46 @@ +! 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 +! Checks the unparsing of different OpenMP task construct + +program block_construct_unparsing + integer:: x + !CHECK: !$OMP TASKGROUP TASK_REDUCTION(+:x) + !CHECK: !$OMP TASK IN_REDUCTION(+:x) + !CHECK: x = x+5 + !CHECK: !$OMP END TASK + !CHECK: !$OMP END TASKGROUP + !$omp taskgroup task_reduction(+:x) + !$omp task in_reduction(+:x) + x = x + 5 + !$omp end task + !$omp end taskgroup +!PARSE-TREE: OpenMPConstruct -> OpenMPBlockConstruct +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = taskgroup +!PARSE-TREE: OmpClauseList -> OmpClause -> TaskReduction -> OmpReductionClause +!PARSE-TREE: OmpReductionOperator -> DefinedOperator -> IntrinsicOperator = Add +!PARSE-TREE: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' +!PARSE-TREE: Block +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPBlockConstruct +!PARSE-TREE: OmpBeginBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = task +!PARSE-TREE: OmpClauseList -> OmpClause -> InReduction -> OmpInReductionClause +!PARSE-TREE: OmpReductionOperator -> DefinedOperator -> IntrinsicOperator = Add +!PARSE-TREE: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'x' +!PARSE-TREE: Block +!PARSE-TREE: ExecutionPartConstruct -> ExecutableConstruct -> ActionStmt -> AssignmentStmt = 'x=x+5_4' +!PARSE-TREE: Variable = 'x' +!PARSE-TREE: Designator -> DataRef -> Name = 'x' +!PARSE-TREE: Expr = 'x+5_4' +!PARSE-TREE: Add +!PARSE-TREE: Expr = 'x' +!PARSE-TREE: Designator -> DataRef -> Name = 'x' +!PARSE-TREE: Expr = '5_4' +!PARSE-TREE: LiteralConstant -> IntLiteralConstant = '5' +!PARSE-TREE: OmpEndBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = task +!PARSE-TREE: OmpClauseList -> +!PARSE-TREE: OmpEndBlockDirective +!PARSE-TREE: OmpBlockDirective -> llvm::omp::Directive = taskgroup +!PARSE-TREE: OmpClauseList -> +end program block_construct_unparsing diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td --- a/llvm/include/llvm/Frontend/OpenMP/OMP.td +++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td @@ -283,6 +283,7 @@ } def OMPC_InReduction : Clause<"in_reduction"> { let clangClass = "OMPInReductionClause"; + let flangClass = "OmpInReductionClause"; } def OMPC_UnifiedAddress : Clause<"unified_address"> { let clangClass = "OMPUnifiedAddressClause";