Skip to content

Commit 4f6bd12

Browse files
committed
Adding parsing support for omp loop, target loop directives
1 parent 5ec91b3 commit 4f6bd12

File tree

7 files changed

+121
-0
lines changed

7 files changed

+121
-0
lines changed

flang/include/flang/Semantics/openmp-directive-sets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ static const OmpDirectiveSet loopConstructSet{
242242
Directive::OMPD_parallel_master_taskloop,
243243
Directive::OMPD_parallel_master_taskloop_simd,
244244
Directive::OMPD_simd,
245+
Directive::OMPD_target_loop,
245246
Directive::OMPD_target_parallel_do,
246247
Directive::OMPD_target_parallel_do_simd,
247248
Directive::OMPD_target_parallel_loop,

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
378378
"DISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_distribute),
379379
"DO SIMD" >> pure(llvm::omp::Directive::OMPD_do_simd),
380380
"DO" >> pure(llvm::omp::Directive::OMPD_do),
381+
"LOOP" >> pure(llvm::omp::Directive::OMPD_loop),
381382
"MASKED TASKLOOP SIMD" >>
382383
pure(llvm::omp::Directive::OMPD_masked_taskloop_simd),
383384
"MASKED TASKLOOP" >> pure(llvm::omp::Directive::OMPD_masked_taskloop),
@@ -388,9 +389,13 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
388389
"PARALLEL MASKED TASKLOOP" >>
389390
pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop),
390391
"SIMD" >> pure(llvm::omp::Directive::OMPD_simd),
392+
"TARGET LOOP" >>
393+
pure(llvm::omp::Directive::OMPD_target_loop),
391394
"TARGET PARALLEL DO SIMD" >>
392395
pure(llvm::omp::Directive::OMPD_target_parallel_do_simd),
393396
"TARGET PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_target_parallel_do),
397+
"TARGET PARALLEL LOOP" >>
398+
pure(llvm::omp::Directive::OMPD_target_parallel_loop),
394399
"TARGET SIMD" >> pure(llvm::omp::Directive::OMPD_target_simd),
395400
"TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD" >>
396401
pure(llvm::omp::Directive::
@@ -401,6 +406,8 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
401406
pure(llvm::omp::Directive::OMPD_target_teams_distribute_simd),
402407
"TARGET TEAMS DISTRIBUTE" >>
403408
pure(llvm::omp::Directive::OMPD_target_teams_distribute),
409+
"TARGET TEAMS LOOP" >>
410+
pure(llvm::omp::Directive::OMPD_target_teams_loop),
404411
"TASKLOOP SIMD" >> pure(llvm::omp::Directive::OMPD_taskloop_simd),
405412
"TASKLOOP" >> pure(llvm::omp::Directive::OMPD_taskloop),
406413
"TEAMS DISTRIBUTE PARALLEL DO SIMD" >>

flang/lib/Parser/unparse.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,6 +2194,9 @@ class UnparseVisitor {
21942194
case llvm::omp::Directive::OMPD_do_simd:
21952195
Word("DO SIMD ");
21962196
break;
2197+
case llvm::omp::Directive::OMPD_loop:
2198+
Word("LOOP ");
2199+
break;
21972200
case llvm::omp::Directive::OMPD_masked_taskloop_simd:
21982201
Word("MASKED TASKLOOP SIMD");
21992202
break;
@@ -2215,12 +2218,18 @@ class UnparseVisitor {
22152218
case llvm::omp::Directive::OMPD_simd:
22162219
Word("SIMD ");
22172220
break;
2221+
case llvm::omp::Directive::OMPD_target_loop:
2222+
Word("TARGET LOOP ");
2223+
break;
22182224
case llvm::omp::Directive::OMPD_target_parallel_do:
22192225
Word("TARGET PARALLEL DO ");
22202226
break;
22212227
case llvm::omp::Directive::OMPD_target_parallel_do_simd:
22222228
Word("TARGET PARALLEL DO SIMD ");
22232229
break;
2230+
case llvm::omp::Directive::OMPD_target_parallel_loop:
2231+
Word("TARGET PARALLEL LOOP ");
2232+
break;
22242233
case llvm::omp::Directive::OMPD_target_teams_distribute:
22252234
Word("TARGET TEAMS DISTRIBUTE ");
22262235
break;
@@ -2233,6 +2242,9 @@ class UnparseVisitor {
22332242
case llvm::omp::Directive::OMPD_target_teams_distribute_simd:
22342243
Word("TARGET TEAMS DISTRIBUTE SIMD ");
22352244
break;
2245+
case llvm::omp::Directive::OMPD_target_teams_loop:
2246+
Word("TARGET TEAMS LOOP ");
2247+
break;
22362248
case llvm::omp::Directive::OMPD_target_simd:
22372249
Word("TARGET SIMD ");
22382250
break;

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,19 +1602,23 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
16021602
case llvm::omp::Directive::OMPD_distribute_simd:
16031603
case llvm::omp::Directive::OMPD_do:
16041604
case llvm::omp::Directive::OMPD_do_simd:
1605+
case llvm::omp::Directive::OMPD_loop:
16051606
case llvm::omp::Directive::OMPD_masked_taskloop_simd:
16061607
case llvm::omp::Directive::OMPD_masked_taskloop:
16071608
case llvm::omp::Directive::OMPD_parallel_do:
16081609
case llvm::omp::Directive::OMPD_parallel_do_simd:
16091610
case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
16101611
case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
16111612
case llvm::omp::Directive::OMPD_simd:
1613+
case llvm::omp::Directive::OMPD_target_loop:
16121614
case llvm::omp::Directive::OMPD_target_parallel_do:
16131615
case llvm::omp::Directive::OMPD_target_parallel_do_simd:
1616+
case llvm::omp::Directive::OMPD_target_parallel_loop:
16141617
case llvm::omp::Directive::OMPD_target_teams_distribute:
16151618
case llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do:
16161619
case llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do_simd:
16171620
case llvm::omp::Directive::OMPD_target_teams_distribute_simd:
1621+
case llvm::omp::Directive::OMPD_target_teams_loop:
16181622
case llvm::omp::Directive::OMPD_target_simd:
16191623
case llvm::omp::Directive::OMPD_taskloop:
16201624
case llvm::omp::Directive::OMPD_taskloop_simd:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
! This test checks lowering of OpenMP loop Directive.
2+
3+
! RUN: %not_todo_cmd bbc -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
4+
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -o - %s 2>&1 | FileCheck %s
5+
6+
! CHECK: not yet implemented: Unhandled directive loop
7+
subroutine test_loop()
8+
integer :: i, j = 1
9+
!$omp loop
10+
do i=1,10
11+
j = j + 1
12+
end do
13+
!$omp end loop
14+
end subroutine
15+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
! RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck --ignore-case %s
3+
! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp %s | FileCheck --check-prefix="PARSE-TREE" %s
4+
5+
! Check for parsing of loop directive
6+
7+
subroutine test_loop
8+
integer :: i, j = 1
9+
!PARSE-TREE: OmpBeginLoopDirective
10+
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = loop
11+
!CHECK: !$omp loop
12+
!$omp loop
13+
do i=1,10
14+
j = j + 1
15+
end do
16+
!$omp end loop
17+
end subroutine
18+
19+
subroutine test_target_loop
20+
integer :: i, j = 1
21+
!PARSE-TREE: OmpBeginLoopDirective
22+
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target loop
23+
!CHECK: !$omp target loop
24+
!$omp target loop
25+
do i=1,10
26+
j = j + 1
27+
end do
28+
!$omp end target loop
29+
end subroutine
30+
31+
subroutine test_target_teams_loop
32+
integer :: i, j = 1
33+
!PARSE-TREE: OmpBeginLoopDirective
34+
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target teams loop
35+
!CHECK: !$omp target teams loop
36+
!$omp target teams loop
37+
do i=1,10
38+
j = j + 1
39+
end do
40+
!$omp end target teams loop
41+
end subroutine
42+
43+
subroutine test_target_parallel_loop
44+
integer :: i, j = 1
45+
!PARSE-TREE: OmpBeginLoopDirective
46+
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = target parallel loop
47+
!CHECK: !$omp target parallel loop
48+
!$omp target parallel loop
49+
do i=1,10
50+
j = j + 1
51+
end do
52+
!$omp end target parallel loop
53+
end subroutine

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,6 +2232,35 @@ def OMP_teams_loop : Directive<"teams loop"> {
22322232
];
22332233
let leafConstructs = [OMP_Teams, OMP_loop];
22342234
}
2235+
def OMP_target_loop : Directive<"target loop"> {
2236+
let allowedClauses = [
2237+
VersionedClause<OMPC_Allocate>,
2238+
VersionedClause<OMPC_Depend>,
2239+
VersionedClause<OMPC_FirstPrivate>,
2240+
VersionedClause<OMPC_IsDevicePtr>,
2241+
VersionedClause<OMPC_HasDeviceAddr, 51>,
2242+
VersionedClause<OMPC_LastPrivate>,
2243+
VersionedClause<OMPC_Map>,
2244+
VersionedClause<OMPC_Private>,
2245+
VersionedClause<OMPC_Reduction>,
2246+
VersionedClause<OMPC_UsesAllocators, 50>,
2247+
VersionedClause<OMPC_OMPX_Attribute>,
2248+
VersionedClause<OMPC_InReduction, 50>,
2249+
2250+
];
2251+
let allowedOnceClauses = [
2252+
VersionedClause<OMPC_Bind, 50>,
2253+
VersionedClause<OMPC_Collapse>,
2254+
VersionedClause<OMPC_Order>,
2255+
VersionedClause<OMPC_ThreadLimit>,
2256+
VersionedClause<OMPC_OMPX_DynCGroupMem>,
2257+
VersionedClause<OMPC_If>,
2258+
VersionedClause<OMPC_Device>,
2259+
VersionedClause<OMPC_DefaultMap>,
2260+
VersionedClause<OMPC_NoWait>,
2261+
];
2262+
let leafConstructs = [OMP_Target, OMP_loop];
2263+
}
22352264
def OMP_target_teams_loop : Directive<"target teams loop"> {
22362265
let allowedClauses = [
22372266
VersionedClause<OMPC_If>,

0 commit comments

Comments
 (0)