Skip to content

Commit b585c43

Browse files
[Flang][OpenMP] : Add a temporary lowering for workshare directive (#78268)
As a temporary solution, lower workshare to the single directive
1 parent 0709eeb commit b585c43

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
@@ -1810,7 +1810,11 @@ genOMP(Fortran::lower::AbstractConverter &converter,
18101810
/*outerCombined=*/false);
18111811
break;
18121812
case llvm::omp::Directive::OMPD_workshare:
1813-
TODO(currentLocation, "Workshare construct");
1813+
// FIXME: Workshare is not a commonly used OpenMP construct, an
1814+
// implementation for this feature will come later. For the codes
1815+
// that use this construct, add a single construct for now.
1816+
genSingleOp(converter, semaCtx, eval, /*genNested=*/true, currentLocation,
1817+
beginClauseList, endClauseList);
18141818
break;
18151819
default:
18161820
singleDirective = false;
@@ -1845,7 +1849,8 @@ genOMP(Fortran::lower::AbstractConverter &converter,
18451849
}
18461850
if ((llvm::omp::workShareSet & llvm::omp::blockConstructSet)
18471851
.test(directive.v)) {
1848-
TODO(currentLocation, "Workshare construct");
1852+
genSingleOp(converter, semaCtx, eval, /*genNested=*/false, currentLocation,
1853+
beginClauseList, endClauseList);
18491854
combinedDirective = true;
18501855
}
18511856
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)