Skip to content

Commit 092a819

Browse files
[Flang][OpenMP] Add frontend support for directives involving master (#113893)
Issue deprecation warning for these directives. Lowering currently supports parallel master, for all other combined or composite directives involving master, issue TODO errors. Note: The first commit changes the formatting and generalizes the deprecation message emission for reuse in the second commit. I can pull it out into a separate commit if required.
1 parent f447cf1 commit 092a819

17 files changed

+293
-32
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ static const OmpDirectiveSet blockConstructSet{
210210
Directive::OMPD_ordered,
211211
Directive::OMPD_parallel,
212212
Directive::OMPD_parallel_masked,
213+
Directive::OMPD_parallel_master,
213214
Directive::OMPD_parallel_workshare,
214215
Directive::OMPD_scope,
215216
Directive::OMPD_single,

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,19 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
583583
"MASKED TASKLOOP SIMD" >>
584584
pure(llvm::omp::Directive::OMPD_masked_taskloop_simd),
585585
"MASKED TASKLOOP" >> pure(llvm::omp::Directive::OMPD_masked_taskloop),
586+
"MASTER TASKLOOP SIMD" >>
587+
pure(llvm::omp::Directive::OMPD_master_taskloop_simd),
588+
"MASTER TASKLOOP" >> pure(llvm::omp::Directive::OMPD_master_taskloop),
586589
"PARALLEL DO SIMD" >> pure(llvm::omp::Directive::OMPD_parallel_do_simd),
587590
"PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_parallel_do),
588591
"PARALLEL MASKED TASKLOOP SIMD" >>
589592
pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd),
590593
"PARALLEL MASKED TASKLOOP" >>
591594
pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop),
595+
"PARALLEL MASTER TASKLOOP SIMD" >>
596+
pure(llvm::omp::Directive::OMPD_parallel_master_taskloop_simd),
597+
"PARALLEL MASTER TASKLOOP" >>
598+
pure(llvm::omp::Directive::OMPD_parallel_master_taskloop),
592599
"SIMD" >> pure(llvm::omp::Directive::OMPD_simd),
593600
"TARGET LOOP" >> pure(llvm::omp::Directive::OMPD_target_loop),
594601
"TARGET PARALLEL DO SIMD" >>
@@ -706,6 +713,7 @@ TYPE_PARSER(construct<OmpBlockDirective>(first(
706713
"MASTER" >> pure(llvm::omp::Directive::OMPD_master),
707714
"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered),
708715
"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked),
716+
"PARALLEL MASTER" >> pure(llvm::omp::Directive::OMPD_parallel_master),
709717
"PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare),
710718
"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel),
711719
"SCOPE" >> pure(llvm::omp::Directive::OMPD_scope),

flang/lib/Parser/unparse.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,6 +2274,12 @@ class UnparseVisitor {
22742274
case llvm::omp::Directive::OMPD_masked_taskloop:
22752275
Word("MASKED TASKLOOP");
22762276
break;
2277+
case llvm::omp::Directive::OMPD_master_taskloop_simd:
2278+
Word("MASTER TASKLOOP SIMD");
2279+
break;
2280+
case llvm::omp::Directive::OMPD_master_taskloop:
2281+
Word("MASTER TASKLOOP");
2282+
break;
22772283
case llvm::omp::Directive::OMPD_parallel_do:
22782284
Word("PARALLEL DO ");
22792285
break;
@@ -2286,6 +2292,12 @@ class UnparseVisitor {
22862292
case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
22872293
Word("PARALLEL MASKED TASKLOOP");
22882294
break;
2295+
case llvm::omp::Directive::OMPD_parallel_master_taskloop_simd:
2296+
Word("PARALLEL MASTER TASKLOOP SIMD");
2297+
break;
2298+
case llvm::omp::Directive::OMPD_parallel_master_taskloop:
2299+
Word("PARALLEL MASTER TASKLOOP");
2300+
break;
22892301
case llvm::omp::Directive::OMPD_simd:
22902302
Word("SIMD ");
22912303
break;
@@ -2390,6 +2402,9 @@ class UnparseVisitor {
23902402
case llvm::omp::Directive::OMPD_parallel_masked:
23912403
Word("PARALLEL MASKED");
23922404
break;
2405+
case llvm::omp::Directive::OMPD_parallel_master:
2406+
Word("PARALLEL MASTER");
2407+
break;
23932408
case llvm::omp::Directive::OMPD_parallel_workshare:
23942409
Word("PARALLEL WORKSHARE ");
23952410
break;

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
15311531
case llvm::omp::Directive::OMPD_masked:
15321532
case llvm::omp::Directive::OMPD_parallel_masked:
15331533
case llvm::omp::Directive::OMPD_master:
1534+
case llvm::omp::Directive::OMPD_parallel_master:
15341535
case llvm::omp::Directive::OMPD_ordered:
15351536
case llvm::omp::Directive::OMPD_parallel:
15361537
case llvm::omp::Directive::OMPD_scope:
@@ -1550,7 +1551,8 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
15501551
// TODO others
15511552
break;
15521553
}
1553-
if (beginDir.v == llvm::omp::Directive::OMPD_master)
1554+
if (beginDir.v == llvm::omp::Directive::OMPD_master ||
1555+
beginDir.v == llvm::omp::Directive::OMPD_parallel_master)
15541556
IssueNonConformanceWarning(beginDir.v, beginDir.source);
15551557
ClearDataSharingAttributeObjects();
15561558
ClearPrivateDataSharingAttributeObjects();
@@ -1563,7 +1565,9 @@ void OmpAttributeVisitor::Post(const parser::OpenMPBlockConstruct &x) {
15631565
const auto &beginDir{std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
15641566
switch (beginDir.v) {
15651567
case llvm::omp::Directive::OMPD_masked:
1568+
case llvm::omp::Directive::OMPD_master:
15661569
case llvm::omp::Directive::OMPD_parallel_masked:
1570+
case llvm::omp::Directive::OMPD_parallel_master:
15671571
case llvm::omp::Directive::OMPD_parallel:
15681572
case llvm::omp::Directive::OMPD_scope:
15691573
case llvm::omp::Directive::OMPD_single:
@@ -1634,10 +1638,14 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
16341638
case llvm::omp::Directive::OMPD_loop:
16351639
case llvm::omp::Directive::OMPD_masked_taskloop_simd:
16361640
case llvm::omp::Directive::OMPD_masked_taskloop:
1641+
case llvm::omp::Directive::OMPD_master_taskloop_simd:
1642+
case llvm::omp::Directive::OMPD_master_taskloop:
16371643
case llvm::omp::Directive::OMPD_parallel_do:
16381644
case llvm::omp::Directive::OMPD_parallel_do_simd:
16391645
case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
16401646
case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
1647+
case llvm::omp::Directive::OMPD_parallel_master_taskloop_simd:
1648+
case llvm::omp::Directive::OMPD_parallel_master_taskloop:
16411649
case llvm::omp::Directive::OMPD_simd:
16421650
case llvm::omp::Directive::OMPD_target_loop:
16431651
case llvm::omp::Directive::OMPD_target_parallel_do:
@@ -1662,7 +1670,11 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
16621670
default:
16631671
break;
16641672
}
1665-
if (beginDir.v == llvm::omp::Directive::OMPD_target_loop)
1673+
if (beginDir.v == llvm::omp::OMPD_master_taskloop ||
1674+
beginDir.v == llvm::omp::OMPD_master_taskloop_simd ||
1675+
beginDir.v == llvm::omp::OMPD_parallel_master_taskloop ||
1676+
beginDir.v == llvm::omp::OMPD_parallel_master_taskloop_simd ||
1677+
beginDir.v == llvm::omp::Directive::OMPD_target_loop)
16661678
IssueNonConformanceWarning(beginDir.v, beginDir.source);
16671679
ClearDataSharingAttributeObjects();
16681680
SetContextAssociatedLoopLevel(GetAssociatedLoopLevelFromClauses(clauseList));
@@ -2891,18 +2903,39 @@ void OmpAttributeVisitor::AddOmpRequiresToScope(Scope &scope,
28912903

28922904
void OmpAttributeVisitor::IssueNonConformanceWarning(
28932905
llvm::omp::Directive D, parser::CharBlock source) {
2894-
std::string warnStr = "";
2895-
std::string dirName = llvm::omp::getOpenMPDirectiveName(D).str();
2906+
std::string warnStr;
2907+
llvm::raw_string_ostream warnStrOS(warnStr);
2908+
warnStrOS << "OpenMP directive "
2909+
<< parser::ToUpperCaseLetters(
2910+
llvm::omp::getOpenMPDirectiveName(D).str())
2911+
<< " has been deprecated";
2912+
2913+
auto setAlternativeStr = [&warnStrOS](llvm::StringRef alt) {
2914+
warnStrOS << ", please use " << alt << " instead.";
2915+
};
28962916
switch (D) {
28972917
case llvm::omp::OMPD_master:
2898-
warnStr = "OpenMP directive '" + dirName +
2899-
"' has been deprecated, please use 'masked' instead.";
2918+
setAlternativeStr("MASKED");
2919+
break;
2920+
case llvm::omp::OMPD_master_taskloop:
2921+
setAlternativeStr("MASKED TASKLOOP");
2922+
break;
2923+
case llvm::omp::OMPD_master_taskloop_simd:
2924+
setAlternativeStr("MASKED TASKLOOP SIMD");
2925+
break;
2926+
case llvm::omp::OMPD_parallel_master:
2927+
setAlternativeStr("PARALLEL MASKED");
2928+
break;
2929+
case llvm::omp::OMPD_parallel_master_taskloop:
2930+
setAlternativeStr("PARALLEL MASKED TASKLOOP");
2931+
break;
2932+
case llvm::omp::OMPD_parallel_master_taskloop_simd:
2933+
setAlternativeStr("PARALLEL_MASKED TASKLOOP SIMD");
29002934
break;
29012935
case llvm::omp::OMPD_target_loop:
2902-
default:
2903-
warnStr = "OpenMP directive '" + dirName + "' has been deprecated.";
2936+
default:;
29042937
}
2905-
context_.Warn(
2906-
common::UsageWarning::OpenMPUsage, source, "%s"_warn_en_US, warnStr);
2938+
context_.Warn(common::UsageWarning::OpenMPUsage, source, "%s"_warn_en_US,
2939+
warnStrOS.str());
29072940
}
29082941
} // namespace Fortran::semantics
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
! This test checks lowering of OpenMP master taskloop 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+
subroutine test_master_taskloop
7+
integer :: i, j = 1
8+
!CHECK: not yet implemented: Taskloop construct
9+
!$omp master taskloop
10+
do i=1,10
11+
j = j + 1
12+
end do
13+
!$omp end master taskloop
14+
end subroutine
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
! This test checks lowering of OpenMP master taskloop simd 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+
subroutine test_master_taskloop_simd()
7+
integer :: i, j = 1
8+
!CHECK: not yet implemented: Composite TASKLOOP SIMD
9+
!$omp master taskloop simd
10+
do i=1,10
11+
j = j + 1
12+
end do
13+
!$omp end master taskloop simd
14+
end subroutine
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
! This test checks lowering of OpenMP parallel master taskloop simd 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+
subroutine test_parallel_master_taskloop_simd
7+
integer :: i, j = 1
8+
!CHECK: not yet implemented: Composite TASKLOOP SIMD
9+
!$omp parallel master taskloop simd
10+
do i=1,10
11+
j = j + 1
12+
end do
13+
!$omp end parallel master taskloop simd
14+
end subroutine
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
! This test checks lowering of OpenMP parallel master taskloop 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+
subroutine test_parallel_master_taskloop
7+
integer :: i, j = 1
8+
!CHECK: not yet implemented: Taskloop construct
9+
!$omp parallel master taskloop
10+
do i=1,10
11+
j = j + 1
12+
end do
13+
!$omp end parallel master taskloop
14+
end subroutine
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! This test checks lowering of the parallel master combined construct.
2+
3+
! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
4+
! RUN: %flang_fc1 -fopenmp -emit-hlfir %s -o - | FileCheck %s
5+
6+
! CHECK-LABEL: func @_QPparallel_master
7+
subroutine parallel_master(x)
8+
integer :: x
9+
!CHECK: omp.parallel {
10+
!CHECK: omp.master {
11+
!$omp parallel master
12+
x = 1
13+
!$omp end parallel master
14+
!CHECK: }
15+
!CHECK: }
16+
end subroutine parallel_master
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
! RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck --ignore-case %s
2+
! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp %s | FileCheck --check-prefix="PARSE-TREE" %s
3+
4+
! Check for parsing of master directive
5+
6+
7+
subroutine test_master()
8+
integer :: c = 1
9+
!PARSE-TREE: OmpBeginBlockDirective
10+
!PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = master
11+
!CHECK: !$omp master
12+
!$omp master
13+
c = c + 1
14+
!$omp end master
15+
end subroutine
16+
17+
subroutine test_master_taskloop_simd()
18+
integer :: i, j = 1
19+
!PARSE-TREE: OmpBeginLoopDirective
20+
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = master taskloop simd
21+
!CHECK: !$omp master taskloop simd
22+
!$omp master taskloop simd
23+
do i=1,10
24+
j = j + 1
25+
end do
26+
!$omp end master taskloop simd
27+
end subroutine
28+
29+
subroutine test_master_taskloop
30+
integer :: i, j = 1
31+
!PARSE-TREE: OmpBeginLoopDirective
32+
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = master taskloop
33+
!CHECK: !$omp master taskloop
34+
!$omp master taskloop
35+
do i=1,10
36+
j = j + 1
37+
end do
38+
!$omp end master taskloop
39+
end subroutine
40+
41+
subroutine test_parallel_master
42+
integer :: c = 2
43+
!PARSE-TREE: OmpBeginBlockDirective
44+
!PARSE-TREE-NEXT: OmpBlockDirective -> llvm::omp::Directive = parallel master
45+
!CHECK: !$omp parallel master
46+
!$omp parallel master
47+
c = c + 2
48+
!$omp end parallel master
49+
end subroutine
50+
51+
subroutine test_parallel_master_taskloop_simd
52+
integer :: i, j = 1
53+
!PARSE-TREE: OmpBeginLoopDirective
54+
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel master taskloop simd
55+
!CHECK: !$omp parallel master taskloop simd
56+
!$omp parallel master taskloop simd
57+
do i=1,10
58+
j = j + 1
59+
end do
60+
!$omp end parallel master taskloop simd
61+
end subroutine
62+
63+
subroutine test_parallel_master_taskloop
64+
integer :: i, j = 1
65+
!PARSE-TREE: OmpBeginLoopDirective
66+
!PARSE-TREE-NEXT: OmpLoopDirective -> llvm::omp::Directive = parallel master taskloop
67+
!CHECK: !$omp parallel master taskloop
68+
!$omp parallel master taskloop
69+
do i=1,10
70+
j = j + 1
71+
end do
72+
!$omp end parallel master taskloop
73+
end subroutine

flang/test/Semantics/OpenMP/clause-validity01.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,14 +476,14 @@
476476
! 2.13.1 master
477477

478478
!$omp parallel
479-
!WARNING: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
479+
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
480480
!$omp master
481481
a=3.14
482482
!$omp end master
483483
!$omp end parallel
484484

485485
!$omp parallel
486-
!WARNING: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
486+
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
487487
!ERROR: NUM_THREADS clause is not allowed on the MASTER directive
488488
!$omp master num_threads(4)
489489
a=3.14

0 commit comments

Comments
 (0)