File: variadics.mlir

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (400 lines) | stat: -rw-r--r-- 14,226 bytes parent folder | download | duplicates (11)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
// RUN: mlir-opt %s --irdl-file=%S/variadics.irdl.mlir -split-input-file -verify-diagnostics | FileCheck %s

//===----------------------------------------------------------------------===//
// Single operand
//===----------------------------------------------------------------------===//

// Test an operation with a single operand.
func.func @testSingleOperand(%x: i32) {
  "testvar.single_operand"(%x) : (i32) -> ()
  // CHECK: "testvar.single_operand"(%{{.*}}) : (i32) -> ()
  return
}

// -----

// Test an operation with a single operand definition and a wrong number of operands.
func.func @testSingleOperandFail(%x: i32) {
  // expected-error@+1 {{op expects exactly 1 operands, but got 2}}
  "testvar.single_operand"(%x, %x) : (i32, i32) -> ()  
  return
}

// -----

// Test an operation with a single operand definition and a wrong number of operands.
func.func @testSingleOperandFail() {
  // expected-error@+1 {{op expects exactly 1 operands, but got 0}}
  "testvar.single_operand"() : () -> ()  
  return
}

// -----


//===----------------------------------------------------------------------===//
// Variadic operand
//===----------------------------------------------------------------------===//

// Test an operation with a single variadic operand.
func.func @testVarOperand(%x: i16, %y: i32, %z: i64) {
  "testvar.var_operand"(%x, %z) : (i16, i64) -> ()
  // CHECK: "testvar.var_operand"(%{{.*}}, %{{.*}}) : (i16, i64) -> ()
  "testvar.var_operand"(%x, %y, %z) : (i16, i32, i64) -> ()
  // CHECK-NEXT: "testvar.var_operand"(%{{.*}}, %{{.*}}, %{{.*}}) : (i16, i32, i64) -> ()
  "testvar.var_operand"(%x, %y, %y, %z) : (i16, i32, i32, i64) -> ()
  // CHECK-NEXT: "testvar.var_operand"(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) : (i16, i32, i32, i64) -> ()
  "testvar.var_operand"(%x, %y, %y, %y, %z) : (i16, i32, i32, i32, i64) -> ()
  // CHECK-NEXT: "testvar.var_operand"(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) : (i16, i32, i32, i32, i64) -> ()
  return
}

// -----

// Check that the verifier of a variadic operand  fails if the variadic is given
// a wrong type.
func.func @testVarOperandFail(%x: i16, %y: i64, %z: i64) {
  // expected-error@+1 {{expected 'i32' but got 'i64'}}
  "testvar.var_operand"(%x, %y, %z) : (i16, i64, i64) -> ()
  return
}

// -----

// Check that the verifier of a variadic operand fails if the variadic is given
// a wrong type on the second value.
func.func @testVarOperandFail(%x: i16, %y1: i32, %y2: i64, %z: i64) {
  // expected-error@+1 {{expected 'i32' but got 'i64'}}
  "testvar.var_operand"(%x, %y1, %y2, %z) : (i16, i32, i64, i64) -> ()
  return
}

// -----

// Check that if we do not give enough operands, the verifier fails.
func.func @testVarOperandFail() {
  // expected-error@+1 {{op expects at least 2 operands, but got 0}}
  "testvar.var_operand"() : () -> ()
  return
}

// -----

//===----------------------------------------------------------------------===//
// Optional operand
//===----------------------------------------------------------------------===//


// Test an operation with a single optional operand.
func.func @testOptOperand(%x: i16, %y: i32, %z: i64) {
  "testvar.opt_operand"(%x, %z) : (i16, i64) -> ()
  // CHECK: "testvar.opt_operand"(%{{.*}}, %{{.*}}) : (i16, i64) -> ()
  "testvar.opt_operand"(%x, %y, %z) : (i16, i32, i64) -> ()
  // CHECK-NEXT: "testvar.opt_operand"(%{{.*}}, %{{.*}}, %{{.*}}) : (i16, i32, i64) -> ()
  return
}

// -----

// Check that the verifier of an optional operand fails if the variadic is
// given a wrong type.
func.func @testOptOperandFail(%x: i16, %y: i64, %z: i64) {
  // expected-error@+1 {{expected 'i32' but got 'i64'}}
  "testvar.opt_operand"(%x, %y, %z) : (i16, i64, i64) -> ()
  return
}

// -----

// Check that the verifier of an optional operand fails if there are too
// many operands.
func.func @testOptOperandFail(%x: i16, %y: i32, %z: i64) {
  // expected-error@+1 {{op expects at most 3 operands, but got 4}}
  "testvar.opt_operand"(%x, %y, %y, %z) : (i16, i32, i32, i64) -> ()
  return
}

// -----

// Check that the verifier of an optional operand fails if there are not
// enough operands.
func.func @testOptOperandFail(%x: i16) {
  // expected-error@+1 {{op expects at least 2 operands, but got 1}}
  "testvar.opt_operand"(%x) : (i16) -> ()
  return
}

