1// RUN: mlir-opt --test-data-layout-query %s | FileCheck %s
2
3// CHECK-LABEL: @no_layout_builtin
4func @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 @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 @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 @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 @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 @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 @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 @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 @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