brintos

brintos / llvm-project-archived public Read only

0
0
Text · 13.8 KiB · 873f248 Raw
401 lines · plain
1// RUN: mlir-opt %s --irdl-file=%S/variadics.irdl.mlir -split-input-file -verify-diagnostics | FileCheck %s2 3//===----------------------------------------------------------------------===//4// Single operand5//===----------------------------------------------------------------------===//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  return12}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  return21}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  return30}31 32// -----33 34 35//===----------------------------------------------------------------------===//36// Variadic operand37//===----------------------------------------------------------------------===//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  return50}51 52// -----53 54// Check that the verifier of a variadic operand  fails if the variadic is given55// 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  return60}61 62// -----63 64// Check that the verifier of a variadic operand fails if the variadic is given65// 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  return70}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  return79}80 81// -----82 83//===----------------------------------------------------------------------===//84// Optional operand85//===----------------------------------------------------------------------===//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  return95}96 97// -----98 99// Check that the verifier of an optional operand fails if the variadic is100// 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  return105}106 107// -----108 109// Check that the verifier of an optional operand fails if there are too110// 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  return115}116 117// -----118 119// Check that the verifier of an optional operand fails if there are not120// 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  return125}126 127// -----128 129//===----------------------------------------------------------------------===//130// Multiple variadic131//===----------------------------------------------------------------------===//132 133// Check that an operation with multiple variadics expects the segment size134// attribute135func.func @testMultOperandsMissingSegment(%x: i16, %z: i64) {136  // expected-error@+1 {{'operandSegmentSizes' attribute is expected but not provided}}137  "testvar.var_and_opt_operand"(%x, %x, %z) : (i16, i16, i64) -> ()138  return139}140 141// -----142 143// Check that an operation with multiple variadics expects the segment size144// attribute of the right type145func.func @testMultOperandsWrongSegmentType(%x: i16, %z: i64) {146  // expected-error@+1 {{'operandSegmentSizes' attribute is expected to be a dense i32 array}}147  "testvar.var_and_opt_operand"(%x, %x, %z) {operandSegmentSizes = i32} : (i16, i16, i64) -> ()148  return149}150 151// -----152 153// Check that an operation with multiple variadics with the right segment size154// verifies.155func.func @testMultOperands(%x: i16, %y: i32, %z: i64) {156  "testvar.var_and_opt_operand"(%x, %x, %z) {operandSegmentSizes = array<i32: 2, 0, 1>} : (i16, i16, i64) -> ()157  // CHECK: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}, %{{.*}}) {operandSegmentSizes = array<i32: 2, 0, 1>} : (i16, i16, i64) -> ()158  "testvar.var_and_opt_operand"(%x, %x, %y, %z) {operandSegmentSizes = array<i32: 2, 1, 1>} : (i16, i16, i32, i64) -> ()159  // CHECK-NEXT: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {operandSegmentSizes = array<i32: 2, 1, 1>} : (i16, i16, i32, i64) -> ()160  "testvar.var_and_opt_operand"(%y, %z) {operandSegmentSizes = array<i32: 0, 1, 1>} : (i32, i64) -> ()161  // CHECK-NEXT: "testvar.var_and_opt_operand"(%{{.*}}, %{{.*}}) {operandSegmentSizes = array<i32: 0, 1, 1>} : (i32, i64) -> ()162  return163}164 165// -----166 167// Check that the segment sizes expects non-negative values168func.func @testMultOperandsSegmentNegative() {169  // expected-error@+1 {{'operandSegmentSizes' attribute for specifying operand segments must have non-negative values}}170  "testvar.var_and_opt_operand"() {operandSegmentSizes = array<i32: 2, -1, 1>} : () -> ()171  return172}173 174// -----175 176// Check that the segment sizes expects 1 for single values177func.func @testMultOperandsSegmentWrongSingle() {178  // expected-error@+1 {{element 2 in 'operandSegmentSizes' attribute must be equal to 1}}179  "testvar.var_and_opt_operand"() {operandSegmentSizes = array<i32: 0, 0, 0>} : () -> ()180  return181}182 183// -----184 185// Check that the segment sizes expects not more than 1 for optional values186func.func @testMultOperandsSegmentWrongOptional() {187  // expected-error@+1 {{element 1 in 'operandSegmentSizes' attribute must be equal to 0 or 1}}188  "testvar.var_and_opt_operand"() {operandSegmentSizes = array<i32: 0, 2, 0>} : () -> ()189  return190}191 192// -----193 194// Check that the sum of the segment sizes should be equal to the number of operands195func.func @testMultOperandsSegmentWrongOptional(%y: i32, %z: i64) {196  // expected-error@+1 {{sum of elements in 'operandSegmentSizes' attribute must be equal to the number of operands}}197  "testvar.var_and_opt_operand"(%y, %z) {operandSegmentSizes = array<i32: 0, 0, 1>} : (i32, i64) -> ()198  return199}200 201// -----202 203//===----------------------------------------------------------------------===//204// Single result205//===----------------------------------------------------------------------===//206 207// Test an operation with a single result.208func.func @testSingleResult() {209  %x = "testvar.single_result"() : () -> i32210  // CHECK: %{{.*}} = "testvar.single_result"() : () -> i32211  return212}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  return221}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  return230}231 232// -----233 234 235//===----------------------------------------------------------------------===//236// Variadic result237//===----------------------------------------------------------------------===//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  return251}252 253// -----254 255// Check that the verifier of a variadic result  fails if the variadic is given256// a wrong type.257func.func @testVarResultFail() {258  // expected-error@+1 {{expected 'i32' but got 'i64'}}259  "testvar.var_result"() : () -> (i16, i64, i64)260  return261}262 263// -----264 265// Check that the verifier of a variadic result fails if the variadic is given266// 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  return271}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  return280}281 282// -----283 284//===----------------------------------------------------------------------===//285// Optional result286//===----------------------------------------------------------------------===//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  return296}297 298// -----299 300// Check that the verifier of an optional result fails if the variadic is301// given a wrong type.302func.func @testOptResultFail() {303  // expected-error@+1 {{expected 'i32' but got 'i64'}}304  "testvar.opt_result"() : () -> (i16, i64, i64)305  return306}307 308// -----309 310// Check that the verifier of an optional result fails if there are too311// 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  return316}317 318// -----319 320// Check that the verifier of an optional result fails if there are not321// enough results.322func.func @testOptResultFail() {323  // expected-error@+1 {{op expects at least 2 results, but got 1}}324  "testvar.opt_result"() : () -> (i16)325  return326}327 328// -----329 330//===----------------------------------------------------------------------===//331// Multiple variadic332//===----------------------------------------------------------------------===//333 334// Check that an operation with multiple variadics expects the segment size335// attribute336func.func @testMultResultsMissingSegment() {337  // expected-error@+1 {{'resultSegmentSizes' attribute is expected but not provided}}338  "testvar.var_and_opt_result"() : () -> (i16, i16, i64)339  return340}341 342// -----343 344// Check that an operation with multiple variadics expects the segment size345// attribute of the right type346func.func @testMultResultsWrongSegmentType() {347  // expected-error@+1 {{'resultSegmentSizes' attribute is expected to be a dense i32 array}}348  "testvar.var_and_opt_result"() {resultSegmentSizes = i32} : () -> (i16, i16, i64)349  return350}351 352// -----353 354// Check that an operation with multiple variadics with the right segment size355// verifies.356func.func @testMultResults() {357  "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, 0, 1>} : () -> (i16, i16, i64)358  // CHECK: "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, 0, 1>} : () -> (i16, i16, i64)359  "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, 1, 1>} : () -> (i16, i16, i32, i64)360  // CHECK-NEXT: "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, 1, 1>} : () -> (i16, i16, i32, i64)361  "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 0, 1, 1>} : () -> (i32, i64)362  // CHECK-NEXT: "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 0, 1, 1>} : () -> (i32, i64)363  return364}365 366// -----367 368// Check that the segment sizes expects non-negative values369func.func @testMultResultsSegmentNegative() {370  // expected-error@+1 {{'resultSegmentSizes' attribute for specifying result segments must have non-negative values}}371  "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 2, -1, 1>} : () -> ()372  return373}374 375// -----376 377// Check that the segment sizes expects 1 for single values378func.func @testMultResultsSegmentWrongSingle() {379  // expected-error@+1 {{element 2 in 'resultSegmentSizes' attribute must be equal to 1}}380  "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 0, 0, 0>} : () -> ()381  return382}383 384// -----385 386// Check that the segment sizes expects not more than 1 for optional values387func.func @testMultResultsSegmentWrongOptional() {388  // expected-error@+1 {{element 1 in 'resultSegmentSizes' attribute must be equal to 0 or 1}}389  "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 0, 2, 0>} : () -> ()390  return391}392 393// -----394 395// Check that the sum of the segment sizes should be equal to the number of results396func.func @testMultResultsSegmentWrongOptional() {397  // expected-error@+1 {{sum of elements in 'resultSegmentSizes' attribute must be equal to the number of results}}398  "testvar.var_and_opt_result"() {resultSegmentSizes = array<i32: 0, 0, 1>} : () -> (i32, i64)399  return400}401