Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / OpenMP / parallel-lastprivate-clause-scalar.f90
blobcd0d8786d05f8b3030e00e21659811e8e550f45a
1 ! This test checks lowering of `FIRSTPRIVATE` clause for scalar types.
3 ! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s
4 ! RUN: flang-new -fc1 -fopenmp -emit-fir %s -o - | FileCheck %s
6 !CHECK: func @_QPlastprivate_character(%[[ARG1:.*]]: !fir.boxchar<1>{{.*}}) {
7 !CHECK-DAG: %[[ARG1_UNBOX:.*]]:2 = fir.unboxchar
8 !CHECK-DAG: %[[FIVE:.*]] = arith.constant 5 : index
10 !CHECK: omp.parallel {
11 !CHECK-DAG: %[[ARG1_PVT:.*]] = fir.alloca !fir.char<1,5> {bindc_name = "arg1",
13 ! Check that we are accessing the clone inside the loop
14 !CHECK-DAG: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
15 !CHECK-DAG: %[[NEG_ONE:.*]] = arith.constant -1 : i32
16 !CHECK-NEXT: %[[ADDR:.*]] = fir.address_of(@_QQcl.
17 !CHECK-NEXT: %[[CVT0:.*]] = fir.convert %[[ADDR]]
18 !CHECK-NEXT: %[[CNST:.*]] = arith.constant
19 !CHECK-NEXT: %[[CALL_BEGIN_IO:.*]] = fir.call @_FortranAioBeginExternalListOutput(%[[NEG_ONE]], %[[CVT0]], %[[CNST]]) {{.*}}: (i32, !fir.ref<i8>, i32) -> !fir.ref<i8>
20 !CHECK-NEXT: %[[CVT_0_1:.*]] = fir.convert %[[ARG1_PVT]]
21 !CHECK-NEXT: %[[CVT_0_2:.*]] = fir.convert %[[FIVE]]
22 !CHECK-NEXT: %[[CALL_OP_ASCII:.*]] = fir.call @_FortranAioOutputAscii(%[[CALL_BEGIN_IO]], %[[CVT_0_1]], %[[CVT_0_2]])
23 !CHECK-NEXT: %[[CALL_END_IO:.*]] = fir.call @_FortranAioEndIoStatement(%[[CALL_BEGIN_IO]])
25 ! Testing last iteration check
26 !CHECK-NEXT: %[[IV_CMP:.*]] = arith.cmpi eq, %[[INDX_WS]]
27 !CHECK: scf.if %[[IV_CMP]] {
29 ! Testing lastprivate val update
30 !CHECK-DAG: %[[CVT:.*]] = fir.convert %[[ARG1_UNBOX]]#0 : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<i8>
31 !CHECK-DAG: %[[CVT1:.*]] = fir.convert %[[ARG1_PVT]] : (!fir.ref<!fir.char<1,5>>) -> !fir.ref<i8>
32 !CHECK-DAG: fir.call @llvm.memmove.p0.p0.i64(%[[CVT]], %[[CVT1]]{{.*}})
33 !CHECK-DAG: }
34 !CHECK-DAG: omp.yield
36 subroutine lastprivate_character(arg1)
37 character(5) :: arg1
38 !$OMP PARALLEL
39 !$OMP DO LASTPRIVATE(arg1)
40 do n = 1, 5
41 arg1(n:n) = 'c'
42 print *, arg1
43 end do
44 !$OMP END DO
45 !$OMP END PARALLEL
46 end subroutine
48 !CHECK: func @_QPlastprivate_int(%[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "arg1"}) {
49 !CHECK-DAG: omp.parallel {
50 !CHECK-DAG: %[[CLONE:.*]] = fir.alloca i32 {bindc_name = "arg1"
51 !CHECK: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
53 ! Testing last iteration check
54 !CHECK-DAG: %[[IV_CMP:.*]] = arith.cmpi eq, %[[INDX_WS]]
55 !CHECK-DAG: scf.if %[[IV_CMP]] {
57 ! Testing lastprivate val update
58 !CHECK-NEXT: %[[CLONE_LD:.*]] = fir.load %[[CLONE]] : !fir.ref<i32>
59 !CHECK-NEXT: fir.store %[[CLONE_LD]] to %[[ARG1]] : !fir.ref<i32>
60 !CHECK-DAG: }
61 !CHECK-DAG: omp.yield
63 subroutine lastprivate_int(arg1)
64 integer :: arg1
65 !$OMP PARALLEL
66 !$OMP DO LASTPRIVATE(arg1)
67 do n = 1, 5
68 arg1 = 2
69 print *, arg1
70 end do
71 !$OMP END DO
72 !$OMP END PARALLEL
73 print *, arg1
74 end subroutine
76 !CHECK: func.func @_QPmult_lastprivate_int(%[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "arg1"}, %[[ARG2:.*]]: !fir.ref<i32> {fir.bindc_name = "arg2"}) {
77 !CHECK: omp.parallel {
78 !CHECK-DAG: %[[CLONE1:.*]] = fir.alloca i32 {bindc_name = "arg1"
79 !CHECK-DAG: %[[CLONE2:.*]] = fir.alloca i32 {bindc_name = "arg2"
80 !CHECK: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
82 ! Testing last iteration check
83 !CHECK: %[[IV_CMP1:.*]] = arith.cmpi eq, %[[INDX_WS]]
84 !CHECK-NEXT: scf.if %[[IV_CMP1]] {
85 ! Testing lastprivate val update
86 !CHECK-DAG: %[[CLONE_LD1:.*]] = fir.load %[[CLONE1]] : !fir.ref<i32>
87 !CHECK-DAG: fir.store %[[CLONE_LD1]] to %[[ARG1]] : !fir.ref<i32>
88 !CHECK-DAG: %[[CLONE_LD2:.*]] = fir.load %[[CLONE2]] : !fir.ref<i32>
89 !CHECK-DAG: fir.store %[[CLONE_LD2]] to %[[ARG2]] : !fir.ref<i32>
90 !CHECK: }
91 !CHECK: omp.yield
93 subroutine mult_lastprivate_int(arg1, arg2)
94 integer :: arg1, arg2
95 !$OMP PARALLEL
96 !$OMP DO LASTPRIVATE(arg1) LASTPRIVATE(arg2)
97 do n = 1, 5
98 arg1 = 2
99 arg2 = 3
100 print *, arg1, arg2
101 end do
102 !$OMP END DO
103 !$OMP END PARALLEL
104 print *, arg1, arg2
105 end subroutine
107 !CHECK: func.func @_QPmult_lastprivate_int2(%[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "arg1"}, %[[ARG2:.*]]: !fir.ref<i32> {fir.bindc_name = "arg2"}) {
108 !CHECK: omp.parallel {
109 !CHECK-DAG: %[[CLONE1:.*]] = fir.alloca i32 {bindc_name = "arg1"
110 !CHECK-DAG: %[[CLONE2:.*]] = fir.alloca i32 {bindc_name = "arg2"
111 !CHECK: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
113 !Testing last iteration check
114 !CHECK: %[[IV_CMP1:.*]] = arith.cmpi eq, %[[INDX_WS]]
115 !CHECK-NEXT: scf.if %[[IV_CMP1]] {
116 !Testing lastprivate val update
117 !CHECK-DAG: %[[CLONE_LD2:.*]] = fir.load %[[CLONE2]] : !fir.ref<i32>
118 !CHECK-DAG: fir.store %[[CLONE_LD2]] to %[[ARG2]] : !fir.ref<i32>
119 !CHECK-DAG: %[[CLONE_LD1:.*]] = fir.load %[[CLONE1]] : !fir.ref<i32>
120 !CHECK-DAG: fir.store %[[CLONE_LD1]] to %[[ARG1]] : !fir.ref<i32>
121 !CHECK: }
122 !CHECK: omp.yield
124 subroutine mult_lastprivate_int2(arg1, arg2)
125 integer :: arg1, arg2
126 !$OMP PARALLEL
127 !$OMP DO LASTPRIVATE(arg1, arg2)
128 do n = 1, 5
129 arg1 = 2
130 arg2 = 3
131 print *, arg1, arg2
132 end do
133 !$OMP END DO
134 !$OMP END PARALLEL
135 print *, arg1, arg2
136 end subroutine
138 !CHECK: func.func @_QPfirstpriv_lastpriv_int(%[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "arg1"}, %[[ARG2:.*]]: !fir.ref<i32> {fir.bindc_name = "arg2"}) {
139 !CHECK: omp.parallel {
140 ! Firstprivate update
141 !CHECK-DAG: %[[CLONE1:.*]] = fir.alloca i32 {bindc_name = "arg1"
142 !CHECK-DAG: %[[FPV_LD:.*]] = fir.load %[[ARG1]] : !fir.ref<i32>
143 !CHECK-DAG: fir.store %[[FPV_LD]] to %[[CLONE1]] : !fir.ref<i32>
144 ! Lastprivate Allocation
145 !CHECK-DAG: %[[CLONE2:.*]] = fir.alloca i32 {bindc_name = "arg2"
146 !CHECK-NOT: omp.barrier
147 !CHECK: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
149 ! Testing last iteration check
150 !CHECK: %[[IV_CMP1:.*]] = arith.cmpi eq, %[[INDX_WS]]
151 !CHECK-NEXT: scf.if %[[IV_CMP1]] {
152 ! Testing lastprivate val update
153 !CHECK-NEXT: %[[CLONE_LD:.*]] = fir.load %[[CLONE2]] : !fir.ref<i32>
154 !CHECK-NEXT: fir.store %[[CLONE_LD]] to %[[ARG2]] : !fir.ref<i32>
155 !CHECK-NEXT: }
156 !CHECK-NEXT: omp.yield
158 subroutine firstpriv_lastpriv_int(arg1, arg2)
159 integer :: arg1, arg2
160 !$OMP PARALLEL
161 !$OMP DO FIRSTPRIVATE(arg1) LASTPRIVATE(arg2)
162 do n = 1, 5
163 arg1 = 2
164 arg2 = 3
165 print *, arg1, arg2
166 end do
167 !$OMP END DO
168 !$OMP END PARALLEL
169 print *, arg1, arg2
170 end subroutine
172 !CHECK: func.func @_QPfirstpriv_lastpriv_int2(%[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "arg1"}) {
173 !CHECK: omp.parallel {
174 ! Firstprivate update
175 !CHECK-NEXT: %[[CLONE1:.*]] = fir.alloca i32 {bindc_name = "arg1"
176 !CHECK-NEXT: %[[FPV_LD:.*]] = fir.load %[[ARG1]] : !fir.ref<i32>
177 !CHECK-NEXT: fir.store %[[FPV_LD]] to %[[CLONE1]] : !fir.ref<i32>
178 !CHECK-NEXT: omp.barrier
179 !CHECK: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
180 ! Testing last iteration check
181 !CHECK: %[[IV_CMP1:.*]] = arith.cmpi eq, %[[INDX_WS]]
182 !CHECK-NEXT: scf.if %[[IV_CMP1]] {
183 ! Testing lastprivate val update
184 !CHECK-NEXT: %[[CLONE_LD:.*]] = fir.load %[[CLONE1]] : !fir.ref<i32>
185 !CHECK-NEXT: fir.store %[[CLONE_LD]] to %[[ARG1]] : !fir.ref<i32>
186 !CHECK-NEXT: }
187 !CHECK-NEXT: omp.yield
189 subroutine firstpriv_lastpriv_int2(arg1)
190 integer :: arg1
191 !$OMP PARALLEL
192 !$OMP DO FIRSTPRIVATE(arg1) LASTPRIVATE(arg1)
193 do n = 1, 5
194 arg1 = 2
195 print *, arg1
196 end do
197 !$OMP END DO
198 !$OMP END PARALLEL
199 print *, arg1
200 end subroutine