aboutsummaryrefslogtreecommitdiff
path: root/mlir/test/IR/dynamic.mlir
blob: cf03414c89a3560245a417fbb05259b5d7b0d44e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// RUN: mlir-opt -allow-unregistered-dialect %s -split-input-file -verify-diagnostics | FileCheck %s
// Verify that extensible dialects can register dynamic operations and types.

//===----------------------------------------------------------------------===//
// Dynamic type
//===----------------------------------------------------------------------===//

// CHECK-LABEL: func @succeededDynamicTypeVerifier
func.func @succeededDynamicTypeVerifier() {
  // CHECK: %{{.*}} = "unregistered_op"() : () -> !test.dynamic_singleton
  "unregistered_op"() : () -> !test.dynamic_singleton
  // CHECK-NEXT: "unregistered_op"() : () -> !test.dynamic_pair<i32, f64>
  "unregistered_op"() : () -> !test.dynamic_pair<i32, f64>
  // CHECK-NEXT: %{{.*}} = "unregistered_op"() : () -> !test.dynamic_pair<!test.dynamic_pair<i32, f64>, !test.dynamic_singleton>
  "unregistered_op"() : () -> !test.dynamic_pair<!test.dynamic_pair<i32, f64>, !test.dynamic_singleton>
  return
}

// -----

func.func @failedDynamicTypeVerifier() {
  // expected-error@+1 {{expected 0 type arguments, but had 1}}
  "unregistered_op"() : () -> !test.dynamic_singleton<f64>
  return
}

// -----

func.func @failedDynamicTypeVerifier2() {
  // expected-error@+1 {{expected 2 type arguments, but had 1}}
  "unregistered_op"() : () -> !test.dynamic_pair<f64>
  return
}

// -----

// CHECK-LABEL: func @customTypeParserPrinter
func.func @customTypeParserPrinter() {
  // CHECK: "unregistered_op"() : () -> !test.dynamic_custom_assembly_format<f32:f64>
  "unregistered_op"() : () -> !test.dynamic_custom_assembly_format<f32 : f64>
  return
}

// -----

//===----------------------------------------------------------------------===//
// Dynamic attribute
//===----------------------------------------------------------------------===//

// CHECK-LABEL: func @succeededDynamicAttributeVerifier
func.func @succeededDynamicAttributeVerifier() {
  // CHECK: "unregistered_op"() {test_attr = #test.dynamic_singleton} : () -> ()
  "unregistered_op"() {test_attr = #test.dynamic_singleton} : () -> ()
  // CHECK-NEXT: "unregistered_op"() {test_attr = #test.dynamic_pair<3 : i32, 5 : i32>} : () -> ()
  "unregistered_op"() {test_attr = #test.dynamic_pair<3 : i32, 5 : i32>} : () -> ()
  // CHECK-NEXT: "unregistered_op"() {test_attr = #test.dynamic_pair<#test.dynamic_pair<3 : i32, 5 : i32>, f64>} : () -> ()
  "unregistered_op"() {test_attr = #test.dynamic_pair<#test.dynamic_pair<3 : i32, 5 : i32>, f64>} : () -> ()
  return
}

// -----

func.func @failedDynamicAttributeVerifier() {
  // expected-error@+1 {{expected 0 attribute arguments, but had 1}}
  "unregistered_op"() {test_attr = #test.dynamic_singleton<f64>} : () -> ()
  return
}

// -----

func.func @failedDynamicAttributeVerifier2() {
  // expected-error@+1 {{expected 2 attribute arguments, but had 1}}
  "unregistered_op"() {test_attr = #test.dynamic_pair<f64>} : () -> ()
  return
}

// -----

// CHECK-LABEL: func @customAttributeParserPrinter
func.func @customAttributeParserPrinter() {
  // CHECK: "unregistered_op"() {test_attr = #test.dynamic_custom_assembly_format<f32:f64>} : () -> ()
  "unregistered_op"() {test_attr = #test.dynamic_custom_assembly_format<f32:f64>} : () -> ()
  return
}

//===----------------------------------------------------------------------===//
// Dynamic op
//===----------------------------------------------------------------------===//

// -----

// CHECK-LABEL: func @succeededDynamicOpVerifier
func.func @succeededDynamicOpVerifier(%a: f32) {
  // CHECK: "test.dynamic_generic"() : () -> ()
  // CHECK-NEXT: %{{.*}} = "test.dynamic_generic"(%{{.*}}) : (f32) -> f64
  // CHECK-NEXT: %{{.*}}:2 = "test.dynamic_one_operand_two_results"(%{{.*}}) : (f32) -> (f64, f64)
  "test.dynamic_generic"() : () -> ()
  "test.dynamic_generic"(%a) : (f32) -> f64
  "test.dynamic_one_operand_two_results"(%a) : (f32) -> (f64, f64)
  return
}

// -----

func.func @failedDynamicOpVerifier() {
  // expected-error@+1 {{expected 1 operand, but had 0}}
  "test.dynamic_one_operand_two_results"() : () -> (f64, f64)
  return
}

// -----

func.func @failedDynamicOpVerifier2(%a: f32) {
  // expected-error@+1 {{expected 2 results, but had 0}}
  "test.dynamic_one_operand_two_results"(%a) : (f32) -> ()
  return
}

// -----

// CHECK-LABEL: func @customOpParserPrinter
func.func @customOpParserPrinter() {
  // CHECK: test.dynamic_custom_parser_printer custom_keyword
  test.dynamic_custom_parser_printer custom_keyword
  return
}

//===----------------------------------------------------------------------===//
// Dynamic dialect
//===----------------------------------------------------------------------===//

// -----

// Check that the verifier of a dynamic operation in a dynamic dialect
// can fail. This shows that the dialect is correctly registered.

func.func @failedDynamicDialectOpVerifier() {
  // expected-error@+1 {{expected a single result, no operands and no regions}}
  "test_dyn.one_result"() : () -> ()
  return
}