Skip to content

Commit fddca99

Browse files
[Flang][OpenMP] : Add a temporary lowering for workshare directive
As a temporary solution, lower workshare to the single directive.
1 parent 8a87f76 commit fddca99

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,11 @@ genOMP(Fortran::lower::AbstractConverter &converter,
17401740
/*outerCombined=*/false);
17411741
break;
17421742
case llvm::omp::Directive::OMPD_workshare:
1743-
TODO(currentLocation, "Workshare construct");
1743+
// FIXME: Workshare is not a commonly used OpenMP construct, an
1744+
// implementation for this feature will come later. For the codes
1745+
// that use this construct, add a single construct for now.
1746+
genSingleOp(converter, semaCtx, eval, /*genNested=*/true, currentLocation,
1747+
beginClauseList, endClauseList);
17441748
break;
17451749
default:
17461750
singleDirective = false;
@@ -1775,7 +1779,8 @@ genOMP(Fortran::lower::AbstractConverter &converter,
17751779
}
17761780
if ((llvm::omp::workShareSet & llvm::omp::blockConstructSet)
17771781
.test(directive.v)) {
1778-
TODO(currentLocation, "Workshare construct");
1782+
genSingleOp(converter, semaCtx, eval, /*genNested=*/false, currentLocation,
1783+
beginClauseList, endClauseList);
17791784
combinedDirective = true;
17801785
}
17811786
if (!combinedDirective)

flang/test/Lower/OpenMP/workshare.f90

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
3+
4+
!CHECK-LABEL: func @_QPsb1
5+
subroutine sb1(arr)
6+
integer :: arr(:)
7+
!CHECK: omp.parallel {
8+
!$omp parallel
9+
!CHECK: omp.single {
10+
!$omp workshare
11+
arr = 0
12+
!$omp end workshare
13+
!CHECK: }
14+
!$omp end parallel
15+
!CHECK: }
16+
end subroutine
17+
18+
!CHECK-LABEL: func @_QPsb2
19+
subroutine sb2(arr)
20+
integer :: arr(:)
21+
!CHECK: omp.parallel {
22+
!$omp parallel
23+
!CHECK: omp.single nowait {
24+
!$omp workshare
25+
arr = 0
26+
!$omp end workshare nowait
27+
!CHECK: }
28+
!$omp end parallel
29+
!CHECK: }
30+
end subroutine
31+
32+
!CHECK-LABEL: func @_QPsb3
33+
subroutine sb3(arr)
34+
integer :: arr(:)
35+
!CHECK: omp.parallel {
36+
!CHECK: omp.single {
37+
!$omp parallel workshare
38+
arr = 0
39+
!$omp end parallel workshare
40+
!CHECK: }
41+
!CHECK: }
42+
end subroutine

0 commit comments

Comments
 (0)