[flang-commits] [flang] [Flang][OpenMP] Enables parsing of threadset clause (PR #169856)

via flang-commits flang-commits at lists.llvm.org
Thu Nov 27 13:40:17 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-fir-hlfir

Author: Anchu Rajendran S (anchuraj)

<details>
<summary>Changes</summary>

Enables parsing support for `threadset` clause in OpenMP. Initial support was added in https://github.com/llvm/llvm-project/pull/135807

---
Full diff: https://github.com/llvm/llvm-project/pull/169856.diff


5 Files Affected:

- (modified) flang/lib/Parser/openmp-parsers.cpp (+7-1) 
- (modified) flang/lib/Parser/unparse.cpp (+1) 
- (added) flang/test/Lower/OpenMP/Todo/threadset.f90 (+10) 
- (added) flang/test/Parser/OpenMP/threadset-clause.f90 (+79) 
- (added) flang/test/Semantics/OpenMP/threadset-clause.f90 (+9) 


``````````diff
diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index e2da60ed19de8..45abcc13be267 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -1168,6 +1168,10 @@ TYPE_PARSER(construct<OmpTaskReductionClause>(
 
 TYPE_PARSER(construct<OmpTransparentClause>(scalarIntExpr))
 
+TYPE_PARSER(construct<OmpThreadsetClause>(
+    "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<OmpClause>(construct<OmpClause::Permutation>(
                          parenthesized(nonemptyList(scalarIntExpr)))) ||
-    "THREADS" >> construct<OmpClause>(construct<OmpClause::Threads>()) ||
+    "THREADS"_id >> construct<OmpClause>(construct<OmpClause::Threads>()) ||
+    "THREADSET" >> construct<OmpClause>(construct<OmpClause::Threadset>(
+                       parenthesized(Parser<OmpThreadsetClause>{}))) ||
     "THREAD_LIMIT" >> construct<OmpClause>(construct<OmpClause::ThreadLimit>(
                           parenthesized(scalarIntExpr))) ||
     "TO" >> construct<OmpClause>(construct<OmpClause::To>(
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..dfd27aace1ed1
--- /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_team)
+  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

``````````

</details>


https://github.com/llvm/llvm-project/pull/169856


More information about the flang-commits mailing list