Skip to content

Commit 29ce16b

Browse files
anchurajAlexisPerry
authored andcommitted
Adding parsing support for omp loop, target loop directives (llvm#93517)
Change adds parsing support for omp loop, omp target loop, omp target parallel loop and omp target teams loop.
1 parent d4aca04 commit 29ce16b

File tree

7 files changed

+126
-0
lines changed

7 files changed

+126
-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: 5 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,12 @@ 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" >> pure(llvm::omp::Directive::OMPD_target_loop),
391393
"TARGET PARALLEL DO SIMD" >>
392394
pure(llvm::omp::Directive::OMPD_target_parallel_do_simd),
393395
"TARGET PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_target_parallel_do),
396+
"TARGET PARALLEL LOOP" >>
397+
pure(llvm::omp::Directive::OMPD_target_parallel_loop),
394398
"TARGET SIMD" >> pure(llvm::omp::Directive::OMPD_target_simd),
395399
"TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD" >>
396400
pure(llvm::omp::Directive::
@@ -401,6 +405,7 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
401405
pure(llvm::omp::Directive::OMPD_target_teams_distribute_simd),
402406
"TARGET TEAMS DISTRIBUTE" >>
403407
pure(llvm::omp::Directive::OMPD_target_teams_distribute),
408+
"TARGET TEAMS LOOP" >> pure(llvm::omp::Directive::OMPD_target_teams_loop),
404409
"TASKLOOP SIMD" >> pure(llvm::omp::Directive::OMPD_taskloop_simd),
405410
"TASKLOOP" >> pure(llvm::omp::Directive::OMPD_taskloop),
406411
"TEAMS DISTRIBUTE PARALLEL DO SIMD" >>

flang/lib/Parser/unparse.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,9 @@ class UnparseVisitor {
22072207
case llvm::omp::Directive::OMPD_do_simd:
22082208
Word("DO SIMD ");
22092209
break;
2210+
case llvm::omp::Directive::OMPD_loop:
2211+
Word("LOOP ");
2212+
break;
22102213
case llvm::omp::Directive::OMPD_masked_taskloop_simd:
22112214
Word("MASKED TASKLOOP SIMD");
22122215
break;
@@ -2228,12 +2231,18 @@ class UnparseVisitor {
22282231
case llvm::omp::Directive::OMPD_simd:
22292232
Word("SIMD ");
22302233
break;
2234+
case llvm::omp::Directive::OMPD_target_loop:
2235+
Word("TARGET LOOP ");
2236+
break;
22312237
case llvm::omp::Directive::OMPD_target_parallel_do:
22322238
Word("TARGET PARALLEL DO ");
22332239
break;
22342240
case llvm::omp::Directive::OMPD_target_parallel_do_simd:
22352241
Word("TARGET PARALLEL DO SIMD ");
22362242
break;
2243+
case llvm::omp::Directive::OMPD_target_parallel_loop:
2244+
Word("TARGET PARALLEL LOOP ");
2245+
break;
22372246
case llvm::omp::Directive::OMPD_target_teams_distribute:
22382247
Word("TARGET TEAMS DISTRIBUTE ");
22392248
break;
@@ -2246,6 +2255,9 @@ class UnparseVisitor {
22462255
case llvm::omp::Directive::OMPD_target_teams_distribute_simd:
22472256
Word("TARGET TEAMS DISTRIBUTE SIMD ");
22482257
break;
2258+
case llvm::omp::Directive::OMPD_target_teams_loop:
2259+
Word("TARGET TEAMS LOOP ");
2260+
break;
22492261
case llvm::omp::Directive::OMPD_target_simd:
22502262
Word("TARGET SIMD ");
22512263
break;

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 10 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:
@@ -1629,6 +1633,12 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
16291633
default:
16301634
break;
16311635
}
1636+
if (beginDir.v == llvm::omp::Directive::OMPD_target_loop)
1637+
if (context_.ShouldWarn(common::UsageWarning::OpenMPUsage)) {
1638+
context_.Say(beginDir.source,
1639+
"Usage of directive %s is non-confirming to OpenMP standard"_warn_en_US,
1640+
llvm::omp::getOpenMPDirectiveName(beginDir.v).str());
1641+
}
16321642
ClearDataSharingAttributeObjects();
16331643
SetContextAssociatedLoopLevel(GetAssociatedLoopLevelFromClauses(clauseList));
16341644

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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,36 @@ def OMP_ForSimd : Directive<"for simd"> {
13151315
let leafConstructs = [OMP_For, OMP_Simd];
13161316
let category = CA_Executable;
13171317
}
1318+
def OMP_target_loop : Directive<"target loop"> {
1319+
let allowedClauses = [
1320+
VersionedClause<OMPC_Allocate>,
1321+
VersionedClause<OMPC_Depend>,
1322+
VersionedClause<OMPC_FirstPrivate>,
1323+
VersionedClause<OMPC_IsDevicePtr>,
1324+
VersionedClause<OMPC_HasDeviceAddr, 51>,
1325+
VersionedClause<OMPC_LastPrivate>,
1326+
VersionedClause<OMPC_Map>,
1327+
VersionedClause<OMPC_Private>,
1328+
VersionedClause<OMPC_Reduction>,
1329+
VersionedClause<OMPC_UsesAllocators, 50>,
1330+
VersionedClause<OMPC_OMPX_Attribute>,
1331+
VersionedClause<OMPC_InReduction, 50>,
1332+
1333+
];
1334+
let allowedOnceClauses = [
1335+
VersionedClause<OMPC_Bind, 50>,
1336+
VersionedClause<OMPC_Collapse>,
1337+
VersionedClause<OMPC_Order>,
1338+
VersionedClause<OMPC_ThreadLimit>,
1339+
VersionedClause<OMPC_OMPX_DynCGroupMem>,
1340+
VersionedClause<OMPC_If>,
1341+
VersionedClause<OMPC_Device>,
1342+
VersionedClause<OMPC_DefaultMap>,
1343+
VersionedClause<OMPC_NoWait>,
1344+
];
1345+
let leafConstructs = [OMP_Target, OMP_loop];
1346+
let category = CA_Executable;
1347+
}
13181348
def OMP_MaskedTaskloop : Directive<"masked taskloop"> {
13191349
let allowedClauses = [
13201350
VersionedClause<OMPC_Allocate>,

0 commit comments

Comments
 (0)