Skip to content

Commit 09ecc8e

Browse files
committed
[Flang][OpenMP] Enables parsing of threadset clause
1 parent 1b8a4aa commit 09ecc8e

File tree

5 files changed

+106
-1
lines changed

5 files changed

+106
-1
lines changed

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,10 @@ TYPE_PARSER(construct<OmpTaskReductionClause>(
11681168

11691169
TYPE_PARSER(construct<OmpTransparentClause>(scalarIntExpr))
11701170

1171+
TYPE_PARSER(construct<OmpThreadsetClause>(
1172+
"omp_pool" >> pure(OmpThreadsetClause::ThreadsetPolicy::Omp_Pool) ||
1173+
"omp_team" >> pure(OmpThreadsetClause::ThreadsetPolicy::Omp_Team)))
1174+
11711175
// OMP 5.0 2.11.4 allocate-clause -> ALLOCATE ([allocator:] variable-name-list)
11721176
// OMP 5.2 2.13.4 allocate-clause -> ALLOCATE ([allocate-modifier
11731177
// [, allocate-modifier] :]
@@ -1519,7 +1523,9 @@ TYPE_PARSER( //
15191523
parenthesized(nonemptyList(scalarIntExpr)))) ||
15201524
"PERMUTATION" >> construct<OmpClause>(construct<OmpClause::Permutation>(
15211525
parenthesized(nonemptyList(scalarIntExpr)))) ||
1522-
"THREADS" >> construct<OmpClause>(construct<OmpClause::Threads>()) ||
1526+
"THREADS"_id >> construct<OmpClause>(construct<OmpClause::Threads>()) ||
1527+
"THREADSET" >> construct<OmpClause>(construct<OmpClause::Threadset>(
1528+
parenthesized(Parser<OmpThreadsetClause>{}))) ||
15231529
"THREAD_LIMIT" >> construct<OmpClause>(construct<OmpClause::ThreadLimit>(
15241530
parenthesized(scalarIntExpr))) ||
15251531
"TO" >> construct<OmpClause>(construct<OmpClause::To>(

flang/lib/Parser/unparse.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,6 +2789,7 @@ class UnparseVisitor {
27892789
WALK_NESTED_ENUM(OmpTaskDependenceType, Value) // OMP task-dependence-type
27902790
WALK_NESTED_ENUM(OmpScheduleClause, Kind) // OMP schedule-kind
27912791
WALK_NESTED_ENUM(OmpSeverityClause, Severity) // OMP severity
2792+
WALK_NESTED_ENUM(OmpThreadsetClause, ThreadsetPolicy) // OMP threadset
27922793
WALK_NESTED_ENUM(OmpAccessGroup, Value)
27932794
WALK_NESTED_ENUM(OmpDeviceModifier, Value) // OMP device modifier
27942795
WALK_NESTED_ENUM(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -fopenmp-version=60 -o - %s 2>&1 | FileCheck %s
2+
3+
! CHECK: not yet implemented: THREADSET clause is not implemented yet
4+
5+
subroutine f00(x)
6+
integer :: x(10)
7+
!$omp task threadset(omp_pool)
8+
x = x + 1
9+
!$omp end task
10+
end
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
!RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=60 %s | FileCheck --ignore-case --check-prefix="UNPARSE" %s
2+
!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=60 %s | FileCheck --check-prefix="PARSE-TREE" %s
3+
4+
subroutine f00(x)
5+
integer :: x(10)
6+
!$omp task threadset(omp_pool)
7+
x = x + 1
8+
!$omp end task
9+
end
10+
11+
!UNPARSE: SUBROUTINE f00 (x)
12+
!UNPARSE: INTEGER x(10_4)
13+
!UNPARSE: !$OMP TASK THREADSET(OMP_POOL)
14+
!UNPARSE: x=x+1_4
15+
!UNPARSE: !$OMP END TASK
16+
!UNPARSE: END SUBROUTINE
17+
18+
!PARSE-TREE: OmpBeginDirective
19+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = task
20+
!PARSE-TREE: | OmpClauseList -> OmpClause -> Threadset -> OmpThreadsetClause -> ThreadsetPolicy = Omp_Pool
21+
22+
subroutine f001(x)
23+
integer :: x(10)
24+
!$omp task threadset(omp_team)
25+
x = x + 1
26+
!$omp end task
27+
end
28+
29+
!UNPARSE: SUBROUTINE f001 (x)
30+
!UNPARSE: INTEGER x(10_4)
31+
!UNPARSE: !$OMP TASK THREADSET(OMP_TEAM)
32+
!UNPARSE: x=x+1_4
33+
!UNPARSE: !$OMP END TASK
34+
!UNPARSE: END SUBROUTINE
35+
36+
!PARSE-TREE: OmpBeginDirective
37+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = task
38+
!PARSE-TREE: | OmpClauseList -> OmpClause -> Threadset -> OmpThreadsetClause -> ThreadsetPolicy = Omp_Team
39+
40+
41+
subroutine f002(x)
42+
integer :: i
43+
!$omp taskloop threadset(omp_team)
44+
do i = 1, 10
45+
end do
46+
!$omp end taskloop
47+
end
48+
49+
!UNPARSE: SUBROUTINE f002 (x)
50+
!UNPARSE: INTEGER i
51+
!UNPARSE: !$OMP TASKLOOP THREADSET(OMP_TEAM)
52+
!UNPARSE: DO i=1_4,10_4
53+
!UNPARSE: END DO
54+
!UNPARSE: !$OMP END TASK
55+
!UNPARSE: END SUBROUTINE
56+
57+
!PARSE-TREE: OmpBeginLoopDirective
58+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = taskloop
59+
!PARSE-TREE: | OmpClauseList -> OmpClause -> Threadset -> OmpThreadsetClause -> ThreadsetPolicy = Omp_Team
60+
61+
subroutine f003(x)
62+
integer :: i
63+
!$omp taskloop threadset(omp_team)
64+
do i = 1, 10
65+
end do
66+
!$omp end taskloop
67+
end
68+
69+
!UNPARSE: SUBROUTINE f003 (x)
70+
!UNPARSE: INTEGER i
71+
!UNPARSE: !$OMP TASKLOOP THREADSET(OMP_POOL)
72+
!UNPARSE: DO i=1_4,10_4
73+
!UNPARSE: END DO
74+
!UNPARSE: !$OMP END TASK
75+
!UNPARSE: END SUBROUTINE
76+
77+
!PARSE-TREE: OmpBeginLoopDirective
78+
!PARSE-TREE: | OmpDirectiveName -> llvm::omp::Directive = taskloop
79+
!PARSE-TREE: | OmpClauseList -> OmpClause -> Threadset -> OmpThreadsetClause -> ThreadsetPolicy = Omp_Pool
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=45
2+
3+
subroutine f00(x)
4+
integer :: x(10)
5+
!ERROR: THREADSET clause is not allowed on directive TASK in OpenMP v4.5, try -fopenmp-version=60
6+
!$omp task threadset(omp_pool)
7+
x = x + 1
8+
!$omp end task
9+
end

0 commit comments

Comments
 (0)