// -----

//===----------------------------------------------------------------------===//
// Multiple variadic
//===----------------------------------------------------------------------===//

// Check that an operation with multiple variadics expects the segment size
// attribute
func.func @testMultOperandsMissingSegment(%x: i16, %z: i64) {
  // expected-error@+1 {{'operand_segment_sizes' attribute is expected but not provided}}
  "testvar.var_and_opt_operand"(%x, %x, %z) : (i16, i16, i64) -> ()
  return
}

// -----

// Check that an operation with multiple variadics expects the segment size
// attribute of the right type
func.func @testMultOperandsWrongSegmentType(%x: i16, %z: i64) {
  // expected-error@+1 {{'operand_segment_sizes' attribute is expected to be a dense i32 array}}
  "testvar.var_and_opt_operand"(%x, %x, %z) {operand_segment_sizes = i32} : (i16, i16, i64) -> ()
  return
}

// -----

// Check that an operation with multiple variadics with the right segment size
// verifies.
func.func @testMultOperands(%x: i16, %y: i32, %z: i64) {
  "testvar.var_and_opt_operand"(%x, %x, %z) {operand_segment_sizes = array<i32: 2, 0, 1>} : (i16, i16, i64) -> ()
  // CHECK: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}, %{{.*}}) {operand_segment_sizes = array<i32: 2, 0, 1>} : (i16, i16, i64) -> ()
  "testvar.var_and_opt_operand"(%x, %x, %y, %z) {operand_segment_sizes = array<i32: 2, 1, 1>} : (i16, i16, i32, i64) -> ()
  // CHECK-NEXT: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {operand_segment_sizes = array<i32: 2, 1, 1>} : (i16, i16, i32, i64) -> ()
  "testvar.var_and_opt_operand"(%y, %z) {operand_segment_sizes = array<i32: 0, 1, 1>} : (i32, i64) -> ()
  // CHECK-NEXT: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}) {operand_segment_sizes = array<i32: 0, 1, 1>} : (i32, i64) -> ()
  return
}

// -----

// Check that the segment sizes expects non-negative values
func.func @testMultOperandsSegmentNegative() {
  // expected-error@+1 {{'operand_segment_sizes' attribute for specifying operand segments must have non-negative values}}
  "testvar.var_and_opt_operand"() {operand_segment_sizes = array<i32: 2, -1, 1>} : () -> ()
  return
}

// -----

// Check that the segment sizes expects 1 for single values
func.func @testMultOperandsSegmentWrongSingle() {
  // expected-error@+1 {{element 2 in 'operand_segment_sizes' attribute must be equal to 1}}
  "testvar.var_and_opt_operand"() {operand_segment_sizes = array<i32: 0, 0, 0>} : () -> ()
  return
}

// -----

// Check that the segment sizes expects not more than 1 for optional values
func.func @testMultOperandsSegmentWrongOptional() {
  // expected-error@+1 {{element 1 in 'operand_segment_sizes' attribute must be equal to 0 or 1}}
  "testvar.var_and_opt_operand"() {operand_segment_sizes = array<i32: 0, 2, 0>} : () -> ()
  return
}

// -----

// Check that the sum of the segment sizes should be equal to the number of operands
func.func @testMultOperandsSegmentWrongOptional(%y: i32, %z: i64) {
  // expected-error@+1 {{sum of elements in 'operand_segment_sizes' attribute must be equal to the number of operands}}
  "testvar.var_and_opt_operand"(%y, %z) {operand_segment_sizes = array<i32: 0, 0, 1>} : (i32, i64) -> ()
  return
}

// -----

//===----------------------------------------------------------------------===//
// Single result
//===----------------------------------------------------------------------===//

// Test an operation with a single result.
func.func @testSingleResult() {
  %x = "testvar.single_result"() : () -> i32
  // CHECK: %{{.*}} = "testvar.single_result"() : () -> i32
  return
}

// -----

// Test an operation with a single result definition and a wrong number of results.
func.func @testSingleResultFail() {
  // expected-error@+1 {{op expects exactly 1 results, but got 2}}
  %x, %y = "testvar.single_result"() : () -> (i32, i32)  
  return
}

// -----

// Test an operation with a single result definition and a wrong number of results.
func.func @testSingleResultFail() {
  // expected-error@+1 {{op expects exactly 1 results, but got 0}}
  "testvar.single_result"() : () -> ()  
  return
}

// -----


//===----------------------------------------------------------------------===//
// Variadic result
//===----------------------------------------------------------------------===//


// Test an operation with a single variadic result.
func.func @testVarResult() {
  "testvar.var_result"() : () -> (i16, i64)
  // CHECK: "testvar.var_result"() : () -> (i16, i64)
  "testvar.var_result"() : () -> (i16, i32, i64)
  // CHECK-NEXT: "testvar.var_result"() : () -> (i16, i32, i64)
  "testvar.var_result"() : () -> (i16, i32, i32, i64)
  // CHECK-NEXT: "testvar.var_result"() : () -> (i16, i32, i32, i64)
  "testvar.var_result"() : () -> (i16, i32, i32, i32, i64)
  // CHECK-NEXT: "testvar.var_result"() : () -> (i16, i32, i32, i32, i64)
  return
}

