Skip to content

Commit 6ad9565

Browse files
committed
[flang][OpenMP] Try to unify induction var privatization
This PR tries to unify the paths taken by flang to privatize the induction variable of loops. With the changes introduced here, both cases below are now privatized in the same way: ```fortran subroutine nested_constructs implicit none integer :: i !$omp parallel default(private) do i = 1, 10 end do !$omp end parallel end subroutine ``` ```fortran subroutine nested_constructs implicit none integer :: i !$omp parallel private(i) do i = 1, 10 end do !$omp end parallel end subroutine ```
1 parent d98a785 commit 6ad9565

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,6 @@ void OmpAttributeVisitor::ResolveSeqLoopIndexInParallelOrTaskConstruct(
16741674
// parallel or task
16751675
if (auto *symbol{ResolveOmp(iv, Symbol::Flag::OmpPrivate, targetIt->scope)}) {
16761676
targetIt++;
1677-
symbol->set(Symbol::Flag::OmpPreDetermined);
16781677
iv.symbol = symbol; // adjust the symbol within region
16791678
for (auto it{dirContext_.rbegin()}; it != targetIt; ++it) {
16801679
AddToContextObjectWithDSA(*symbol, Symbol::Flag::OmpPrivate, *it);

flang/test/Lower/OpenMP/default-clause.f90

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,16 +537,21 @@ subroutine nested_constructs
537537

538538
integer :: y, z
539539
!CHECK: omp.parallel {
540-
!CHECK: %[[INNER_J:.*]] = fir.alloca i32 {bindc_name = "j", pinned}
541-
!CHECK: %[[INNER_J_DECL:.*]]:2 = hlfir.declare %[[INNER_J]] {{.*}}
542-
!CHECK: %[[INNER_I:.*]] = fir.alloca i32 {bindc_name = "i", pinned}
543-
!CHECK: %[[INNER_I_DECL:.*]]:2 = hlfir.declare %[[INNER_I]] {{.*}}
540+
544541
!CHECK: %[[INNER_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_constructsEy"}
545542
!CHECK: %[[INNER_Y_DECL:.*]]:2 = hlfir.declare %[[INNER_Y]] {{.*}}
546543
!CHECK: %[[TEMP:.*]] = fir.load %[[Y_DECL]]#0 : !fir.ref<i32>
547544
!CHECK: hlfir.assign %[[TEMP]] to %[[INNER_Y_DECL]]#0 temporary_lhs : i32, !fir.ref<i32>
545+
546+
!CHECK: %[[INNER_I:.*]] = fir.alloca i32 {bindc_name = "i", pinned, uniq_name
547+
!CHECK: %[[INNER_I_DECL:.*]]:2 = hlfir.declare %[[INNER_I]] {{.*}}
548+
549+
!CHECK: %[[INNER_J:.*]] = fir.alloca i32 {bindc_name = "j", pinned, uniq_name
550+
!CHECK: %[[INNER_J_DECL:.*]]:2 = hlfir.declare %[[INNER_J]] {{.*}}
551+
548552
!CHECK: %[[INNER_Z:.*]] = fir.alloca i32 {bindc_name = "z", pinned, uniq_name = "_QFnested_constructsEz"}
549553
!CHECK: %[[INNER_Z_DECL:.*]]:2 = hlfir.declare %[[INNER_Z]] {{.*}}
554+
550555
!$omp parallel default(private) firstprivate(y)
551556
!CHECK: {{.*}} = fir.do_loop {{.*}} {
552557
do i = 1, 10

flang/test/Semantics/OpenMP/do05-positivecase.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ program omp_do
99
!DEF: /omp_do/n ObjectEntity INTEGER(4)
1010
integer i,n
1111
!$omp parallel
12-
!DEF: /omp_do/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
12+
!DEF: /omp_do/OtherConstruct1/i (OmpPrivate) HostAssoc INTEGER(4)
1313
do i=1,10
1414
!$omp single
1515
print *, "hello"

flang/test/Semantics/OpenMP/symbol08.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ subroutine test_do
3737
do j=6,10
3838
!REF: /test_do/a
3939
a(1,1,1) = 0.
40-
!DEF: /test_do/OtherConstruct1/k (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
40+
!DEF: /test_do/OtherConstruct1/k (OmpPrivate) HostAssoc INTEGER(4)
4141
do k=11,15
4242
!REF: /test_do/a
4343
!REF: /test_do/OtherConstruct1/k
@@ -170,9 +170,9 @@ subroutine test_simd
170170
!$omp parallel do simd
171171
!DEF: /test_simd/OtherConstruct1/i (OmpLinear, OmpPreDetermined) HostAssoc INTEGER(4)
172172
do i=1,5
173-
!DEF: /test_simd/OtherConstruct1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
173+
!DEF: /test_simd/OtherConstruct1/j (OmpPrivate) HostAssoc INTEGER(4)
174174
do j=6,10
175-
!DEF: /test_simd/OtherConstruct1/k (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
175+
!DEF: /test_simd/OtherConstruct1/k (OmpPrivate) HostAssoc INTEGER(4)
176176
do k=11,15
177177
!REF: /test_simd/a
178178
!REF: /test_simd/OtherConstruct1/k
@@ -228,7 +228,7 @@ subroutine test_seq_loop
228228
print *, i, j
229229
!$omp parallel
230230
!REF: /test_seq_loop/i
231-
!DEF: /test_seq_loop/OtherConstruct1/OtherConstruct1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
231+
!DEF: /test_seq_loop/OtherConstruct1/OtherConstruct1/j (OmpPrivate) HostAssoc INTEGER(4)
232232
print *, i, j
233233
!$omp do
234234
!DEF: /test_seq_loop/OtherConstruct1/OtherConstruct1/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)

0 commit comments

Comments
 (0)