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

Anchu Rajendran S via flang-commits flang-commits at lists.llvm.org
Fri Nov 28 09:34:15 PST 2025


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

>From 087107466e6a6464ca657bc23cfba16ecb1a869d Mon Sep 17 00:00:00 2001
From: Anchu Rajendran <asudhaku at amd.com>
Date: Wed, 26 Nov 2025 17:37:54 -0600
Subject: [PATCH] [Flang][OpenMP] Enables parsing of threadset clause

---
 flang/lib/Parser/openmp-parsers.cpp           |  8 +-
 flang/lib/Parser/unparse.cpp                  |  1 +
 flang/test/Lower/OpenMP/Todo/threadset.f90    | 10 +++
 flang/test/Parser/OpenMP/threadset-clause.f90 | 79 +++++++++++++++++++
 .../Semantics/OpenMP/threadset-clause.f90     |  9 +++
 5 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Lower/OpenMP/Todo/threadset.f90
 create mode 100644 flang/test/Parser/OpenMP/threadset-clause.f90
 create mode 100644 flang/test/Semantics/OpenMP/threadset-clause.f90

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..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



More information about the flang-commits mailing list