1 // RUN: mlir-opt -allow-unregistered-dialect %s | mlir-opt -allow-unregistered-dialect -verify-diagnostics | FileCheck %s
3 // CHECK: %[[I64:.*]] =
4 %i64 = "foo.op"() : () -> (i64)
5 // CHECK: %[[I32:.*]] =
6 %i32 = "foo.op"() : () -> (i32)
7 // CHECK: %[[MEMREF:.*]] =
8 %memref = "foo.op"() : () -> (memref<1xf64>)
10 // CHECK: test.format_literal_op keyword_$. -> :, = <> () []( ) ? + * {
11 // CHECK-NEXT: } {foo.some_attr}
12 test.format_literal_op keyword_$. -> :, = <> () []( ) ? + * {
15 // CHECK: test.format_attr_op 10
17 test.format_attr_op 10
19 // CHECK: test.format_opt_attr_op_a(10)
20 // CHECK-NOT: {opt_attr
21 test.format_opt_attr_op_a(10)
22 test.format_opt_attr_op_a
24 // CHECK: test.format_opt_attr_op_b 10
25 // CHECK-NOT: {opt_attr
26 test.format_opt_attr_op_b 10
27 test.format_opt_attr_op_b
29 // CHECK: test.format_symbol_name_attr_op @name
31 test.format_symbol_name_attr_op @name
33 // CHECK: test.format_symbol_name_attr_op @opt_name
35 test.format_symbol_name_attr_op @opt_name
36 test.format_opt_symbol_name_attr_op
38 // CHECK: test.format_opt_symbol_ref_attr_op @foo
39 // CHECK: test.format_opt_symbol_ref_attr_op {test.unit}
40 test.format_opt_symbol_ref_attr_op @foo {test.unit}
41 test.format_opt_symbol_ref_attr_op {test.unit}
43 // CHECK: test.format_attr_dict_w_keyword attributes {attr = 10 : i64}
44 test.format_attr_dict_w_keyword attributes {attr = 10 : i64}
46 // CHECK: test.format_attr_dict_w_keyword attributes {attr = 10 : i64, opt_attr = 10 : i64}
47 test.format_attr_dict_w_keyword attributes {attr = 10 : i64, opt_attr = 10 : i64}
49 // CHECK: test.format_buildable_type_op %[[I64]]
50 %ignored = test.format_buildable_type_op %i64
52 //===----------------------------------------------------------------------===//
54 //===----------------------------------------------------------------------===//
56 // CHECK: test.format_region_a_op {
57 // CHECK-NEXT: test.return
58 test.format_region_a_op {
59 "test.return"() : () -> ()
62 // CHECK: test.format_region_b_op {
63 // CHECK-NEXT: test.return
64 test.format_region_b_op {
65 "test.return"() : () -> ()
68 // CHECK: test.format_region_c_op region {
69 // CHECK-NEXT: test.return
70 test.format_region_c_op region {
71 "test.return"() : () -> ()
73 // CHECK: test.format_region_c_op
74 // CHECK-NOT: region {
75 test.format_region_c_op
77 // CHECK: test.format_variadic_region_a_op {
78 // CHECK-NEXT: test.return
80 // CHECK-NEXT: test.return
82 test.format_variadic_region_a_op {
83 "test.return"() : () -> ()
85 "test.return"() : () -> ()
87 // CHECK: test.format_variadic_region_b_op {
88 // CHECK-NEXT: test.return
90 // CHECK-NEXT: test.return
91 // CHECK-NEXT: } found_regions
92 test.format_variadic_region_b_op {
93 "test.return"() : () -> ()
95 "test.return"() : () -> ()
97 // CHECK: test.format_variadic_region_b_op
99 // CHECK-NOT: found_regions
100 test.format_variadic_region_b_op
102 // CHECK: test.format_implicit_terminator_region_a_op {
104 test.format_implicit_terminator_region_a_op {
105 "test.return"() : () -> ()
107 // CHECK: test.format_implicit_terminator_region_a_op {
108 // CHECK-NEXT: test.return"() {foo.attr
109 test.format_implicit_terminator_region_a_op {
110 "test.return"() {foo.attr} : () -> ()
112 // CHECK: test.format_implicit_terminator_region_a_op {
113 // CHECK-NEXT: test.return"(%[[I64]]) : (i64)
114 test.format_implicit_terminator_region_a_op {
115 "test.return"(%i64) : (i64) -> ()
118 //===----------------------------------------------------------------------===//
120 //===----------------------------------------------------------------------===//
122 // CHECK: test.format_result_a_op memref<1xf64>
123 %ignored_a:2 = test.format_result_a_op memref<1xf64>
125 // CHECK: test.format_result_b_op i64, memref<1xf64>
126 %ignored_b:2 = test.format_result_b_op i64, memref<1xf64>
128 // CHECK: test.format_result_c_op (i64) -> memref<1xf64>
129 %ignored_c:2 = test.format_result_c_op (i64) -> memref<1xf64>
131 // CHECK: test.format_variadic_result : i64, i64, i64
132 %ignored_v:3 = test.format_variadic_result : i64, i64, i64
134 // CHECK: test.format_multiple_variadic_results : (i64, i64, i64), (i32, i32)
135 %ignored_mv:5 = test.format_multiple_variadic_results : (i64, i64, i64), (i32, i32)
137 //===----------------------------------------------------------------------===//
139 //===----------------------------------------------------------------------===//
141 // CHECK: test.format_operand_a_op %[[I64]], %[[MEMREF]] : i64, memref<1xf64>
142 test.format_operand_a_op %i64, %memref : i64, memref<1xf64>
144 // CHECK: test.format_operand_b_op %[[I64]], %[[MEMREF]] : memref<1xf64>
145 test.format_operand_b_op %i64, %memref : memref<1xf64>
147 // CHECK: test.format_operand_c_op %[[I64]], %[[MEMREF]] : i64, memref<1xf64>
148 test.format_operand_c_op %i64, %memref : i64, memref<1xf64>
150 // CHECK: test.format_operand_d_op %[[I64]], %[[MEMREF]] : memref<1xf64>
151 test.format_operand_d_op %i64, %memref : memref<1xf64>
153 // CHECK: test.format_operand_e_op %[[I64]], %[[MEMREF]] : i64, memref<1xf64>
154 test.format_operand_e_op %i64, %memref : i64, memref<1xf64>
156 // CHECK: test.format_variadic_operand %[[I64]], %[[I64]], %[[I64]] : i64, i64, i64
157 test.format_variadic_operand %i64, %i64, %i64 : i64, i64, i64
159 // CHECK: test.format_variadic_of_variadic_operand (%[[I64]], %[[I64]]), (), (%[[I64]]) : (i64, i64), (), (i64)
160 test.format_variadic_of_variadic_operand (%i64, %i64), (), (%i64) : (i64, i64), (), (i64)
162 // CHECK: test.format_multiple_variadic_operands (%[[I64]], %[[I64]], %[[I64]]), (%[[I64]], %[[I32]] : i64, i32)
163 test.format_multiple_variadic_operands (%i64, %i64, %i64), (%i64, %i32 : i64, i32)
165 //===----------------------------------------------------------------------===//
167 //===----------------------------------------------------------------------===//
169 "foo.successor_test_region"() ({
171 // CHECK: test.format_successor_a_op ^bb1 {attr}
172 test.format_successor_a_op ^bb1 {attr}
175 // CHECK: test.format_successor_a_op ^bb1, ^bb2 {attr}
176 test.format_successor_a_op ^bb1, ^bb2 {attr}
179 // CHECK: test.format_successor_a_op {attr}
180 test.format_successor_a_op {attr}
182 }) { arg_names = ["i", "j", "k"] } : () -> ()
184 //===----------------------------------------------------------------------===//
185 // Format optional attributes
186 //===----------------------------------------------------------------------===//
188 // CHECK: test.format_optional_unit_attribute is_optional
189 test.format_optional_unit_attribute is_optional
191 // CHECK: test.format_optional_unit_attribute
192 // CHECK-NOT: is_optional
193 test.format_optional_unit_attribute
195 // CHECK: test.format_optional_unit_attribute_no_elide unit
196 test.format_optional_unit_attribute_no_elide unit
198 // CHECK: test.format_optional_unit_property is_optional
199 test.format_optional_unit_property is_optional
201 // CHECK: test.format_optional_unit_property
202 // CHECK-NOT: is_optional
203 test.format_optional_unit_property
205 // CHECK: test.format_optional_unit_property_no_elide unit
206 test.format_optional_unit_property_no_elide unit
208 // CHECK: test.format_optional_enum_attr case5
209 test.format_optional_enum_attr case5
211 // CHECK: test.format_optional_enum_attr
212 // CHECK-NOT: "case5"
213 test.format_optional_enum_attr
215 // CHECK: test.format_optional_default_attrs "foo" @foo case10
216 test.format_optional_default_attrs "foo" @foo case10
218 // CHECK: test.format_optional_default_attr
219 // CHECK-NOT: "default"
220 // CHECK-NOT: @default
222 test.format_optional_default_attrs "default" @default case5
224 //===----------------------------------------------------------------------===//
225 // Format optional operands and results
226 //===----------------------------------------------------------------------===//
228 // CHECK: test.format_optional_operand_result_a_op(%[[I64]] : i64) : i64
229 test.format_optional_operand_result_a_op(%i64 : i64) : i64
231 // CHECK: test.format_optional_operand_result_a_op( : ) : i64
232 test.format_optional_operand_result_a_op( : ) : i64
234 // CHECK: test.format_optional_operand_result_a_op(%[[I64]] : i64) :
236 test.format_optional_operand_result_a_op(%i64 : i64) :
238 // CHECK: test.format_optional_operand_result_a_op(%[[I64]] : i64) : [%[[I64]], %[[I64]]]
239 test.format_optional_operand_result_a_op(%i64 : i64) : [%i64, %i64]
241 // CHECK: test.format_optional_operand_result_b_op(%[[I64]] : i64) : i64
242 test.format_optional_operand_result_b_op(%i64 : i64) : i64
244 // CHECK: test.format_optional_operand_result_b_op : i64
245 test.format_optional_operand_result_b_op( : ) : i64
247 // CHECK: test.format_optional_operand_result_b_op : i64
248 test.format_optional_operand_result_b_op : i64
250 //===----------------------------------------------------------------------===//
251 // Format optional results
252 //===----------------------------------------------------------------------===//
254 // CHECK: test.format_optional_result_a_op
255 test.format_optional_result_a_op
257 // CHECK: test.format_optional_result_a_op : i64 -> i64, i64
258 test.format_optional_result_a_op : i64 -> i64, i64
260 // CHECK: test.format_optional_result_b_op
261 test.format_optional_result_b_op
263 // CHECK: test.format_optional_result_b_op : i64 -> i64, i64
264 test.format_optional_result_b_op : i64 -> i64, i64
266 // CHECK: test.format_optional_result_c_op : (i64) -> (i64, i64)
267 test.format_optional_result_c_op : (i64) -> (i64, i64)
269 //===----------------------------------------------------------------------===//
270 // Format optional with else
271 //===----------------------------------------------------------------------===//
273 // CHECK: test.format_optional_else then
274 test.format_optional_else then
276 // CHECK: test.format_optional_else else
277 test.format_optional_else else
279 //===----------------------------------------------------------------------===//
280 // Format a custom attribute
281 //===----------------------------------------------------------------------===//
283 // CHECK: test.format_compound_attr <1, !test.smpla, [5, 6]>
284 test.format_compound_attr <1, !test.smpla, [5, 6]>
289 // CHECK: module attributes {test.nested = #test.cmpnd_nested<nested = <1, !test.smpla, [5, 6]>>} {
290 module attributes {test.nested = #test.cmpnd_nested<nested = <1, !test.smpla, [5, 6]>>} {
295 // Same as above, but fully spelling the inner attribute prefix `#test.cmpnd_a`.
296 // CHECK: module attributes {test.nested = #test.cmpnd_nested<nested = <1, !test.smpla, [5, 6]>>} {
297 module attributes {test.nested = #test.cmpnd_nested<nested = #test.cmpnd_a<1, !test.smpla, [5, 6]>>} {
300 // CHECK: test.format_nested_attr <nested = <1, !test.smpla, [5, 6]>>
301 test.format_nested_attr #test.cmpnd_nested<nested = <1, !test.smpla, [5, 6]>>
305 // Same as above, but fully spelling the inner attribute prefix `#test.cmpnd_a`.
306 // CHECK: test.format_nested_attr <nested = <1, !test.smpla, [5, 6]>>
307 test.format_nested_attr #test.cmpnd_nested<nested = #test.cmpnd_a<1, !test.smpla, [5, 6]>>
311 // CHECK: module attributes {test.someAttr = #test.cmpnd_nested_inner<42 <1, !test.smpla, [5, 6]>>}
312 module attributes {test.someAttr = #test.cmpnd_nested_inner<42 <1, !test.smpla, [5, 6]>>}
318 // CHECK: module attributes {test.someAttr = #test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>}
319 module attributes {test.someAttr = #test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>}
325 // CHECK: test.format_cpmd_nested_attr nested <i <42 <1, !test.smpla, [5, 6]>>>
326 test.format_cpmd_nested_attr nested <i <42 <1, !test.smpla, [5, 6]>>>
330 // CHECK: test.format_qual_cpmd_nested_attr nested #test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>
331 test.format_qual_cpmd_nested_attr nested #test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>
335 // Check the `qualified` directive in the declarative assembly format.
336 // CHECK: @qualifiedCompoundNestedExplicit(%arg0: !test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>)
337 func.func @qualifiedCompoundNestedExplicit(%arg0: !test.cmpnd_nested_outer<i !test.cmpnd_inner<42 <1, !test.smpla, [5, 6]>>>) -> () {
338 // Verify that the type prefix is not elided
339 // CHECK: format_qual_cpmd_nested_type %arg0 nested !test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>
340 test.format_qual_cpmd_nested_type %arg0 nested !test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>
346 //===----------------------------------------------------------------------===//
347 // Format custom directives
348 //===----------------------------------------------------------------------===//
350 // CHECK: test.format_custom_directive_operands %[[I64]], %[[I64]] -> (%[[I64]])
351 test.format_custom_directive_operands %i64, %i64 -> (%i64)
353 // CHECK: test.format_custom_directive_operands %[[I64]] -> (%[[I64]])
354 test.format_custom_directive_operands %i64 -> (%i64)
356 // CHECK: test.format_custom_directive_operands_and_types %[[I64]], %[[I64]] -> (%[[I64]]) : i64, i64 -> (i64)
357 test.format_custom_directive_operands_and_types %i64, %i64 -> (%i64) : i64, i64 -> (i64)
359 // CHECK: test.format_custom_directive_operands_and_types %[[I64]] -> (%[[I64]]) : i64 -> (i64)
360 test.format_custom_directive_operands_and_types %i64 -> (%i64) : i64 -> (i64)
362 // CHECK: test.format_custom_directive_attributes 54 : i64
363 test.format_custom_directive_attributes 54 : i64
365 // CHECK: test.format_custom_directive_attributes 54 : i64, 46 : i64
366 test.format_custom_directive_attributes 54 : i64, 46 : i64
368 // CHECK: test.format_custom_directive_regions {
369 // CHECK-NEXT: test.return
371 test.format_custom_directive_regions {
372 "test.return"() : () -> ()
375 // CHECK: test.format_custom_directive_regions {
376 // CHECK-NEXT: test.return
378 // CHECK-NEXT: test.return
380 test.format_custom_directive_regions {
381 "test.return"() : () -> ()
383 "test.return"() : () -> ()
386 // CHECK: test.format_custom_directive_results : i64, i64 -> (i64)
387 test.format_custom_directive_results : i64, i64 -> (i64)
389 // CHECK: test.format_custom_directive_results : i64 -> (i64)
390 test.format_custom_directive_results : i64 -> (i64)
392 // CHECK: test.format_custom_directive_results_with_type_refs : i64, i64 -> (i64) type_refs_capture : i64, i64 -> (i64)
393 test.format_custom_directive_results_with_type_refs : i64, i64 -> (i64) type_refs_capture : i64, i64 -> (i64)
395 // CHECK: test.format_custom_directive_results_with_type_refs : i64 -> (i64) type_refs_capture : i64 -> (i64)
396 test.format_custom_directive_results_with_type_refs : i64 -> (i64) type_refs_capture : i64 -> (i64)
398 // CHECK: test.format_custom_directive_with_optional_operand_ref %[[I64]] : 1
399 test.format_custom_directive_with_optional_operand_ref %i64 : 1
401 // CHECK: test.format_custom_directive_with_optional_operand_ref : 0
402 test.format_custom_directive_with_optional_operand_ref : 0
405 // CHECK: test.format_custom_directive_successors ^bb1, ^bb2
406 test.format_custom_directive_successors ^bb1, ^bb2
409 // CHECK: test.format_custom_directive_successors ^bb2
410 test.format_custom_directive_successors ^bb2
416 // CHECK: test.format_custom_directive_spacing "a" "b"
417 test.format_custom_directive_spacing "a" "b"
419 // CHECK: test.format_literal_following_optional_group(5 : i32) : i32 {a}
420 test.format_literal_following_optional_group(5 : i32) : i32 {a}
422 func.func @variadic(%a: i32) {
423 // CHECK: test.ellipsis(%{{.*}} ...) : i32 ...
424 test.ellipsis(%a ...) : i32 ...
428 //===----------------------------------------------------------------------===//
429 // Format trait type inference
430 //===----------------------------------------------------------------------===//
432 // CHECK: test.format_infer_variadic_type_from_non_variadic %[[I64]], %[[I64]] : i64
433 test.format_infer_variadic_type_from_non_variadic %i64, %i64 : i64
435 //===----------------------------------------------------------------------===//
436 // AllTypesMatch type inference
437 //===----------------------------------------------------------------------===//
439 // CHECK: test.format_all_types_match_var %[[I64]], %[[I64]] : i64
440 %ignored_res1 = test.format_all_types_match_var %i64, %i64 : i64
442 // CHECK: test.format_all_types_match_attr 1 : i64, %[[I64]]
443 %ignored_res2 = test.format_all_types_match_attr 1 : i64, %i64
445 //===----------------------------------------------------------------------===//
446 // TypesMatchWith type inference
447 //===----------------------------------------------------------------------===//
449 // CHECK: test.format_types_match_var %[[I64]] : i64
450 %ignored_res3 = test.format_types_match_var %i64 : i64
452 // CHECK: test.format_types_match_variadic %[[I64]], %[[I64]], %[[I64]] : i64, i64, i64
453 %ignored_res4:3 = test.format_types_match_variadic %i64, %i64, %i64 : i64, i64, i64
455 // CHECK: test.format_types_match_attr 1 : i64
456 %ignored_res5 = test.format_types_match_attr 1 : i64
458 // CHECK: test.format_types_match_context %[[I64]] : i64
459 %ignored_res6 = test.format_types_match_context %i64 : i64
461 //===----------------------------------------------------------------------===//
462 // InferTypeOpInterface type inference
463 //===----------------------------------------------------------------------===//
465 // CHECK: test.format_infer_type
466 %ignored_res7a = test.format_infer_type
468 // CHECK: test.format_infer_type2
469 %ignored_res7b = test.format_infer_type2
471 // CHECK: test.format_infer_type_all_operands_and_types(%[[I64]], %[[I32]]) : i64, i32
472 %ignored_res8:2 = test.format_infer_type_all_operands_and_types(%i64, %i32) : i64, i32
474 // CHECK: test.format_infer_type_all_types_one_operand(%[[I64]], %[[I32]]) : i64, i32
475 %ignored_res9:2 = test.format_infer_type_all_types_one_operand(%i64, %i32) : i64, i32
477 // CHECK: test.format_infer_type_all_types_two_operands(%[[I64]], %[[I32]]) (%[[I64]], %[[I32]]) : i64, i32, i64, i32
478 %ignored_res10:4 = test.format_infer_type_all_types_two_operands(%i64, %i32) (%i64, %i32) : i64, i32, i64, i32
480 // CHECK: test.format_infer_type_all_types(%[[I64]], %[[I32]]) : i64, i32
481 %ignored_res11:2 = test.format_infer_type_all_types(%i64, %i32) : i64, i32
483 // CHECK: test.format_infer_type_regions
484 // CHECK-NEXT: ^bb0(%{{.*}}: {{.*}}, %{{.*}}: {{.*}}):
485 %ignored_res12:2 = test.format_infer_type_regions {
486 ^bb0(%arg0: i32, %arg1: f32):
487 "test.terminator"() : () -> ()
490 // CHECK: test.format_infer_type_variadic_operands(%[[I32]], %[[I32]] : i32, i32) (%[[I64]], %[[I64]] : i64, i64)
491 %ignored_res13:4 = test.format_infer_type_variadic_operands(%i32, %i32 : i32, i32) (%i64, %i64 : i64, i64)
493 // CHECK: test.with_properties_and_attr 16 < {rhs = 16 : i64}>
494 test.with_properties_and_attr 16 <{rhs = 16 : i64}>
496 // CHECK: test.with_properties_and_inferred_type 16 < {rhs = 16 : i64}>
497 %should_be_i32 = test.with_properties_and_inferred_type 16 <{rhs = 16 : i64}>
498 // Assert through the verifier that its inferred as i32.
499 test.format_all_types_match_var %should_be_i32, %i32 : i32
501 // CHECK: test.using_property_in_custom_and_other [1, 4, 20] < {other = 16 : i64}>
502 test.using_property_in_custom_and_other [1, 4, 20] <{other = 16 : i64}>
504 //===----------------------------------------------------------------------===//
505 // Check DefaultValuedStrAttr
506 //===----------------------------------------------------------------------===//
508 // CHECK: test.has_str_value
509 test.has_str_value {}
511 //===----------------------------------------------------------------------===//
513 //===----------------------------------------------------------------------===//
515 // CHECK-LABEL: @else_anchor_op
516 func.func @else_anchor_op(%a: !test.else_anchor<?>, %b: !test.else_anchor<5>) {
517 // CHECK: test.else_anchor(?) {a = !test.else_anchor_struct<?>}
518 test.else_anchor(?) {a = !test.else_anchor_struct<?>}
519 // CHECK: test.else_anchor(%{{.*}} : !test.else_anchor<?>) {a = !test.else_anchor_struct<a = 0>}
520 test.else_anchor(%a : !test.else_anchor<?>) {a = !test.else_anchor_struct<a = 0>}
521 // CHECK: test.else_anchor(%{{.*}} : !test.else_anchor<5>) {a = !test.else_anchor_struct<b = 0>}
522 test.else_anchor(%b : !test.else_anchor<5>) {a = !test.else_anchor_struct<b = 0>}