Skip to content

Commit 5b66987

Browse files
[Flang][OpenMP] NFC: Port worksharing loop tests to HLFIR lowering
These are copies of tests in ../flang/test/Lower/OpenMP/FIR/wsloop-*
1 parent af47517 commit 5b66987

18 files changed

+1933
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
! This test checks that chunk size is passed correctly when lowering of
2+
! OpenMP DO Directive(Worksharing) with chunk size
3+
4+
! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
5+
6+
program wsloop
7+
integer :: i
8+
integer :: chunk
9+
10+
! CHECK-LABEL: func.func @_QQmain() attributes {fir.bindc_name = "wsloop"} {
11+
! CHECK: %[[CHUNK_REF:.*]] = fir.alloca i32 {bindc_name = "chunk", uniq_name = "_QFEchunk"}
12+
! CHECK: %[[VAL_0:.*]]:2 = hlfir.declare %[[CHUNK_REF]] {uniq_name = "_QFEchunk"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
13+
14+
!$OMP DO SCHEDULE(static, 4)
15+
16+
do i=1, 9
17+
print*, i
18+
19+
! CHECK: %[[VAL_2:.*]] = arith.constant 1 : i32
20+
! CHECK: %[[VAL_3:.*]] = arith.constant 9 : i32
21+
! CHECK: %[[VAL_4:.*]] = arith.constant 1 : i32
22+
! CHECK: %[[VAL_5:.*]] = arith.constant 4 : i32
23+
! CHECK: omp.wsloop schedule(static = %[[VAL_5]] : i32) nowait for (%[[ARG0:.*]]) : i32 = (%[[VAL_2]]) to (%[[VAL_3]]) inclusive step (%[[VAL_4]]) {
24+
! CHECK: fir.store %[[ARG0]] to %[[STORE_IV:.*]]#1 : !fir.ref<i32>
25+
! CHECK: %[[LOAD_IV:.*]] = fir.load %[[STORE_IV]]#0 : !fir.ref<i32>
26+
! CHECK: {{.*}} = fir.call @_FortranAioOutputInteger32({{.*}}, %[[LOAD_IV]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
27+
! CHECK: omp.yield
28+
! CHECK: }
29+
30+
end do
31+
!$OMP END DO NOWAIT
32+
!$OMP DO SCHEDULE(static, 2+2)
33+
34+
do i=1, 9
35+
print*, i*2
36+
37+
! CHECK: %[[VAL_14:.*]] = arith.constant 1 : i32
38+
! CHECK: %[[VAL_15:.*]] = arith.constant 9 : i32
39+
! CHECK: %[[VAL_16:.*]] = arith.constant 1 : i32
40+
! CHECK: %[[VAL_17:.*]] = arith.constant 4 : i32
41+
! CHECK: omp.wsloop schedule(static = %[[VAL_17]] : i32) nowait for (%[[ARG1:.*]]) : i32 = (%[[VAL_14]]) to (%[[VAL_15]]) inclusive step (%[[VAL_16]]) {
42+
! CHECK: fir.store %[[ARG1]] to %[[STORE_IV1:.*]]#1 : !fir.ref<i32>
43+
! CHECK: %[[VAL_24:.*]] = arith.constant 2 : i32
44+
! CHECK: %[[LOAD_IV1:.*]] = fir.load %[[STORE_IV1]]#0 : !fir.ref<i32>
45+
! CHECK: %[[VAL_25:.*]] = arith.muli %[[VAL_24]], %[[LOAD_IV1]] : i32
46+
! CHECK: {{.*}} = fir.call @_FortranAioOutputInteger32({{.*}}, %[[VAL_25]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
47+
! CHECK: omp.yield
48+
! CHECK: }
49+
50+
end do
51+
!$OMP END DO NOWAIT
52+
chunk = 6
53+
!$OMP DO SCHEDULE(static, chunk)
54+
55+
do i=1, 9
56+
print*, i*3
57+
end do
58+
!$OMP END DO NOWAIT
59+
! CHECK: %[[VAL_28:.*]] = arith.constant 6 : i32
60+
! CHECK: hlfir.assign %[[VAL_28]] to %[[VAL_0]]#0 : i32, !fir.ref<i32>
61+
! CHECK: %[[VAL_29:.*]] = arith.constant 1 : i32
62+
! CHECK: %[[VAL_30:.*]] = arith.constant 9 : i32
63+
! CHECK: %[[VAL_31:.*]] = arith.constant 1 : i32
64+
! CHECK: %[[VAL_32:.*]] = fir.load %[[VAL_0]]#0 : !fir.ref<i32>
65+
! CHECK: omp.wsloop schedule(static = %[[VAL_32]] : i32) nowait for (%[[ARG2:.*]]) : i32 = (%[[VAL_29]]) to (%[[VAL_30]]) inclusive step (%[[VAL_31]]) {
66+
! CHECK: fir.store %[[ARG2]] to %[[STORE_IV2:.*]]#1 : !fir.ref<i32>
67+
! CHECK: %[[VAL_39:.*]] = arith.constant 3 : i32
68+
! CHECK: %[[LOAD_IV2:.*]] = fir.load %[[STORE_IV2]]#0 : !fir.ref<i32>
69+
! CHECK: %[[VAL_40:.*]] = arith.muli %[[VAL_39]], %[[LOAD_IV2]] : i32
70+
! CHECK: {{.*}} = fir.call @_FortranAioOutputInteger32({{.*}}, %[[VAL_40]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
71+
! CHECK: omp.yield
72+
! CHECK: }
73+
! CHECK: return
74+
! CHECK: }
75+
76+
end
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
! This test checks lowering of OpenMP DO Directive(Worksharing) with collapse.
2+
3+
! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
4+
5+
!CHECK-LABEL: func.func @_QQmain() attributes {fir.bindc_name = "wsloop_collapse"} {
6+
program wsloop_collapse
7+
!CHECK: %[[VAL_0:.*]] = fir.alloca i32 {adapt.valuebyref, pinned}
8+
!CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFEk"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
9+
!CHECK: %[[VAL_2:.*]] = fir.alloca i32 {adapt.valuebyref, pinned}
10+
!CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_2]] {uniq_name = "_QFEj"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
11+
!CHECK: %[[VAL_4:.*]] = fir.alloca i32 {adapt.valuebyref, pinned}
12+
!CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_4]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
13+
!CHECK: %[[VAL_6:.*]] = fir.alloca i32 {bindc_name = "a", uniq_name = "_QFEa"}
14+
!CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_6]] {uniq_name = "_QFEa"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
15+
!CHECK: %[[VAL_8:.*]] = fir.alloca i32 {bindc_name = "b", uniq_name = "_QFEb"}
16+
!CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_8]] {uniq_name = "_QFEb"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
17+
!CHECK: %[[VAL_10:.*]] = fir.alloca i32 {bindc_name = "c", uniq_name = "_QFEc"}
18+
!CHECK: %[[VAL_11:.*]]:2 = hlfir.declare %[[VAL_10]] {uniq_name = "_QFEc"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
19+
!CHECK: %[[VAL_12:.*]] = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
20+
!CHECK: %[[VAL_13:.*]]:2 = hlfir.declare %[[VAL_12]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
21+
!CHECK: %[[VAL_14:.*]] = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFEj"}
22+
!CHECK: %[[VAL_15:.*]]:2 = hlfir.declare %[[VAL_14]] {uniq_name = "_QFEj"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
23+
!CHECK: %[[VAL_16:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFEk"}
24+
!CHECK: %[[VAL_17:.*]]:2 = hlfir.declare %[[VAL_16]] {uniq_name = "_QFEk"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
25+
!CHECK: %[[VAL_18:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
26+
!CHECK: %[[VAL_19:.*]]:2 = hlfir.declare %[[VAL_18]] {uniq_name = "_QFEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
27+
integer :: i, j, k
28+
integer :: a, b, c
29+
integer :: x
30+
!CHECK: %[[VAL_20:.*]] = arith.constant 3 : i32
31+
!CHECK: hlfir.assign %[[VAL_20]] to %[[VAL_7]]#0 : i32, !fir.ref<i32>
32+
a=3
33+
!CHECK: %[[VAL_21:.*]] = arith.constant 2 : i32
34+
!CHECK: hlfir.assign %[[VAL_21]] to %[[VAL_9]]#0 : i32, !fir.ref<i32>
35+
b=2
36+
!CHECK: %[[VAL_22:.*]] = arith.constant 5 : i32
37+
!CHECK: hlfir.assign %[[VAL_22]] to %[[VAL_11]]#0 : i32, !fir.ref<i32>
38+
c=5
39+
!CHECK: %[[VAL_23:.*]] = arith.constant 0 : i32
40+
!CHECK: hlfir.assign %[[VAL_23]] to %[[VAL_19]]#0 : i32, !fir.ref<i32>
41+
x=0
42+
43+
!CHECK: %[[VAL_24:.*]] = arith.constant 1 : i32
44+
!CHECK: %[[VAL_25:.*]] = fir.load %[[VAL_7]]#0 : !fir.ref<i32>
45+
!CHECK: %[[VAL_26:.*]] = arith.constant 1 : i32
46+
!CHECK: %[[VAL_27:.*]] = arith.constant 1 : i32
47+
!CHECK: %[[VAL_28:.*]] = fir.load %[[VAL_9]]#0 : !fir.ref<i32>
48+
!CHECK: %[[VAL_29:.*]] = arith.constant 1 : i32
49+
!CHECK: %[[VAL_30:.*]] = arith.constant 1 : i32
50+
!CHECK: %[[VAL_31:.*]] = fir.load %[[VAL_11]]#0 : !fir.ref<i32>
51+
!CHECK: %[[VAL_32:.*]] = arith.constant 1 : i32
52+
!CHECK: omp.wsloop for (%[[VAL_33:.*]], %[[VAL_34:.*]], %[[VAL_35:.*]]) : i32 = (%[[VAL_24]], %[[VAL_27]], %[[VAL_30]]) to (%[[VAL_25]], %[[VAL_28]], %[[VAL_31]]) inclusive step (%[[VAL_26]], %[[VAL_29]], %[[VAL_32]]) {
53+
!$omp do collapse(3)
54+
do i = 1, a
55+
do j= 1, b
56+
do k = 1, c
57+
!CHECK: fir.store %[[VAL_33]] to %[[VAL_5]]#1 : !fir.ref<i32>
58+
!CHECK: fir.store %[[VAL_34]] to %[[VAL_3]]#1 : !fir.ref<i32>
59+
!CHECK: fir.store %[[VAL_35]] to %[[VAL_1]]#1 : !fir.ref<i32>
60+
!CHECK: %[[VAL_36:.*]] = fir.load %[[VAL_19]]#0 : !fir.ref<i32>
61+
!CHECK: %[[VAL_37:.*]] = fir.load %[[VAL_5]]#0 : !fir.ref<i32>
62+
!CHECK: %[[VAL_38:.*]] = arith.addi %[[VAL_36]], %[[VAL_37]] : i32
63+
!CHECK: %[[VAL_39:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i32>
64+
!CHECK: %[[VAL_40:.*]] = arith.addi %[[VAL_38]], %[[VAL_39]] : i32
65+
!CHECK: %[[VAL_41:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<i32>
66+
!CHECK: %[[VAL_42:.*]] = arith.addi %[[VAL_40]], %[[VAL_41]] : i32
67+
!CHECK: hlfir.assign %[[VAL_42]] to %[[VAL_19]]#0 : i32, !fir.ref<i32>
68+
!CHECK: omp.yield
69+
x = x + i + j + k
70+
end do
71+
end do
72+
end do
73+
!CHECK: }
74+
!$omp end do
75+
!CHECK: return
76+
!CHECK: }
77+
end program wsloop_collapse
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
! This test checks lowering of OpenMP DO Directive (Worksharing) with
2+
! monotonic schedule modifier.
3+
4+
! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
5+
6+
program wsloop_dynamic
7+
integer :: i
8+
!CHECK-LABEL: func @_QQmain()
9+
10+
!$OMP PARALLEL
11+
!CHECK: omp.parallel {
12+
13+
!$OMP DO SCHEDULE(monotonic:dynamic)
14+
!CHECK: %[[ALLOCA_IV:.*]] = fir.alloca i32 {{{.*}}, pinned}
15+
!CHECK: %[[WS_LB:.*]] = arith.constant 1 : i32
16+
!CHECK: %[[WS_UB:.*]] = arith.constant 9 : i32
17+
!CHECK: %[[WS_STEP:.*]] = arith.constant 1 : i32
18+
!CHECK: omp.wsloop schedule(dynamic, monotonic) nowait for (%[[I:.*]]) : i32 = (%[[WS_LB]]) to (%[[WS_UB]]) inclusive step (%[[WS_STEP]])
19+
!CHECK: fir.store %[[I]] to %[[ALLOCA_IV:.*]]#1 : !fir.ref<i32>
20+
21+
do i=1, 9
22+
print*, i
23+
!CHECK: %[[RTBEGIN:.*]] = fir.call @_FortranAioBeginExternalListOutput
24+
!CHECK: %[[LOAD:.*]] = fir.load %[[ALLOCA_IV]]#0 : !fir.ref<i32>
25+
!CHECK: fir.call @_FortranAioOutputInteger32(%[[RTBEGIN]], %[[LOAD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
26+
!CHECK: fir.call @_FortranAioEndIoStatement(%[[RTBEGIN]]) {{.*}}: (!fir.ref<i8>) -> i32
27+
end do
28+
!CHECK: omp.yield
29+
!CHECK: omp.terminator
30+
!CHECK: }
31+
32+
!$OMP END DO NOWAIT
33+
!$OMP END PARALLEL
34+
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
! This test checks lowering of OpenMP DO Directive(Worksharing) with
2+
! non-monotonic schedule modifier.
3+
4+
! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
5+
6+
program wsloop_dynamic
7+
integer :: i
8+
!CHECK-LABEL: func @_QQmain()
9+
10+
11+
!$OMP PARALLEL
12+
!CHECK: omp.parallel {
13+
14+
!$OMP DO SCHEDULE(nonmonotonic:dynamic)
15+
!CHECK: %[[I_REF:.*]] = fir.alloca i32 {{{.*}}, pinned}
16+
!CHECK: %[[ALLOCA_IV:.*]]:2 = hlfir.declare %[[I_REF]] {uniq_name = "_QFEi"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
17+
!CHECK: %[[WS_LB:.*]] = arith.constant 1 : i32
18+
!CHECK: %[[WS_UB:.*]] = arith.constant 9 : i32
19+
!CHECK: %[[WS_STEP:.*]] = arith.constant 1 : i32
20+
!CHECK: omp.wsloop schedule(dynamic, nonmonotonic) nowait for (%[[I:.*]]) : i32 = (%[[WS_LB]]) to (%[[WS_UB]]) inclusive step (%[[WS_STEP]])
21+
!CHECK: fir.store %[[I]] to %[[ALLOCA_IV]]#1 : !fir.ref<i32>
22+
23+
do i=1, 9
24+
print*, i
25+
!CHECK: %[[RTBEGIN:.*]] = fir.call @_FortranAioBeginExternalListOutput
26+
!CHECK: %[[LOAD:.*]] = fir.load %[[ALLOCA_IV]]#0 : !fir.ref<i32>
27+
!CHECK: fir.call @_FortranAioOutputInteger32(%[[RTBEGIN]], %[[LOAD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1
28+
!CHECK: fir.call @_FortranAioEndIoStatement(%[[RTBEGIN]]) {{.*}}: (!fir.ref<i8>) -> i32
29+
end do
30+
!CHECK: omp.yield
31+
!CHECK: }
32+
!CHECK: omp.terminator
33+
!CHECK: }
34+
35+
!$OMP END DO NOWAIT
36+
!$OMP END PARALLEL
37+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
! This test checks lowering of worksharing-loop construct with ordered clause.
2+
3+
! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
4+
5+
! This checks lowering ordered clause specified without parameter
6+
subroutine wsloop_ordered_no_para()
7+
integer :: a(10), i
8+
9+
! CHECK: omp.wsloop ordered(0) for (%{{.*}}) : i32 = (%{{.*}}) to (%{{.*}}) inclusive step (%{{.*}}) {
10+
! CHECK: omp.yield
11+
! CHECK: }
12+
13+
!$omp do ordered
14+
do i = 2, 10
15+
!$omp ordered
16+
a(i) = a(i-1) + 1
17+
!$omp end ordered
18+
end do
19+
!$omp end do
20+
21+
end
22+
23+
! This checks lowering ordered clause specified with a parameter
24+
subroutine wsloop_ordered_with_para()
25+
integer :: a(10), i
26+
27+
! CHECK: func @_QPwsloop_ordered_with_para() {
28+
! CHECK: omp.wsloop ordered(1) for (%{{.*}}) : i32 = (%{{.*}}) to (%{{.*}}) inclusive step (%{{.*}}) {
29+
! CHECK: omp.yield
30+
! CHECK: }
31+
32+
!$omp do ordered(1)
33+
do i = 2, 10
34+
!!$omp ordered depend(sink: i-1)
35+
a(i) = a(i-1) + 1
36+
!!$omp ordered depend(source)
37+
end do
38+
!$omp end do
39+
40+
end

0 commit comments

Comments
 (0)