1 // Test FIR types conversion.
3 // RUN: fir-opt --split-input-file --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s | FileCheck %s
6 // Test sequence types `!fir.array`
7 // Note that we're switching from column-major to row-major here.
9 func.func private @foo0(%arg0: !fir.array<10x12xi64>)
11 // CHECK-SAME: !llvm.array<12 x array<10 x i64>>
12 func.func private @foo1(%arg0: !fir.array<?xf32>)
14 // CHECK-SAME: !llvm.ptr<f32>
15 func.func private @foo2(%arg0: !fir.array<?x?xf128>)
17 // CHECK-SAME: !llvm.ptr<f128>
18 func.func private @foo3(%arg0: !fir.array<*:i32>)
20 // CHECK-SAME: !llvm.ptr<i32>
21 func.func private @foo4(%arg0: !fir.array<3x?xi32>)
23 // CHECK-SAME: !llvm.ptr<array<3 x i32>>
24 func.func private @foo5(%arg0: !fir.array<?x6xi32>)
26 // CHECK-SAME: !llvm.ptr<i32>
27 func.func private @foo6(%arg0: !fir.array<2x?x3x?x4xi32>)
29 // CHECK-SAME: !llvm.ptr<array<2 x i32>
30 func.func private @foo7(%arg0: !fir.array<6x?x!fir.char<1,?>>)
32 // CHECK-SAME: !llvm.ptr<i8>
33 func.func private @foo8(%arg0: !fir.array<6x?x!fir.char<1,3>>)
35 // CHECK-SAME: !llvm.ptr<array<6 x array<3 x i8>
39 // Test reference types `!fir.ref`
41 func.func private @foo0(%arg0: !fir.ref<i32>)
43 // CHECK-SAME: !llvm.ptr<i32>
44 func.func private @foo1(%arg0: !fir.ref<!fir.array<10xf32>>)
46 // CHECK-SAME: !llvm.ptr<array<10 x f32>>
47 func.func private @foo2(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.type<_QMs1Ta1{x:i32,y:f32}>>>>)
49 // CHECK-SAME: !llvm.ptr<struct<(ptr<struct<"_QMs1Ta1", (i32, f32)>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr<i{{.*}}>, array<1 x i{{.*}}>)>>
50 func.func private @foo3(%arg0: !fir.ref<!fir.array<10x?x11xf32>>)
52 // CHECK-SAME: !llvm.ptr<array<10 x f32>>
53 func.func private @foo4(%arg0: !fir.ref<!fir.array<10x11x?x?xf32>>)
55 // CHECK-SAME: !llvm.ptr<array<11 x array<10 x f32>>>
56 func.func private @foo5(%arg0: !fir.ref<!fir.array<10x!fir.char<1,?>>>)
58 // CHECK-SAME: !llvm.ptr<i8>
59 func.func private @foo6(%arg0: !fir.ref<!fir.array<10x!fir.char<2,8>>>)
61 // CHECK-SAME: !llvm.ptr<array<10 x array<8 x i16>
62 func.func private @foo7(%arg0: !fir.ref<!fir.box<!fir.array<?xf32>>>)
64 // CHECK-SAME: !llvm.ptr<struct<(ptr<f32>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i{{.*}}>>)>>
68 // Test pointer types `!fir.ptr`
70 func.func private @foo0(%arg0: !fir.ptr<i32>)
72 // CHECK-SAME: !llvm.ptr<i32>
74 func.func private @foo1(%arg0: !fir.ptr<!fir.array<10xf32>>)
76 // CHECK-SAME: !llvm.ptr<array<10 x f32>>
80 // Test box types `!fir.box`
82 func.func private @foo0(%arg0: !fir.box<!fir.array<?xf32>>)
84 // CHECK-SAME: !llvm.ptr<struct<(ptr<f32>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i{{.*}}>>)>>
86 func.func private @foo1(%arg0: !fir.box<!fir.array<10xf32>>)
88 // CHECK-SAME: !llvm.ptr<struct<(ptr<array<10 x f32>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i{{.*}}>>)>>
90 func.func private @foo2(%arg0: !fir.box<!fir.ref<i64>>)
92 // CHECK-SAME: !llvm.ptr<struct<(ptr<i64>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}})>>
94 func.func private @foo3(%arg0: !fir.box<!fir.type<derived{f:f32}>>)
96 // CHECK-SAME: !llvm.ptr<struct<(ptr<struct<"derived", (f32)>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr<i{{.*}}>, array<1 x i{{.*}}>)>>
98 func.func private @foo4(%arg0: !fir.box<!fir.heap<!fir.type<_QMs1Ta1{x:i32,y:f32}>>>)
100 // CHECK-SAME: !llvm.ptr<struct<(ptr<struct<"_QMs1Ta1", (i32, f32)>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr<i{{.*}}>, array<1 x i{{.*}}>)>>
104 // Test char types `!fir.char<k, n>`
106 func.func private @foo0(%arg0: !fir.char<1, 4>, %arg1: !fir.char<1, ?>)
108 // CHECK-SAME: !llvm.array<4 x i8>
111 func.func private @foo1(%arg0: !fir.char<2, 12>, %arg1: !fir.char<2, ?>)
113 // CHECK-SAME: !llvm.array<12 x i16>
116 func.func private @foo2(%arg0: !fir.char<4, 8>, %arg1: !fir.char<4, ?>)
118 // CHECK-SAME: !llvm.array<8 x i32>
123 // Test `!fir.heap<>` conversion.
124 func.func private @foo0(%arg0: !fir.heap<i32>)
126 // CHECK-SAME: !llvm.ptr<i32>
128 func.func private @foo1(%arg0: !fir.heap<!fir.array<4xf32>>)
130 // CHECK-SAME: !llvm.ptr<array<4 x f32>>
132 func.func private @foo2(%arg0: !fir.heap<!fir.array<?xf32>>)
134 // CHECK-SAME: !llvm.ptr<f32>
136 func.func private @foo3(%arg0: !fir.heap<!fir.char<1,10>>)
138 // CHECK-SAME: !llvm.ptr<array<10 x i8>>
140 func.func private @foo4(%arg0: !fir.heap<!fir.char<1,?>>)
142 // CHECK-SAME: !llvm.ptr<i8>
144 func.func private @foo5(%arg0: !fir.heap<!fir.array<2xf32>>)
146 // CHECK-SAME: !llvm.ptr<array<2 x f32>>
148 func.func private @foo6(%arg0: !fir.heap<!fir.array<?x?xf32>>)
150 // CHECK-SAME: !llvm.ptr<f32>
152 func.func private @foo7(%arg0: !fir.heap<!fir.type<ZT>>)
154 // CHECK-SAME: !llvm.ptr<struct<"ZT", ()>>
156 func.func private @foo8(%arg0: !fir.heap<!fir.type<_QMalloc_assignTt{i:i32}>>)
158 // CHECK-SAME: !llvm.ptr<struct<"_QMalloc_assignTt", (i32)>>
162 // Test `!fir.integer<KIND>` conversion.
164 func.func private @foo0(%arg0: !fir.int<1>)
168 func.func private @foo1(%arg0: !fir.int<2>)
172 func.func private @foo2(%arg0: !fir.int<4>)
176 func.func private @foo3(%arg0: !fir.int<8>)
180 func.func private @foo4(%arg0: !fir.int<16>)
186 // Test `!fir.logical<KIND>` conversion.
188 func.func private @foo0(%arg0: !fir.logical<1>)
192 func.func private @foo1(%arg0: !fir.logical<2>)
196 func.func private @foo2(%arg0: !fir.logical<4>)
200 func.func private @foo3(%arg0: !fir.logical<8>)
204 func.func private @foo4(%arg0: !fir.logical<16>)
210 // Test `!fir.llvm_ptr` conversion.
212 func.func private @foo0(%arg0: !fir.llvm_ptr<i8>)
214 // CHECK-SAME: !llvm.ptr<i8>
216 func.func private @foo1(%arg0: !fir.llvm_ptr<!fir.ref<f32>>)
218 // CHECK-SAME: !llvm.ptr<ptr<f32>>
220 func.func private @foo2(%arg0: !fir.llvm_ptr<!fir.ref<!fir.box<!fir.ptr<i32>>>>)
222 // CHECK-SAME: !llvm.ptr<ptr<struct<(ptr<i32>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}})>>>
224 func.func private @foo3(%arg0: !fir.llvm_ptr<!fir.ptr<f32>>)
226 // CHECK-SAME: !llvm.ptr<ptr<f32>>
230 // Test MLIR `complex<KIND>` conversion.
232 func.func private @foo0(%arg0: complex<f16>)
234 // CHECK-SAME: !llvm.struct<(f16, f16)>)
236 func.func private @foo1(%arg0: complex<bf16>)
238 // CHECK-SAME: !llvm.struct<(bf16, bf16)>)
240 func.func private @foo2(%arg0: complex<f32>)
242 // CHECK-SAME: !llvm.struct<(f32, f32)>)
244 func.func private @foo3(%arg0: complex<f64>)
246 // CHECK-SAME: !llvm.struct<(f64, f64)>)
248 func.func private @foo4(%arg0: complex<f80>)
250 // CHECK-SAME: !llvm.struct<(f80, f80)>)
252 func.func private @foo5(%arg0: complex<f128>)
254 // CHECK-SAME: !llvm.struct<(f128, f128)>)
258 // Test `!fir.complex<KIND>` conversion.
260 func.func private @foo0(%arg0: !fir.complex<2>)
262 // CHECK-SAME: !llvm.struct<(f16, f16)>)
264 func.func private @foo1(%arg0: !fir.complex<3>)
266 // CHECK-SAME: !llvm.struct<(bf16, bf16)>)
268 func.func private @foo2(%arg0: !fir.complex<4>)
270 // CHECK-SAME: !llvm.struct<(f32, f32)>)
272 func.func private @foo3(%arg0: !fir.complex<8>)
274 // CHECK-SAME: !llvm.struct<(f64, f64)>)
276 func.func private @foo4(%arg0: !fir.complex<10>)
278 // CHECK-SAME: !llvm.struct<(f80, f80)>)
280 func.func private @foo5(%arg0: !fir.complex<16>)
282 // CHECK-SAME: !llvm.struct<(f128, f128)>)
286 // Test `!fir.vector<>` conversion.
288 func.func private @foo0(%arg0: !fir.vector<2:f16>)
290 // CHECK-SAME: vector<2xf16>
292 func.func private @foo1(%arg0: !fir.vector<20:bf16>)
294 // CHECK-SAME: vector<20xbf16>
296 func.func private @foo2(%arg0: !fir.vector<30:f32>)
298 // CHECK-SAME: vector<30xf32>
300 func.func private @foo3(%arg0: !fir.vector<55:f64>)
302 // CHECK-SAME: vector<55xf64>
304 func.func private @foo4(%arg0: !fir.vector<15:f80>)
306 // CHECK-SAME: vector<15xf80>
308 func.func private @foo5(%arg0: !fir.vector<28:f128>)
310 // CHECK-SAME: vector<28xf128>
312 func.func private @foo6(%arg0: !fir.vector<100:i1>)
314 // CHECK-SAME: vector<100xi1>
316 func.func private @foo7(%arg0: !fir.vector<10:i8>)
318 // CHECK-SAME: vector<10xi8>
320 func.func private @foo8(%arg0: !fir.vector<12:i16>)
322 // CHECK-SAME: vector<12xi16>
324 func.func private @foo9(%arg0: !fir.vector<20:i32>)
326 // CHECK-SAME: vector<20xi32>
328 func.func private @foo10(%arg0: !fir.vector<30:i64>)
329 // CHECK-LABEL: foo10
330 // CHECK-SAME: vector<30xi64>
332 func.func private @foo11(%arg0: !fir.vector<2:!fir.real<2>>)
333 // CHECK-LABEL: foo11
334 // CHECK-SAME: vector<2xf16>
336 func.func private @foo12(%arg0: !fir.vector<2:!fir.real<3>>)
337 // CHECK-LABEL: foo12
338 // CHECK-SAME: vector<2xbf16>
340 func.func private @foo13(%arg0: !fir.vector<2:!fir.real<4>>)
341 // CHECK-LABEL: foo13
342 // CHECK-SAME: vector<2xf32>
344 func.func private @foo14(%arg0: !fir.vector<2:!fir.real<8>>)
345 // CHECK-LABEL: foo14
346 // CHECK-SAME: vector<2xf64>
348 func.func private @foo15(%arg0: !fir.vector<2:!fir.real<10>>)
349 // CHECK-LABEL: foo15
350 // CHECK-SAME: vector<2xf80>
352 func.func private @foo16(%arg0: !fir.vector<2:!fir.real<16>>)
353 // CHECK-LABEL: foo16
354 // CHECK-SAME: vector<2xf128>
358 // Test `!fir.boxchar<n>` conversion
360 func.func private @foo0(%arg0: !fir.boxchar<1>)
362 // CHECK-SAME: !llvm.struct<(ptr<i8>, i64)>
364 func.func private @foo1(%arg0: !fir.boxchar<2>)
366 // CHECK-SAME: !llvm.struct<(ptr<i16>, i64)>
370 // Test `!fir.field` conversion
372 func.func private @foo0(%arg0: !fir.field)
378 // Test `!fir.len` conversion.
380 func.func private @foo0(%arg0: !fir.len)
386 // Test `!fir.tdesc` conversion.
388 func.func private @foo0(%arg0: !fir.tdesc<!fir.type<x>>)
390 // CHECK-SAME: !llvm.ptr<i8>
392 func.func private @foo1(%arg : !fir.tdesc<!fir.array<100xf32>>)
394 // CHECK-SAME: !llvm.ptr<i8>
396 func.func private @foo2(%arg : !fir.tdesc<f32>)
398 // CHECK-SAME: !llvm.ptr<i8>
400 func.func private @foo3(%arg : !fir.tdesc<!fir.type<derived7{f1:f32,f2:f32}>>)
402 // CHECK-SAME: !llvm.ptr<i8>
406 // Test nested tuple types
407 func.func private @foo0(%arg0: tuple<i64, tuple<f32, i64>>)
409 // CHECK-SAME: !llvm.struct<(i64, struct<(f32, i64)>)>
413 // Test that fir.box inside tuple and derived type are lowered to struct type.
414 func.func private @foo0(%arg0: tuple<i64, !fir.box<i32>>)
416 // CHECK-SAME: !llvm.struct<(i64, struct<(ptr<i32>, i{{.*}})>)>
418 func.func private @foo1(%arg0: !fir.type<derived8{a:i64,b:!fir.box<i32>}>)
420 // CHECK-SAME: !llvm.struct<"derived8", (i64, struct<(ptr<i32>, i{{.*}})>)>
424 // Test fir.box<none> translation.
425 // `none` is used for polymorphic type.
426 func.func private @foo0(%arg0: !fir.box<none>)
428 // CHECK-SAME: !llvm.ptr<struct<(ptr<struct<()>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}})>>)