diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index e2da60ed19de8..8932539c50cc0 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -1168,6 +1168,10 @@ TYPE_PARSER(construct( TYPE_PARSER(construct(scalarIntExpr)) +TYPE_PARSER(construct( + "OMP_POOL" >> pure(OmpThreadsetClause::ThreadsetPolicy::Omp_Pool) || + "OMP_TEAM" >> pure(OmpThreadsetClause::ThreadsetPolicy::Omp_Team))) + // OMP 5.0 2.11.4 allocate-clause -> ALLOCATE ([allocator:] variable-name-list) // OMP 5.2 2.13.4 allocate-clause -> ALLOCATE ([allocate-modifier // [, allocate-modifier] :] @@ -1519,7 +1523,9 @@ TYPE_PARSER( // parenthesized(nonemptyList(scalarIntExpr)))) || "PERMUTATION" >> construct(construct( parenthesized(nonemptyList(scalarIntExpr)))) || - "THREADS" >> construct(construct()) || + "THREADS"_id >> construct(construct()) || + "THREADSET" >> construct(construct( + parenthesized(Parser{}))) || "THREAD_LIMIT" >> construct(construct( parenthesized(scalarIntExpr))) || "TO" >> construct(construct( diff --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp index f81200d092b11..2a6d389e8ecf9 100644 --- a/flang/lib/Parser/unparse.cpp +++ b/flang/lib/Parser/unparse.cpp @@ -2789,6 +2789,7 @@ class UnparseVisitor { WALK_NESTED_ENUM(OmpTaskDependenceType, Value) // OMP task-dependence-type WALK_NESTED_ENUM(OmpScheduleClause, Kind) // OMP schedule-kind WALK_NESTED_ENUM(OmpSeverityClause, Severity) // OMP severity + WALK_NESTED_ENUM(OmpThreadsetClause, ThreadsetPolicy) // OMP threadset WALK_NESTED_ENUM(OmpAccessGroup, Value) WALK_NESTED_ENUM(OmpDeviceModifier, Value) // OMP device modifier WALK_NESTED_ENUM( diff --git a/flang/test/Lower/OpenMP/Todo/threadset.f90 b/flang/test/Lower/OpenMP/Todo/threadset.f90 new file mode 100644 index 0000000000000..b022baf02654b --- /dev/null +++ b/flang/test/Lower/OpenMP/Todo/threadset.f90 @@ -0,0 +1,10 @@ +! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -fopenmp-version=60 -o - %s 2>&1 | FileCheck %s + +! CHECK: not yet implemented: THREADSET clause is not implemented yet + +subroutine f00(x) + integer :: x(10) + !$omp task threadset(omp_pool) + x = x + 1 + !$omp end task +end diff --git a/flang/test/Parser/OpenMP/threadset-clause.f90 b/flang/test/Parser/OpenMP/threadset-clause.f90 new file mode 100644 index 0000000000000..3f19302c3ca1f --- /dev/null +++ b/flang/test/Parser/OpenMP/threadset-clause.f90 @@ -0,0 +1,79 @@ +!RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=60 %s | FileCheck --ignore-case --check-prefix="UNPARSE" %s +!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=60 %s | FileCheck --check-prefix="PARSE-TREE" %s + +subroutine f00(x) + integer :: x(10) +!$omp task threadset(omp_pool) + x = x + 1 +!$omp end task +end + +!UNPARSE: SUBROUTINE f00 (x) +!UNPARSE: INTEGER x(10_4) +!UNPARSE: !$OMP TASK THREADSET(OMP_POOL) +!UNPARSE: x=x+1_4 +!UNPARSE: !$OMP END TASK +!UNPARSE: END SUBROUTINE + +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = task +!PARSE-TREE: | OmpClauseList -> OmpClause -> Threadset -> OmpThreadsetClause -> ThreadsetPolicy = Omp_Pool + +subroutine f001(x) + integer :: x(10) +!$omp task threadset(omp_team) + x = x + 1 +!$omp end task +end + +!UNPARSE: SUBROUTINE f001 (x) +!UNPARSE: INTEGER x(10_4) +!UNPARSE: !$OMP TASK THREADSET(OMP_TEAM) +!UNPARSE: x=x+1_4 +!UNPARSE: !$OMP END TASK +!UNPARSE: END SUBROUTINE + +!PARSE-TREE: OmpBeginDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = task +!PARSE-TREE: | OmpClauseList -> OmpClause -> Threadset -> OmpThreadsetClause -> ThreadsetPolicy = Omp_Team + + +subroutine f002(x) + integer :: i +!$omp taskloop threadset(omp_team) + do i = 1, 10 + end do +!$omp end taskloop +end + +!UNPARSE: SUBROUTINE f002 (x) +!UNPARSE: INTEGER i +!UNPARSE: !$OMP TASKLOOP THREADSET(OMP_TEAM) +!UNPARSE: DO i=1_4,10_4 +!UNPARSE: END DO +!UNPARSE: !$OMP END TASK +!UNPARSE: END SUBROUTINE + +!PARSE-TREE: OmpBeginLoopDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = taskloop +!PARSE-TREE: | OmpClauseList -> OmpClause -> Threadset -> OmpThreadsetClause -> ThreadsetPolicy = Omp_Team + +subroutine f003(x) + integer :: i +!$omp taskloop threadset(omp_pool) + do i = 1, 10 + end do +!$omp end taskloop +end + +!UNPARSE: SUBROUTINE f003 (x) +!UNPARSE: INTEGER i +!UNPARSE: !$OMP TASKLOOP THREADSET(OMP_POOL) +!UNPARSE: DO i=1_4,10_4 +!UNPARSE: END DO +!UNPARSE: !$OMP END TASK +!UNPARSE: END SUBROUTINE + +!PARSE-TREE: OmpBeginLoopDirective +!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = taskloop +!PARSE-TREE: | OmpClauseList -> OmpClause -> Threadset -> OmpThreadsetClause -> ThreadsetPolicy = Omp_Pool diff --git a/flang/test/Semantics/OpenMP/threadset-clause.f90 b/flang/test/Semantics/OpenMP/threadset-clause.f90 new file mode 100644 index 0000000000000..59cd3ef503bd9 --- /dev/null +++ b/flang/test/Semantics/OpenMP/threadset-clause.f90 @@ -0,0 +1,9 @@ +!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=45 + +subroutine f00(x) + integer :: x(10) +!ERROR: THREADSET clause is not allowed on directive TASK in OpenMP v4.5, try -fopenmp-version=60 +!$omp task threadset(omp_pool) + x = x + 1 +!$omp end task +end