llvm-project
514 строк · 19.2 Кб
1// RUN: mlir-opt -allow-unregistered-dialect %s | mlir-opt -allow-unregistered-dialect -verify-diagnostics | FileCheck %s
2
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>)
9
10// CHECK: test.format_literal_op keyword_$. -> :, = <> () []( ) ? + * {
11// CHECK-NEXT: } {foo.some_attr}
12test.format_literal_op keyword_$. -> :, = <> () []( ) ? + * {
13} {foo.some_attr}
14
15// CHECK: test.format_attr_op 10
16// CHECK-NOT: {attr
17test.format_attr_op 10
18
19// CHECK: test.format_opt_attr_op_a(10)
20// CHECK-NOT: {opt_attr
21test.format_opt_attr_op_a(10)
22test.format_opt_attr_op_a
23
24// CHECK: test.format_opt_attr_op_b 10
25// CHECK-NOT: {opt_attr
26test.format_opt_attr_op_b 10
27test.format_opt_attr_op_b
28
29// CHECK: test.format_symbol_name_attr_op @name
30// CHECK-NOT: {attr
31test.format_symbol_name_attr_op @name
32
33// CHECK: test.format_symbol_name_attr_op @opt_name
34// CHECK-NOT: {attr
35test.format_symbol_name_attr_op @opt_name
36test.format_opt_symbol_name_attr_op
37
38// CHECK: test.format_opt_symbol_ref_attr_op @foo
39// CHECK: test.format_opt_symbol_ref_attr_op {test.unit}
40test.format_opt_symbol_ref_attr_op @foo {test.unit}
41test.format_opt_symbol_ref_attr_op {test.unit}
42
43// CHECK: test.format_attr_dict_w_keyword attributes {attr = 10 : i64}
44test.format_attr_dict_w_keyword attributes {attr = 10 : i64}
45
46// CHECK: test.format_attr_dict_w_keyword attributes {attr = 10 : i64, opt_attr = 10 : i64}
47test.format_attr_dict_w_keyword attributes {attr = 10 : i64, opt_attr = 10 : i64}
48
49// CHECK: test.format_buildable_type_op %[[I64]]
50%ignored = test.format_buildable_type_op %i64
51
52//===----------------------------------------------------------------------===//
53// Format regions
54//===----------------------------------------------------------------------===//
55
56// CHECK: test.format_region_a_op {
57// CHECK-NEXT: test.return
58test.format_region_a_op {
59"test.return"() : () -> ()
60}
61
62// CHECK: test.format_region_b_op {
63// CHECK-NEXT: test.return
64test.format_region_b_op {
65"test.return"() : () -> ()
66}
67
68// CHECK: test.format_region_c_op region {
69// CHECK-NEXT: test.return
70test.format_region_c_op region {
71"test.return"() : () -> ()
72}
73// CHECK: test.format_region_c_op
74// CHECK-NOT: region {
75test.format_region_c_op
76
77// CHECK: test.format_variadic_region_a_op {
78// CHECK-NEXT: test.return
79// CHECK-NEXT: }, {
80// CHECK-NEXT: test.return
81// CHECK-NEXT: }
82test.format_variadic_region_a_op {
83"test.return"() : () -> ()
84}, {
85"test.return"() : () -> ()
86}
87// CHECK: test.format_variadic_region_b_op {
88// CHECK-NEXT: test.return
89// CHECK-NEXT: }, {
90// CHECK-NEXT: test.return
91// CHECK-NEXT: } found_regions
92test.format_variadic_region_b_op {
93"test.return"() : () -> ()
94}, {
95"test.return"() : () -> ()
96} found_regions
97// CHECK: test.format_variadic_region_b_op
98// CHECK-NOT: {
99// CHECK-NOT: found_regions
100test.format_variadic_region_b_op
101
102// CHECK: test.format_implicit_terminator_region_a_op {
103// CHECK-NEXT: }
104test.format_implicit_terminator_region_a_op {
105"test.return"() : () -> ()
106}
107// CHECK: test.format_implicit_terminator_region_a_op {
108// CHECK-NEXT: test.return"() {foo.attr
109test.format_implicit_terminator_region_a_op {
110"test.return"() {foo.attr} : () -> ()
111}
112// CHECK: test.format_implicit_terminator_region_a_op {
113// CHECK-NEXT: test.return"(%[[I64]]) : (i64)
114test.format_implicit_terminator_region_a_op {
115"test.return"(%i64) : (i64) -> ()
116}
117
118//===----------------------------------------------------------------------===//
119// Format results
120//===----------------------------------------------------------------------===//
121
122// CHECK: test.format_result_a_op memref<1xf64>
123%ignored_a:2 = test.format_result_a_op memref<1xf64>
124
125// CHECK: test.format_result_b_op i64, memref<1xf64>
126%ignored_b:2 = test.format_result_b_op i64, memref<1xf64>
127
128// CHECK: test.format_result_c_op (i64) -> memref<1xf64>
129%ignored_c:2 = test.format_result_c_op (i64) -> memref<1xf64>
130
131// CHECK: test.format_variadic_result : i64, i64, i64
132%ignored_v:3 = test.format_variadic_result : i64, i64, i64
133
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)
136
137//===----------------------------------------------------------------------===//
138// Format operands
139//===----------------------------------------------------------------------===//
140
141// CHECK: test.format_operand_a_op %[[I64]], %[[MEMREF]] : i64, memref<1xf64>
142test.format_operand_a_op %i64, %memref : i64, memref<1xf64>
143
144// CHECK: test.format_operand_b_op %[[I64]], %[[MEMREF]] : memref<1xf64>
145test.format_operand_b_op %i64, %memref : memref<1xf64>
146
147// CHECK: test.format_operand_c_op %[[I64]], %[[MEMREF]] : i64, memref<1xf64>
148test.format_operand_c_op %i64, %memref : i64, memref<1xf64>
149
150// CHECK: test.format_operand_d_op %[[I64]], %[[MEMREF]] : memref<1xf64>
151test.format_operand_d_op %i64, %memref : memref<1xf64>
152
153// CHECK: test.format_operand_e_op %[[I64]], %[[MEMREF]] : i64, memref<1xf64>
154test.format_operand_e_op %i64, %memref : i64, memref<1xf64>
155
156// CHECK: test.format_variadic_operand %[[I64]], %[[I64]], %[[I64]] : i64, i64, i64
157test.format_variadic_operand %i64, %i64, %i64 : i64, i64, i64
158
159// CHECK: test.format_variadic_of_variadic_operand (%[[I64]], %[[I64]]), (), (%[[I64]]) : (i64, i64), (), (i64)
160test.format_variadic_of_variadic_operand (%i64, %i64), (), (%i64) : (i64, i64), (), (i64)
161
162// CHECK: test.format_multiple_variadic_operands (%[[I64]], %[[I64]], %[[I64]]), (%[[I64]], %[[I32]] : i64, i32)
163test.format_multiple_variadic_operands (%i64, %i64, %i64), (%i64, %i32 : i64, i32)
164
165//===----------------------------------------------------------------------===//
166// Format successors
167//===----------------------------------------------------------------------===//
168
169"foo.successor_test_region"() ({
170^bb0:
171// CHECK: test.format_successor_a_op ^bb1 {attr}
172test.format_successor_a_op ^bb1 {attr}
173
174^bb1:
175// CHECK: test.format_successor_a_op ^bb1, ^bb2 {attr}
176test.format_successor_a_op ^bb1, ^bb2 {attr}
177
178^bb2:
179// CHECK: test.format_successor_a_op {attr}
180test.format_successor_a_op {attr}
181
182}) { arg_names = ["i", "j", "k"] } : () -> ()
183
184//===----------------------------------------------------------------------===//
185// Format optional attributes
186//===----------------------------------------------------------------------===//
187
188// CHECK: test.format_optional_unit_attribute is_optional
189test.format_optional_unit_attribute is_optional
190
191// CHECK: test.format_optional_unit_attribute
192// CHECK-NOT: is_optional
193test.format_optional_unit_attribute
194
195// CHECK: test.format_optional_unit_attribute_no_elide unit
196test.format_optional_unit_attribute_no_elide unit
197
198// CHECK: test.format_optional_enum_attr case5
199test.format_optional_enum_attr case5
200
201// CHECK: test.format_optional_enum_attr
202// CHECK-NOT: "case5"
203test.format_optional_enum_attr
204
205// CHECK: test.format_optional_default_attrs "foo" @foo case10
206test.format_optional_default_attrs "foo" @foo case10
207
208// CHECK: test.format_optional_default_attr
209// CHECK-NOT: "default"
210// CHECK-NOT: @default
211// CHECK-NOT: case5
212test.format_optional_default_attrs "default" @default case5
213
214//===----------------------------------------------------------------------===//
215// Format optional operands and results
216//===----------------------------------------------------------------------===//
217
218// CHECK: test.format_optional_operand_result_a_op(%[[I64]] : i64) : i64
219test.format_optional_operand_result_a_op(%i64 : i64) : i64
220
221// CHECK: test.format_optional_operand_result_a_op( : ) : i64
222test.format_optional_operand_result_a_op( : ) : i64
223
224// CHECK: test.format_optional_operand_result_a_op(%[[I64]] : i64) :
225// CHECK-NOT: i64
226test.format_optional_operand_result_a_op(%i64 : i64) :
227
228// CHECK: test.format_optional_operand_result_a_op(%[[I64]] : i64) : [%[[I64]], %[[I64]]]
229test.format_optional_operand_result_a_op(%i64 : i64) : [%i64, %i64]
230
231// CHECK: test.format_optional_operand_result_b_op(%[[I64]] : i64) : i64
232test.format_optional_operand_result_b_op(%i64 : i64) : i64
233
234// CHECK: test.format_optional_operand_result_b_op : i64
235test.format_optional_operand_result_b_op( : ) : i64
236
237// CHECK: test.format_optional_operand_result_b_op : i64
238test.format_optional_operand_result_b_op : i64
239
240//===----------------------------------------------------------------------===//
241// Format optional results
242//===----------------------------------------------------------------------===//
243
244// CHECK: test.format_optional_result_a_op
245test.format_optional_result_a_op
246
247// CHECK: test.format_optional_result_a_op : i64 -> i64, i64
248test.format_optional_result_a_op : i64 -> i64, i64
249
250// CHECK: test.format_optional_result_b_op
251test.format_optional_result_b_op
252
253// CHECK: test.format_optional_result_b_op : i64 -> i64, i64
254test.format_optional_result_b_op : i64 -> i64, i64
255
256// CHECK: test.format_optional_result_c_op : (i64) -> (i64, i64)
257test.format_optional_result_c_op : (i64) -> (i64, i64)
258
259//===----------------------------------------------------------------------===//
260// Format optional with else
261//===----------------------------------------------------------------------===//
262
263// CHECK: test.format_optional_else then
264test.format_optional_else then
265
266// CHECK: test.format_optional_else else
267test.format_optional_else else
268
269//===----------------------------------------------------------------------===//
270// Format a custom attribute
271//===----------------------------------------------------------------------===//
272
273// CHECK: test.format_compound_attr <1, !test.smpla, [5, 6]>
274test.format_compound_attr <1, !test.smpla, [5, 6]>
275
276//-----
277
278
279// CHECK: module attributes {test.nested = #test.cmpnd_nested<nested = <1, !test.smpla, [5, 6]>>} {
280module attributes {test.nested = #test.cmpnd_nested<nested = <1, !test.smpla, [5, 6]>>} {
281}
282
283//-----
284
285// Same as above, but fully spelling the inner attribute prefix `#test.cmpnd_a`.
286// CHECK: module attributes {test.nested = #test.cmpnd_nested<nested = <1, !test.smpla, [5, 6]>>} {
287module attributes {test.nested = #test.cmpnd_nested<nested = #test.cmpnd_a<1, !test.smpla, [5, 6]>>} {
288}
289
290// CHECK: test.format_nested_attr <nested = <1, !test.smpla, [5, 6]>>
291test.format_nested_attr #test.cmpnd_nested<nested = <1, !test.smpla, [5, 6]>>
292
293//-----
294
295// Same as above, but fully spelling the inner attribute prefix `#test.cmpnd_a`.
296// CHECK: test.format_nested_attr <nested = <1, !test.smpla, [5, 6]>>
297test.format_nested_attr #test.cmpnd_nested<nested = #test.cmpnd_a<1, !test.smpla, [5, 6]>>
298
299//-----
300
301// CHECK: module attributes {test.someAttr = #test.cmpnd_nested_inner<42 <1, !test.smpla, [5, 6]>>}
302module attributes {test.someAttr = #test.cmpnd_nested_inner<42 <1, !test.smpla, [5, 6]>>}
303{
304}
305
306//-----
307
308// CHECK: module attributes {test.someAttr = #test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>}
309module attributes {test.someAttr = #test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>}
310{
311}
312
313//-----
314
315// CHECK: test.format_cpmd_nested_attr nested <i <42 <1, !test.smpla, [5, 6]>>>
316test.format_cpmd_nested_attr nested <i <42 <1, !test.smpla, [5, 6]>>>
317
318//-----
319
320// CHECK: test.format_qual_cpmd_nested_attr nested #test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>
321test.format_qual_cpmd_nested_attr nested #test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>
322
323//-----
324
325// Check the `qualified` directive in the declarative assembly format.
326// CHECK: @qualifiedCompoundNestedExplicit(%arg0: !test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>)
327func.func @qualifiedCompoundNestedExplicit(%arg0: !test.cmpnd_nested_outer<i !test.cmpnd_inner<42 <1, !test.smpla, [5, 6]>>>) -> () {
328// Verify that the type prefix is not elided
329// CHECK: format_qual_cpmd_nested_type %arg0 nested !test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>
330test.format_qual_cpmd_nested_type %arg0 nested !test.cmpnd_nested_outer<i <42 <1, !test.smpla, [5, 6]>>>
331return
332}
333
334//-----
335
336//===----------------------------------------------------------------------===//
337// Format custom directives
338//===----------------------------------------------------------------------===//
339
340// CHECK: test.format_custom_directive_operands %[[I64]], %[[I64]] -> (%[[I64]])
341test.format_custom_directive_operands %i64, %i64 -> (%i64)
342
343// CHECK: test.format_custom_directive_operands %[[I64]] -> (%[[I64]])
344test.format_custom_directive_operands %i64 -> (%i64)
345
346// CHECK: test.format_custom_directive_operands_and_types %[[I64]], %[[I64]] -> (%[[I64]]) : i64, i64 -> (i64)
347test.format_custom_directive_operands_and_types %i64, %i64 -> (%i64) : i64, i64 -> (i64)
348
349// CHECK: test.format_custom_directive_operands_and_types %[[I64]] -> (%[[I64]]) : i64 -> (i64)
350test.format_custom_directive_operands_and_types %i64 -> (%i64) : i64 -> (i64)
351
352// CHECK: test.format_custom_directive_attributes 54 : i64
353test.format_custom_directive_attributes 54 : i64
354
355// CHECK: test.format_custom_directive_attributes 54 : i64, 46 : i64
356test.format_custom_directive_attributes 54 : i64, 46 : i64
357
358// CHECK: test.format_custom_directive_regions {
359// CHECK-NEXT: test.return
360// CHECK-NEXT: }
361test.format_custom_directive_regions {
362"test.return"() : () -> ()
363}
364
365// CHECK: test.format_custom_directive_regions {
366// CHECK-NEXT: test.return
367// CHECK-NEXT: }, {
368// CHECK-NEXT: test.return
369// CHECK-NEXT: }
370test.format_custom_directive_regions {
371"test.return"() : () -> ()
372}, {
373"test.return"() : () -> ()
374}
375
376// CHECK: test.format_custom_directive_results : i64, i64 -> (i64)
377test.format_custom_directive_results : i64, i64 -> (i64)
378
379// CHECK: test.format_custom_directive_results : i64 -> (i64)
380test.format_custom_directive_results : i64 -> (i64)
381
382// CHECK: test.format_custom_directive_results_with_type_refs : i64, i64 -> (i64) type_refs_capture : i64, i64 -> (i64)
383test.format_custom_directive_results_with_type_refs : i64, i64 -> (i64) type_refs_capture : i64, i64 -> (i64)
384
385// CHECK: test.format_custom_directive_results_with_type_refs : i64 -> (i64) type_refs_capture : i64 -> (i64)
386test.format_custom_directive_results_with_type_refs : i64 -> (i64) type_refs_capture : i64 -> (i64)
387
388// CHECK: test.format_custom_directive_with_optional_operand_ref %[[I64]] : 1
389test.format_custom_directive_with_optional_operand_ref %i64 : 1
390
391// CHECK: test.format_custom_directive_with_optional_operand_ref : 0
392test.format_custom_directive_with_optional_operand_ref : 0
393
394func.func @foo() {
395// CHECK: test.format_custom_directive_successors ^bb1, ^bb2
396test.format_custom_directive_successors ^bb1, ^bb2
397
398^bb1:
399// CHECK: test.format_custom_directive_successors ^bb2
400test.format_custom_directive_successors ^bb2
401
402^bb2:
403return
404}
405
406// CHECK: test.format_custom_directive_spacing "a" "b"
407test.format_custom_directive_spacing "a" "b"
408
409// CHECK: test.format_literal_following_optional_group(5 : i32) : i32 {a}
410test.format_literal_following_optional_group(5 : i32) : i32 {a}
411
412func.func @variadic(%a: i32) {
413// CHECK: test.ellipsis(%{{.*}} ...) : i32 ...
414test.ellipsis(%a ...) : i32 ...
415return
416}
417
418//===----------------------------------------------------------------------===//
419// Format trait type inference
420//===----------------------------------------------------------------------===//
421
422// CHECK: test.format_infer_variadic_type_from_non_variadic %[[I64]], %[[I64]] : i64
423test.format_infer_variadic_type_from_non_variadic %i64, %i64 : i64
424
425//===----------------------------------------------------------------------===//
426// AllTypesMatch type inference
427//===----------------------------------------------------------------------===//
428
429// CHECK: test.format_all_types_match_var %[[I64]], %[[I64]] : i64
430%ignored_res1 = test.format_all_types_match_var %i64, %i64 : i64
431
432// CHECK: test.format_all_types_match_attr 1 : i64, %[[I64]]
433%ignored_res2 = test.format_all_types_match_attr 1 : i64, %i64
434
435//===----------------------------------------------------------------------===//
436// TypesMatchWith type inference
437//===----------------------------------------------------------------------===//
438
439// CHECK: test.format_types_match_var %[[I64]] : i64
440%ignored_res3 = test.format_types_match_var %i64 : i64
441
442// CHECK: test.format_types_match_variadic %[[I64]], %[[I64]], %[[I64]] : i64, i64, i64
443%ignored_res4:3 = test.format_types_match_variadic %i64, %i64, %i64 : i64, i64, i64
444
445// CHECK: test.format_types_match_attr 1 : i64
446%ignored_res5 = test.format_types_match_attr 1 : i64
447
448// CHECK: test.format_types_match_context %[[I64]] : i64
449%ignored_res6 = test.format_types_match_context %i64 : i64
450
451//===----------------------------------------------------------------------===//
452// InferTypeOpInterface type inference
453//===----------------------------------------------------------------------===//
454
455// CHECK: test.format_infer_type
456%ignored_res7a = test.format_infer_type
457
458// CHECK: test.format_infer_type2
459%ignored_res7b = test.format_infer_type2
460
461// CHECK: test.format_infer_type_all_operands_and_types(%[[I64]], %[[I32]]) : i64, i32
462%ignored_res8:2 = test.format_infer_type_all_operands_and_types(%i64, %i32) : i64, i32
463
464// CHECK: test.format_infer_type_all_types_one_operand(%[[I64]], %[[I32]]) : i64, i32
465%ignored_res9:2 = test.format_infer_type_all_types_one_operand(%i64, %i32) : i64, i32
466
467// CHECK: test.format_infer_type_all_types_two_operands(%[[I64]], %[[I32]]) (%[[I64]], %[[I32]]) : i64, i32, i64, i32
468%ignored_res10:4 = test.format_infer_type_all_types_two_operands(%i64, %i32) (%i64, %i32) : i64, i32, i64, i32
469
470// CHECK: test.format_infer_type_all_types(%[[I64]], %[[I32]]) : i64, i32
471%ignored_res11:2 = test.format_infer_type_all_types(%i64, %i32) : i64, i32
472
473// CHECK: test.format_infer_type_regions
474// CHECK-NEXT: ^bb0(%{{.*}}: {{.*}}, %{{.*}}: {{.*}}):
475%ignored_res12:2 = test.format_infer_type_regions {
476^bb0(%arg0: i32, %arg1: f32):
477"test.terminator"() : () -> ()
478}
479
480// CHECK: test.format_infer_type_variadic_operands(%[[I32]], %[[I32]] : i32, i32) (%[[I64]], %[[I64]] : i64, i64)
481%ignored_res13:4 = test.format_infer_type_variadic_operands(%i32, %i32 : i32, i32) (%i64, %i64 : i64, i64)
482
483// CHECK: test.with_properties_and_attr 16 < {rhs = 16 : i64}>
484test.with_properties_and_attr 16 <{rhs = 16 : i64}>
485
486// CHECK: test.with_properties_and_inferred_type 16 < {rhs = 16 : i64}>
487%should_be_i32 = test.with_properties_and_inferred_type 16 <{rhs = 16 : i64}>
488// Assert through the verifier that its inferred as i32.
489test.format_all_types_match_var %should_be_i32, %i32 : i32
490
491// CHECK: test.using_property_in_custom_and_other [1, 4, 20] < {other = 16 : i64}>
492test.using_property_in_custom_and_other [1, 4, 20] <{other = 16 : i64}>
493
494//===----------------------------------------------------------------------===//
495// Check DefaultValuedStrAttr
496//===----------------------------------------------------------------------===//
497
498// CHECK: test.has_str_value
499test.has_str_value {}
500
501//===----------------------------------------------------------------------===//
502// ElseAnchorOp
503//===----------------------------------------------------------------------===//
504
505// CHECK-LABEL: @else_anchor_op
506func.func @else_anchor_op(%a: !test.else_anchor<?>, %b: !test.else_anchor<5>) {
507// CHECK: test.else_anchor(?) {a = !test.else_anchor_struct<?>}
508test.else_anchor(?) {a = !test.else_anchor_struct<?>}
509// CHECK: test.else_anchor(%{{.*}} : !test.else_anchor<?>) {a = !test.else_anchor_struct<a = 0>}
510test.else_anchor(%a : !test.else_anchor<?>) {a = !test.else_anchor_struct<a = 0>}
511// CHECK: test.else_anchor(%{{.*}} : !test.else_anchor<5>) {a = !test.else_anchor_struct<b = 0>}
512test.else_anchor(%b : !test.else_anchor<5>) {a = !test.else_anchor_struct<b = 0>}
513return
514}
515