Debian Codegraph @

flang/test/Fir/convert-to-llvm-openmp-and-fir.fir

raw
1 // RUN: fir-opt --split-input-file --cfg-conversion --fir-to-llvm-ir="target=aarch64-unknown-linux-gnu" %s | FileCheck %s
2
3 func.func @_QPsb1(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}, %arg1: !fir.ref<!fir.array<?xi32>> {fir.bindc_name = "arr"}) {
4 %c1_i64 = arith.constant 1 : i64
5 %c1_i32 = arith.constant 1 : i32
6 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsbEi"}
7 omp.parallel {
8 %1 = fir.alloca i32 {adapt.valuebyref, pinned}
9 %2 = fir.load %arg0 : !fir.ref<i32>
10 omp.wsloop nowait {
11 omp.loop_nest (%arg2) : i32 = (%c1_i32) to (%2) inclusive step (%c1_i32) {
12 fir.store %arg2 to %1 : !fir.ref<i32>
13 %3 = fir.load %1 : !fir.ref<i32>
14 %4 = fir.convert %3 : (i32) -> i64
15 %5 = arith.subi %4, %c1_i64 : i64
16 %6 = fir.coordinate_of %arg1, %5 : (!fir.ref<!fir.array<?xi32>>, i64) -> !fir.ref<i32>
17 fir.store %3 to %6 : !fir.ref<i32>
18 omp.yield
19 }
20 omp.terminator
21 }
22 omp.terminator
23 }
24 return
25 }
26
27 // CHECK-LABEL: _QPsb1
28 // CHECK-SAME: %[[N_REF:.*]]: !llvm.ptr {fir.bindc_name = "n"}, %[[ARR_REF:.*]]: !llvm.ptr {fir.bindc_name = "arr"}) {
29 // CHECK: %[[ONE_0:.*]] = llvm.mlir.constant(1 : i64) : i64
30 // CHECK: %[[ONE_1:.*]] = llvm.mlir.constant(1 : i64) : i64
31 // CHECK: %[[ONE_2:.*]] = llvm.mlir.constant(1 : i32) : i32
32 // CHECK: omp.parallel {
33 // CHECK: %[[ONE_3:.*]] = llvm.mlir.constant(1 : i64) : i64
34 // CHECK: %[[I_VAR:.*]] = llvm.alloca %[[ONE_3]] x i32 {pinned} : (i64) -> !llvm.ptr
35 // CHECK: %[[N:.*]] = llvm.load %[[N_REF]] : !llvm.ptr -> i32
36 // CHECK: omp.wsloop nowait
37 // CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[ONE_2]]) to (%[[N]]) inclusive step (%[[ONE_2]]) {
38 // CHECK: llvm.store %[[I]], %[[I_VAR]] : i32, !llvm.ptr
39 // CHECK: %[[I1:.*]] = llvm.load %[[I_VAR]] : !llvm.ptr -> i32
40 // CHECK: %[[I1_EXT:.*]] = llvm.sext %[[I1]] : i32 to i64
41 // CHECK: %[[I_CSTYLE:.*]] = llvm.sub %[[I1_EXT]], %[[ONE_1]] : i64
42 // CHECK: %[[ARR_I_REF:.*]] = llvm.getelementptr %[[ARR_REF]][%[[I_CSTYLE]]] : (!llvm.ptr, i64) -> !llvm.ptr
43 // CHECK: llvm.store %[[I1]], %[[ARR_I_REF]] : i32, !llvm.ptr
44 // CHECK: omp.yield
45 // CHECK: }
46 // CHECK: omp.terminator
47 // CHECK: }
48 // CHECK: omp.terminator
49 // CHECK: }
50 // CHECK: llvm.return
51 // CHECK: }
52
53 // -----
54
55 func.func @_QPsb2(%arg0: !fir.ref<i32> {fir.bindc_name = "x"}, %arg1: !fir.ref<i32> {fir.bindc_name = "n"}) {
56 omp.parallel {
57 omp.master {
58 %0 = fir.load %arg1 : !fir.ref<i32>
59 fir.store %0 to %arg0 : !fir.ref<i32>
60 omp.terminator
61 }
62 omp.terminator
63 }
64 return
65 }
66
67 // CHECK-LABEL: _QPsb2
68 // CHECK-SAME: %[[X_REF:.*]]: !llvm.ptr {fir.bindc_name = "x"}, %[[N_REF:.*]]: !llvm.ptr {fir.bindc_name = "n"}) {
69 // CHECK: omp.parallel {
70 // CHECK: omp.master {
71 // CHECK: %[[N:.*]] = llvm.load %[[N_REF]] : !llvm.ptr -> i32
72 // CHECK: llvm.store %[[N]], %[[X_REF]] : i32, !llvm.ptr
73 // CHECK: omp.terminator
74 // CHECK: }
75 // CHECK: omp.terminator
76 // CHECK: }
77 // CHECK: llvm.return
78 // CHECK: }
79
80 // -----
81
82 func.func @_QPsb(%arr: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "arr"}) {
83 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsbEi"}
84 omp.parallel {
85 %c1 = arith.constant 1 : i32
86 %c50 = arith.constant 50 : i32
87 omp.wsloop {
88 omp.loop_nest (%indx) : i32 = (%c1) to (%c50) inclusive step (%c1) {
89 %1 = fir.convert %indx : (i32) -> i64
90 %c1_i64 = arith.constant 1 : i64
91 %2 = arith.subi %1, %c1_i64 : i64
92 %3 = fir.coordinate_of %arr, %2 : (!fir.box<!fir.array<?xi32>>, i64) -> !fir.ref<i32>
93 fir.store %indx to %3 : !fir.ref<i32>
94 omp.yield
95 }
96 omp.terminator
97 }
98 omp.terminator
99 }
100 return
101 }
102
103 // Check only for the structure of the OpenMP portion and the feasibility of the conversion
104 // CHECK-LABEL: @_QPsb
105 // CHECK-SAME: %{{.*}}: !llvm.ptr {fir.bindc_name = "arr"}
106 // CHECK: omp.parallel {
107 // CHECK: %[[C1:.*]] = llvm.mlir.constant(1 : i32) : i32
108 // CHECK: %[[C50:.*]] = llvm.mlir.constant(50 : i32) : i32
109 // CHECK: omp.wsloop {
110 // CHECK-NEXT: omp.loop_nest (%[[INDX:.*]]) : i32 = (%[[C1]]) to (%[[C50]]) inclusive step (%[[C1]]) {
111 // CHECK: llvm.store %[[INDX]], %{{.*}} : i32, !llvm.ptr
112 // CHECK: omp.yield
113 // CHECK: omp.terminator
114 // CHECK: omp.terminator
115 // CHECK: llvm.return
116
117 // -----
118
119 func.func private @foo()
120 func.func private @bar()
121
122 func.func @sections_no_data() {
123 omp.sections {
124 omp.section {
125 fir.call @foo() : () -> ()
126 omp.terminator
127 }
128 omp.section {
129 fir.call @bar() : () -> ()
130 omp.terminator
131 }
132 omp.terminator
133 }
134 return
135 }
136
137 // CHECK-LABEL: llvm.func @sections_no_data
138 // CHECK: omp.sections {
139 // CHECK: omp.section {
140 // CHECK: llvm.call @foo() : () -> ()
141 // CHECK: omp.terminator
142 // CHECK: }
143 // CHECK: omp.section {
144 // CHECK: llvm.call @bar() : () -> ()
145 // CHECK: omp.terminator
146 // CHECK: }
147 // CHECK: omp.terminator
148 // CHECK: }
149
150 // -----
151
152 func.func private @foo(!fir.ref<i32>)
153 func.func private @bar(!fir.ref<i32>, !fir.ref<i32>)
154
155 func.func @sections_data_without_clauses(%arg0: !fir.ref<i32> {fir.bindc_name = "a"}, %arg1: !fir.ref<i32> {fir.bindc_name = "b"}) {
156 omp.sections {
157 omp.section {
158 fir.call @foo(%arg0) : (!fir.ref<i32>) -> ()
159 omp.terminator
160 }
161 omp.section {
162 fir.call @bar(%arg0, %arg1) : (!fir.ref<i32>, !fir.ref<i32>) -> ()
163 omp.terminator
164 }
165 omp.terminator
166 }
167 return
168 }
169
170 // CHECK-LABEL: llvm.func @sections_data_without_clauses
171 // CHECK-SAME: (%[[ARG0:.+]]: !llvm.ptr {fir.bindc_name = "a"}, %[[ARG1:.+]]: !llvm.ptr {fir.bindc_name = "b"})
172 // CHECK: omp.sections {
173 // CHECK: omp.section {
174 // CHECK: llvm.call @foo(%arg0) : (!llvm.ptr) -> ()
175 // CHECK: omp.terminator
176 // CHECK: }
177 // CHECK: omp.section {
178 // CHECK: llvm.call @bar(%[[ARG0]], %[[ARG1]]) : (!llvm.ptr, !llvm.ptr) -> ()
179 // CHECK: omp.terminator
180 // CHECK: }
181 // CHECK: omp.terminator
182 // CHECK: }
183
184 // -----
185
186 func.func @_QPsimd1(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}, %arg1: !fir.ref<!fir.array<?xi32>> {fir.bindc_name = "arr"}) {
187 %c1_i64 = arith.constant 1 : i64
188 %c1_i32 = arith.constant 1 : i32
189 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsbEi"}
190 omp.parallel {
191 %1 = fir.alloca i32 {adapt.valuebyref, pinned}
192 %2 = fir.load %arg0 : !fir.ref<i32>
193 omp.simd {
194 omp.loop_nest (%arg2) : i32 = (%c1_i32) to (%2) step (%c1_i32) {
195 fir.store %arg2 to %1 : !fir.ref<i32>
196 %3 = fir.load %1 : !fir.ref<i32>
197 %4 = fir.convert %3 : (i32) -> i64
198 %5 = arith.subi %4, %c1_i64 : i64
199 %6 = fir.coordinate_of %arg1, %5 : (!fir.ref<!fir.array<?xi32>>, i64) -> !fir.ref<i32>
200 fir.store %3 to %6 : !fir.ref<i32>
201 omp.yield
202 }
203 omp.terminator
204 }
205 omp.terminator
206 }
207 return
208 }
209
210 // CHECK-LABEL: _QPsimd1
211 // CHECK-SAME: %[[N_REF:.*]]: !llvm.ptr {fir.bindc_name = "n"}, %[[ARR_REF:.*]]: !llvm.ptr {fir.bindc_name = "arr"}) {
212 // CHECK: %[[ONE_0:.*]] = llvm.mlir.constant(1 : i64) : i64
213 // CHECK: %[[ONE_1:.*]] = llvm.mlir.constant(1 : i64) : i64
214 // CHECK: %[[ONE_2:.*]] = llvm.mlir.constant(1 : i32) : i32
215 // CHECK: omp.parallel {
216 // CHECK: %[[ONE_3:.*]] = llvm.mlir.constant(1 : i64) : i64
217 // CHECK: %[[I_VAR:.*]] = llvm.alloca %[[ONE_3]] x i32 {pinned} : (i64) -> !llvm.ptr
218 // CHECK: %[[N:.*]] = llvm.load %[[N_REF]] : !llvm.ptr -> i32
219 // CHECK: omp.simd {
220 // CHECK-NEXT: omp.loop_nest (%[[I:.*]]) : i32 = (%[[ONE_2]]) to (%[[N]]) step (%[[ONE_2]]) {
221 // CHECK: llvm.store %[[I]], %[[I_VAR]] : i32, !llvm.ptr
222 // CHECK: %[[I1:.*]] = llvm.load %[[I_VAR]] : !llvm.ptr -> i32
223 // CHECK: %[[I1_EXT:.*]] = llvm.sext %[[I1]] : i32 to i64
224 // CHECK: %[[I_CSTYLE:.*]] = llvm.sub %[[I1_EXT]], %[[ONE_1]] : i64
225 // CHECK: %[[ARR_I_REF:.*]] = llvm.getelementptr %[[ARR_REF]][%[[I_CSTYLE]]] : (!llvm.ptr, i64) -> !llvm.ptr
226 // CHECK: llvm.store %[[I1]], %[[ARR_I_REF]] : i32, !llvm.ptr
227 // CHECK: omp.yield
228 // CHECK: }
229 // CHECK: omp.terminator
230 // CHECK: }
231 // CHECK: omp.terminator
232 // CHECK: }
233 // CHECK: llvm.return
234 // CHECK: }
235
236 // -----
237
238 func.func @_QPomp_target_data() {
239 %c1024 = arith.constant 1024 : index
240 %0 = fir.alloca !fir.array<1024xi32> {bindc_name = "a", uniq_name = "_QFomp_target_dataEa"}
241 %c1024_0 = arith.constant 1024 : index
242 %1 = fir.alloca !fir.array<1024xi32> {bindc_name = "b", uniq_name = "_QFomp_target_dataEb"}
243 %c1024_1 = arith.constant 1024 : index
244 %2 = fir.alloca !fir.array<1024xi32> {bindc_name = "c", uniq_name = "_QFomp_target_dataEc"}
245 %c1024_2 = arith.constant 1024 : index
246 %3 = fir.alloca !fir.array<1024xi32> {bindc_name = "d", uniq_name = "_QFomp_target_dataEd"}
247 %c1 = arith.constant 1 : index
248 %c0 = arith.constant 0 : index
249 %4 = arith.subi %c1024, %c1 : index
250 %5 = omp.map.bounds lower_bound(%c0 : index) upper_bound(%4 : index) extent(%c1024 : index) stride(%c1 : index) start_idx(%c1 : index)
251 %6 = omp.map.info var_ptr(%0 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(to) capture(ByRef) bounds(%5) -> !fir.ref<!fir.array<1024xi32>> {name = "a"}
252 %c1_3 = arith.constant 1 : index
253 %c0_4 = arith.constant 0 : index
254 %7 = arith.subi %c1024_0, %c1_3 : index
255 %8 = omp.map.bounds lower_bound(%c0_4 : index) upper_bound(%7 : index) extent(%c1024_0 : index) stride(%c1_3 : index) start_idx(%c1_3 : index)
256 %9 = omp.map.info var_ptr(%1 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(to) capture(ByRef) bounds(%8) -> !fir.ref<!fir.array<1024xi32>> {name = "b"}
257 %c1_5 = arith.constant 1 : index
258 %c0_6 = arith.constant 0 : index
259 %10 = arith.subi %c1024_1, %c1_5 : index
260 %11 = omp.map.bounds lower_bound(%c0_6 : index) upper_bound(%10 : index) extent(%c1024_1 : index) stride(%c1_5 : index) start_idx(%c1_5 : index)
261 %12 = omp.map.info var_ptr(%2 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(always, exit_release_or_enter_alloc) capture(ByRef) bounds(%11) -> !fir.ref<!fir.array<1024xi32>> {name = "c"}
262 omp.target_enter_data map_entries(%6, %9, %12 : !fir.ref<!fir.array<1024xi32>>, !fir.ref<!fir.array<1024xi32>>, !fir.ref<!fir.array<1024xi32>>)
263 %c1_7 = arith.constant 1 : index
264 %c0_8 = arith.constant 0 : index
265 %13 = arith.subi %c1024, %c1_7 : index
266 %14 = omp.map.bounds lower_bound(%c0_8 : index) upper_bound(%13 : index) extent(%c1024 : index) stride(%c1_7 : index) start_idx(%c1_7 : index)
267 %15 = omp.map.info var_ptr(%0 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(from) capture(ByRef) bounds(%14) -> !fir.ref<!fir.array<1024xi32>> {name = "a"}
268 %c1_9 = arith.constant 1 : index
269 %c0_10 = arith.constant 0 : index
270 %16 = arith.subi %c1024_0, %c1_9 : index
271 %17 = omp.map.bounds lower_bound(%c0_10 : index) upper_bound(%16 : index) extent(%c1024_0 : index) stride(%c1_9 : index) start_idx(%c1_9 : index)
272 %18 = omp.map.info var_ptr(%1 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(from) capture(ByRef) bounds(%17) -> !fir.ref<!fir.array<1024xi32>> {name = "b"}
273 %c1_11 = arith.constant 1 : index
274 %c0_12 = arith.constant 0 : index
275 %19 = arith.subi %c1024_1, %c1_11 : index
276 %20 = omp.map.bounds lower_bound(%c0_12 : index) upper_bound(%19 : index) extent(%c1024_1 : index) stride(%c1_11 : index) start_idx(%c1_11 : index)
277 %21 = omp.map.info var_ptr(%2 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%20) -> !fir.ref<!fir.array<1024xi32>> {name = "c"}
278 %c1_13 = arith.constant 1 : index
279 %c0_14 = arith.constant 0 : index
280 %22 = arith.subi %c1024_2, %c1_13 : index
281 %23 = omp.map.bounds lower_bound(%c0_14 : index) upper_bound(%22 : index) extent(%c1024_2 : index) stride(%c1_13 : index) start_idx(%c1_13 : index)
282 %24 = omp.map.info var_ptr(%3 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(always, delete) capture(ByRef) bounds(%23) -> !fir.ref<!fir.array<1024xi32>> {name = "d"}
283 omp.target_exit_data map_entries(%15, %18, %21, %24 : !fir.ref<!fir.array<1024xi32>>, !fir.ref<!fir.array<1024xi32>>, !fir.ref<!fir.array<1024xi32>>, !fir.ref<!fir.array<1024xi32>>)
284 return
285 }
286
287 // CHECK-LABEL: llvm.func @_QPomp_target_data() {
288 // CHECK: %[[VAL_1:.*]] = llvm.mlir.constant(1 : i64) : i64
289 // CHECK: %[[VAL_2:.*]] = llvm.alloca %[[VAL_1]] x !llvm.array<1024 x i32> {bindc_name = "d"} : (i64) -> !llvm.ptr
290 // CHECK: %[[VAL_3:.*]] = llvm.mlir.constant(1 : i64) : i64
291 // CHECK: %[[VAL_4:.*]] = llvm.alloca %[[VAL_3]] x !llvm.array<1024 x i32> {bindc_name = "c"} : (i64) -> !llvm.ptr
292 // CHECK: %[[VAL_5:.*]] = llvm.mlir.constant(1 : i64) : i64
293 // CHECK: %[[VAL_6:.*]] = llvm.alloca %[[VAL_5]] x !llvm.array<1024 x i32> {bindc_name = "b"} : (i64) -> !llvm.ptr
294 // CHECK: %[[VAL_7:.*]] = llvm.mlir.constant(1 : i64) : i64
295 // CHECK: %[[VAL_8:.*]] = llvm.alloca %[[VAL_7]] x !llvm.array<1024 x i32> {bindc_name = "a"} : (i64) -> !llvm.ptr
296 // CHECK: %[[VAL_0:.*]] = llvm.mlir.constant(1024 : index) : i64
297 // CHECK: %[[VAL_9:.*]] = llvm.mlir.constant(1024 : index) : i64
298 // CHECK: %[[VAL_10:.*]] = llvm.mlir.constant(1024 : index) : i64
299 // CHECK: %[[VAL_11:.*]] = llvm.mlir.constant(1024 : index) : i64
300 // CHECK: %[[VAL_12:.*]] = llvm.mlir.constant(1 : index) : i64
301 // CHECK: %[[VAL_13:.*]] = llvm.mlir.constant(0 : index) : i64
302 // CHECK: %[[VAL_14:.*]] = llvm.mlir.constant(1023 : index) : i64
303 // CHECK: %[[VAL_15:.*]] = omp.map.bounds lower_bound(%[[VAL_13]] : i64) upper_bound(%[[VAL_14]] : i64) extent(%[[VAL_0]] : i64) stride(%[[VAL_12]] : i64) start_idx(%[[VAL_12]] : i64)
304 // CHECK: %[[VAL_16:.*]] = omp.map.info var_ptr(%[[VAL_8]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(to) capture(ByRef) bounds(%[[VAL_15]]) -> !llvm.ptr {name = "a"}
305 // CHECK: %[[VAL_17:.*]] = llvm.mlir.constant(1 : index) : i64
306 // CHECK: %[[VAL_18:.*]] = llvm.mlir.constant(0 : index) : i64
307 // CHECK: %[[VAL_19:.*]] = llvm.mlir.constant(1023 : index) : i64
308 // CHECK: %[[VAL_20:.*]] = omp.map.bounds lower_bound(%[[VAL_18]] : i64) upper_bound(%[[VAL_19]] : i64) extent(%[[VAL_9]] : i64) stride(%[[VAL_17]] : i64) start_idx(%[[VAL_17]] : i64)
309 // CHECK: %[[VAL_21:.*]] = omp.map.info var_ptr(%[[VAL_6]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(to) capture(ByRef) bounds(%[[VAL_20]]) -> !llvm.ptr {name = "b"}
310 // CHECK: %[[VAL_22:.*]] = llvm.mlir.constant(1 : index) : i64
311 // CHECK: %[[VAL_23:.*]] = llvm.mlir.constant(0 : index) : i64
312 // CHECK: %[[VAL_24:.*]] = llvm.mlir.constant(1023 : index) : i64
313 // CHECK: %[[VAL_25:.*]] = omp.map.bounds lower_bound(%[[VAL_23]] : i64) upper_bound(%[[VAL_24]] : i64) extent(%[[VAL_10]] : i64) stride(%[[VAL_22]] : i64) start_idx(%[[VAL_22]] : i64)
314 // CHECK: %[[VAL_26:.*]] = omp.map.info var_ptr(%[[VAL_4]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(always, exit_release_or_enter_alloc) capture(ByRef) bounds(%[[VAL_25]]) -> !llvm.ptr {name = "c"}
315 // CHECK: omp.target_enter_data map_entries(%[[VAL_16]], %[[VAL_21]], %[[VAL_26]] : !llvm.ptr, !llvm.ptr, !llvm.ptr)
316 // CHECK: %[[VAL_27:.*]] = llvm.mlir.constant(1 : index) : i64
317 // CHECK: %[[VAL_28:.*]] = llvm.mlir.constant(0 : index) : i64
318 // CHECK: %[[VAL_29:.*]] = llvm.mlir.constant(1023 : index) : i64
319 // CHECK: %[[VAL_30:.*]] = omp.map.bounds lower_bound(%[[VAL_28]] : i64) upper_bound(%[[VAL_29]] : i64) extent(%[[VAL_0]] : i64) stride(%[[VAL_27]] : i64) start_idx(%[[VAL_27]] : i64)
320 // CHECK: %[[VAL_31:.*]] = omp.map.info var_ptr(%[[VAL_8]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(from) capture(ByRef) bounds(%[[VAL_30]]) -> !llvm.ptr {name = "a"}
321 // CHECK: %[[VAL_32:.*]] = llvm.mlir.constant(1 : index) : i64
322 // CHECK: %[[VAL_33:.*]] = llvm.mlir.constant(0 : index) : i64
323 // CHECK: %[[VAL_34:.*]] = llvm.mlir.constant(1023 : index) : i64
324 // CHECK: %[[VAL_35:.*]] = omp.map.bounds lower_bound(%[[VAL_33]] : i64) upper_bound(%[[VAL_34]] : i64) extent(%[[VAL_9]] : i64) stride(%[[VAL_32]] : i64) start_idx(%[[VAL_32]] : i64)
325 // CHECK: %[[VAL_36:.*]] = omp.map.info var_ptr(%[[VAL_6]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(from) capture(ByRef) bounds(%[[VAL_35]]) -> !llvm.ptr {name = "b"}
326 // CHECK: %[[VAL_37:.*]] = llvm.mlir.constant(1 : index) : i64
327 // CHECK: %[[VAL_38:.*]] = llvm.mlir.constant(0 : index) : i64
328 // CHECK: %[[VAL_39:.*]] = llvm.mlir.constant(1023 : index) : i64
329 // CHECK: %[[VAL_40:.*]] = omp.map.bounds lower_bound(%[[VAL_38]] : i64) upper_bound(%[[VAL_39]] : i64) extent(%[[VAL_10]] : i64) stride(%[[VAL_37]] : i64) start_idx(%[[VAL_37]] : i64)
330 // CHECK: %[[VAL_41:.*]] = omp.map.info var_ptr(%[[VAL_4]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(exit_release_or_enter_alloc) capture(ByRef) bounds(%[[VAL_40]]) -> !llvm.ptr {name = "c"}
331 // CHECK: %[[VAL_42:.*]] = llvm.mlir.constant(1 : index) : i64
332 // CHECK: %[[VAL_43:.*]] = llvm.mlir.constant(0 : index) : i64
333 // CHECK: %[[VAL_44:.*]] = llvm.mlir.constant(1023 : index) : i64
334 // CHECK: %[[VAL_45:.*]] = omp.map.bounds lower_bound(%[[VAL_43]] : i64) upper_bound(%[[VAL_44]] : i64) extent(%[[VAL_11]] : i64) stride(%[[VAL_42]] : i64) start_idx(%[[VAL_42]] : i64)
335 // CHECK: %[[VAL_46:.*]] = omp.map.info var_ptr(%[[VAL_2]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(always, delete) capture(ByRef) bounds(%[[VAL_45]]) -> !llvm.ptr {name = "d"}
336 // CHECK: omp.target_exit_data map_entries(%[[VAL_31]], %[[VAL_36]], %[[VAL_41]], %[[VAL_46]] : !llvm.ptr, !llvm.ptr, !llvm.ptr, !llvm.ptr)
337 // CHECK: llvm.return
338 // CHECK: }
339
340 // -----
341
342 func.func @_QPopenmp_target_data_region() {
343 %0 = fir.alloca !fir.array<1024xi32> {bindc_name = "a", uniq_name = "_QFopenmp_target_data_regionEa"}
344 %1 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFopenmp_target_data_regionEi"}
345 %c1024 = arith.constant 1024 : index
346 %c3 = arith.constant 1 : index
347 %c0 = arith.constant 0 : index
348 %c2 = arith.subi %c1024, %c3 : index
349 %bound = omp.map.bounds lower_bound(%c0 : index) upper_bound(%c2 : index) extent(%c1024 : index) stride(%c3 : index) start_idx(%c3 : index)
350 %entry = omp.map.info var_ptr(%0 : !fir.ref<!fir.array<1024xi32>>, !fir.array<1024xi32>) map_clauses(tofrom) capture(ByRef) bounds(%bound) -> !fir.ref<!fir.array<1024xi32>> {name = "a"}
351 omp.target_data map_entries(%entry : !fir.ref<!fir.array<1024xi32>>) {
352 %c1_i32 = arith.constant 1 : i32
353 %2 = fir.convert %c1_i32 : (i32) -> index
354 %c1024_i32 = arith.constant 1024 : i32
355 %3 = fir.convert %c1024_i32 : (i32) -> index
356 %c1 = arith.constant 1 : index
357 %4 = fir.convert %2 : (index) -> i32
358 %5:2 = fir.do_loop %arg0 = %2 to %3 step %c1 iter_args(%arg1 = %4) -> (index, i32) {
359 fir.store %arg1 to %1 : !fir.ref<i32>
360 %6 = fir.load %1 : !fir.ref<i32>
361 %7 = fir.load %1 : !fir.ref<i32>
362 %8 = fir.convert %7 : (i32) -> i64
363 %c1_i64 = arith.constant 1 : i64
364 %9 = arith.subi %8, %c1_i64 : i64
365 %10 = fir.coordinate_of %0, %9 : (!fir.ref<!fir.array<1024xi32>>, i64) -> !fir.ref<i32>
366 fir.store %6 to %10 : !fir.ref<i32>
367 %11 = arith.addi %arg0, %c1 : index
368 %12 = fir.convert %c1 : (index) -> i32
369 %13 = fir.load %1 : !fir.ref<i32>
370 %14 = arith.addi %13, %12 : i32
371 fir.result %11, %14 : index, i32
372 }
373 fir.store %5#1 to %1 : !fir.ref<i32>
374 omp.terminator
375 }
376 return
377 }
378
379 // CHECK-LABEL: llvm.func @_QPopenmp_target_data_region() {
380 // CHECK: %[[VAL_2:.*]] = llvm.mlir.constant(1 : i64) : i64
381 // CHECK: %[[VAL_3:.*]] = llvm.alloca %[[VAL_2]] x i32 {bindc_name = "i"} : (i64) -> !llvm.ptr
382 // CHECK: %[[VAL_0:.*]] = llvm.mlir.constant(1 : i64) : i64
383 // CHECK: %[[VAL_1:.*]] = llvm.alloca %[[VAL_0]] x !llvm.array<1024 x i32> {bindc_name = "a"} : (i64) -> !llvm.ptr
384 // CHECK: %[[VAL_MAX:.*]] = llvm.mlir.constant(1024 : index) : i64
385 // CHECK: %[[VAL_ONE:.*]] = llvm.mlir.constant(1 : index) : i64
386 // CHECK: %[[VAL_ZERO:.*]] = llvm.mlir.constant(0 : index) : i64
387 // CHECK: %[[VAL_UPPER:.*]] = llvm.mlir.constant(1023 : index) : i64
388 // CHECK: %[[VAL_BOUNDS:.*]] = omp.map.bounds lower_bound(%[[VAL_ZERO]] : i64) upper_bound(%[[VAL_UPPER]] : i64) extent(%[[VAL_MAX]] : i64) stride(%[[VAL_ONE]] : i64) start_idx(%[[VAL_ONE]] : i64)
389 // CHECK: %[[VAL_MAP:.*]] = omp.map.info var_ptr(%[[VAL_1]] : !llvm.ptr, !llvm.array<1024 x i32>) map_clauses(tofrom) capture(ByRef) bounds(%[[VAL_BOUNDS]]) -> !llvm.ptr {name = "a"}
390 // CHECK: omp.target_data map_entries(%[[VAL_MAP]] : !llvm.ptr) {
391 // CHECK: %[[VAL_4:.*]] = llvm.mlir.constant(1 : i32) : i32
392 // CHECK: %[[VAL_5:.*]] = llvm.sext %[[VAL_4]] : i32 to i64
393 // CHECK: %[[VAL_6:.*]] = llvm.mlir.constant(1024 : i32) : i32
394 // CHECK: %[[VAL_7:.*]] = llvm.sext %[[VAL_6]] : i32 to i64
395 // CHECK: %[[VAL_8:.*]] = llvm.mlir.constant(1 : index) : i64
396 // CHECK: %[[VAL_9:.*]] = llvm.trunc %[[VAL_5]] : i64 to i32
397 // CHECK: %[[VAL_10:.*]] = llvm.sub %[[VAL_7]], %[[VAL_5]] : i64
398 // CHECK: %[[VAL_11:.*]] = llvm.add %[[VAL_10]], %[[VAL_8]] : i64
399 // CHECK: llvm.br ^bb1(%[[VAL_5]], %[[VAL_9]], %[[VAL_11]] : i64, i32, i64)
400 // CHECK: ^bb1(%[[VAL_12:.*]]: i64, %[[VAL_13:.*]]: i32, %[[VAL_14:.*]]: i64):
401 // CHECK: %[[VAL_15:.*]] = llvm.mlir.constant(0 : index) : i64
402 // CHECK: %[[VAL_16:.*]] = llvm.icmp "sgt" %[[VAL_14]], %[[VAL_15]] : i64
403 // CHECK: llvm.cond_br %[[VAL_16]], ^bb2, ^bb3
404 // CHECK: ^bb2:
405 // CHECK: llvm.store %[[VAL_13]], %[[VAL_3]] : i32, !llvm.ptr
406 // CHECK: %[[VAL_17:.*]] = llvm.load %[[VAL_3]] : !llvm.ptr -> i32
407 // CHECK: %[[VAL_18:.*]] = llvm.load %[[VAL_3]] : !llvm.ptr -> i32
408 // CHECK: %[[VAL_19:.*]] = llvm.sext %[[VAL_18]] : i32 to i64
409 // CHECK: %[[VAL_20:.*]] = llvm.mlir.constant(1 : i64) : i64
410 // CHECK: %[[VAL_21:.*]] = llvm.sub %[[VAL_19]], %[[VAL_20]] : i64
411 // CHECK: %[[VAL_22:.*]] = llvm.getelementptr %[[VAL_1]][0, %[[VAL_21]]] : (!llvm.ptr, i64) -> !llvm.ptr
412 // CHECK: llvm.store %[[VAL_17]], %[[VAL_22]] : i32, !llvm.ptr
413 // CHECK: %[[VAL_23:.*]] = llvm.add %[[VAL_12]], %[[VAL_8]] : i64
414 // CHECK: %[[VAL_24:.*]] = llvm.trunc %[[VAL_8]] : i64 to i32
415 // CHECK: %[[VAL_25:.*]] = llvm.load %[[VAL_3]] : !llvm.ptr -> i32
416 // CHECK: %[[VAL_26:.*]] = llvm.add %[[VAL_25]], %[[VAL_24]] : i32
417 // CHECK: %[[VAL_27:.*]] = llvm.add %[[VAL_12]], %[[VAL_8]] : i64
418 // CHECK: %[[VAL_28:.*]] = llvm.mlir.constant(1 : index) : i64
419 // CHECK: %[[VAL_29:.*]] = llvm.sub %[[VAL_14]], %[[VAL_28]] : i64
420 // CHECK: llvm.br ^bb1(%[[VAL_27]], %[[VAL_26]], %[[VAL_29]] : i64, i32, i64)
421 // CHECK: ^bb3:
422 // CHECK: llvm.store %[[VAL_13]], %[[VAL_3]] : i32, !llvm.ptr
423 // CHECK: omp.terminator
424 // CHECK: }
425 // CHECK: llvm.return
426 // CHECK: }
427
428 // -----
429
430 func.func @_QPomp_target_data_empty() {
431 %0 = fir.alloca !fir.array<1024xi32> {bindc_name = "a", uniq_name = "_QFomp_target_data_emptyEa"}
432 omp.target_data use_device_addr(%0 : !fir.ref<!fir.array<1024xi32>>) {
433 }
434 return
435 }
436
437 // CHECK-LABEL: llvm.func @_QPomp_target_data_empty
438 // CHECK: omp.target_data use_device_addr(%1 : !llvm.ptr) {
439 // CHECK: }
440
441 // -----
442
443 func.func @_QPomp_target() {
444 %c512 = arith.constant 512 : index
445 %0 = fir.alloca !fir.array<512xi32> {bindc_name = "a", uniq_name = "_QFomp_targetEa"}
446 %c64_i32 = arith.constant 64 : i32
447 %c1 = arith.constant 1 : index
448 %c0 = arith.constant 0 : index
449 %1 = arith.subi %c512, %c1 : index
450 %2 = omp.map.bounds lower_bound(%c0 : index) upper_bound(%1 : index) extent(%c512 : index) stride(%c1 : index) start_idx(%c1 : index)
451 %3 = omp.map.info var_ptr(%0 : !fir.ref<!fir.array<512xi32>>, !fir.array<512xi32>) map_clauses(tofrom) capture(ByRef) bounds(%2) -> !fir.ref<!fir.array<512xi32>> {name = "a"}
452 omp.target thread_limit(%c64_i32 : i32) map_entries(%3 -> %arg0 : !fir.ref<!fir.array<512xi32>>) {
453 ^bb0(%arg0: !fir.ref<!fir.array<512xi32>>):
454 %c10_i32 = arith.constant 10 : i32
455 %c1_i64 = arith.constant 1 : i64
456 %c1_i64_0 = arith.constant 1 : i64
457 %4 = arith.subi %c1_i64, %c1_i64_0 : i64
458 %5 = fir.coordinate_of %arg0, %4 : (!fir.ref<!fir.array<512xi32>>, i64) -> !fir.ref<i32>
459 fir.store %c10_i32 to %5 : !fir.ref<i32>
460 omp.terminator
461 }
462 return
463 }
464
465 // CHECK-LABEL: llvm.func @_QPomp_target() {
466 // CHECK: %[[VAL_0:.*]] = llvm.mlir.constant(1 : i64) : i64
467 // CHECK: %[[VAL_1:.*]] = llvm.alloca %[[VAL_0]] x !llvm.array<512 x i32> {bindc_name = "a"} : (i64) -> !llvm.ptr
468 // CHECK: %[[EXTENT:.*]] = llvm.mlir.constant(512 : index) : i64
469 // CHECK: %[[VAL_2:.*]] = llvm.mlir.constant(64 : i32) : i32
470 // CHECK: %[[STRIDE:.*]] = llvm.mlir.constant(1 : index) : i64
471 // CHECK: %[[LOWER:.*]] = llvm.mlir.constant(0 : index) : i64
472 // CHECK: %[[UPPER:.*]] = llvm.mlir.constant(511 : index) : i64
473 // CHECK: %[[BOUNDS:.*]] = omp.map.bounds lower_bound(%[[LOWER]] : i64) upper_bound(%[[UPPER]] : i64) extent(%[[EXTENT]] : i64) stride(%[[STRIDE]] : i64) start_idx(%[[STRIDE]] : i64)
474 // CHECK: %[[MAP:.*]] = omp.map.info var_ptr(%[[VAL_1]] : !llvm.ptr, !llvm.array<512 x i32>) map_clauses(tofrom) capture(ByRef) bounds(%[[BOUNDS]]) -> !llvm.ptr {name = "a"}
475 // CHECK: omp.target thread_limit(%[[VAL_2]] : i32) map_entries(%[[MAP]] -> %[[ARG_0:.*]] : !llvm.ptr) {
476 // CHECK: ^bb0(%[[ARG_0]]: !llvm.ptr):
477 // CHECK: %[[VAL_3:.*]] = llvm.mlir.constant(10 : i32) : i32
478 // CHECK: %[[VAL_4:.*]] = llvm.mlir.constant(1 : i64) : i64
479 // CHECK: %[[VAL_5:.*]] = llvm.mlir.constant(1 : i64) : i64
480 // CHECK: %[[VAL_6:.*]] = llvm.mlir.constant(0 : i64) : i64
481 // CHECK: %[[VAL_7:.*]] = llvm.getelementptr %[[ARG_0]][0, %[[VAL_6]]] : (!llvm.ptr, i64) -> !llvm.ptr
482 // CHECK: llvm.store %[[VAL_3]], %[[VAL_7]] : i32, !llvm.ptr
483 // CHECK: omp.terminator
484 // CHECK: }
485 // CHECK: llvm.return
486 // CHECK: }
487
488 // -----
489
490 func.func @_QPsimd_with_nested_loop() {
491 %0 = fir.alloca i32 {adapt.valuebyref}
492 %1 = fir.alloca !fir.array<10xi32> {bindc_name = "a", uniq_name = "_QFsimd_with_nested_loopEa"}
493 %2 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsimd_with_nested_loopEi"}
494 %3 = fir.alloca i32 {bindc_name = "j", uniq_name = "_QFsimd_with_nested_loopEj"}
495 %c1_i32 = arith.constant 1 : i32
496 %c10_i32 = arith.constant 10 : i32
497 %c1_i32_0 = arith.constant 1 : i32
498 omp.simd {
499 omp.loop_nest (%arg0) : i32 = (%c1_i32) to (%c10_i32) inclusive step (%c1_i32_0) {
500 fir.store %arg0 to %0 : !fir.ref<i32>
501 %c1_i32_1 = arith.constant 1 : i32
502 %4 = fir.convert %c1_i32_1 : (i32) -> index
503 %c10_i32_2 = arith.constant 10 : i32
504 %5 = fir.convert %c10_i32_2 : (i32) -> index
505 %c1 = arith.constant 1 : index
506 %6 = fir.do_loop %arg1 = %4 to %5 step %c1 -> index {
507 %8 = fir.convert %arg1 : (index) -> i32
508 fir.store %8 to %3 : !fir.ref<i32>
509 %9 = fir.load %0 : !fir.ref<i32>
510 %10 = fir.load %0 : !fir.ref<i32>
511 %11 = fir.convert %10 : (i32) -> i64
512 %c1_i64 = arith.constant 1 : i64
513 %12 = arith.subi %11, %c1_i64 : i64
514 %13 = fir.coordinate_of %1, %12 : (!fir.ref<!fir.array<10xi32>>, i64) -> !fir.ref<i32>
515 fir.store %9 to %13 : !fir.ref<i32>
516 %14 = arith.addi %arg1, %c1 : index
517 fir.result %14 : index
518 }
519 %7 = fir.convert %6 : (index) -> i32
520 fir.store %7 to %3 : !fir.ref<i32>
521 omp.yield
522 }
523 omp.terminator
524 }
525 return
526 }
527
528 // CHECK-LABEL: llvm.func @_QPsimd_with_nested_loop() {
529 // CHECK: %[[LOWER:.*]] = llvm.mlir.constant(1 : i32) : i32
530 // CHECK: %[[UPPER:.*]] = llvm.mlir.constant(10 : i32) : i32
531 // CHECK: %[[STEP:.*]] = llvm.mlir.constant(1 : i32) : i32
532 // CHECK: omp.simd {
533 // CHECK-NEXT: omp.loop_nest (%[[CNT:.*]]) : i32 = (%[[LOWER]]) to (%[[UPPER]]) inclusive step (%[[STEP]]) {
534 // CHECK: llvm.br ^bb1(%[[VAL_1:.*]], %[[VAL_2:.*]] : i64, i64)
535 // CHECK: ^bb1(%[[VAL_3:.*]]: i64, %[[VAL_4:.*]]: i64):
536 // CHECK: %[[VAL_5:.*]] = llvm.mlir.constant(0 : index) : i64
537 // CHECK: %[[VAL_6:.*]] = llvm.icmp "sgt" %[[VAL_4]], %[[VAL_5]] : i64
538 // CHECK: llvm.cond_br %[[VAL_6]], ^bb2, ^bb3
539 // CHECK: ^bb2:
540 // CHECK: llvm.br ^bb1(%[[VAL_7:.*]], %[[VAL_8:.*]] : i64, i64)
541 // CHECK: ^bb3:
542 // CHECK: omp.yield
543 // CHECK: }
544 // CHECK: omp.terminator
545 // CHECK: }
546 // CHECK: llvm.return
547 // CHECK: }
548
549 // -----
550
551 func.func @_QPomp_taskgroup() {
552 omp.taskgroup {
553 omp.task {
554 fir.call @_QPwork() : () -> ()
555 omp.terminator
556 }
557 omp.terminator
558 }
559 return
560 }
561 func.func private @_QPwork()
562
563 // CHECK-LABEL: llvm.func @_QPomp_taskgroup() {
564 // CHECK: omp.taskgroup {
565 // CHECK: omp.task {
566 // CHECK: llvm.call @_QPwork() : () -> ()
567 // CHECK: omp.terminator
568 // CHECK: }
569 // CHECK: omp.terminator
570 // CHECK: }
571 // CHECK: llvm.return
572 // CHECK: }
573 // CHECK: llvm.func @_QPwork() attributes {sym_visibility = "private"}
574 // CHECK: }
575
576 // -----
577
578
579 func.func @_QQmain() {
580 %c0 = arith.constant 0 : index
581 %c5 = arith.constant 5 : index
582 %c1 = arith.constant 1 : index
583 %0 = fir.alloca i32
584 omp.taskgroup {
585 %1 = fir.convert %c1 : (index) -> i32
586 cf.br ^bb1(%1, %c5 : i32, index)
587 ^bb1(%2: i32, %3: index): // 2 preds: ^bb0, ^bb2
588 %4 = arith.cmpi sgt, %3, %c0 : index
589 cf.cond_br %4, ^bb2, ^bb3
590 ^bb2: // pred: ^bb1
591 fir.store %2 to %0 : !fir.ref<i32>
592 omp.task {
593 fir.call @_QFPdo_work(%0) : (!fir.ref<i32>) -> ()
594 omp.terminator
595 }
596 %5 = fir.load %0 : !fir.ref<i32>
597 %6 = arith.addi %5, %1 : i32
598 %7 = arith.subi %3, %c1 : index
599 cf.br ^bb1(%6, %7 : i32, index)
600 ^bb3: // pred: ^bb1
601 fir.store %2 to %0 : !fir.ref<i32>
602 omp.terminator
603 }
604 return
605 }
606 func.func private @_QFPdo_work(!fir.ref<i32>)
607
608 // CHECK-LABEL: llvm.func @_QQmain
609 // CHECK: omp.taskgroup {
610 // CHECK: omp.task {
611 // CHECK: llvm.call @_QFPdo_work({{.*}}) : (!llvm.ptr) -> ()
612 // CHECK: omp.terminator
613 // CHECK: }
614 // CHECK: omp.terminator
615 // CHECK: }
616 // CHECK: llvm.return
617 // CHECK: }
618 // CHECK: llvm.func @_QFPdo_work(!llvm.ptr)
619 // CHECK: }
620
621 // -----
622
623 func.func @_QPs() {
624 %0 = fir.address_of(@_QFsEc) : !fir.ref<i32>
625 omp.atomic.update %0 : !fir.ref<i32> {
626 ^bb0(%arg0: i32):
627 %c1_i32 = arith.constant 1 : i32
628 %1 = arith.addi %arg0, %c1_i32 : i32
629 omp.yield(%1 : i32)
630 }
631 return
632 }
633 fir.global internal @_QFsEc : i32 {
634 %c10_i32 = arith.constant 10 : i32
635 fir.has_value %c10_i32 : i32
636 }
637
638 // CHECK-LABEL: llvm.func @_QPs() {
639 // CHECK: %[[GLOBAL_VAR:.*]] = llvm.mlir.addressof @[[GLOBAL:.*]] : !llvm.ptr
640 // CHECK: omp.atomic.update %[[GLOBAL_VAR]] : !llvm.ptr {
641 // CHECK: ^bb0(%[[IN_VAL:.*]]: i32):
642 // CHECK: %[[CONST_1:.*]] = llvm.mlir.constant(1 : i32) : i32
643 // CHECK: %[[OUT_VAL:.*]] = llvm.add %[[IN_VAL]], %[[CONST_1]] : i32
644 // CHECK: omp.yield(%[[OUT_VAL]] : i32)
645 // CHECK: }
646 // CHECK: llvm.return
647 // CHECK: }
648 // CHECK: llvm.mlir.global internal @[[GLOBAL]]() {{.*}} : i32 {
649 // CHECK: %[[INIT_10:.*]] = llvm.mlir.constant(10 : i32) : i32
650 // CHECK: llvm.return %[[INIT_10]] : i32
651 // CHECK: }
652
653 func.func @_QPsb() {
654 %c10 = arith.constant 10 : index
655 %c1 = arith.constant 1 : index
656 %c1_i32 = arith.constant 1 : i32
657 %c0_i32 = arith.constant 0 : i32
658 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsbEi"}
659 %1 = fir.alloca i32 {bindc_name = "li", uniq_name = "_QFsbEli"}
660 fir.store %c0_i32 to %1 : !fir.ref<i32>
661 omp.sections {
662 omp.section {
663 %2 = fir.convert %c1 : (index) -> i32
664 %3:2 = fir.do_loop %arg0 = %c1 to %c10 step %c1 iter_args(%arg1 = %2) -> (index, i32) {
665 fir.store %arg1 to %0 : !fir.ref<i32>
666 %4 = fir.load %1 : !fir.ref<i32>
667 %5 = arith.addi %4, %c1_i32 : i32
668 fir.store %5 to %1 : !fir.ref<i32>
669 %6 = arith.addi %arg0, %c1 : index
670 %7 = fir.convert %c1 : (index) -> i32
671 %8 = fir.load %0 : !fir.ref<i32>
672 %9 = arith.addi %8, %7 : i32
673 fir.result %6, %9 : index, i32
674 }
675 fir.store %3#1 to %0 : !fir.ref<i32>
676 omp.terminator
677 }
678 omp.terminator
679 }
680 return
681 }
682
683 // CHECK: llvm.func @_QPsb() {
684 // CHECK: %[[SIZE:.*]] = llvm.mlir.constant(1 : i64) : i64
685 // CHECK: %[[LI_REF:.*]] = llvm.alloca %[[SIZE]] x i32 {bindc_name = "li"} : (i64) -> !llvm.ptr
686 // CHECK: %[[ONE:.*]] = llvm.mlir.constant(1 : i32) : i32
687 // CHECK: omp.sections {
688 // CHECK: omp.section {
689 // CHECK: llvm.br ^[[BB_ENTRY:.*]]({{.*}})
690 // CHECK: ^[[BB_ENTRY]]({{.*}}):
691 // CHECK: %[[EXIT_COND:.*]] = llvm.icmp "sgt"
692 // CHECK: llvm.cond_br %[[EXIT_COND]], ^[[BB_LOOP_BODY:.*]], ^[[BB_EXIT:.*]]
693 // CHECK: ^[[BB_LOOP_BODY]]:
694 // CHECK: %[[LI_VAL:.*]] = llvm.load %[[LI_REF]] : !llvm.ptr -> i32
695 // CHECK: %[[LI_INC:.*]] = llvm.add %[[LI_VAL]], %[[ONE]] : i32
696 // CHECK: llvm.store %[[LI_INC]], %[[LI_REF]] : i32, !llvm.ptr
697 // CHECK: llvm.br ^[[BB_ENTRY]]({{.*}})
698 // CHECK: ^[[BB_EXIT]]:
699 // CHECK: omp.terminator
700 // CHECK: }
701 // CHECK: omp.terminator
702 // CHECK: }
703 // CHECK: llvm.return
704 // CHECK: }
705
706 // -----
707
708 // CHECK: omp.declare_reduction @[[EQV_REDUCTION:.*]] : i32 init {
709 // CHECK: ^bb0(%{{.*}}: i32):
710 // CHECK: %[[TRUE:.*]] = llvm.mlir.constant(1 : i64) : i32
711 // CHECK: omp.yield(%[[TRUE]] : i32)
712 // CHECK: } combiner {
713 // CHECK: ^bb0(%[[ARG_1:.*]]: i32, %[[ARG_2:.*]]: i32):
714 // CHECK: %[[ZERO_1:.*]] = llvm.mlir.constant(0 : i64) : i32
715 // CHECK: %[[ARGVAL_1:.*]] = llvm.icmp "ne" %[[ARG_1]], %[[ZERO_1]] : i32
716 // CHECK: %[[ZERO_2:.*]] = llvm.mlir.constant(0 : i64) : i32
717 // CHECK: %[[ARGVAL_2:.*]] = llvm.icmp "ne" %[[ARG_2]], %[[ZERO_2]] : i32
718 // CHECK: %[[RES:.*]] = llvm.icmp "eq" %[[ARGVAL_1]], %[[ARGVAL_2]] : i1
719 // CHECK: %[[RES_EXT:.*]] = llvm.zext %[[RES]] : i1 to i32
720 // CHECK: omp.yield(%[[RES_EXT]] : i32)
721 // CHECK: }
722 // CHECK-LABEL: @_QPsimple_reduction
723 // CHECK-SAME: %[[ARRAY_REF:.*]]: !llvm.ptr
724 // CHECK: %[[VAL_1:.*]] = llvm.mlir.constant(1 : i64) : i64
725 // CHECK: %[[RED_ACCUMULATOR:.*]] = llvm.alloca %[[VAL_1]] x i32 {bindc_name = "x"} : (i64) -> !llvm.ptr
726 // CHECK: omp.parallel {
727 // CHECK: omp.wsloop reduction(@[[EQV_REDUCTION]] %[[RED_ACCUMULATOR]] -> %[[PRV:.+]] : !llvm.ptr) {
728 // CHECK-NEXT: omp.loop_nest
729 // CHECK: %[[ARRAY_ELEM_REF:.*]] = llvm.getelementptr %[[ARRAY_REF]][0, %{{.*}}] : (!llvm.ptr, i64) -> !llvm.ptr
730 // CHECK: %[[ARRAY_ELEM:.*]] = llvm.load %[[ARRAY_ELEM_REF]] : !llvm.ptr -> i32
731 // CHECK: %[[LPRV:.+]] = llvm.load %[[PRV]] : !llvm.ptr -> i32
732 // CHECK: %[[ZERO_1:.*]] = llvm.mlir.constant(0 : i64) : i32
733 // CHECK: %[[ARGVAL_1:.*]] = llvm.icmp "ne" %[[LPRV]], %[[ZERO_1]] : i32
734 // CHECK: %[[ZERO_2:.*]] = llvm.mlir.constant(0 : i64) : i32
735 // CHECK: %[[ARGVAL_2:.*]] = llvm.icmp "ne" %[[ARRAY_ELEM]], %[[ZERO_2]] : i32
736 // CHECK: %[[RES:.*]] = llvm.icmp "eq" %[[ARGVAL_2]], %[[ARGVAL_1]] : i1
737 // CHECK: %[[RES_EXT:.*]] = llvm.zext %[[RES]] : i1 to i32
738 // CHECK: llvm.store %[[RES_EXT]], %[[PRV]] : i32, !llvm.ptr
739 // CHECK: omp.yield
740 // CHECK: omp.terminator
741 // CHECK: omp.terminator
742 // CHECK: llvm.return
743
744 omp.declare_reduction @eqv_reduction : !fir.logical<4> init {
745 ^bb0(%arg0: !fir.logical<4>):
746 %true = arith.constant true
747 %0 = fir.convert %true : (i1) -> !fir.logical<4>
748 omp.yield(%0 : !fir.logical<4>)
749 } combiner {
750 ^bb0(%arg0: !fir.logical<4>, %arg1: !fir.logical<4>):
751 %0 = fir.convert %arg0 : (!fir.logical<4>) -> i1
752 %1 = fir.convert %arg1 : (!fir.logical<4>) -> i1
753 %2 = arith.cmpi eq, %0, %1 : i1
754 %3 = fir.convert %2 : (i1) -> !fir.logical<4>
755 omp.yield(%3 : !fir.logical<4>)
756 }
757 func.func @_QPsimple_reduction(%arg0: !fir.ref<!fir.array<100x!fir.logical<4>>> {fir.bindc_name = "y"}) {
758 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsimple_reductionEi"}
759 %1 = fir.alloca !fir.logical<4> {bindc_name = "x", uniq_name = "_QFsimple_reductionEx"}
760 %true = arith.constant true
761 %2 = fir.convert %true : (i1) -> !fir.logical<4>
762 fir.store %2 to %1 : !fir.ref<!fir.logical<4>>
763 omp.parallel {
764 %3 = fir.alloca i32 {adapt.valuebyref, pinned}
765 %c1_i32 = arith.constant 1 : i32
766 %c100_i32 = arith.constant 100 : i32
767 %c1_i32_0 = arith.constant 1 : i32
768 omp.wsloop reduction(@eqv_reduction %1 -> %prv : !fir.ref<!fir.logical<4>>) {
769 omp.loop_nest (%arg1) : i32 = (%c1_i32) to (%c100_i32) inclusive step (%c1_i32_0) {
770 fir.store %arg1 to %3 : !fir.ref<i32>
771 %4 = fir.load %3 : !fir.ref<i32>
772 %5 = fir.convert %4 : (i32) -> i64
773 %c1_i64 = arith.constant 1 : i64
774 %6 = arith.subi %5, %c1_i64 : i64
775 %7 = fir.coordinate_of %arg0, %6 : (!fir.ref<!fir.array<100x!fir.logical<4>>>, i64) -> !fir.ref<!fir.logical<4>>
776 %8 = fir.load %7 : !fir.ref<!fir.logical<4>>
777 %lprv = fir.load %prv : !fir.ref<!fir.logical<4>>
778 %lprv1 = fir.convert %lprv : (!fir.logical<4>) -> i1
779 %9 = fir.convert %8 : (!fir.logical<4>) -> i1
780 %10 = arith.cmpi eq, %9, %lprv1 : i1
781 %11 = fir.convert %10 : (i1) -> !fir.logical<4>
782 fir.store %11 to %prv : !fir.ref<!fir.logical<4>>
783 omp.yield
784 }
785 omp.terminator
786 }
787 omp.terminator
788 }
789 return
790 }
791
792 // -----
793
794 // CHECK: llvm.func @_QPs
795 // CHECK: omp.atomic.read %{{.*}} = %{{.*}} : !llvm.ptr, !llvm.struct<(f32, f32)>
796
797 func.func @_QPs(%arg0: !fir.ref<!fir.complex<4>> {fir.bindc_name = "x"}) {
798 %0 = fir.alloca !fir.complex<4> {bindc_name = "v", uniq_name = "_QFsEv"}
799 omp.atomic.read %0 = %arg0 : !fir.ref<!fir.complex<4>>, !fir.complex<4>
800 return
801 }
802
803 // -----
804
805 // Test if llvm.alloca is properly inserted in the omp section
806
807 //CHECK: %[[CONST0:.*]] = llvm.mlir.constant(1 : i64) : i64
808 //CHECK: %[[CONST:.*]] = llvm.mlir.constant(1 : i64) : i64
809 //CHECK: %[[ALLOCA:.*]] = llvm.alloca %[[CONST]] x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)> {bindc_name = "iattr"} : (i64) -> !llvm.ptr
810 //CHECK: omp.parallel {
811 //CHECK: %[[CONST_1:.*]] = llvm.mlir.constant(1 : i32) : i32
812 //CHECK: %[[ALLOCA_1:.*]] = llvm.alloca %[[CONST_1:.*]] x !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)> {alignment = 8 : i64} : (i32) -> !llvm.ptr
813 //CHECK: %[[LOAD:.*]] = llvm.load %[[ALLOCA]] : !llvm.ptr -> !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>
814 //CHECK: llvm.store %[[LOAD]], %[[ALLOCA_1]] : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>, !llvm.ptr
815 //CHECK: %[[GEP:.*]] = llvm.getelementptr %[[ALLOCA_1]][0, 0] : (!llvm.ptr) -> !llvm.ptr
816 //CHECK: %[[LOAD_2:.*]] = llvm.load %[[GEP]] : !llvm.ptr -> !llvm.ptr
817 //CHECK: omp.terminator
818 //CHECK: }
819
820 func.func @_QQmain() attributes {fir.bindc_name = "mn"} {
821 %0 = fir.alloca !fir.box<!fir.ptr<i32>> {bindc_name = "iattr", uniq_name = "_QFEiattr"}
822 %1 = fir.zero_bits !fir.ptr<i32>
823 %2 = fir.embox %1 : (!fir.ptr<i32>) -> !fir.box<!fir.ptr<i32>>
824 fir.store %2 to %0 : !fir.ref<!fir.box<!fir.ptr<i32>>>
825 %3 = fir.address_of(@_QFEx) : !fir.ref<i32>
826 %4 = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFEy"}
827 %5 = fir.embox %3 : (!fir.ref<i32>) -> !fir.box<!fir.ptr<i32>>
828 fir.store %5 to %0 : !fir.ref<!fir.box<!fir.ptr<i32>>>
829 omp.parallel {
830 %6 = fir.load %4 : !fir.ref<i32>
831 %7 = fir.load %0 : !fir.ref<!fir.box<!fir.ptr<i32>>>
832 %8 = fir.box_addr %7 : (!fir.box<!fir.ptr<i32>>) -> !fir.ptr<i32>
833 fir.store %6 to %8 : !fir.ptr<i32>
834 omp.terminator
835 }
836 return
837 }
838 fir.global internal @_QFEx target : i32 {
839 %0 = fir.zero_bits i32
840 fir.has_value %0 : i32
841 }
842
843 // -----
844
845 // Test if llvm.alloca is properly inserted in the omp ordered region
846
847 // CHECK: llvm.func @sub_
848 func.func @sub_() {
849 %c0 = arith.constant 0 : index
850 %c1 = arith.constant 1 : index
851 %0 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFsubEi"}
852 // CHECK: omp.ordered.region
853 omp.ordered.region {
854 %1 = fir.convert %c1 : (index) -> i32
855 cf.br ^bb1(%1, %c1 : i32, index)
856 ^bb1(%2: i32, %3: index): // 2 preds: ^bb0, ^bb2
857 %4 = arith.cmpi sgt, %3, %c0 : index
858 cf.cond_br %4, ^bb2, ^bb3
859 ^bb2: // pred: ^bb1
860 fir.store %2 to %0 : !fir.ref<i32>
861 %5 = fir.load %0 : !fir.ref<i32>
862 // CHECK: llvm.add
863 %6 = arith.addi %5, %1 : i32
864 // CHECK: llvm.sub
865 %7 = arith.subi %3, %c1 : index
866 cf.br ^bb1(%6, %7 : i32, index)
867 ^bb3: // pred: ^bb1
868 fir.store %2 to %0 : !fir.ref<i32>
869 // CHECK: omp.terminator
870 omp.terminator
871 }
872 return
873 }
874
875 // -----
876
877 // CHECK-LABEL: llvm.func @flush_standalone_
878 // CHECK-SAME: %[[ARG_A:.*]]: !llvm.ptr {fir.bindc_name = "a"}, %[[ARG_B:.*]]: !llvm.ptr {fir.bindc_name = "b"}, %[[ARG_C:.*]]: !llvm.ptr {fir.bindc_name = "c"})
879 func.func @flush_standalone_(%arg0: !fir.ref<i32> {fir.bindc_name = "a"}, %arg1: !fir.ref<i32> {fir.bindc_name = "b"}, %arg2: !fir.ref<i32> {fir.bindc_name = "c"}) {
880 // CHECK: omp.flush(%[[ARG_A]], %[[ARG_B]], %[[ARG_C]] : !llvm.ptr, !llvm.ptr, !llvm.ptr)
881 omp.flush(%arg0, %arg1, %arg2 : !fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>)
882 // CHECK: omp.flush
883 omp.flush
884 return
885 }
886
887 // CHECK-LABEL: llvm.func @flush_parallel_
888 // CHECK-SAME: %[[ARG_A:.*]]: !llvm.ptr {fir.bindc_name = "a"}, %[[ARG_B:.*]]: !llvm.ptr {fir.bindc_name = "b"}, %[[ARG_C:.*]]: !llvm.ptr {fir.bindc_name = "c"})
889 func.func @flush_parallel_(%arg0: !fir.ref<i32> {fir.bindc_name = "a"}, %arg1: !fir.ref<i32> {fir.bindc_name = "b"}, %arg2: !fir.ref<i32> {fir.bindc_name = "c"}) {
890 // CHECK: omp.parallel {
891 omp.parallel {
892 // CHECK: omp.flush(%[[ARG_A]], %[[ARG_B]], %[[ARG_C]] : !llvm.ptr, !llvm.ptr, !llvm.ptr)
893 omp.flush(%arg0, %arg1, %arg2 : !fir.ref<i32>, !fir.ref<i32>, !fir.ref<i32>)
894 // CHECK: omp.flush
895 omp.flush
896 // CHECK: %[[A_VAL:.*]] = llvm.load %[[ARG_A]] : !llvm.ptr -> i32
897 %0 = fir.load %arg0 : !fir.ref<i32>
898 // CHECK: %[[B_VAL:.*]] = llvm.load %[[ARG_B]] : !llvm.ptr -> i32
899 %1 = fir.load %arg1 : !fir.ref<i32>
900 // CHECK: %[[C_VAL:.*]] = llvm.add %[[A_VAL]], %[[B_VAL]] : i32
901 %2 = arith.addi %0, %1 : i32
902 // CHECK: llvm.store %[[C_VAL]], %[[ARG_C]] : i32, !llvm.ptr
903 fir.store %2 to %arg2 : !fir.ref<i32>
904 // CHECK: omp.terminator
905 omp.terminator
906 // CHECK: }
907 }
908 return
909 }
910
911 // -----
912
913 // CHECK: omp.critical.declare @help hint(contended)
914 omp.critical.declare @help hint(contended)
915
916 // CHECK: llvm.func @omp_critical_() {
917 func.func @omp_critical_() {
918 // CHECK: %[[Y_REF:.*]] = llvm.alloca %{{.*}} x i32 {bindc_name = "y"} : (i64) -> !llvm.ptr
919 %0 = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFomp_criticalEx"}
920 // CHECK: %[[X_REF:.*]] = llvm.alloca %{{.*}} x i32 {bindc_name = "x"} : (i64) -> !llvm.ptr
921 %1 = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFomp_criticalEy"}
922 // CHECK: omp.critical(@help)
923 omp.critical(@help) {
924 // CHECK: %[[X_VAL:.*]] = llvm.load %[[X_REF]] : !llvm.ptr -> i32
925 %2 = fir.load %0 : !fir.ref<i32>
926 // CHECK: %[[Y_VAL:.*]] = llvm.load %[[Y_REF]] : !llvm.ptr -> i32
927 %3 = fir.load %1 : !fir.ref<i32>
928 // CHECK: %[[RESULT:.*]] = llvm.add %[[X_VAL]], %[[Y_VAL]] : i32
929 %4 = arith.addi %2, %3 : i32
930 // CHECK: llvm.store %[[RESULT]], %[[X_REF]] : i32, !llvm.ptr
931 fir.store %4 to %0 : !fir.ref<i32>
932 // CHECK: omp.terminator
933 omp.terminator
934 }
935 return
936 }
937
938 // -----
939
940 // CHECK-LABEL: llvm.func @omp_map_info_descriptor_type_conversion
941 // CHECK-SAME: %[[ARG_0:.*]]: !llvm.ptr)
942
943 func.func @omp_map_info_descriptor_type_conversion(%arg0 : !fir.ref<!fir.box<!fir.heap<i32>>>) {
944 // CHECK: %[[GEP:.*]] = llvm.getelementptr %[[ARG_0]][0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>
945 %0 = fir.box_offset %arg0 base_addr : (!fir.ref<!fir.box<!fir.heap<i32>>>) -> !fir.llvm_ptr<!fir.ref<i32>>
946 // CHECK: %[[MEMBER_MAP:.*]] = omp.map.info var_ptr(%[[GEP]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
947 %1 = omp.map.info var_ptr(%0 : !fir.llvm_ptr<!fir.ref<i32>>, i32) map_clauses(tofrom) capture(ByRef) -> !fir.llvm_ptr<!fir.ref<i32>> {name = ""}
948 // CHECK: %[[DESC_MAP:.*]] = omp.map.info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)>) map_clauses(always, delete) capture(ByRef) members(%[[MEMBER_MAP]] : [0] : !llvm.ptr) -> !llvm.ptr {name = ""}
949 %2 = omp.map.info var_ptr(%arg0 : !fir.ref<!fir.box<!fir.heap<i32>>>, !fir.box<!fir.heap<i32>>) map_clauses(always, delete) capture(ByRef) members(%1 : [0] : !fir.llvm_ptr<!fir.ref<i32>>) -> !fir.ref<!fir.box<!fir.heap<i32>>> {name = ""}
950 // CHECK: omp.target_exit_data map_entries(%[[DESC_MAP]] : !llvm.ptr)
951 omp.target_exit_data map_entries(%2 : !fir.ref<!fir.box<!fir.heap<i32>>>)
952 return
953 }
954
955 // -----
956
957 // CHECK-LABEL: llvm.func @omp_map_info_derived_type_explicit_member_conversion
958 // CHECK-SAME: %[[ARG_0:.*]]: !llvm.ptr)
959
960 func.func @omp_map_info_derived_type_explicit_member_conversion(%arg0 : !fir.ref<!fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}>>) {
961 // CHECK: %[[GEP:.*]] = llvm.getelementptr %[[ARG_0]][0, 2] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFderived_type", (f32, array<10 x i32>, i32)>
962 %0 = fir.field_index int, !fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}>
963 %1 = fir.coordinate_of %arg0, %0 : (!fir.ref<!fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}>>, !fir.field) -> !fir.ref<i32>
964 // CHECK: %[[MAP_MEMBER_1:.*]] = omp.map.info var_ptr(%[[GEP]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "dtype%int"}
965 %2 = omp.map.info var_ptr(%1 : !fir.ref<i32>, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref<i32> {name = "dtype%int"}
966 // CHECK: %[[GEP_2:.*]] = llvm.getelementptr %[[ARG_0]][0, 0] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFderived_type", (f32, array<10 x i32>, i32)>
967 %3 = fir.field_index real, !fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}>
968 %4 = fir.coordinate_of %arg0, %3 : (!fir.ref<!fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}>>, !fir.field) -> !fir.ref<f32>
969 // CHECK: %[[MAP_MEMBER_2:.*]] = omp.map.info var_ptr(%[[GEP_2]] : !llvm.ptr, f32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "dtype%real"}
970 %5 = omp.map.info var_ptr(%4 : !fir.ref<f32>, f32) map_clauses(tofrom) capture(ByRef) -> !fir.ref<f32> {name = "dtype%real"}
971 // CHECK: %[[MAP_PARENT:.*]] = omp.map.info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.struct<"_QFderived_type", (f32, array<10 x i32>, i32)>) map_clauses(tofrom) capture(ByRef) members(%[[MAP_MEMBER_1]], %[[MAP_MEMBER_2]] : [2], [0] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {name = "dtype", partial_map = true}
972 %6 = omp.map.info var_ptr(%arg0 : !fir.ref<!fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}>>, !fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}>) map_clauses(tofrom) capture(ByRef) members(%2, %5 : [2], [0] : !fir.ref<i32>, !fir.ref<f32>) -> !fir.ref<!fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}>> {name = "dtype", partial_map = true}
973 // CHECK: omp.target map_entries(%[[MAP_MEMBER_1]] -> %[[ARG_1:.*]], %[[MAP_MEMBER_2]] -> %[[ARG_2:.*]], %[[MAP_PARENT]] -> %[[ARG_3:.*]] : !llvm.ptr, !llvm.ptr, !llvm.ptr) {
974 // CHECK: ^bb0(%[[ARG_1]]: !llvm.ptr, %[[ARG_2]]: !llvm.ptr, %[[ARG_3]]: !llvm.ptr):
975 omp.target map_entries(%2 -> %arg1, %5 -> %arg2, %6 -> %arg3 : !fir.ref<i32>, !fir.ref<f32>, !fir.ref<!fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}>>) {
976 ^bb0(%arg1: !fir.ref<f32>, %arg2: !fir.ref<i32>, %arg3: !fir.ref<!fir.type<_QFderived_type{real:f32,array:!fir.array<10xi32>,int:i32}>>):
977 omp.terminator
978 }
979 return
980 }
981
982 // -----
983
984 // CHECK-LABEL: llvm.func @omp_map_info_nested_derived_type_explicit_member_conversion
985 // CHECK-SAME: %[[ARG_0:.*]]: !llvm.ptr)
986
987 func.func @omp_map_info_nested_derived_type_explicit_member_conversion(%arg0 : !fir.ref<!fir.type<_QFTtop_layer{array_i:!fir.array<10xi32>,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>>) {
988 // CHECK: %[[GEP:.*]] = llvm.getelementptr %[[ARG_0]][0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFTtop_layer", (array<10 x i32>, struct<"_QFTbottom_layer", (array<10 x f32>, f64)>, i32)>
989 %0 = fir.field_index nested, !fir.type<_QFTtop_layer{array_i:!fir.array<10xi32>,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>
990 %1 = fir.coordinate_of %arg0, %0 : (!fir.ref<!fir.type<_QFTtop_layer{array_i:!fir.array<10xi32>,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>>, !fir.field) -> !fir.ref<!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>>
991 // CHECK: %[[GEP_2:.*]] = llvm.getelementptr %[[GEP]][0, 1] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFTbottom_layer", (array<10 x f32>, f64)>
992 %2 = fir.field_index i2, !fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>
993 %3 = fir.coordinate_of %1, %2 : (!fir.ref<!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>>, !fir.field) -> !fir.ref<f64>
994 // CHECK: %[[MAP_MEMBER_1:.*]] = omp.map.info var_ptr(%[[GEP_2]] : !llvm.ptr, f64) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr
995 %4 = omp.map.info var_ptr(%3 : !fir.ref<f64>, f64) map_clauses(tofrom) capture(ByRef) -> !fir.ref<f64>
996 // CHECK: %[[GEP_3:.*]] = llvm.getelementptr %[[ARG_0]][0, 2] : (!llvm.ptr) -> !llvm.ptr, !llvm.struct<"_QFTtop_layer", (array<10 x i32>, struct<"_QFTbottom_layer", (array<10 x f32>, f64)>, i32)>
997 %5 = fir.field_index k, !fir.type<_QFTtop_layer{array_i:!fir.array<10xi32>,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>
998 %6 = fir.coordinate_of %arg0, %5 : (!fir.ref<!fir.type<_QFTtop_layer{array_i:!fir.array<10xi32>,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>>, !fir.field) -> !fir.ref<i32>
999 // CHECK: %[[MAP_MEMBER_2:.*]] = omp.map.info var_ptr(%[[GEP_3]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr
1000 %7 = omp.map.info var_ptr(%6 : !fir.ref<i32>, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref<i32>
1001 // CHECK: %[[PARENT_MAP:.*]] = omp.map.info var_ptr(%[[ARG_0]] : !llvm.ptr, !llvm.struct<"_QFTtop_layer", (array<10 x i32>, struct<"_QFTbottom_layer", (array<10 x f32>, f64)>, i32)>) map_clauses(tofrom) capture(ByRef) members(%[[MAP_MEMBER_1]], %[[MAP_MEMBER_2]] : [1,1], [2,-1] : !llvm.ptr, !llvm.ptr) -> !llvm.ptr {partial_map = true}
1002 %9 = omp.map.info var_ptr(%arg0 : !fir.ref<!fir.type<_QFTtop_layer{array_i:!fir.array<10xi32>,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>>, !fir.type<_QFTtop_layer{array_i:!fir.array<10xi32>,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>) map_clauses(tofrom) capture(ByRef) members(%4, %7 : [1,1], [2,-1] : !fir.ref<f64>, !fir.ref<i32>) -> !fir.ref<!fir.type<_QFTtop_layer{array_i:!fir.array<10xi32>,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>> {partial_map = true}
1003 // CHECK: omp.target map_entries(%[[MAP_MEMBER_1]] -> %{{.*}}, %[[MAP_MEMBER_2]] -> %{{.*}}, %[[PARENT_MAP]] -> %{{.*}} : !llvm.ptr, !llvm.ptr, !llvm.ptr) {
1004 // CHECK: ^bb0(%{{.*}}: !llvm.ptr, %{{.*}}: !llvm.ptr, %{{.*}}: !llvm.ptr):
1005 omp.target map_entries(%4 -> %arg1, %7 -> %arg2, %9 -> %arg3 : !fir.ref<f64>, !fir.ref<i32>, !fir.ref<!fir.type<_QFTtop_layer{array_i:!fir.array<10xi32>,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>>) {
1006 ^bb0(%arg1: !fir.ref<i32>, %arg2: !fir.ref<f64>, %arg3: !fir.ref<!fir.type<_QFTtop_layer{array_i:!fir.array<10xi32>,nested:!fir.type<_QFTbottom_layer{array_i2:!fir.array<10xf32>,i2:f64}>,k:i32}>>):
1007 omp.terminator
1008 }
1009 return
1010 }
1011
1012 // -----
1013
1014 // CHECK-LABEL: llvm.func @omp_map_common_block_using_common_block_symbol
1015
1016 // CHECK: %[[ADDR_OF:.*]] = llvm.mlir.addressof @var_common_ : !llvm.ptr
1017 // CHECK: %[[CB_MAP:.*]] = omp.map.info var_ptr(%[[ADDR_OF]] : !llvm.ptr, !llvm.array<8 x i8>) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "var_common"}
1018 // CHECK: omp.target map_entries(%[[CB_MAP]] -> %[[ARG0:.*]] : !llvm.ptr) {
1019 // CHECK: ^bb0(%[[ARG0]]: !llvm.ptr):
1020 // CHECK: %[[VAR_2_OFFSET:.*]] = llvm.mlir.constant(4 : index) : i64
1021 // CHECK: %[[VAR_1_OFFSET:.*]] = llvm.mlir.constant(0 : index) : i64
1022 // CHECK: %{{.*}} = llvm.getelementptr %[[ARG0]][%[[VAR_1_OFFSET]]] : (!llvm.ptr, i64) -> !llvm.ptr, i8
1023 // CHECK: %{{.*}} = llvm.getelementptr %[[ARG0]][%[[VAR_2_OFFSET]]] : (!llvm.ptr, i64) -> !llvm.ptr, i8
1024
1025 func.func @omp_map_common_block_using_common_block_symbol() {
1026 %0 = fir.address_of(@var_common_) : !fir.ref<!fir.array<8xi8>>
1027 %1 = omp.map.info var_ptr(%0 : !fir.ref<!fir.array<8xi8>>, !fir.array<8xi8>) map_clauses(tofrom) capture(ByRef) -> !fir.ref<!fir.array<8xi8>> {name = "var_common"}
1028 omp.target map_entries(%1 -> %arg0 : !fir.ref<!fir.array<8xi8>>) {
1029 ^bb0(%arg0: !fir.ref<!fir.array<8xi8>>):
1030 %c4 = arith.constant 4 : index
1031 %c0 = arith.constant 0 : index
1032 %c20_i32 = arith.constant 20 : i32
1033 %2 = fir.convert %arg0 : (!fir.ref<!fir.array<8xi8>>) -> !fir.ref<!fir.array<?xi8>>
1034 %3 = fir.coordinate_of %2, %c0 : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
1035 %4 = fir.convert %3 : (!fir.ref<i8>) -> !fir.ref<i32>
1036 %5 = fir.convert %arg0 : (!fir.ref<!fir.array<8xi8>>) -> !fir.ref<!fir.array<?xi8>>
1037 %6 = fir.coordinate_of %5, %c4 : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
1038 %7 = fir.convert %6 : (!fir.ref<i8>) -> !fir.ref<i32>
1039 %8 = fir.load %4 : !fir.ref<i32>
1040 %9 = arith.addi %8, %c20_i32 : i32
1041 fir.store %9 to %7 : !fir.ref<i32>
1042 omp.terminator
1043 }
1044 return
1045 }
1046
1047 fir.global common @var_common_(dense<0> : vector<8xi8>) {alignment = 4 : i64} : !fir.array<8xi8>
1048
1049 // -----
1050
1051 // CHECK-LABEL: llvm.func @omp_map_common_block_using_common_block_members
1052
1053 // CHECK: %[[VAR_2_OFFSET:.*]] = llvm.mlir.constant(4 : index) : i64
1054 // CHECK: %[[VAR_1_OFFSET:.*]] = llvm.mlir.constant(0 : index) : i64
1055 // CHECK: %[[ADDR_OF:.*]] = llvm.mlir.addressof @var_common_ : !llvm.ptr
1056 // CHECK: %[[VAR_1_CB_GEP:.*]] = llvm.getelementptr %[[ADDR_OF]][%[[VAR_1_OFFSET]]] : (!llvm.ptr, i64) -> !llvm.ptr, i8
1057 // CHECK: %[[VAR_2_CB_GEP:.*]] = llvm.getelementptr %[[ADDR_OF]][%[[VAR_2_OFFSET]]] : (!llvm.ptr, i64) -> !llvm.ptr, i8
1058 // CHECK: %[[MAP_CB_VAR_1:.*]] = omp.map.info var_ptr(%[[VAR_1_CB_GEP]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "var1"}
1059 // CHECK: %[[MAP_CB_VAR_2:.*]] = omp.map.info var_ptr(%[[VAR_2_CB_GEP]] : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = "var2"}
1060 // CHECK: omp.target map_entries(%[[MAP_CB_VAR_1]] -> %[[ARG0:.*]], %[[MAP_CB_VAR_2]] -> %[[ARG1:.*]] : !llvm.ptr, !llvm.ptr) {
1061 // CHECK: ^bb0(%[[ARG0]]: !llvm.ptr, %[[ARG1]]: !llvm.ptr):
1062
1063 func.func @omp_map_common_block_using_common_block_members() {
1064 %c4 = arith.constant 4 : index
1065 %c0 = arith.constant 0 : index
1066 %0 = fir.address_of(@var_common_) : !fir.ref<!fir.array<8xi8>>
1067 %1 = fir.convert %0 : (!fir.ref<!fir.array<8xi8>>) -> !fir.ref<!fir.array<?xi8>>
1068 %2 = fir.coordinate_of %1, %c0 : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
1069 %3 = fir.convert %2 : (!fir.ref<i8>) -> !fir.ref<i32>
1070 %4 = fir.convert %0 : (!fir.ref<!fir.array<8xi8>>) -> !fir.ref<!fir.array<?xi8>>
1071 %5 = fir.coordinate_of %4, %c4 : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
1072 %6 = fir.convert %5 : (!fir.ref<i8>) -> !fir.ref<i32>
1073 %7 = omp.map.info var_ptr(%3 : !fir.ref<i32>, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref<i32> {name = "var1"}
1074 %8 = omp.map.info var_ptr(%6 : !fir.ref<i32>, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref<i32> {name = "var2"}
1075 omp.target map_entries(%7 -> %arg0, %8 -> %arg1 : !fir.ref<i32>, !fir.ref<i32>) {
1076 ^bb0(%arg0: !fir.ref<i32>, %arg1: !fir.ref<i32>):
1077 %c10_i32 = arith.constant 10 : i32
1078 %9 = fir.load %arg0 : !fir.ref<i32>
1079 %10 = arith.muli %9, %c10_i32 : i32
1080 fir.store %10 to %arg1 : !fir.ref<i32>
1081 omp.terminator
1082 }
1083 return
1084 }
1085
1086 fir.global common @var_common_(dense<0> : vector<8xi8>) {alignment = 4 : i64} : !fir.array<8xi8>