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: preferred = 4
7  // CHECK: size = 4
8  "test.data_layout_query"() : () -> i32
9  // CHECK: alignment = 8
10  // CHECK: preferred = 8
11  // CHECK: size = 8
12  "test.data_layout_query"() : () -> f64
13  return
14}
15
16// CHECK-LABEL: @no_layout_custom
17func @no_layout_custom() {
18  // CHECK: alignment = 1
19  // CHECK: preferred = 1
20  // CHECK: size = 1
21  "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
22  return
23}
24
25// CHECK-LABEL: @layout_op_no_layout
26func @layout_op_no_layout() {
27  "test.op_with_data_layout"() ({
28    // CHECK: alignment = 1
29    // CHECK: preferred = 1
30    // CHECK: size = 1
31    "test.data_layout_query"() : () -> !test.test_type_with_layout<1000>
32    "test.maybe_terminator"() : () -> ()
33  }) : () -> ()
34  return
35}
36
37// CHECK-LABEL: @layout_op
38func @layout_op() {
39  "test.op_with_data_layout"() ({
40    // CHECK: alignment = 20
41    // CHECK: preferred = 1
42    // CHECK: size = 10
43    "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
44    "test.maybe_terminator"() : () -> ()
45  }) { dlti.dl_spec = #dlti.dl_spec<
46      #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 10]>,
47      #dlti.dl_entry<!test.test_type_with_layout<20>, ["alignment", 20]>
48  >} : () -> ()
49  return
50}
51
52// Make sure the outer op with layout may be missing the spec.
53// CHECK-LABEL: @nested_inner_only
54func @nested_inner_only() {
55  "test.op_with_data_layout"() ({
56    "test.op_with_data_layout"() ({
57      // CHECK: alignment = 20
58      // CHECK: preferred = 1
59      // CHECK: size = 10
60      "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
61      "test.maybe_terminator"() : () -> ()
62    }) { dlti.dl_spec = #dlti.dl_spec<
63        #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 10]>,
64        #dlti.dl_entry<!test.test_type_with_layout<20>, ["alignment", 20]>
65    >} : () -> ()
66    "test.maybe_terminator"() : () -> ()
67  }) : () -> ()
68  return
69}
70
71// Make sure the inner op with layout may be missing the spec.
72// CHECK-LABEL: @nested_outer_only
73func @nested_outer_only() {
74  "test.op_with_data_layout"() ({
75    "test.op_with_data_layout"() ({
76      // CHECK: alignment = 20
77      // CHECK: preferred = 1
78      // CHECK: size = 10
79      "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
80      "test.maybe_terminator"() : () -> ()
81    }) : () -> ()
82    "test.maybe_terminator"() : () -> ()
83  }) { dlti.dl_spec = #dlti.dl_spec<
84      #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 10]>,
85      #dlti.dl_entry<!test.test_type_with_layout<20>, ["alignment", 20]>
86    >} : () -> ()
87  return
88}
89
90// CHECK-LABEL: @nested_middle_only
91func @nested_middle_only() {
92  "test.op_with_data_layout"() ({
93    "test.op_with_data_layout"() ({
94      "test.op_with_data_layout"() ({
95        // CHECK: alignment = 20
96        // CHECK: preferred = 1
97        // CHECK: size = 10
98        "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
99        "test.maybe_terminator"() : () -> ()
100    }) : () -> ()
101    "test.maybe_terminator"() : () -> ()
102    }) { dlti.dl_spec = #dlti.dl_spec<
103        #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 10]>,
104        #dlti.dl_entry<!test.test_type_with_layout<20>, ["alignment", 20]>
105      >} : () -> ()
106    "test.maybe_terminator"() : () -> ()
107  }) : () -> ()
108  return
109}
110
111// CHECK-LABEL: @nested_combine_with_missing
112func @nested_combine_with_missing() {
113  "test.op_with_data_layout"() ({
114    "test.op_with_data_layout"() ({
115      "test.op_with_data_layout"() ({
116        // CHECK: alignment = 20
117        // CHECK: preferred = 30
118        // CHECK: size = 10
119        "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
120        "test.maybe_terminator"() : () -> ()
121      }) : () -> ()
122    "test.maybe_terminator"() : () -> ()
123    }) { dlti.dl_spec = #dlti.dl_spec<
124        #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 10]>,
125        #dlti.dl_entry<!test.test_type_with_layout<20>, ["alignment", 20]>
126      >} : () -> ()
127    // CHECK: alignment = 1
128    // CHECK: preferred = 30
129    // CHECK: size = 42
130    "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
131    "test.maybe_terminator"() : () -> ()
132  }) { dlti.dl_spec = #dlti.dl_spec<
133      #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 42]>,
134      #dlti.dl_entry<!test.test_type_with_layout<30>, ["preferred", 30]>
135  >}: () -> ()
136  return
137}
138
139// CHECK-LABEL: @nested_combine_all
140func @nested_combine_all() {
141  "test.op_with_data_layout"() ({
142    "test.op_with_data_layout"() ({
143      "test.op_with_data_layout"() ({
144        // CHECK: alignment = 20
145        // CHECK: preferred = 30
146        // CHECK: size = 3
147        "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
148        "test.maybe_terminator"() : () -> ()
149      }) { dlti.dl_spec = #dlti.dl_spec<
150          #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 3]>,
151          #dlti.dl_entry<!test.test_type_with_layout<30>, ["preferred", 30]>
152        >} : () -> ()
153      // CHECK: alignment = 20
154      // CHECK: preferred = 30
155      // CHECK: size = 10
156      "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
157      "test.maybe_terminator"() : () -> ()
158    }) { dlti.dl_spec = #dlti.dl_spec<
159        #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 10]>,
160        #dlti.dl_entry<!test.test_type_with_layout<20>, ["alignment", 20]>
161      >} : () -> ()
162    // CHECK: alignment = 1
163    // CHECK: preferred = 30
164    // CHECK: size = 42
165    "test.data_layout_query"() : () -> !test.test_type_with_layout<10>
166    "test.maybe_terminator"() : () -> ()
167  }) { dlti.dl_spec = #dlti.dl_spec<
168      #dlti.dl_entry<!test.test_type_with_layout<10>, ["size", 42]>,
169      #dlti.dl_entry<!test.test_type_with_layout<30>, ["preferred", 30]>
170  >}: () -> ()
171  return
172}
173