1 // RUN: mlir-opt --test-data-layout-query --split-input-file --verify-diagnostics %s | FileCheck %s
6 // CHECK: alignment = 8
7 // CHECK: alloca_memory_space = 0
9 // CHECK: endianness = ""
10 // CHECK: global_memory_space = 0
12 // CHECK: preferred = 8
13 // CHECK: program_memory_space = 0
15 // CHECK: stack_alignment = 0
16 "test.data_layout_query"() : () -> !llvm.ptr
17 // CHECK: alignment = 8
18 // CHECK: alloca_memory_space = 0
19 // CHECK: bitsize = 64
20 // CHECK: endianness = ""
21 // CHECK: global_memory_space = 0
23 // CHECK: preferred = 8
24 // CHECK: program_memory_space = 0
26 // CHECK: stack_alignment = 0
27 "test.data_layout_query"() : () -> !llvm.ptr<3>
28 // CHECK: alignment = 8
29 // CHECK: alloca_memory_space = 0
30 // CHECK: bitsize = 64
31 // CHECK: endianness = ""
32 // CHECK: global_memory_space = 0
34 // CHECK: preferred = 8
35 // CHECK: program_memory_space = 0
37 // CHECK: stack_alignment = 0
38 "test.data_layout_query"() : () -> !llvm.ptr<5>
45 module attributes { dlti.dl_spec = #dlti.dl_spec<
46 #dlti.dl_entry<!llvm.ptr, dense<[32, 32, 64]> : vector<3xi64>>,
47 #dlti.dl_entry<!llvm.ptr<5>, dense<[64, 64, 64]> : vector<3xi64>>,
48 #dlti.dl_entry<!llvm.ptr<4>, dense<[32, 64, 64, 24]> : vector<4xi64>>,
49 #dlti.dl_entry<"dlti.endianness", "little">,
50 #dlti.dl_entry<"dlti.alloca_memory_space", 5 : ui64>,
51 #dlti.dl_entry<"dlti.global_memory_space", 2 : ui64>,
52 #dlti.dl_entry<"dlti.program_memory_space", 3 : ui64>,
53 #dlti.dl_entry<"dlti.stack_alignment", 128 : i64>
57 // CHECK: alignment = 4
58 // CHECK: alloca_memory_space = 5
59 // CHECK: bitsize = 32
60 // CHECK: endianness = "little"
61 // CHECK: global_memory_space = 2
63 // CHECK: preferred = 8
64 // CHECK: program_memory_space = 3
66 // CHECK: stack_alignment = 128
67 "test.data_layout_query"() : () -> !llvm.ptr
68 // CHECK: alignment = 4
69 // CHECK: alloca_memory_space = 5
70 // CHECK: bitsize = 32
71 // CHECK: endianness = "little"
72 // CHECK: global_memory_space = 2
74 // CHECK: preferred = 8
75 // CHECK: program_memory_space = 3
77 // CHECK: stack_alignment = 128
78 "test.data_layout_query"() : () -> !llvm.ptr<3>
79 // CHECK: alignment = 8
80 // CHECK: alloca_memory_space = 5
81 // CHECK: bitsize = 64
82 // CHECK: endianness = "little"
83 // CHECK: global_memory_space = 2
85 // CHECK: preferred = 8
86 // CHECK: program_memory_space = 3
88 // CHECK: stack_alignment = 128
89 "test.data_layout_query"() : () -> !llvm.ptr<5>
90 // CHECK: alignment = 8
91 // CHECK: alloca_memory_space = 5
92 // CHECK: bitsize = 32
93 // CHECK: endianness = "little"
94 // CHECK: global_memory_space = 2
96 // CHECK: preferred = 8
97 // CHECK: program_memory_space = 3
99 // CHECK: stack_alignment = 128
100 "test.data_layout_query"() : () -> !llvm.ptr<4>
107 // expected-error@below {{expected layout attribute for '!llvm.ptr' to be a dense integer elements attribute with 3 or 4 elements}}
108 module attributes { dlti.dl_spec = #dlti.dl_spec<
109 #dlti.dl_entry<!llvm.ptr, dense<[64.0, 64.0, 64.0]> : vector<3xf32>>
111 func.func @pointer() {
118 // expected-error@below {{preferred alignment is expected to be at least as large as ABI alignment}}
119 module attributes { dlti.dl_spec = #dlti.dl_spec<
120 #dlti.dl_entry<!llvm.ptr, dense<[64, 64, 32]> : vector<3xi64>>
122 func.func @pointer() {
129 // expected-error @below {{expected i64 parameters for '!llvm.ptr'}}
130 module attributes { dlti.dl_spec = #dlti.dl_spec<
131 #dlti.dl_entry<!llvm.ptr, dense<[32, 32, 64]> : vector<3xi32>>
139 func.func @no_spec() {
141 // CHECK: alignment = 4
142 // CHECK: bitsize = 32
144 // CHECK: preferred = 4
146 "test.data_layout_query"() : () -> !llvm.struct<(i32)>
149 // CHECK: alignment = 8
150 // CHECK: bitsize = 128
152 // CHECK: preferred = 8
154 "test.data_layout_query"() : () -> !llvm.struct<(i32, f64)>
156 // padding at end of struct
157 // CHECK: alignment = 8
158 // CHECK: bitsize = 128
160 // CHECK: preferred = 8
162 "test.data_layout_query"() : () -> !llvm.struct<(f64, i32)>
165 // CHECK: alignment = 1
166 // CHECK: bitsize = 96
168 // CHECK: preferred = 8
170 "test.data_layout_query"() : () -> !llvm.struct<packed (f64, i32)>
173 // CHECK: alignment = 1
174 // CHECK: bitsize = 0
176 // CHECK: preferred = 1
178 "test.data_layout_query"() : () -> !llvm.struct<()>
185 module attributes { dlti.dl_spec = #dlti.dl_spec<
186 #dlti.dl_entry<!llvm.struct<()>, dense<[32, 32]> : vector<2xi64>>
190 // Strict alignment is applied
191 // CHECK: alignment = 4
192 // CHECK: bitsize = 16
194 // CHECK: preferred = 4
196 "test.data_layout_query"() : () -> !llvm.struct<(i16)>
198 // No impact on structs that have stricter requirements
199 // CHECK: alignment = 8
200 // CHECK: bitsize = 128
202 // CHECK: preferred = 8
204 "test.data_layout_query"() : () -> !llvm.struct<(i32, f64)>
206 // Only the preferred alignment of structs is affected
207 // CHECK: alignment = 1
208 // CHECK: bitsize = 32
210 // CHECK: preferred = 4
212 "test.data_layout_query"() : () -> !llvm.struct<packed (i16, i16)>
215 // CHECK: alignment = 4
216 // CHECK: bitsize = 0
218 // CHECK: preferred = 4
220 "test.data_layout_query"() : () -> !llvm.struct<()>
227 module attributes { dlti.dl_spec = #dlti.dl_spec<
228 #dlti.dl_entry<!llvm.struct<()>, dense<[32]> : vector<1xi64>>
230 // CHECK: @spec_without_preferred
231 func.func @spec_without_preferred() {
232 // abi alignment is applied to both preferred and abi
233 // CHECK: alignment = 4
234 // CHECK: bitsize = 16
235 // CHECK: preferred = 4
237 "test.data_layout_query"() : () -> !llvm.struct<(i16)>
244 // expected-error@below {{unexpected layout attribute for struct '!llvm.struct<(i8)>'}}
245 module attributes { dlti.dl_spec = #dlti.dl_spec<
246 #dlti.dl_entry<!llvm.struct<(i8)>, dense<[64, 64]> : vector<2xi64>>
248 func.func @struct() {
255 // expected-error@below {{expected layout attribute for '!llvm.struct<()>' to be a dense integer elements attribute of 1 or 2 elements}}
256 module attributes { dlti.dl_spec = #dlti.dl_spec<
257 #dlti.dl_entry<!llvm.struct<()>, dense<[64, 64, 64]> : vector<3xi64>>
259 func.func @struct() {
266 // expected-error@below {{preferred alignment is expected to be at least as large as ABI alignment}}
267 module attributes { dlti.dl_spec = #dlti.dl_spec<
268 #dlti.dl_entry<!llvm.struct<()>, dense<[64, 32]> : vector<2xi64>>
270 func.func @struct() {
279 func.func @arrays() {
281 // CHECK: alignment = 4
282 // CHECK: bitsize = 64
284 // CHECK: preferred = 4
286 "test.data_layout_query"() : () -> !llvm.array<2 x i32>
289 // CHECK: alignment = 8
290 // CHECK: bitsize = 0
292 // CHECK: preferred = 8
294 "test.data_layout_query"() : () -> !llvm.array<0 x f64>
296 // alignment info matches element type
297 // CHECK: alignment = 4
298 // CHECK: bitsize = 64
300 // CHECK: preferred = 8
302 "test.data_layout_query"() : () -> !llvm.array<1 x i64>
309 module attributes { dlti.dl_spec = #dlti.dl_spec<
310 #dlti.dl_entry<!llvm.struct<()>, dense<[64]> : vector<1xi64>>
312 // CHECK: @overaligned
313 func.func @overaligned() {
314 // Over aligned element types are respected
315 // CHECK: alignment = 8
316 // CHECK: bitsize = 128
317 // CHECK: preferred = 8
319 "test.data_layout_query"() : () -> !llvm.array<2 x struct<(i8)>>
326 // expected-error @below {{expected i64 entries for '!llvm.struct<()>'}}
327 module attributes { dlti.dl_spec = #dlti.dl_spec<
328 #dlti.dl_entry<!llvm.struct<()>, dense<[64]> : vector<1xi32>>