// -----

// Check that the verifier of a variadic result  fails if the variadic is given
// a wrong type.
func.func @testVarResultFail() {
  // expected-error@+1 {{expected 'i32' but got 'i64'}}
  "testvar.var_result"() : () -> (i16, i64, i64)
  return
}

// -----

// Check that the verifier of a variadic result fails if the variadic is given
// a wrong type on the second value.
func.func @testVarResultFail() {
  // expected-error@+1 {{expected 'i32' but got 'i64'}}
  "testvar.var_result"() : () -> (i16, i32, i64, i64)
  return
}

// -----

// Check that if we do not give enough results, the verifier fails.
func.func @testVarResultFail() {
  // expected-error@+1 {{op expects at least 2 results, but got 0}}
  "testvar.var_result"() : () -> ()
  return
}

// -----

//===----------------------------------------------------------------------===//
// Optional result
//===----------------------------------------------------------------------===//


// Test an operation with a single optional result.
func.func @testOptResult() {
  "testvar.opt_result"() : () -> (i16, i64)
  // CHECK: "testvar.opt_result"() : () -> (i16, i64)
  "testvar.opt_result"() : () -> (i16, i32, i64)
  // CHECK-NEXT: "testvar.opt_result"() : () -> (i16, i32, i64)
  return
}

// -----

// Check that the verifier of an optional result fails if the variadic is
// given a wrong type.
func.func @testOptResultFail() {
  // expected-error@+1 {{expected 'i32' but got 'i64'}}
  "testvar.opt_result"() : () -> (i16, i64, i64)
  return
}

// -----

// Check that the verifier of an optional result fails if there are too
// many results.
func.func @testOptResultFail() {
  // expected-error@+1 {{op expects at most 3 results, but got 4}}
  "testvar.opt_result"() : () -> (i16, i32, i32, i64)
  return
}

// -----

// Check that the verifier of an optional result fails if there are not
// enough results.
func.func @testOptResultFail() {
  // expected-error@+1 {{op expects at least 2 results, but got 1}}
  "testvar.opt_result"() : () -> (i16)
  return
}

// -----

//===----------------------------------------------------------------------===//
// Multiple variadic
//===----------------------------------------------------------------------===//

// Check that an operation with multiple variadics expects the segment size
// attribute
func.func @testMultResultsMissingSegment() {
  // expected-error@+1 {{'result_segment_sizes' attribute is expected but not provided}}
  "testvar.var_and_opt_result"() : () -> (i16, i16, i64)
  return
}

// -----

// Check that an operation with multiple variadics expects the segment size
// attribute of the right type
func.func @testMultResultsWrongSegmentType() {
  // expected-error@+1 {{'result_segment_sizes' attribute is expected to be a dense i32 array}}
  "testvar.var_and_opt_result"() {result_segment_sizes = i32} : () -> (i16, i16, i64)
  return
}

// -----

// Check that an operation with multiple variadics with the right segment size
// verifies.
func.func @testMultResults() {
  "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 2, 0, 1>} : () -> (i16, i16, i64)
  // CHECK: "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 2, 0, 1>} : () -> (i16, i16, i64)
  "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 2, 1, 1>} : () -> (i16, i16, i32, i64)
  // CHECK-NEXT: "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 2, 1, 1>} : () -> (i16, i16, i32, i64)
  "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 0, 1, 1>} : () -> (i32, i64)
  // CHECK-NEXT: "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 0, 1, 1>} : () -> (i32, i64)
  return
}

// -----

// Check that the segment sizes expects non-negative values
func.func @testMultResultsSegmentNegative() {
  // expected-error@+1 {{'result_segment_sizes' attribute for specifying result segments must have non-negative values}}
  "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 2, -1, 1>} : () -> ()
  return
}

// -----

// Check that the segment sizes expects 1 for single values
func.func @testMultResultsSegmentWrongSingle() {
  // expected-error@+1 {{element 2 in 'result_segment_sizes' attribute must be equal to 1}}
  "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 0, 0, 0>} : () -> ()
  return
}

// -----

// Check that the segment sizes expects not more than 1 for optional values
func.func @testMultResultsSegmentWrongOptional() {
  // expected-error@+1 {{element 1 in 'result_segment_sizes' attribute must be equal to 0 or 1}}
  "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 0, 2, 0>} : () -> ()
  return
}

// -----

// Check that the sum of the segment sizes should be equal to the number of results
func.func @testMultResultsSegmentWrongOptional() {
  // expected-error@+1 {{sum of elements in 'result_segment_sizes' attribute must be equal to the number of results}}
  "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 0, 0, 1>} : () -> (i32, i64)
  return
}