Skip to content

Commit 1bd4f97

Browse files
authored
[flang][OpenMP] Put taskgroup in a new scope (#144122)
Although taskgroup is a privatizing construct, because of task_reduction clause, a new scope was not being created for it. This could cause an extra privatization of variables when taskgroup was lowered, because its scope would be the same as of the parent privatizing construct. This fixes regressions in tests 1052_0201 and 1052_0205, from Fujitsu testsuite. This issue didn't happen before because implicit symbols were being created in a different way before #142154.
1 parent 25dcd23 commit 1bd4f97

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,6 @@ bool OmpVisitor::NeedsScope(const parser::OpenMPBlockConstruct &x) {
17291729
switch (beginDir.v) {
17301730
case llvm::omp::Directive::OMPD_master:
17311731
case llvm::omp::Directive::OMPD_ordered:
1732-
case llvm::omp::Directive::OMPD_taskgroup:
17331732
return false;
17341733
default:
17351734
return true;

flang/test/Lower/OpenMP/implicit-dsa.f90

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
! Privatizers
77

8+
! CHECK-LABEL: omp.private
9+
! CHECK-SAME: {type = firstprivate} @[[TEST7_Y_FIRSTPRIV:.*]] : i32
10+
! CHECK-SAME: copy {
11+
12+
! CHECK-LABEL: omp.private
13+
! CHECK-SAME: {type = firstprivate} @[[TEST7_X_FIRSTPRIV:.*]] : i32
14+
! CHECK-SAME: copy {
15+
816
! CHECK-LABEL: omp.private
917
! CHECK-SAME: {type = private} @[[TEST6_Y_PRIV:.*]] : i32
1018
! CHECK-NOT: copy {
@@ -277,22 +285,19 @@ subroutine implicit_dsa_test6
277285
!$omp end task
278286
end subroutine
279287

280-
! Test taskgroup - it uses the same scope as task.
288+
! Test taskgroup.
281289
!CHECK-LABEL: func @_QPimplicit_dsa_test7
282290
!CHECK: %[[X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFimplicit_dsa_test7Ex"}
283291
!CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {uniq_name = "_QFimplicit_dsa_test7Ex"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
284292
!CHECK: %[[Y:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFimplicit_dsa_test7Ey"}
285293
!CHECK: %[[Y_DECL:.*]]:2 = hlfir.declare %[[Y]] {uniq_name = "_QFimplicit_dsa_test7Ey"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
286-
!CHECK: omp.task {
294+
!CHECK: omp.task private(@[[TEST7_X_FIRSTPRIV]] %[[X_DECL]]#0 -> %[[PRIV_X:[^,]*]],
295+
!CHECK-SAME: @[[TEST7_Y_FIRSTPRIV]] %[[Y_DECL]]#0 -> %[[PRIV_Y:.*]] : !fir.ref<i32>, !fir.ref<i32>) {
296+
!CHECK: %[[PRIV_X_DECL:.*]]:2 = hlfir.declare %[[PRIV_X]] {uniq_name = "_QFimplicit_dsa_test7Ex"}
297+
!CHECK: %[[PRIV_Y_DECL:.*]]:2 = hlfir.declare %[[PRIV_Y]] {uniq_name = "_QFimplicit_dsa_test7Ey"}
287298
!CHECK: omp.taskgroup {
288-
!CHECK-NEXT: %[[PRIV_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFimplicit_dsa_test7Ex"}
289-
!CHECK-NEXT: %[[PRIV_X_DECL:.*]]:2 = hlfir.declare %[[PRIV_X]] {uniq_name = "_QFimplicit_dsa_test7Ex"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
290-
!CHECK-NEXT: %[[TEMP:.*]] = fir.load %[[X_DECL]]#0 : !fir.ref<i32>
299+
!CHECK-NEXT: %[[TEMP:.*]] = fir.load %[[PRIV_Y_DECL]]#0 : !fir.ref<i32>
291300
!CHECK-NEXT: hlfir.assign %[[TEMP]] to %[[PRIV_X_DECL]]#0 : i32, !fir.ref<i32>
292-
!CHECK-NEXT: %[[PRIV_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFimplicit_dsa_test7Ey"}
293-
!CHECK-NEXT: %[[PRIV_Y_DECL:.*]]:2 = hlfir.declare %[[PRIV_Y]] {uniq_name = "_QFimplicit_dsa_test7Ey"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
294-
!CHECK-NEXT: %[[TEMP2:.*]] = fir.load %[[Y_DECL]]#0 : !fir.ref<i32>
295-
!CHECK-NEXT: hlfir.assign %[[TEMP2]] to %[[PRIV_Y_DECL]]#0 : i32, !fir.ref<i32>
296301
!CHECK: }
297302
!CHECK: }
298303
subroutine implicit_dsa_test7
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
2+
3+
! Check that variables are not privatized twice when TASKGROUP is used.
4+
5+
!CHECK-LABEL: func.func @_QPsub() {
6+
!CHECK: omp.parallel {
7+
!CHECK: %[[PAR_I:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFsubEi"}
8+
!CHECK: omp.master {
9+
!CHECK: omp.taskgroup {
10+
!CHECK-NEXT: omp.task private(@_QFsubEi_firstprivate_i32 %[[PAR_I]]#0 -> %[[TASK_I:.*]] : !fir.ref<i32>) {
11+
!CHECK: %[[TASK_I_DECL:.*]]:2 = hlfir.declare %[[TASK_I]] {uniq_name = "_QFsubEi"}
12+
!CHECK: }
13+
!CHECK: }
14+
!CHECK: }
15+
!CHECK: }
16+
17+
subroutine sub()
18+
integer, dimension(10) :: a
19+
integer :: i
20+
21+
!$omp parallel
22+
!$omp master
23+
do i=1,10
24+
!$omp taskgroup
25+
!$omp task shared(a)
26+
a(i) = 1
27+
!$omp end task
28+
!$omp end taskgroup
29+
end do
30+
!$omp end master
31+
!$omp end parallel
32+
end subroutine

flang/test/Semantics/OpenMP/implicit-dsa.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ subroutine implicit_dsa_test6
141141
!$omp end task
142142
end subroutine
143143

144-
! Test taskgroup - it uses the same scope as task.
144+
! Test taskgroup.
145145
!DEF: /implicit_dsa_test7 (Subroutine) Subprogram
146146
subroutine implicit_dsa_test7
147147
!DEF: /implicit_dsa_test7/x ObjectEntity INTEGER(4)
@@ -150,8 +150,8 @@ subroutine implicit_dsa_test7
150150

151151
!$omp task
152152
!$omp taskgroup
153-
!DEF: /implicit_dsa_test7/OtherConstruct1/x (OmpFirstPrivate, OmpImplicit) HostAssoc INTEGER(4)
154-
!DEF: /implicit_dsa_test7/OtherConstruct1/y (OmpFirstPrivate, OmpImplicit) HostAssoc INTEGER(4)
153+
!DEF: /implicit_dsa_test7/OtherConstruct1/OtherConstruct1/x HostAssoc INTEGER(4)
154+
!DEF: /implicit_dsa_test7/OtherConstruct1/OtherConstruct1/y HostAssoc INTEGER(4)
155155
x = y
156156
!$omp end taskgroup
157157
!$omp end task

0 commit comments

Comments
 (0)