1// RUN: mlir-opt --test-data-layout-query %s | FileCheck %s
2
3// CHECK-LABEL: @no_layout_builtin
4func.func @no_layout_builtin() {
5  // CHECK: alignment = 4
6  // CHECK: bitsize = 32
7  // CHECK: preferred = 4
8  // CHECK: size = 4
9  "test.data_layout_query"() : () -> i32
10  // CHECK: alignment = 8
11  // CHECK: bitsize = 64
12  // CHECK: preferred = 8
13  // CHECK: size = 8
14  "test.data_layout_query"() : () -> f64
15  // CHECK: alignment = 4
16  // CHECK: bitsize = 64
17  // CHECK: preferred = 4
18  // CHECK: size = 8
19  "test.data_layout_query"() : () -> complex<f32>
20  // CHECK: alignment = 1
21  // CHECK: bitsize = 14
22  // CHECK: preferred = 1
23  // CHECK: size = 2
24  "test.data_layout_query"() : () -> complex<i6>
25  return
26
27}
28
29// CHECK-LABEL: @no_layout_custom
30func.func @no_layout_custom() {
31  // CHECK: alignment = 1
32  // CHECK: bitsize = 1
33  // CHECK: preferred = 1
34  // CHECK: size = 1
35  "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
36  return
37}
38
39// CHECK-LABEL: @layout_op_no_layout
40func.func @layout_op_no_layout() {
41  "test.op_with_data_layout"() ({
42    // CHECK: alignment = 1
43    // CHECK: bitsize = 1
44    // CHECK: preferred = 1
45    // CHECK: size = 1
46    "test.data_layout_query"() : () -> !test.test_type_with_layout<1000>
47    "test.maybe_terminator"() : () -> ()
48  }) : () -> ()
49  return
50}
51
52// CHECK-LABEL: @layout_op
53func.func @layout_op() {
54  "test.op_with_data_layout"() ({
55    // CHECK: alignment = 20
56    // CHECK: bitsize = 10
57    // CHECK: preferred = 1
58    // CHECK: size = 2
59    "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
60    "test.maybe_terminator"() : () -> ()
61  }) { dlti.dl_spec = #dlti.dl_spec<
62      #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 10]>,
63      #dlti.dl_entry<!test.test_type_with_layout<20>, ["alignment", 20]>
64  >} : () -> ()
65  return
66}
67
68// Make sure the outer op with layout may be missing the spec.
69// CHECK-LABEL: @nested_inner_only
70func.func @nested_inner_only() {
71  "test.op_with_data_layout"() ({
72    "test.op_with_data_layout"() ({
73      // CHECK: alignment = 20
74      // CHECK: bitsize = 10
75      // CHECK: preferred = 1
76      // CHECK: size = 2
77      "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
78      "test.maybe_terminator"() : () -> ()
79    }) { dlti.dl_spec = #dlti.dl_spec<
80        #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 10]>,
81        #dlti.dl_entry<!test.test_type_with_layout<20>, ["alignment", 20]>
82    >} : () -> ()
83    "test.maybe_terminator"() : () -> ()
84  }) : () -> ()
85  return
86}
87
88// Make sure the inner op with layout may be missing the spec.
89// CHECK-LABEL: @nested_outer_only
90func.func @nested_outer_only() {
91  "test.op_with_data_layout"() ({
92    "test.op_with_data_layout"() ({
93      // CHECK: alignment = 20
94      // CHECK: bitsize = 10
95      // CHECK: preferred = 1
96      // CHECK: size = 2
97      "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
98      "test.maybe_terminator"() : () -> ()
99    }) : () -> ()
100    "test.maybe_terminator"() : () -> ()
101  }) { dlti.dl_spec = #dlti.dl_spec<
102      #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 10]>,
103      #dlti.dl_entry<!test.test_type_with_layout<20>, ["alignment", 20]>
104    >} : () -> ()
105  return
106}
107
108// CHECK-LABEL: @nested_middle_only
109func.func @nested_middle_only() {
110  "test.op_with_data_layout"() ({
111    "test.op_with_data_layout"() ({
112      "test.op_with_data_layout"() ({
113        // CHECK: alignment = 20
114        // CHECK: bitsize = 10
115        // CHECK: preferred = 1
116        // CHECK: size = 2
117        "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
118        "test.maybe_terminator"() : () -> ()
119    }) : () -> ()
120    "test.maybe_terminator"() : () -> ()
121    }) { dlti.dl_spec = #dlti.dl_spec<
122        #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 10]>,
123        #dlti.dl_entry<!test.test_type_with_layout<20>, ["alignment", 20]>
124      >} : () -> ()
125    "test.maybe_terminator"() : () -> ()
126  }) : () -> ()
127  return
128}
129
130// CHECK-LABEL: @nested_combine_with_missing
131func.func @nested_combine_with_missing() {
132  "test.op_with_data_layout"() ({
133    "test.op_with_data_layout"() ({
134      "test.op_with_data_layout"() ({
135        // CHECK: alignment = 20
136        // CHECK: bitsize = 10
137        // CHECK: preferred = 30
138        // CHECK: size = 2
139        "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
140        "test.maybe_terminator"() : () -> ()
141      }) : () -> ()
142    "test.maybe_terminator"() : () -> ()
143    }) { dlti.dl_spec = #dlti.dl_spec<
144        #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 10]>,
145        #dlti.dl_entry<!test.test_type_with_layout<20>, ["alignment", 20]>
146      >} : () -> ()
147    // CHECK: alignment = 1
148    // CHECK: bitsize = 42
149    // CHECK: preferred = 30
150    // CHECK: size = 6
151    "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
152    "test.maybe_terminator"() : () -> ()
153  }) { dlti.dl_spec = #dlti.dl_spec<
154      #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 42]>,
155      #dlti.dl_entry<!test.test_type_with_layout<30>, ["preferred", 30]>
156  >}: () -> ()
157  return
158}
159
160// CHECK-LABEL: @nested_combine_all
161func.func @nested_combine_all() {
162  "test.op_with_data_layout"() ({
163    "test.op_with_data_layout"() ({
164      "test.op_with_data_layout"() ({
165        // CHECK: alignment = 20
166        // CHECK: bitsize = 3
167        // CHECK: preferred = 30
168        // CHECK: size = 1
169        "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
170        "test.maybe_terminator"() : () -> ()
171      }) { dlti.dl_spec = #dlti.dl_spec<
172          #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 3]>,
173          #dlti.dl_entry<!test.test_type_with_layout<30>, ["preferred", 30]>
174        >} : () -> ()
175      // CHECK: alignment = 20
176      // CHECK: bitsize = 10
177      // CHECK: preferred = 30
178      // CHECK: size = 2
179      "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
180      "test.maybe_terminator"() : () -> ()
181    }) { dlti.dl_spec = #dlti.dl_spec<
182        #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 10]>,
183        #dlti.dl_entry<!test.test_type_with_layout<20>, ["alignment", 20]>
184      >} : () -> ()
185    // CHECK: alignment = 1
186    // CHECK: bitsize = 42
187    // CHECK: preferred = 30
188    // CHECK: size = 6
189    "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
190    "test.maybe_terminator"() : () -> ()
191  }) { dlti.dl_spec = #dlti.dl_spec<
192      #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 42]>,
193      #dlti.dl_entry<!test.test_type_with_layout<30>, ["preferred", 30]>
194  >}: () -> ()
195  return
196}
197
198// CHECK-LABEL: @integers
199func.func @integers() {
200  "test.op_with_data_layout"() ({
201    // CHECK: alignment = 8
202    // CHECK: bitsize = 32
203    // CHECK: preferred = 8
204    "test.data_layout_query"() : () -> i32
205    // CHECK: alignment = 16
206    // CHECK: bitsize = 56
207    // CHECK: preferred = 16
208    "test.data_layout_query"() : () -> i56
209    // CHECK: alignment = 16
210    // CHECK: bitsize = 64
211    // CHECK: preferred = 16
212    "test.data_layout_query"() : () -> i64
213    // CHECK: alignment = 16
214    // CHECK: bitsize = 128
215    // CHECK: preferred = 16
216    "test.data_layout_query"() : () -> i128
217    "test.maybe_terminator"() : () -> ()
218  }) { dlti.dl_spec = #dlti.dl_spec<
219      #dlti.dl_entry<i32, dense<64> : vector<1xi32>>,
220      #dlti.dl_entry<i64, dense<128> : vector<1xi32>>
221    >} : () -> ()
222  "test.op_with_data_layout"() ({
223    // CHECK: alignment = 8
224    // CHECK: bitsize = 32
225    // CHECK: preferred = 16
226    "test.data_layout_query"() : () -> i32
227    // CHECK: alignment = 16
228    // CHECK: bitsize = 56
229    // CHECK: preferred = 32
230    "test.data_layout_query"() : () -> i56
231    // CHECK: alignment = 16
232    // CHECK: bitsize = 64
233    // CHECK: preferred = 32
234    "test.data_layout_query"() : () -> i64
235    // CHECK: alignment = 16
236    // CHECK: bitsize = 128
237    // CHECK: preferred = 32
238    "test.data_layout_query"() : () -> i128
239    "test.maybe_terminator"() : () -> ()
240  }) { dlti.dl_spec = #dlti.dl_spec<
241      #dlti.dl_entry<i32, dense<[64, 128]> : vector<2xi32>>,
242      #dlti.dl_entry<i64, dense<[128, 256]> : vector<2xi32>>
243    >} : () -> ()
244  return
245}
246
247func.func @floats() {
248  "test.op_with_data_layout"() ({
249    // CHECK: alignment = 8
250    // CHECK: bitsize = 32
251    // CHECK: preferred = 8
252    "test.data_layout_query"() : () -> f32
253    // CHECK: alignment = 16
254    // CHECK: bitsize = 80
255    // CHECK: preferred = 16
256    "test.data_layout_query"() : () -> f80
257    "test.maybe_terminator"() : () -> ()
258  }) { dlti.dl_spec = #dlti.dl_spec<
259      #dlti.dl_entry<f32, dense<64> : vector<1xi32>>,
260      #dlti.dl_entry<f80, dense<128> : vector<1xi32>>
261    >} : () -> ()
262  "test.op_with_data_layout"() ({
263    // CHECK: alignment = 8
264    // CHECK: bitsize = 32
265    // CHECK: preferred = 16
266    "test.data_layout_query"() : () -> f32
267    // CHECK: alignment = 16
268    // CHECK: bitsize = 80
269    // CHECK: preferred = 32
270    "test.data_layout_query"() : () -> f80
271    "test.maybe_terminator"() : () -> ()
272  }) { dlti.dl_spec = #dlti.dl_spec<
273      #dlti.dl_entry<f32, dense<[64, 128]> : vector<2xi32>>,
274      #dlti.dl_entry<f80, dense<[128, 256]> : vector<2xi32>>
275    >} : () -> ()
276  return
277}
278