Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / OpenMP / default-clause.f90
blob4f4da79ae24dfd5264c7a9bfbb5ba8548843c61d
1 ! This test checks lowering of OpenMP parallel directive
2 ! with `DEFAULT` clause present.
4 ! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
5 ! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s
8 !CHECK: func @_QQmain() attributes {fir.bindc_name = "default_clause_lowering"} {
9 !CHECK: %[[W:.*]] = fir.alloca i32 {bindc_name = "w", uniq_name = "_QFEw"}
10 !CHECK: %[[X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
11 !CHECK: %[[Y:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFEy"}
12 !CHECK: %[[Z:.*]] = fir.alloca i32 {bindc_name = "z", uniq_name = "_QFEz"}
13 !CHECK: omp.parallel {
14 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}
15 !CHECK: %[[const:.*]] = fir.load %[[X]] : !fir.ref<i32>
16 !CHECK: fir.store %[[const]] to %[[PRIVATE_X]] : !fir.ref<i32>
17 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFEy"}
18 !CHECK: %[[PRIVATE_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFEw"}
19 !CHECK: %[[const:.*]] = arith.constant 2 : i32
20 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
21 !CHECK: %[[result:.*]] = arith.muli %[[const]], %[[temp]] : i32
22 !CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
23 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_W]] : !fir.ref<i32>
24 !CHECK: %[[const:.*]] = arith.constant 45 : i32
25 !CHECK: %[[result:.*]] = arith.addi %[[temp]], %[[const]] : i32
26 !CHECK: fir.store %[[result]] to %[[Z]] : !fir.ref<i32>
27 !CHECK: omp.terminator
28 !CHECK: }
30 program default_clause_lowering
31 integer :: x, y, z, w
33 !$omp parallel default(private) firstprivate(x) shared(z)
34 x = y * 2
35 z = w + 45
36 !$omp end parallel
38 !CHECK: omp.parallel {
39 !CHECK: %[[temp:.*]] = fir.load %[[Y]] : !fir.ref<i32>
40 !CHECK: fir.store %[[temp]] to %[[X]] : !fir.ref<i32>
41 !CHECK: omp.terminator
42 !CHECK: }
44 !$omp parallel default(shared)
45 x = y
46 !$omp end parallel
48 !CHECK: omp.parallel {
49 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}
50 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFEy"}
51 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
52 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
53 !CHECK: omp.terminator
54 !CHECK: }
56 !$omp parallel default(none) private(x, y)
57 x = y
58 !$omp end parallel
60 !CHECK: omp.parallel {
61 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFEy"}
62 !CHECK: %[[temp:.*]] = fir.load %[[Y]] : !fir.ref<i32>
63 !CHECK: fir.store %[[temp]] to %[[PRIVATE_Y]] : !fir.ref<i32>
64 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}
65 !CHECK: %[[temp:.*]] = fir.load %[[X]] : !fir.ref<i32>
66 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
67 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
68 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
69 !CHECK: omp.terminator
70 !CHECK: }
72 !$omp parallel default(firstprivate) firstprivate(y)
73 x = y
74 !$omp end parallel
76 !CHECK: omp.parallel {
77 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}
78 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFEy"}
79 !CHECK: %[[temp:.*]] = fir.load %[[Y]] : !fir.ref<i32>
80 !CHECK: fir.store %[[temp]] to %[[PRIVATE_Y]] : !fir.ref<i32>
81 !CHECK: %[[PRIVATE_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFEw"}
82 !CHECK: %[[temp:.*]] = fir.load %[[W]] : !fir.ref<i32>
83 !CHECK: fir.store %[[temp]] to %[[PRIVATE_W]] : !fir.ref<i32>
84 !CHECK: %[[const:.*]] = arith.constant 2 : i32
85 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
86 !CHECK: %[[result:.*]] = arith.muli %[[const]], %[[temp]] : i32
87 !CHECK: fir.store %[[result]] to %[[PRIVATE_X]] : !fir.ref<i32>
88 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_W]] : !fir.ref<i32>
89 !CHECK: %[[const:.*]] = arith.constant 45 : i32
90 !CHECK: %[[result:.*]] = arith.addi %[[temp]], %[[const]] : i32
91 !CHECK: fir.store %[[result]] to %[[Z]] : !fir.ref<i32>
92 !CHECK: omp.terminator
93 !CHECK: }
95 !$omp parallel default(firstprivate) private(x) shared(z)
96 x = y * 2
97 z = w + 45
98 !$omp end parallel
100 !CHECK: omp.parallel {
101 !CHECK: omp.parallel {
102 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}
103 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFEy"}
104 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
105 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
106 !CHECK: omp.terminator
107 !CHECK: }
108 !CHECK: omp.parallel {
109 !CHECK: %[[PRIVATE_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFEw"}
110 !CHECK: %[[temp:.*]] = fir.load %[[W]] : !fir.ref<i32>
111 !CHECK: fir.store %[[temp]] to %[[PRIVATE_W]] : !fir.ref<i32>
112 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFEx"}
113 !CHECK: %[[temp:.*]] = fir.load %[[X]] : !fir.ref<i32>
114 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
115 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
116 !CHECK: fir.store %[[temp]] to %[[PRIVATE_W]] : !fir.ref<i32>
117 !CHECK: omp.terminator
118 !CHECK: }
119 !CHECK: omp.terminator
120 !CHECK: }
121 !$omp parallel
122 !$omp parallel default(private)
123 x = y
124 !$omp end parallel
126 !$omp parallel default(firstprivate)
127 w = x
128 !$omp end parallel
129 !$omp end parallel
131 end program default_clause_lowering
133 subroutine nested_default_clause_tests
134 integer :: x, y, z, w, k, a
136 !CHECK: %[[K:.*]] = fir.alloca i32 {bindc_name = "k", uniq_name = "_QFnested_default_clause_testsEk"}
137 !CHECK: %[[W:.*]] = fir.alloca i32 {bindc_name = "w", uniq_name = "_QFnested_default_clause_testsEw"}
138 !CHECK: %[[X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFnested_default_clause_testsEx"}
139 !CHECK: %[[Y:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFnested_default_clause_testsEy"}
140 !CHECK: %[[Z:.*]] = fir.alloca i32 {bindc_name = "z", uniq_name = "_QFnested_default_clause_testsEz"}
141 !CHECK: omp.parallel {
142 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
143 !CHECK: %[[temp:.*]] = fir.load %[[X]] : !fir.ref<i32>
144 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
145 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
146 !CHECK: %[[PRIVATE_Z:.*]] = fir.alloca i32 {bindc_name = "z", pinned, uniq_name = "_QFnested_default_clause_testsEz"}
147 !CHECK: %[[PRIVATE_K:.*]] = fir.alloca i32 {bindc_name = "k", pinned, uniq_name = "_QFnested_default_clause_testsEk"}
148 !CHECK: omp.parallel {
149 !CHECK: %[[INNER_PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
150 !CHECK: %[[INNER_PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
151 !CHECK: %[[const:.*]] = arith.constant 20 : i32
152 !CHECK: fir.store %[[const]] to %[[INNER_PRIVATE_Y]] : !fir.ref<i32>
153 !CHECK: %[[const:.*]] = arith.constant 10 : i32
154 !CHECK: fir.store %[[const]] to %[[INNER_PRIVATE_X]] : !fir.ref<i32>
155 !CHECK: omp.terminator
156 !CHECK: }
157 !CHECK: omp.parallel {
158 !CHECK: %[[INNER_PRIVATE_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFnested_default_clause_testsEw"}
159 !CHECK: %[[INNER_PRIVATE_Z:.*]] = fir.alloca i32 {bindc_name = "z", pinned, uniq_name = "_QFnested_default_clause_testsEz"}
160 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Z]]
161 !CHECK: fir.store %[[temp]] to %[[INNER_PRIVATE_Z]] : !fir.ref<i32>
162 !CHECK: %[[INNER_PRIVATE_K:.*]] = fir.alloca i32 {bindc_name = "k", pinned, uniq_name = "_QFnested_default_clause_testsEk"}
163 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_K]] : !fir.ref<i32>
164 !CHECK: fir.store %[[temp]] to %[[INNER_PRIVATE_K]] : !fir.ref<i32>
165 !CHECK: %[[const:.*]] = arith.constant 30 : i32
166 !CHECK: fir.store %[[const]] to %[[PRIVATE_Y]] : !fir.ref<i32>
167 !CHECK: %[[const:.*]] = arith.constant 40 : i32
168 !CHECK: fir.store %[[const]] to %[[INNER_PRIVATE_W]] : !fir.ref<i32>
169 !CHECK: %[[const:.*]] = arith.constant 50 : i32
170 !CHECK: fir.store %[[const]] to %[[INNER_PRIVATE_Z]] : !fir.ref<i32>
171 !CHECK: %[[const:.*]] = arith.constant 40 : i32
172 !CHECK: fir.store %[[const]] to %[[INNER_PRIVATE_K]] : !fir.ref<i32>
173 !CHECK: omp.terminator
174 !CHECK: }
175 !CHECK: omp.terminator
176 !CHECK: }
177 !$omp parallel firstprivate(x) private(y) shared(w) default(private)
178 !$omp parallel default(private)
179 y = 20
180 x = 10
181 !$omp end parallel
183 !$omp parallel default(firstprivate) shared(y) private(w)
184 y = 30
185 w = 40
186 z = 50
187 k = 40
188 !$omp end parallel
189 !$omp end parallel
192 !CHECK: omp.parallel {
193 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
194 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
195 !CHECK: %[[PRIVATE_Z:.*]] = fir.alloca i32 {bindc_name = "z", pinned, uniq_name = "_QFnested_default_clause_testsEz"}
196 !CHECK: %[[PRIVATE_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFnested_default_clause_testsEw"}
197 !CHECK: omp.parallel {
198 !CHECK: %[[PRIVATE_INNER_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
199 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
200 !CHECK: fir.store %[[temp]] to %[[PRIVATE_INNER_X]] : !fir.ref<i32>
201 !CHECK: %[[INNER_PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
202 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
203 !CHECK: fir.store %[[temp]] to %[[INNER_PRIVATE_Y]] : !fir.ref<i32>
204 !CHECK: %[[temp:.*]] = fir.load %[[INNER_PRIVATE_Y]] : !fir.ref<i32>
205 !CHECK: fir.store %[[temp]] to %[[PRIVATE_INNER_X]] : !fir.ref<i32>
206 !CHECK: omp.terminator
207 !CHECK: }
208 !CHECK: omp.parallel {
209 !CHECK: %[[PRIVATE_INNER_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFnested_default_clause_testsEw"}
210 !CHECK: %[[PRIVATE_INNER_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
211 !CHECK: %[[temp_1:.*]] = fir.load %[[PRIVATE_INNER_X]] : !fir.ref<i32>
212 !CHECK: %[[temp_2:.*]] = fir.load %[[PRIVATE_Z]] : !fir.ref<i32>
213 !CHECK: %[[result:.*]] = arith.addi %{{.*}}, %{{.*}} : i32
214 !CHECK: fir.store %[[result]] to %[[PRIVATE_INNER_W]] : !fir.ref<i32>
215 !CHECK: omp.terminator
216 !CHECK: }
217 !$omp parallel default(private)
218 !$omp parallel default(firstprivate)
219 x = y
220 !$omp end parallel
222 !$omp parallel default(private) shared(z)
223 w = x + z
224 !$omp end parallel
225 !$omp end parallel
227 !CHECK: omp.parallel {
228 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
229 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
230 !CHECK: %[[PRIVATE_W:.*]] = fir.alloca i32 {bindc_name = "w", pinned, uniq_name = "_QFnested_default_clause_testsEw"}
231 !CHECK: %[[PRIVATE_Z:.*]] = fir.alloca i32 {bindc_name = "z", pinned, uniq_name = "_QFnested_default_clause_testsEz"}
232 !CHECK: omp.parallel {
233 !CHECK: %[[INNER_PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
234 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
235 !CHECK: fir.store %[[temp]] to %[[INNER_PRIVATE_X]] : !fir.ref<i32>
236 !CHECK: %[[INNER_PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
237 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
238 !CHECK: fir.store %[[temp]] to %[[INNER_PRIVATE_Y]] : !fir.ref<i32>
239 !CHECK: %[[temp:.*]] = fir.load %[[INNER_PRIVATE_Y]] : !fir.ref<i32>
240 !CHECK: fir.store %[[temp]] to %[[INNER_PRIVATE_X]] : !fir.ref<i32>
241 !CHECK: omp.terminator
242 !CHECK: }
243 !CHECK: omp.parallel {
244 !CHECK: %[[temp_1:.*]] = fir.load %[[PRIVATE_X]] : !fir.ref<i32>
245 !CHECK: %[[temp_2:.*]] = fir.load %[[PRIVATE_Z]] : !fir.ref<i32>
246 !CHECK: %[[temp_3:.*]] = arith.addi %[[temp_1]], %[[temp_2]] : i32
247 !CHECK: fir.store %[[temp_3]] to %[[PRIVATE_W]] : !fir.ref<i32>
248 !CHECK: omp.terminator
249 !CHECK: }
250 !CHECK: }
251 !$omp parallel default(private)
252 !$omp parallel default(firstprivate)
253 x = y
254 !$omp end parallel
256 !$omp parallel default(shared)
257 w = x + z
258 !$omp end parallel
259 !$omp end parallel
261 !CHECK: omp.parallel {
262 !CHECK: %[[PRIVATE_X:.*]] = fir.alloca i32 {bindc_name = "x", pinned, uniq_name = "_QFnested_default_clause_testsEx"}
263 !CHECK: %[[temp:.*]] = fir.load %[[X]] : !fir.ref<i32>
264 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
265 !CHECK: %[[PRIVATE_Y:.*]] = fir.alloca i32 {bindc_name = "y", pinned, uniq_name = "_QFnested_default_clause_testsEy"}
266 !CHECK: %[[temp:.*]] = fir.load %[[Y]] : !fir.ref<i32>
267 !CHECK: fir.store %[[temp]] to %[[PRIVATE_Y]] : !fir.ref<i32>
268 !CHECK: omp.single {
269 !CHECK: %[[temp:.*]] = fir.load %[[PRIVATE_Y]] : !fir.ref<i32>
270 !CHECK: fir.store %[[temp]] to %[[PRIVATE_X]] : !fir.ref<i32>
271 !CHECK: omp.terminator
272 !CHECK: }
273 !CHECK: omp.terminator
274 !CHECK: }
275 !CHECK: }
276 !$omp parallel default(firstprivate)
277 !$omp single
278 x = y
279 !$omp end single
280 !$omp end parallel
281 end subroutine