Skip to content

Commit 7d7cb1e

Browse files
ergawygithub-actions[bot]
authored andcommitted
Automerge: [flang][OpenMP] Enable delayed privatization by default omp.wsloop (#122471)
This enable delayed privatization by default for `omp.wsloop` ops, with one caveat! I had to workaround the "impure" alloc region issue that being resolved at the moment. The workaround detects whether the alloc region's argument is used in the region and at the same time defined in block that does not dominate the chosen alloca insertion point. If so, we move the alloca insertion point below the defining instruction of the alloc region argument. This basically reverts to the non-delayed-privatizaiton behavior.
2 parents 2e56936 + 6f82408 commit 7d7cb1e

File tree

73 files changed

+448
-563
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+448
-563
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2511,7 +2511,7 @@ static void genStandaloneDo(lower::AbstractConverter &converter,
25112511

25122512
DataSharingProcessor dsp(converter, semaCtx, item->clauses, eval,
25132513
/*shouldCollectPreDeterminedSymbols=*/true,
2514-
enableDelayedPrivatizationStaging, symTable);
2514+
enableDelayedPrivatization, symTable);
25152515
dsp.processStep1(&wsloopClauseOps);
25162516

25172517
mlir::omp::LoopNestOperands loopNestClauseOps;

flang/test/Lower/OpenMP/DelayedPrivatization/wsloop.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --openmp-enable-delayed-privatization-staging \
1+
! RUN: %flang_fc1 -emit-hlfir -fopenmp \
22
! RUN: -o - %s 2>&1 | FileCheck %s
3-
! RUN: bbc -emit-hlfir -fopenmp --openmp-enable-delayed-privatization-staging -o - %s 2>&1 \
3+
! RUN: bbc -emit-hlfir -fopenmp -o - %s 2>&1 \
44
! RUN: | FileCheck %s
55

66
subroutine wsloop_private

flang/test/Lower/OpenMP/Todo/omp-default-clause-inner-loop.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
! The string "EXPECTED" denotes the expected FIR
1010

1111
! CHECK: omp.parallel private(@{{.*}} %{{.*}} -> %[[PRIVATE_Y:.*]], @{{.*}} %{{.*}} -> %[[PRIVATE_Y:.*]] : !fir.ref<i32>, !fir.ref<i32>) {
12-
! CHECK: %[[TEMP:.*]] = fir.alloca i32 {bindc_name = "x", pinned, {{.*}}}
1312
! CHECK: %[[const_1:.*]] = arith.constant 1 : i32
1413
! CHECK: %[[const_2:.*]] = arith.constant 10 : i32
1514
! CHECK: %[[const_3:.*]] = arith.constant 1 : i32
16-
! CHECK: omp.wsloop {
15+
! CHECK: omp.wsloop private(@{{.*}} %{{.*}} -> %[[TEMP:.*]] : !fir.ref<i32>) {
1716
! CHECK-NEXT: omp.loop_nest (%[[ARG:.*]]) : i32 = (%[[const_1]]) to (%[[const_2]]) inclusive step (%[[const_3]]) {
1817
! CHECK: fir.store %[[ARG]] to %[[TEMP]] : !fir.ref<i32>
1918
! EXPECTED: %[[temp_1:.*]] = fir.load %[[PRIVATE_Z]] : !fir.ref<i32>

flang/test/Lower/OpenMP/associate.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
!CHECK: omp.parallel {
77
!CHECK-NOT: hlfir.declare {{.*}} {uniq_name = "_QFtest_parallel_assocEa"}
88
!CHECK-NOT: hlfir.declare {{.*}} {uniq_name = "_QFtest_parallel_assocEb"}
9-
!CHECK: omp.wsloop {
9+
!CHECK: omp.wsloop private({{.*}}) {
1010
!CHECK: }
1111
!CHECK: }
1212
!CHECK: omp.parallel {{.*}} {
1313
!CHECK-NOT: hlfir.declare {{.*}} {uniq_name = "_QFtest_parallel_assocEb"}
14-
!CHECK: omp.wsloop {
14+
!CHECK: omp.wsloop private({{.*}}) {
1515
!CHECK: }
1616
!CHECK: }
1717
subroutine test_parallel_assoc()

flang/test/Lower/OpenMP/copyin.f90

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,13 @@ subroutine copyin_derived_type()
154154

155155
! CHECK: omp.barrier
156156

157-
! CHECK: %[[VAL_6:.*]] = fir.alloca i32 {bindc_name = "i", pinned, {{.*}}}
158-
! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_6]] {uniq_name = "_QFcombined_parallel_worksharing_loopEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
159157

160158
! CHECK: %[[VAL_11:.*]] = arith.constant 1 : i32
161159
! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_9]]#0 : !fir.ref<i32>
162160
! CHECK: %[[VAL_13:.*]] = arith.constant 1 : i32
163-
! CHECK: omp.wsloop {
161+
! CHECK: omp.wsloop private(@{{.*}} %{{.*}} -> %[[VAL_6:.*]] : !fir.ref<i32>) {
164162
! CHECK-NEXT: omp.loop_nest (%[[VAL_14:.*]]) : i32 = (%[[VAL_11]]) to (%[[VAL_12]]) inclusive step (%[[VAL_13]]) {
163+
! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_6]] {uniq_name = "_QFcombined_parallel_worksharing_loopEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
165164
! CHECK: fir.store %[[VAL_14]] to %[[VAL_7]]#1 : !fir.ref<i32>
166165
! CHECK: fir.call @_QPsub4(%[[VAL_9]]#1) fastmath<contract> : (!fir.ref<i32>) -> ()
167166
! CHECK: omp.yield
@@ -321,15 +320,12 @@ subroutine common_1()
321320
! CHECK: %[[VAL_33:.*]] = fir.load %[[VAL_18]]#0 : !fir.ref<i32>
322321
! CHECK: hlfir.assign %[[VAL_33]] to %[[VAL_31]]#0 : i32, !fir.ref<i32>
323322
! CHECK: omp.barrier
324-
325-
! CHECK: %[[VAL_19:.*]] = fir.alloca i32 {bindc_name = "i", pinned, {{.*}}}
326-
! CHECK: %[[VAL_20:.*]]:2 = hlfir.declare %[[VAL_19]] {uniq_name = "_QFcommon_2Ei"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
327-
328323
! CHECK: %[[VAL_34:.*]] = arith.constant 1 : i32
329324
! CHECK: %[[VAL_35:.*]] = fir.load %[[VAL_26]]#0 : !fir.ref<i32>
330325
! CHECK: %[[VAL_36:.*]] = arith.constant 1 : i32
331-
! CHECK: omp.wsloop {
326+
! CHECK: omp.wsloop private(@{{.*}} %{{.*}} -> %[[VAL_19:.*]] : !fir.ref<i32>) {
332327
! CHECK-NEXT: omp.loop_nest (%[[VAL_37:.*]]) : i32 = (%[[VAL_34]]) to (%[[VAL_35]]) inclusive step (%[[VAL_36]]) {
328+
! CHECK: %[[VAL_20:.*]]:2 = hlfir.declare %[[VAL_19]] {uniq_name = "_QFcommon_2Ei"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
333329
! CHECK: fir.store %[[VAL_37]] to %[[VAL_20]]#1 : !fir.ref<i32>
334330
! CHECK: %[[VAL_38:.*]] = fir.load %[[VAL_31]]#0 : !fir.ref<i32>
335331
! CHECK: %[[VAL_39:.*]] = fir.load %[[VAL_20]]#0 : !fir.ref<i32>

flang/test/Lower/OpenMP/critical.f90

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ subroutine predetermined_privatization()
3838
!CHECK: omp.parallel
3939
!$omp parallel do
4040

41-
!CHECK: %[[PRIV_I_ALLOC:.*]] = fir.alloca i32 {bindc_name = "i", pinned, {{.*}}}
42-
!CHECK: %[[PRIV_I_DECL:.*]]:2 = hlfir.declare %[[PRIV_I_ALLOC]]
4341
do i = 2, 10
44-
!CHECK: omp.wsloop
42+
!CHECK: omp.wsloop private(@{{.*}} %{{.*}} -> %[[PRIV_I_ALLOC:.*]] : !fir.ref<i32>)
4543
!CHECK: omp.loop_nest (%[[IV:[^[:space:]]+]])
44+
!CHECK: %[[PRIV_I_DECL:.*]]:2 = hlfir.declare %[[PRIV_I_ALLOC]]
4645
!CHECK: fir.store %[[IV]] to %[[PRIV_I_DECL]]#1
4746
!CHECK: omp.critical
4847
!$omp critical

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ subroutine skipped_default_clause_checks()
346346
type(it)::iii
347347

348348
!CHECK: omp.parallel {{.*}} {
349-
!CHECK: omp.wsloop reduction(byref @min_byref_i32 %[[VAL_Z_DECLARE]]#0 -> %[[PRV:.+]] : !fir.ref<i32>) {
349+
!CHECK: omp.wsloop private({{.*}}) reduction(byref @min_byref_i32 %[[VAL_Z_DECLARE]]#0 -> %[[PRV:.+]] : !fir.ref<i32>) {
350350
!CHECK-NEXT: omp.loop_nest (%[[ARG:.*]]) {{.*}} {
351351
!CHECK: omp.yield
352352
!CHECK: }

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,13 @@ subroutine nested_default_clause_test4
284284
!CHECK-LABEL: func @_QPnested_default_clause_test5
285285
!CHECK: omp.parallel {
286286

287-
!CHECK: %[[X_ALLOCA:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_test5Ex"}
288-
!CHECK: %[[X_DECLARE:.*]]:2 = hlfir.declare %[[X_ALLOCA]] {{.*}}
289-
290-
!CHECK: %[[LOOP_VAR_ALLOCA:.*]] = fir.alloca i32 {bindc_name = "i", pinned, {{.*}}}
291-
!CHECK: %[[LOOP_VAR_DECLARE:.*]]:2 = hlfir.declare %[[LOOP_VAR_ALLOCA]] {{.*}}
292-
293287
!CHECK: %[[CONST_LB:.*]] = arith.constant 1 : i32
294288
!CHECK: %[[CONST_UB:.*]] = arith.constant 50 : i32
295289
!CHECK: %[[CONST_STEP:.*]] = arith.constant 1 : i32
290+
! CHECK: omp.wsloop private(@{{.*}} %{{.*}} -> %[[X_ALLOCA:.*]], @{{.*}} %{{.*}} -> %[[LOOP_VAR_ALLOCA:.*]] : !fir.ref<i32>, !fir.ref<i32>) {
296291
!CHECK: omp.loop_nest (%[[ARG:.*]]) : i32 = (%[[CONST_LB]]) to (%[[CONST_UB]]) inclusive step (%[[CONST_STEP]]) {
292+
!CHECK: %[[X_DECLARE:.*]]:2 = hlfir.declare %[[X_ALLOCA]] {{.*}}
293+
!CHECK: %[[LOOP_VAR_DECLARE:.*]]:2 = hlfir.declare %[[LOOP_VAR_ALLOCA]] {{.*}}
297294
!CHECK: fir.store %[[ARG]] to %[[LOOP_VAR_DECLARE]]#1 : !fir.ref<i32>
298295
!CHECK: %[[LOADED_X:.*]] = fir.load %[[X_DECLARE]]#0 : !fir.ref<i32>
299296
!CHECK: %[[CONST:.*]] = arith.constant 1 : i32
@@ -321,13 +318,12 @@ subroutine nested_default_clause_test5
321318

322319
!CHECK: %[[Z_VAR_DECLARE:.*]]:2 = hlfir.declare %[[Z_VAR]] {{.*}}
323320

324-
!CHECK: %[[LOOP_VAR:.*]] = fir.alloca i32 {bindc_name = "i", pinned, {{.*}}}
325-
!CHECK: %[[LOOP_VAR_DECLARE:.*]]:2 = hlfir.declare %[[LOOP_VAR]] {{.*}}
326-
327321
!CHECK: %[[CONST_LB:.*]] = arith.constant 1 : i32
328322
!CHECK: %[[CONST_UB:.*]] = arith.constant 10 : i32
329323
!CHECK: %[[CONST_STEP:.*]] = arith.constant 1 : i32
324+
! CHECK: omp.wsloop private(@{{.*}} %{{.*}} -> %[[LOOP_VAR:.*]] : !fir.ref<i32>) {
330325
!CHECK: omp.loop_nest (%[[ARG:.*]]) : i32 = (%[[CONST_LB]]) to (%[[CONST_UB]]) inclusive step (%[[CONST_STEP]]) {
326+
!CHECK: %[[LOOP_VAR_DECLARE:.*]]:2 = hlfir.declare %[[LOOP_VAR]] {{.*}}
331327
!CHECK: fir.store %[[ARG]] to %[[LOOP_VAR_DECLARE]]#1 : !fir.ref<i32>
332328
!CHECK: %[[LOADED_X:.*]] = fir.load %[[X_VAR_DECLARE]]#0 : !fir.ref<i32>
333329
!CHECK: %[[CONST:.*]] = arith.constant 1 : i32
@@ -386,7 +382,7 @@ subroutine skipped_default_clause_checks()
386382
type(it)::iii
387383

388384
!CHECK: omp.parallel {{.*}} {
389-
!CHECK: omp.wsloop reduction(@min_i32 %[[VAL_Z_DECLARE]]#0 -> %[[PRV:.+]] : !fir.ref<i32>) {
385+
!CHECK: omp.wsloop private({{.*}}) reduction(@min_i32 %[[VAL_Z_DECLARE]]#0 -> %[[PRV:.+]] : !fir.ref<i32>) {
390386
!CHECK-NEXT: omp.loop_nest (%[[ARG:.*]]) {{.*}} {
391387
!CHECK: omp.yield
392388
!CHECK: }

flang/test/Lower/OpenMP/hlfir-wsloop.f90

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ subroutine simple_loop
1010
! CHECK-DAG: %[[WS_END:.*]] = arith.constant 9 : i32
1111
! CHECK: omp.parallel
1212
!$OMP PARALLEL
13-
! CHECK-DAG: %[[ALLOCA_IV:.*]] = fir.alloca i32 {{{.*}}, pinned, {{.*}}}
14-
! CHECK: %[[IV:.*]] = fir.declare %[[ALLOCA_IV]] {uniq_name = "_QFsimple_loopEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
15-
! CHECK: omp.wsloop {
13+
! CHECK: omp.wsloop private(@{{.*}} %{{.*}} -> %[[ALLOCA_IV:.*]] : !fir.ref<i32>) {
1614
! CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[WS_ST]]) to (%[[WS_END]]) inclusive step (%[[WS_ST]]) {
1715
!$OMP DO
1816
do i=1, 9
17+
! CHECK: %[[IV:.*]] = fir.declare %[[ALLOCA_IV]] {uniq_name = "_QFsimple_loopEi"} : (!fir.ref<i32>) -> !fir.ref<i32>
1918
! CHECK: fir.store %[[I]] to %[[IV:.*]] : !fir.ref<i32>
2019
! CHECK: %[[LOAD_IV:.*]] = fir.load %[[IV]] : !fir.ref<i32>
2120
! CHECK: fir.call @_FortranAioOutputInteger32({{.*}}, %[[LOAD_IV]]) {{.*}}: (!fir.ref<i8>, i32) -> i1

flang/test/Lower/OpenMP/lastprivate-allocatable.f90

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
! CHECK: fir.store %[[VAL_2]] to %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<i32>>>
99
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0]] {fortran_attrs = {{.*}}<allocatable>, uniq_name = "_QFEa"} : (!fir.ref<!fir.box<!fir.heap<i32>>>) -> (!fir.ref<!fir.box<!fir.heap<i32>>>, !fir.ref<!fir.box<!fir.heap<i32>>>)
1010
! CHECK: omp.parallel {
11-
! create original copy of private variable
12-
! CHECK: %[[VAL_16:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = {{.*}}<allocatable>, uniq_name = "_QFEa"} : (!fir.ref<!fir.box<!fir.heap<i32>>>) -> (!fir.ref<!fir.box<!fir.heap<i32>>>, !fir.ref<!fir.box<!fir.heap<i32>>>)
13-
! CHECK: %[[VAL_17:.*]] = fir.alloca i32 {bindc_name = "i", pinned, uniq_name = "_QFEi"}
14-
! CHECK: %[[VAL_18:.*]]:2 = hlfir.declare %[[VAL_17]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
15-
! CHECK: omp.wsloop {
11+
! CHECK: omp.wsloop private(@{{.*}} %{{.*}} -> %{{.*}}, @{{.*}} %{{.*}} -> %[[VAL_17:.*]] : !fir.ref<!fir.box<!fir.heap<i32>>>, !fir.ref<i32>) {
1612
! CHECK: omp.loop_nest
13+
! CHECK: %[[VAL_16:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = {{.*}}<allocatable>, uniq_name = "_QFEa"} : (!fir.ref<!fir.box<!fir.heap<i32>>>) -> (!fir.ref<!fir.box<!fir.heap<i32>>>, !fir.ref<!fir.box<!fir.heap<i32>>>)
14+
! CHECK: %[[VAL_18:.*]]:2 = hlfir.declare %[[VAL_17]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
15+
1716
! [...]
1817
! if this is the last iteration
1918
! CHECK: fir.if %{{.*}} {

0 commit comments

Comments
 (0)