1// RUN: mlir-opt %s --irdl-file=%S/variadics.irdl.mlir -split-input-file -verify-diagnostics | FileCheck %s 2 3//===----------------------------------------------------------------------===// 4// Single operand 5//===----------------------------------------------------------------------===// 6 7// Test an operation with a single operand. 8func.func @testSingleOperand(%x: i32) { 9 "testvar.single_operand"(%x) : (i32) -> () 10 // CHECK: "testvar.single_operand"(%{{.*}}) : (i32) -> () 11 return 12} 13 14// ----- 15 16// Test an operation with a single operand definition and a wrong number of operands. 17func.func @testSingleOperandFail(%x: i32) { 18 // expected-error@+1 {{op expects exactly 1 operands, but got 2}} 19 "testvar.single_operand"(%x, %x) : (i32, i32) -> () 20 return 21} 22 23// ----- 24 25// Test an operation with a single operand definition and a wrong number of operands. 26func.func @testSingleOperandFail() { 27 // expected-error@+1 {{op expects exactly 1 operands, but got 0}} 28 "testvar.single_operand"() : () -> () 29 return 30} 31 32// ----- 33 34 35//===----------------------------------------------------------------------===// 36// Variadic operand 37//===----------------------------------------------------------------------===// 38 39// Test an operation with a single variadic operand. 40func.func @testVarOperand(%x: i16, %y: i32, %z: i64) { 41 "testvar.var_operand"(%x, %z) : (i16, i64) -> () 42 // CHECK: "testvar.var_operand"(%{{.*}}, %{{.*}}) : (i16, i64) -> () 43 "testvar.var_operand"(%x, %y, %z) : (i16, i32, i64) -> () 44 // CHECK-NEXT: "testvar.var_operand"(%{{.*}}, %{{.*}}, %{{.*}}) : (i16, i32, i64) -> () 45 "testvar.var_operand"(%x, %y, %y, %z) : (i16, i32, i32, i64) -> () 46 // CHECK-NEXT: "testvar.var_operand"(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) : (i16, i32, i32, i64) -> () 47 "testvar.var_operand"(%x, %y, %y, %y, %z) : (i16, i32, i32, i32, i64) -> () 48 // CHECK-NEXT: "testvar.var_operand"(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) : (i16, i32, i32, i32, i64) -> () 49 return 50} 51 52// ----- 53 54// Check that the verifier of a variadic operand fails if the variadic is given 55// a wrong type. 56func.func @testVarOperandFail(%x: i16, %y: i64, %z: i64) { 57 // expected-error@+1 {{expected 'i32' but got 'i64'}} 58 "testvar.var_operand"(%x, %y, %z) : (i16, i64, i64) -> () 59 return 60} 61 62// ----- 63 64// Check that the verifier of a variadic operand fails if the variadic is given 65// a wrong type on the second value. 66func.func @testVarOperandFail(%x: i16, %y1: i32, %y2: i64, %z: i64) { 67 // expected-error@+1 {{expected 'i32' but got 'i64'}} 68 "testvar.var_operand"(%x, %y1, %y2, %z) : (i16, i32, i64, i64) -> () 69 return 70} 71 72// ----- 73 74// Check that if we do not give enough operands, the verifier fails. 75func.func @testVarOperandFail() { 76 // expected-error@+1 {{op expects at least 2 operands, but got 0}} 77 "testvar.var_operand"() : () -> () 78 return 79} 80 81// ----- 82 83//===----------------------------------------------------------------------===// 84// Optional operand 85//===----------------------------------------------------------------------===// 86 87 88// Test an operation with a single optional operand. 89func.func @testOptOperand(%x: i16, %y: i32, %z: i64) { 90 "testvar.opt_operand"(%x, %z) : (i16, i64) -> () 91 // CHECK: "testvar.opt_operand"(%{{.*}}, %{{.*}}) : (i16, i64) -> () 92 "testvar.opt_operand"(%x, %y, %z) : (i16, i32, i64) -> () 93 // CHECK-NEXT: "testvar.opt_operand"(%{{.*}}, %{{.*}}, %{{.*}}) : (i16, i32, i64) -> () 94 return 95} 96 97// ----- 98 99// Check that the verifier of an optional operand fails if the variadic is 100// given a wrong type. 101func.func @testOptOperandFail(%x: i16, %y: i64, %z: i64) { 102 // expected-error@+1 {{expected 'i32' but got 'i64'}} 103 "testvar.opt_operand"(%x, %y, %z) : (i16, i64, i64) -> () 104 return 105} 106 107// ----- 108 109// Check that the verifier of an optional operand fails if there are too 110// many operands. 111func.func @testOptOperandFail(%x: i16, %y: i32, %z: i64) { 112 // expected-error@+1 {{op expects at most 3 operands, but got 4}} 113 "testvar.opt_operand"(%x, %y, %y, %z) : (i16, i32, i32, i64) -> () 114 return 115} 116 117// ----- 118 119// Check that the verifier of an optional operand fails if there are not 120// enough operands. 121func.func @testOptOperandFail(%x: i16) { 122 // expected-error@+1 {{op expects at least 2 operands, but got 1}} 123 "testvar.opt_operand"(%x) : (i16) -> () 124 return 125} 126 127// ----- 128 129//===----------------------------------------------------------------------===// 130// Multiple variadic 131//===----------------------------------------------------------------------===// 132 133// Check that an operation with multiple variadics expects the segment size 134// attribute 135func.func @testMultOperandsMissingSegment(%x: i16, %z: i64) { 136 // expected-error@+1 {{'operand_segment_sizes' attribute is expected but not provided}} 137 "testvar.var_and_opt_operand"(%x, %x, %z) : (i16, i16, i64) -> () 138 return 139} 140 141// ----- 142 143// Check that an operation with multiple variadics expects the segment size 144// attribute of the right type 145func.func @testMultOperandsWrongSegmentType(%x: i16, %z: i64) { 146 // expected-error@+1 {{'operand_segment_sizes' attribute is expected to be a dense i32 array}} 147 "testvar.var_and_opt_operand"(%x, %x, %z) {operand_segment_sizes = i32} : (i16, i16, i64) -> () 148 return 149} 150 151// ----- 152 153// Check that an operation with multiple variadics with the right segment size 154// verifies. 155func.func @testMultOperands(%x: i16, %y: i32, %z: i64) { 156 "testvar.var_and_opt_operand"(%x, %x, %z) {operand_segment_sizes = array<i32: 2, 0, 1>} : (i16, i16, i64) -> () 157 // CHECK: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}, %{{.*}}) {operand_segment_sizes = array<i32: 2, 0, 1>} : (i16, i16, i64) -> () 158 "testvar.var_and_opt_operand"(%x, %x, %y, %z) {operand_segment_sizes = array<i32: 2, 1, 1>} : (i16, i16, i32, i64) -> () 159 // CHECK-NEXT: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {operand_segment_sizes = array<i32: 2, 1, 1>} : (i16, i16, i32, i64) -> () 160 "testvar.var_and_opt_operand"(%y, %z) {operand_segment_sizes = array<i32: 0, 1, 1>} : (i32, i64) -> () 161 // CHECK-NEXT: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}) {operand_segment_sizes = array<i32: 0, 1, 1>} : (i32, i64) -> () 162 return 163} 164 165// ----- 166 167// Check that the segment sizes expects non-negative values 168func.func @testMultOperandsSegmentNegative() { 169 // expected-error@+1 {{'operand_segment_sizes' attribute for specifying operand segments must have non-negative values}} 170 "testvar.var_and_opt_operand"() {operand_segment_sizes = array<i32: 2, -1, 1>} : () -> () 171 return 172} 173 174// ----- 175 176// Check that the segment sizes expects 1 for single values 177func.func @testMultOperandsSegmentWrongSingle() { 178 // expected-error@+1 {{element 2 in 'operand_segment_sizes' attribute must be equal to 1}} 179 "testvar.var_and_opt_operand"() {operand_segment_sizes = array<i32: 0, 0, 0>} : () -> () 180 return 181} 182 183// ----- 184 185// Check that the segment sizes expects not more than 1 for optional values 186func.func @testMultOperandsSegmentWrongOptional() { 187 // expected-error@+1 {{element 1 in 'operand_segment_sizes' attribute must be equal to 0 or 1}} 188 "testvar.var_and_opt_operand"() {operand_segment_sizes = array<i32: 0, 2, 0>} : () -> () 189 return 190} 191 192// ----- 193 194// Check that the sum of the segment sizes should be equal to the number of operands 195func.func @testMultOperandsSegmentWrongOptional(%y: i32, %z: i64) { 196 // expected-error@+1 {{sum of elements in 'operand_segment_sizes' attribute must be equal to the number of operands}} 197 "testvar.var_and_opt_operand"(%y, %z) {operand_segment_sizes = array<i32: 0, 0, 1>} : (i32, i64) -> () 198 return 199} 200 201// ----- 202 203//===----------------------------------------------------------------------===// 204// Single result 205//===----------------------------------------------------------------------===// 206 207// Test an operation with a single result. 208func.func @testSingleResult() { 209 %x = "testvar.single_result"() : () -> i32 210 // CHECK: %{{.*}} = "testvar.single_result"() : () -> i32 211 return 212} 213 214// ----- 215 216// Test an operation with a single result definition and a wrong number of results. 217func.func @testSingleResultFail() { 218 // expected-error@+1 {{op expects exactly 1 results, but got 2}} 219 %x, %y = "testvar.single_result"() : () -> (i32, i32) 220 return 221} 222 223// ----- 224 225// Test an operation with a single result definition and a wrong number of results. 226func.func @testSingleResultFail() { 227 // expected-error@+1 {{op expects exactly 1 results, but got 0}} 228 "testvar.single_result"() : () -> () 229 return 230} 231 232// ----- 233 234 235//===----------------------------------------------------------------------===// 236// Variadic result 237//===----------------------------------------------------------------------===// 238 239 240// Test an operation with a single variadic result. 241func.func @testVarResult() { 242 "testvar.var_result"() : () -> (i16, i64) 243 // CHECK: "testvar.var_result"() : () -> (i16, i64) 244 "testvar.var_result"() : () -> (i16, i32, i64) 245 // CHECK-NEXT: "testvar.var_result"() : () -> (i16, i32, i64) 246 "testvar.var_result"() : () -> (i16, i32, i32, i64) 247 // CHECK-NEXT: "testvar.var_result"() : () -> (i16, i32, i32, i64) 248 "testvar.var_result"() : () -> (i16, i32, i32, i32, i64) 249 // CHECK-NEXT: "testvar.var_result"() : () -> (i16, i32, i32, i32, i64) 250 return 251} 252 253// ----- 254 255// Check that the verifier of a variadic result fails if the variadic is given 256// a wrong type. 257func.func @testVarResultFail() { 258 // expected-error@+1 {{expected 'i32' but got 'i64'}} 259 "testvar.var_result"() : () -> (i16, i64, i64) 260 return 261} 262 263// ----- 264 265// Check that the verifier of a variadic result fails if the variadic is given 266// a wrong type on the second value. 267func.func @testVarResultFail() { 268 // expected-error@+1 {{expected 'i32' but got 'i64'}} 269 "testvar.var_result"() : () -> (i16, i32, i64, i64) 270 return 271} 272 273// ----- 274 275// Check that if we do not give enough results, the verifier fails. 276func.func @testVarResultFail() { 277 // expected-error@+1 {{op expects at least 2 results, but got 0}} 278 "testvar.var_result"() : () -> () 279 return 280} 281 282// ----- 283 284//===----------------------------------------------------------------------===// 285// Optional result 286//===----------------------------------------------------------------------===// 287 288 289// Test an operation with a single optional result. 290func.func @testOptResult() { 291 "testvar.opt_result"() : () -> (i16, i64) 292 // CHECK: "testvar.opt_result"() : () -> (i16, i64) 293 "testvar.opt_result"() : () -> (i16, i32, i64) 294 // CHECK-NEXT: "testvar.opt_result"() : () -> (i16, i32, i64) 295 return 296} 297 298// ----- 299 300// Check that the verifier of an optional result fails if the variadic is 301// given a wrong type. 302func.func @testOptResultFail() { 303 // expected-error@+1 {{expected 'i32' but got 'i64'}} 304 "testvar.opt_result"() : () -> (i16, i64, i64) 305 return 306} 307 308// ----- 309 310// Check that the verifier of an optional result fails if there are too 311// many results. 312func.func @testOptResultFail() { 313 // expected-error@+1 {{op expects at most 3 results, but got 4}} 314 "testvar.opt_result"() : () -> (i16, i32, i32, i64) 315 return 316} 317 318// ----- 319 320// Check that the verifier of an optional result fails if there are not 321// enough results. 322func.func @testOptResultFail() { 323 // expected-error@+1 {{op expects at least 2 results, but got 1}} 324 "testvar.opt_result"() : () -> (i16) 325 return 326} 327 328// ----- 329 330//===----------------------------------------------------------------------===// 331// Multiple variadic 332//===----------------------------------------------------------------------===// 333 334// Check that an operation with multiple variadics expects the segment size 335// attribute 336func.func @testMultResultsMissingSegment() { 337 // expected-error@+1 {{'result_segment_sizes' attribute is expected but not provided}} 338 "testvar.var_and_opt_result"() : () -> (i16, i16, i64) 339 return 340} 341 342// ----- 343 344// Check that an operation with multiple variadics expects the segment size 345// attribute of the right type 346func.func @testMultResultsWrongSegmentType() { 347 // expected-error@+1 {{'result_segment_sizes' attribute is expected to be a dense i32 array}} 348 "testvar.var_and_opt_result"() {result_segment_sizes = i32} : () -> (i16, i16, i64) 349 return 350} 351 352// ----- 353 354// Check that an operation with multiple variadics with the right segment size 355// verifies. 356func.func @testMultResults() { 357 "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 2, 0, 1>} : () -> (i16, i16, i64) 358 // CHECK: "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 2, 0, 1>} : () -> (i16, i16, i64) 359 "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 2, 1, 1>} : () -> (i16, i16, i32, i64) 360 // CHECK-NEXT: "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 2, 1, 1>} : () -> (i16, i16, i32, i64) 361 "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 0, 1, 1>} : () -> (i32, i64) 362 // CHECK-NEXT: "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 0, 1, 1>} : () -> (i32, i64) 363 return 364} 365 366// ----- 367 368// Check that the segment sizes expects non-negative values 369func.func @testMultResultsSegmentNegative() { 370 // expected-error@+1 {{'result_segment_sizes' attribute for specifying result segments must have non-negative values}} 371 "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 2, -1, 1>} : () -> () 372 return 373} 374 375// ----- 376 377// Check that the segment sizes expects 1 for single values 378func.func @testMultResultsSegmentWrongSingle() { 379 // expected-error@+1 {{element 2 in 'result_segment_sizes' attribute must be equal to 1}} 380 "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 0, 0, 0>} : () -> () 381 return 382} 383 384// ----- 385 386// Check that the segment sizes expects not more than 1 for optional values 387func.func @testMultResultsSegmentWrongOptional() { 388 // expected-error@+1 {{element 1 in 'result_segment_sizes' attribute must be equal to 0 or 1}} 389 "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 0, 2, 0>} : () -> () 390 return 391} 392 393// ----- 394 395// Check that the sum of the segment sizes should be equal to the number of results 396func.func @testMultResultsSegmentWrongOptional() { 397 // expected-error@+1 {{sum of elements in 'result_segment_sizes' attribute must be equal to the number of results}} 398 "testvar.var_and_opt_result"() {result_segment_sizes = array<i32: 0, 0, 1>} : () -> (i32, i64) 399 return 400} 401