Skip to content

Commit 6f6b7df

Browse files
[Flang][OpenMP] Add frontend support for directives involving master
Issue deprecation warning for these directives. Lowering currently supports parallel master, for all other combined or composite directives involving master, issue TODO errors.
1 parent 3edc459 commit 6f6b7df

File tree

11 files changed

+263
-6
lines changed

11 files changed

+263
-6
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_single,
215216
Directive::OMPD_target,

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,12 +572,19 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
572572
"MASKED TASKLOOP SIMD" >>
573573
pure(llvm::omp::Directive::OMPD_masked_taskloop_simd),
574574
"MASKED TASKLOOP" >> pure(llvm::omp::Directive::OMPD_masked_taskloop),
575+
"MASTER TASKLOOP SIMD" >>
576+
pure(llvm::omp::Directive::OMPD_master_taskloop_simd),
577+
"MASTER TASKLOOP" >> pure(llvm::omp::Directive::OMPD_master_taskloop),
575578
"PARALLEL DO SIMD" >> pure(llvm::omp::Directive::OMPD_parallel_do_simd),
576579
"PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_parallel_do),
577580
"PARALLEL MASKED TASKLOOP SIMD" >>
578581
pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd),
579582
"PARALLEL MASKED TASKLOOP" >>
580583
pure(llvm::omp::Directive::OMPD_parallel_masked_taskloop),
584+
"PARALLEL MASTER TASKLOOP SIMD" >>
585+
pure(llvm::omp::Directive::OMPD_parallel_master_taskloop_simd),
586+
"PARALLEL MASTER TASKLOOP" >>
587+
pure(llvm::omp::Directive::OMPD_parallel_master_taskloop),
581588
"SIMD" >> pure(llvm::omp::Directive::OMPD_simd),
582589
"TARGET LOOP" >> pure(llvm::omp::Directive::OMPD_target_loop),
583590
"TARGET PARALLEL DO SIMD" >>
@@ -695,6 +702,7 @@ TYPE_PARSER(construct<OmpBlockDirective>(first(
695702
"MASTER" >> pure(llvm::omp::Directive::OMPD_master),
696703
"ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered),
697704
"PARALLEL MASKED" >> pure(llvm::omp::Directive::OMPD_parallel_masked),
705+
"PARALLEL MASTER" >> pure(llvm::omp::Directive::OMPD_parallel_master),
698706
"PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare),
699707
"PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel),
700708
"SINGLE" >> pure(llvm::omp::Directive::OMPD_single),

flang/lib/Parser/unparse.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,12 @@ class UnparseVisitor {
22642264
case llvm::omp::Directive::OMPD_masked_taskloop:
22652265
Word("MASKED TASKLOOP");
22662266
break;
2267+
case llvm::omp::Directive::OMPD_master_taskloop_simd:
2268+
Word("MASTER TASKLOOP SIMD");
2269+
break;
2270+
case llvm::omp::Directive::OMPD_master_taskloop:
2271+
Word("MASTER TASKLOOP");
2272+
break;
22672273
case llvm::omp::Directive::OMPD_parallel_do:
22682274
Word("PARALLEL DO ");
22692275
break;
@@ -2276,6 +2282,12 @@ class UnparseVisitor {
22762282
case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
22772283
Word("PARALLEL MASKED TASKLOOP");
22782284
break;
2285+
case llvm::omp::Directive::OMPD_parallel_master_taskloop_simd:
2286+
Word("PARALLEL MASTER TASKLOOP SIMD");
2287+
break;
2288+
case llvm::omp::Directive::OMPD_parallel_master_taskloop:
2289+
Word("PARALLEL MASTER TASKLOOP");
2290+
break;
22792291
case llvm::omp::Directive::OMPD_simd:
22802292
Word("SIMD ");
22812293
break;
@@ -2380,6 +2392,9 @@ class UnparseVisitor {
23802392
case llvm::omp::Directive::OMPD_parallel_masked:
23812393
Word("PARALLEL MASKED");
23822394
break;
2395+
case llvm::omp::Directive::OMPD_parallel_master:
2396+
Word("PARALLEL MASTER");
2397+
break;
23832398
case llvm::omp::Directive::OMPD_parallel_workshare:
23842399
Word("PARALLEL WORKSHARE ");
23852400
break;

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
15241524
case llvm::omp::Directive::OMPD_masked:
15251525
case llvm::omp::Directive::OMPD_parallel_masked:
15261526
case llvm::omp::Directive::OMPD_master:
1527+
case llvm::omp::Directive::OMPD_parallel_master:
15271528
case llvm::omp::Directive::OMPD_ordered:
15281529
case llvm::omp::Directive::OMPD_parallel:
15291530
case llvm::omp::Directive::OMPD_single:
@@ -1542,7 +1543,8 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
15421543
// TODO others
15431544
break;
15441545
}
1545-
if (beginDir.v == llvm::omp::Directive::OMPD_master)
1546+
if (beginDir.v == llvm::omp::Directive::OMPD_master ||
1547+
beginDir.v == llvm::omp::Directive::OMPD_parallel_master)
15461548
IssueNonConformanceWarning(beginDir.v, beginDir.source);
15471549
ClearDataSharingAttributeObjects();
15481550
ClearPrivateDataSharingAttributeObjects();
@@ -1555,7 +1557,9 @@ void OmpAttributeVisitor::Post(const parser::OpenMPBlockConstruct &x) {
15551557
const auto &beginDir{std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
15561558
switch (beginDir.v) {
15571559
case llvm::omp::Directive::OMPD_masked:
1560+
case llvm::omp::Directive::OMPD_master:
15581561
case llvm::omp::Directive::OMPD_parallel_masked:
1562+
case llvm::omp::Directive::OMPD_parallel_master:
15591563
case llvm::omp::Directive::OMPD_parallel:
15601564
case llvm::omp::Directive::OMPD_single:
15611565
case llvm::omp::Directive::OMPD_target:
@@ -1625,10 +1629,14 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
16251629
case llvm::omp::Directive::OMPD_loop:
16261630
case llvm::omp::Directive::OMPD_masked_taskloop_simd:
16271631
case llvm::omp::Directive::OMPD_masked_taskloop:
1632+
case llvm::omp::Directive::OMPD_master_taskloop_simd:
1633+
case llvm::omp::Directive::OMPD_master_taskloop:
16281634
case llvm::omp::Directive::OMPD_parallel_do:
16291635
case llvm::omp::Directive::OMPD_parallel_do_simd:
16301636
case llvm::omp::Directive::OMPD_parallel_masked_taskloop_simd:
16311637
case llvm::omp::Directive::OMPD_parallel_masked_taskloop:
1638+
case llvm::omp::Directive::OMPD_parallel_master_taskloop_simd:
1639+
case llvm::omp::Directive::OMPD_parallel_master_taskloop:
16321640
case llvm::omp::Directive::OMPD_simd:
16331641
case llvm::omp::Directive::OMPD_target_loop:
16341642
case llvm::omp::Directive::OMPD_target_parallel_do:
@@ -1653,7 +1661,11 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
16531661
default:
16541662
break;
16551663
}
1656-
if (beginDir.v == llvm::omp::Directive::OMPD_target_loop)
1664+
if (beginDir.v == llvm::omp::OMPD_master_taskloop ||
1665+
beginDir.v == llvm::omp::OMPD_master_taskloop_simd ||
1666+
beginDir.v == llvm::omp::OMPD_parallel_master_taskloop ||
1667+
beginDir.v == llvm::omp::OMPD_parallel_master_taskloop_simd ||
1668+
beginDir.v == llvm::omp::Directive::OMPD_target_loop)
16571669
IssueNonConformanceWarning(beginDir.v, beginDir.source);
16581670
ClearDataSharingAttributeObjects();
16591671
SetContextAssociatedLoopLevel(GetAssociatedLoopLevelFromClauses(clauseList));
@@ -2882,7 +2894,10 @@ void OmpAttributeVisitor::IssueNonConformanceWarning(
28822894
llvm::omp::Directive D, parser::CharBlock source) {
28832895
std::string warnStr;
28842896
llvm::raw_string_ostream warnStrOS(warnStr);
2885-
warnStrOS << "OpenMP directive " << parser::ToUpperCaseLetters(llvm::omp::getOpenMPDirectiveName(D).str()) << " has been deprecated";
2897+
warnStrOS << "OpenMP directive "
2898+
<< parser::ToUpperCaseLetters(
2899+
llvm::omp::getOpenMPDirectiveName(D).str())
2900+
<< " has been deprecated";
28862901

28872902
auto setAlternativeStr = [&warnStrOS](llvm::StringRef alt) {
28882903
warnStrOS << ", please use " << alt << " instead.";
@@ -2891,11 +2906,25 @@ void OmpAttributeVisitor::IssueNonConformanceWarning(
28912906
case llvm::omp::OMPD_master:
28922907
setAlternativeStr("MASKED");
28932908
break;
2909+
case llvm::omp::OMPD_master_taskloop:
2910+
setAlternativeStr("MASKED TASKLOOP");
2911+
break;
2912+
case llvm::omp::OMPD_master_taskloop_simd:
2913+
setAlternativeStr("MASKED TASKLOOP SIMD");
2914+
break;
2915+
case llvm::omp::OMPD_parallel_master:
2916+
setAlternativeStr("PARALLEL MASKED");
2917+
break;
2918+
case llvm::omp::OMPD_parallel_master_taskloop:
2919+
setAlternativeStr("PARALLEL MASKED TASKLOOP");
2920+
break;
2921+
case llvm::omp::OMPD_parallel_master_taskloop_simd:
2922+
setAlternativeStr("PARALLEL_MASKED TASKLOOP SIMD");
28942923
break;
28952924
case llvm::omp::OMPD_target_loop:
2896-
default:
2925+
default:;
28972926
}
2898-
context_.Warn(
2899-
common::UsageWarning::OpenMPUsage, source, "%s"_warn_en_US, warnStrOS.str());
2927+
context_.Warn(common::UsageWarning::OpenMPUsage, source, "%s"_warn_en_US,
2928+
warnStrOS.str());
29002929
}
29012930
} // 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
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp -Werror
2+
3+
! Check for deprecation of master directive and its combined/composite variants
4+
5+
subroutine test_master()
6+
integer :: c = 1
7+
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
8+
!$omp master
9+
c = c + 1
10+
!$omp end master
11+
end subroutine
12+
13+
subroutine test_parallel_master
14+
integer :: c = 2
15+
!WARNING: OpenMP directive PARALLEL MASTER has been deprecated, please use PARALLEL MASKED instead.
16+
!$omp parallel master
17+
c = c + 2
18+
!$omp end parallel master
19+
end subroutine
20+
21+
subroutine test_master_taskloop_simd()
22+
integer :: i, j = 1
23+
!WARNING: OpenMP directive MASTER TASKLOOP SIMD has been deprecated, please use MASKED TASKLOOP SIMD instead.
24+
!$omp master taskloop simd
25+
do i=1,10
26+
j = j + 1
27+
end do
28+
!$omp end master taskloop simd
29+
end subroutine
30+
31+
subroutine test_master_taskloop
32+
integer :: i, j = 1
33+
!WARNING: OpenMP directive MASTER TASKLOOP has been deprecated, please use MASKED TASKLOOP instead.
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_taskloop_simd
42+
integer :: i, j = 1
43+
!WARNING: OpenMP directive PARALLEL MASTER TASKLOOP SIMD has been deprecated, please use PARALLEL_MASKED TASKLOOP SIMD instead.
44+
!$omp parallel master taskloop simd
45+
do i=1,10
46+
j = j + 1
47+
end do
48+
!$omp end parallel master taskloop simd
49+
end subroutine
50+
51+
subroutine test_parallel_master_taskloop
52+
integer :: i, j = 1
53+
!WARNING: OpenMP directive PARALLEL MASTER TASKLOOP has been deprecated, please use PARALLEL MASKED TASKLOOP instead.
54+
!$omp parallel master taskloop
55+
do i=1,10
56+
j = j + 1
57+
end do
58+
!$omp end parallel master taskloop
59+
end subroutine

0 commit comments

Comments
 (0)