1// RUN: mlir-opt %s -split-input-file -allow-unregistered-dialect -verify-diagnostics | FileCheck %s 2 3//===----------------------------------------------------------------------===// 4// Test AnyAttrOf attributes 5//===----------------------------------------------------------------------===// 6 7func.func @any_attr_of_pass() { 8 "test.any_attr_of_i32_str"() { 9 // CHECK: attr = 3 : i32 10 attr = 3 : i32 11 } : () -> () 12 13 "test.any_attr_of_i32_str"() { 14 // CHECK: attr = "string_data" 15 attr = "string_data" 16 } : () -> () 17 18 return 19} 20 21// ----- 22 23func.func @any_attr_of_fail() { 24 // expected-error @+1 {{'test.any_attr_of_i32_str' op attribute 'attr' failed to satisfy constraint: 32-bit signless integer attribute or string attribute}} 25 "test.any_attr_of_i32_str"() { 26 attr = 3 : i64 27 } : () -> () 28 29 return 30} 31 32// ----- 33 34//===----------------------------------------------------------------------===// 35// Test float attributes 36//===----------------------------------------------------------------------===// 37 38func.func @float_attrs_pass() { 39 "test.float_attrs"() { 40 // CHECK: float_attr = 2.000000e+00 : f4E2M1FN 41 float_attr = 2. : f4E2M1FN 42 } : () -> () 43 "test.float_attrs"() { 44 // CHECK: float_attr = 2.000000e+00 : f6E2M3FN 45 float_attr = 2. : f6E2M3FN 46 } : () -> () 47 "test.float_attrs"() { 48 // CHECK: float_attr = 2.000000e+00 : f6E3M2FN 49 float_attr = 2. : f6E3M2FN 50 } : () -> () 51 "test.float_attrs"() { 52 // CHECK: float_attr = 2.000000e+00 : f8E5M2 53 float_attr = 2. : f8E5M2 54 } : () -> () 55 "test.float_attrs"() { 56 // CHECK: float_attr = 2.000000e+00 : f8E4M3 57 float_attr = 2. : f8E4M3 58 } : () -> () 59 "test.float_attrs"() { 60 // CHECK: float_attr = 2.000000e+00 : f8E4M3FN 61 float_attr = 2. : f8E4M3FN 62 } : () -> () 63 "test.float_attrs"() { 64 // CHECK: float_attr = 2.000000e+00 : f8E5M2FNUZ 65 float_attr = 2. : f8E5M2FNUZ 66 } : () -> () 67 "test.float_attrs"() { 68 // CHECK: float_attr = 2.000000e+00 : f8E4M3FNUZ 69 float_attr = 2. : f8E4M3FNUZ 70 } : () -> () 71 "test.float_attrs"() { 72 // CHECK: float_attr = 2.000000e+00 : f8E4M3B11FNUZ 73 float_attr = 2. : f8E4M3B11FNUZ 74 } : () -> () 75 "test.float_attrs"() { 76 // CHECK: float_attr = 2.000000e+00 : f8E3M4 77 float_attr = 2. : f8E3M4 78 } : () -> () 79 "test.float_attrs"() { 80 // CHECK: float_attr = 2.000000e+00 : f8E8M0FNU 81 float_attr = 2. : f8E8M0FNU 82 } : () -> () 83 "test.float_attrs"() { 84 // CHECK: float_attr = 2.000000e+00 : f16 85 float_attr = 2. : f16 86 } : () -> () 87 "test.float_attrs"() { 88 // CHECK: float_attr = 2.000000e+00 : bf16 89 float_attr = 2. : bf16 90 } : () -> () 91 "test.float_attrs"() { 92 // CHECK: float_attr = 2.000000e+00 : tf32 93 float_attr = 2. : tf32 94 } : () -> () 95 "test.float_attrs"() { 96 // CHECK: float_attr = 2.000000e+00 : f32 97 float_attr = 2. : f32 98 } : () -> () 99 "test.float_attrs"() { 100 // CHECK: float_attr = 2.000000e+00 : f64 101 float_attr = 2. : f64 102 } : () -> () 103 "test.float_attrs"() { 104 // CHECK: float_attr = 2.000000e+00 : f80 105 float_attr = 2. : f80 106 } : () -> () 107 "test.float_attrs"() { 108 // CHECK: float_attr = 2.000000e+00 : f128 109 float_attr = 2. : f128 110 } : () -> () 111 return 112} 113 114//===----------------------------------------------------------------------===// 115// Test integer attributes 116//===----------------------------------------------------------------------===// 117 118func.func @int_attrs_pass() { 119 "test.int_attrs"() { 120 // CHECK: any_i32_attr = 5 : ui32 121 any_i32_attr = 5 : ui32, 122 // CHECK-SAME: index_attr = 8 : index 123 index_attr = 8 : index, 124 // CHECK-SAME: si32_attr = 7 : si32 125 si32_attr = 7 : si32, 126 // CHECK-SAME: ui32_attr = 6 : ui32 127 ui32_attr = 6 : ui32 128 } : () -> () 129 130 "test.int_attrs"() { 131 // CHECK: any_i32_attr = 5 : si32 132 any_i32_attr = 5 : si32, 133 index_attr = 8 : index, 134 si32_attr = 7 : si32, 135 ui32_attr = 6 : ui32 136 } : () -> () 137 138 "test.int_attrs"() { 139 // CHECK: any_i32_attr = 5 : i32 140 any_i32_attr = 5 : i32, 141 index_attr = 8 : index, 142 si32_attr = 7 : si32, 143 ui32_attr = 6 : ui32 144 } : () -> () 145 146 return 147} 148 149// ----- 150 151//===----------------------------------------------------------------------===// 152// Check that the maximum and minimum integer attribute values are 153// representable and preserved during a round-trip. 154//===----------------------------------------------------------------------===// 155 156func.func @int_attrs_pass() { 157 "test.in_range_attrs"() { 158 // CHECK: attr_00 = -128 : i8 159 attr_00 = -128 : i8, 160 // CHECK-SAME: attr_01 = 127 : i8 161 attr_01 = 127 : i8, 162 // CHECK-SAME: attr_02 = -128 : si8 163 attr_02 = -128 : si8, 164 // CHECK-SAME: attr_03 = 127 : si8 165 attr_03 = 127 : si8, 166 // CHECK-SAME: attr_04 = 255 : ui8 167 attr_04 = 255 : ui8, 168 // CHECK-SAME: attr_05 = -32768 : i16 169 attr_05 = -32768 : i16, 170 // CHECK-SAME: attr_06 = 32767 : i16 171 attr_06 = 32767 : i16, 172 // CHECK-SAME: attr_07 = -32768 : si16 173 attr_07 = -32768 : si16, 174 // CHECK-SAME: attr_08 = 32767 : si16 175 attr_08 = 32767 : si16, 176 // CHECK-SAME: attr_09 = 65535 : ui16 177 attr_09 = 65535 : ui16, 178 // CHECK-SAME: attr_10 = -2147483647 : i32 179 attr_10 = -2147483647 : i32, 180 // CHECK-SAME: attr_11 = 2147483646 : i32 181 attr_11 = 2147483646 : i32, 182 // CHECK-SAME: attr_12 = -2147483647 : si32 183 attr_12 = -2147483647 : si32, 184 // CHECK-SAME: attr_13 = 2147483646 : si32 185 attr_13 = 2147483646 : si32, 186 // CHECK-SAME: attr_14 = 4294967295 : ui32 187 attr_14 = 4294967295 : ui32, 188 // CHECK-SAME: attr_15 = -9223372036854775808 : i64 189 attr_15 = -9223372036854775808 : i64, 190 // CHECK-SAME: attr_16 = 9223372036854775807 : i64 191 attr_16 = 9223372036854775807 : i64, 192 // CHECK-SAME: attr_17 = -9223372036854775808 : si64 193 attr_17 = -9223372036854775808 : si64, 194 // CHECK-SAME: attr_18 = 9223372036854775807 : si64 195 attr_18 = 9223372036854775807 : si64, 196 // CHECK-SAME: attr_19 = 18446744073709551615 : ui64 197 attr_19 = 18446744073709551615 : ui64, 198 // CHECK-SAME: attr_20 = 1 : ui1 199 attr_20 = 1 : ui1, 200 // CHECK-SAME: attr_21 = -1 : si1 201 attr_21 = -1 : si1, 202 // CHECK-SAME: attr_22 = 79228162514264337593543950335 : ui96 203 attr_22 = 79228162514264337593543950335 : ui96, 204 // CHECK-SAME: attr_23 = -39614081257132168796771975168 : si96 205 attr_23 = -39614081257132168796771975168 : si96 206 } : () -> () 207 208 return 209} 210 211// ----- 212 213//===----------------------------------------------------------------------===// 214// Check that positive values larger than 2^n-1 for signless integers 215// are mapped to their negative signed counterpart. This behaviour is 216// undocumented in the language specification, but it is what the 217// parser currently does. 218//===----------------------------------------------------------------------===// 219 220func.func @int_attrs_pass() { 221 "test.i8_attr"() { 222 // CHECK: attr_00 = -1 : i8 223 attr_00 = 255 : i8, 224 // CHECK-SAME: attr_01 = -1 : i16 225 attr_01 = 65535 : i16, 226 // CHECK-SAME: attr_02 = -1 : i32 227 attr_02 = 4294967295 : i32, 228 // CHECK-SAME: attr_03 = -1 : i64 229 attr_03 = 18446744073709551615 : i64 230 } : () -> () 231 return 232} 233 234// ----- 235 236//===----------------------------------------------------------------------===// 237// Check that i0 is parsed and verified correctly. It can only have value 0. 238// We check it explicitly because there are various special cases for it that 239// are good to verify. 240//===----------------------------------------------------------------------===// 241 242func.func @int0_attrs_pass() { 243 "test.i0_attr"() { 244 // CHECK: attr_00 = 0 : i0 245 attr_00 = 0 : i0, 246 // CHECK: attr_01 = 0 : si0 247 attr_01 = 0 : si0, 248 // CHECK: attr_02 = 0 : ui0 249 attr_02 = 0 : ui0, 250 // CHECK: attr_03 = 0 : i0 251 attr_03 = 0x0000 : i0, 252 // CHECK: attr_04 = 0 : si0 253 attr_04 = 0x0000 : si0, 254 // CHECK: attr_05 = 0 : ui0 255 attr_05 = 0x0000 : ui0 256 } : () -> () 257 return 258} 259 260// ----- 261 262func.func @int0_attrs_negative_fail() { 263 "test.i0_attr"() { 264 // expected-error @+1 {{integer constant out of range for attribute}} 265 attr_00 = -1 : i0 266 } : () -> () 267 return 268} 269 270// ----- 271 272func.func @int0_attrs_positive_fail() { 273 "test.i0_attr"() { 274 // expected-error @+1 {{integer constant out of range for attribute}} 275 attr_00 = 1 : i0 276 } : () -> () 277 return 278} 279 280// ----- 281 282func.func @wrong_int_attrs_signedness_fail() { 283 // expected-error @+1 {{'si32_attr' failed to satisfy constraint: 32-bit signed integer attribute}} 284 "test.int_attrs"() { 285 any_i32_attr = 5 : i32, 286 index_attr = 8 : index, 287 si32_attr = 7 : ui32, 288 ui32_attr = 6 : ui32 289 } : () -> () 290 return 291} 292 293// ----- 294 295func.func @wrong_int_attrs_signedness_fail() { 296 // expected-error @+1 {{'ui32_attr' failed to satisfy constraint: 32-bit unsigned integer attribute}} 297 "test.int_attrs"() { 298 any_i32_attr = 5 : i32, 299 index_attr = 8 : index, 300 si32_attr = 7 : si32, 301 ui32_attr = 6 : si32 302 } : () -> () 303 return 304} 305 306// ----- 307 308func.func @wrong_int_attrs_type_fail() { 309 // expected-error @+1 {{'any_i32_attr' failed to satisfy constraint: 32-bit integer attribute}} 310 "test.int_attrs"() { 311 any_i32_attr = 5.0 : f32, 312 si32_attr = 7 : si32, 313 ui32_attr = 6 : ui32, 314 index_attr = 1 : index 315 } : () -> () 316 return 317} 318 319// ----- 320 321//===----------------------------------------------------------------------===// 322// Test Non-negative Int Attr 323//===----------------------------------------------------------------------===// 324 325func.func @non_negative_int_attr_pass() { 326 // CHECK: test.non_negative_int_attr 327 "test.non_negative_int_attr"() {i32attr = 5 : i32, i64attr = 10 : i64} : () -> () 328 // CHECK: test.non_negative_int_attr 329 "test.non_negative_int_attr"() {i32attr = 0 : i32, i64attr = 0 : i64} : () -> () 330 return 331} 332 333// ----- 334 335func.func @negative_int_attr_fail() { 336 // expected-error @+1 {{'i32attr' failed to satisfy constraint: 32-bit signless integer attribute whose value is non-negative}} 337 "test.non_negative_int_attr"() {i32attr = -5 : i32, i64attr = 10 : i64} : () -> () 338 return 339} 340 341// ----- 342 343func.func @negative_int_attr_fail() { 344 // expected-error @+1 {{'i64attr' failed to satisfy constraint: 64-bit signless integer attribute whose value is non-negative}} 345 "test.non_negative_int_attr"() {i32attr = 5 : i32, i64attr = -10 : i64} : () -> () 346 return 347} 348 349// ----- 350 351//===----------------------------------------------------------------------===// 352// Test Positive Int Attr 353//===----------------------------------------------------------------------===// 354 355func.func @positive_int_attr_pass() { 356 // CHECK: test.positive_int_attr 357 "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = 10 : i64} : () -> () 358 return 359} 360 361// ----- 362 363func.func @positive_int_attr_fail() { 364 // expected-error @+1 {{'i32attr' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive}} 365 "test.positive_int_attr"() {i32attr = 0 : i32, i64attr = 5: i64} : () -> () 366 return 367} 368 369// ----- 370 371func.func @positive_int_attr_fail() { 372 // expected-error @+1 {{'i64attr' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive}} 373 "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = 0: i64} : () -> () 374 return 375} 376 377// ----- 378 379func.func @positive_int_attr_fail() { 380 // expected-error @+1 {{'i32attr' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive}} 381 "test.positive_int_attr"() {i32attr = -10 : i32, i64attr = 5 : i64} : () -> () 382 return 383} 384 385// ----- 386 387func.func @positive_int_attr_fail() { 388 // expected-error @+1 {{'i64attr' failed to satisfy constraint: 64-bit signless integer attribute whose value is positive}} 389 "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = -10 : i64} : () -> () 390 return 391} 392 393// ----- 394 395//===----------------------------------------------------------------------===// 396// Test TypeArrayAttr 397//===----------------------------------------------------------------------===// 398 399func.func @correct_type_array_attr_pass() { 400 // CHECK: test.type_array_attr 401 "test.type_array_attr"() {attr = [i32, f32]} : () -> () 402 return 403} 404 405// ----- 406 407func.func @non_type_in_type_array_attr_fail() { 408 // expected-error @+1 {{'attr' failed to satisfy constraint: type array attribute}} 409 "test.type_array_attr"() {attr = [i32, 5 : i64]} : () -> () 410 return 411} 412 413// ----- 414 415//===----------------------------------------------------------------------===// 416// Test StringAttr with custom type 417//===----------------------------------------------------------------------===// 418 419// CHECK-LABEL: func @string_attr_custom_type_valid 420func.func @string_attr_custom_type_valid() { 421 // CHECK: "string_data" : i64 422 test.string_attr_with_type "string_data" : i64 423 return 424} 425 426// ----- 427 428func.func @string_attr_custom_type_invalid() { 429 // expected-error @+1 {{'attr' failed to satisfy constraint: string attribute of integer}} 430 test.string_attr_with_type "string_data" : f32 431 return 432} 433 434// ----- 435 436// CHECK-LABEL: func @string_attr_custom_mixed_type 437func.func @string_attr_custom_mixed_type() { 438 // CHECK: "string_data" : i64 439 test.string_attr_with_mixed_type "string_data" : i64 440 // CHECK: 42 : i64 441 test.string_attr_with_mixed_type 42 : i64 442 return 443} 444 445// ----- 446 447//===----------------------------------------------------------------------===// 448// Test I32EnumAttr 449//===----------------------------------------------------------------------===// 450 451// CHECK-LABEL: func @allowed_cases_pass 452func.func @allowed_cases_pass() { 453 // CHECK: test.i32_enum_attr 454 %0 = "test.i32_enum_attr"() {attr = 5: i32} : () -> i32 455 // CHECK: test.i32_enum_attr 456 %1 = "test.i32_enum_attr"() {attr = 10: i32} : () -> i32 457 return 458} 459 460// ----- 461 462func.func @disallowed_case7_fail() { 463 // expected-error @+1 {{allowed 32-bit signless integer cases: 5, 10}} 464 %0 = "test.i32_enum_attr"() {attr = 7: i32} : () -> i32 465 return 466} 467 468// ----- 469 470func.func @disallowed_case7_fail() { 471 // expected-error @+1 {{allowed 32-bit signless integer cases: 5, 10}} 472 %0 = "test.i32_enum_attr"() {attr = 5: i64} : () -> i32 473 return 474} 475 476// ----- 477 478//===----------------------------------------------------------------------===// 479// Test I64EnumAttr 480//===----------------------------------------------------------------------===// 481 482// CHECK-LABEL: func @allowed_cases_pass 483func.func @allowed_cases_pass() { 484 // CHECK: test.i64_enum_attr 485 %0 = "test.i64_enum_attr"() {attr = 5: i64} : () -> i32 486 // CHECK: test.i64_enum_attr 487 %1 = "test.i64_enum_attr"() {attr = 10: i64} : () -> i32 488 return 489} 490 491// ----- 492 493func.func @disallowed_case7_fail() { 494 // expected-error @+1 {{allowed 64-bit signless integer cases: 5, 10}} 495 %0 = "test.i64_enum_attr"() {attr = 7: i64} : () -> i32 496 return 497} 498 499// ----- 500 501func.func @disallowed_case7_fail() { 502 // expected-error @+1 {{allowed 64-bit signless integer cases: 5, 10}} 503 %0 = "test.i64_enum_attr"() {attr = 5: i32} : () -> i32 504 return 505} 506 507// ----- 508 509//===----------------------------------------------------------------------===// 510// Test BitEnumAttr 511//===----------------------------------------------------------------------===// 512 513// CHECK-LABEL: func @allowed_cases_pass 514func.func @allowed_cases_pass() { 515 // CHECK: test.op_with_bit_enum <read, write> 516 "test.op_with_bit_enum"() {value = #test.bit_enum<read, write>} : () -> () 517 // CHECK: test.op_with_bit_enum <read, execute> 518 test.op_with_bit_enum <read,execute> 519 return 520} 521 522// ----- 523 524// CHECK-LABEL: func @allowed_cases_pass 525func.func @allowed_cases_pass() { 526 // CHECK: test.op_with_bit_enum_vbar <user | group> 527 "test.op_with_bit_enum_vbar"() { 528 value = #test.bit_enum_vbar<user|group> 529 } : () -> () 530 // CHECK: test.op_with_bit_enum_vbar <user | group | other> 531 test.op_with_bit_enum_vbar <user | group | other> 532 return 533} 534 535// ----- 536 537func.func @disallowed_case_sticky_fail() { 538 // expected-error@+2 {{expected test::TestBitEnum to be one of: read, write, execute}} 539 // expected-error@+1 {{failed to parse TestBitEnumAttr}} 540 "test.op_with_bit_enum"() {value = #test.bit_enum<sticky>} : () -> () 541} 542 543// ----- 544 545//===----------------------------------------------------------------------===// 546// Test FloatElementsAttr 547//===----------------------------------------------------------------------===// 548 549func.func @correct_type_pass() { 550 "test.float_elements_attr"() { 551 // CHECK: scalar_f32_attr = dense<5.000000e+00> : tensor<2xf32> 552 // CHECK: tensor_f64_attr = dense<6.000000e+00> : tensor<4x8xf64> 553 scalar_f32_attr = dense<5.0> : tensor<2xf32>, 554 tensor_f64_attr = dense<6.0> : tensor<4x8xf64> 555 } : () -> () 556 return 557} 558 559// ----- 560 561func.func @wrong_element_type_pass() { 562 // expected-error @+1 {{failed to satisfy constraint: 32-bit float elements attribute of shape [2]}} 563 "test.float_elements_attr"() { 564 scalar_f32_attr = dense<5.0> : tensor<2xf64>, 565 tensor_f64_attr = dense<6.0> : tensor<4x8xf64> 566 } : () -> () 567 return 568} 569 570// ----- 571 572func.func @correct_type_pass() { 573 // expected-error @+1 {{failed to satisfy constraint: 64-bit float elements attribute of shape [4, 8]}} 574 "test.float_elements_attr"() { 575 scalar_f32_attr = dense<5.0> : tensor<2xf32>, 576 tensor_f64_attr = dense<6.0> : tensor<4xf64> 577 } : () -> () 578 return 579} 580 581// ----- 582 583func.func @tf32_elements_attr() { 584 // CHECK: "foo"() {attr = dense<4.000000e+00> : tensor<tf32>} : () -> () 585 "foo"() {attr = dense<4.0> : tensor<tf32>} : () -> () 586 return 587} 588 589// ----- 590 591//===----------------------------------------------------------------------===// 592// Test StringElementsAttr 593//===----------------------------------------------------------------------===// 594 595func.func @simple_scalar_example() { 596 "test.string_elements_attr"() { 597 // CHECK: dense<"example"> 598 scalar_string_attr = dense<"example"> : tensor<2x!unknown<"">> 599 } : () -> () 600 return 601} 602 603// ----- 604 605func.func @escape_string_example() { 606 "test.string_elements_attr"() { 607 // CHECK: dense<"new\0Aline"> 608 scalar_string_attr = dense<"new\nline"> : tensor<2x!unknown<"">> 609 } : () -> () 610 return 611} 612 613// ----- 614 615func.func @simple_scalar_example() { 616 "test.string_elements_attr"() { 617 // CHECK: dense<["example1", "example2"]> 618 scalar_string_attr = dense<["example1", "example2"]> : tensor<2x!unknown<"">> 619 } : () -> () 620 return 621} 622 623 624// ----- 625 626//===----------------------------------------------------------------------===// 627// Test DenseArrayAttr 628//===----------------------------------------------------------------------===// 629 630// CHECK-LABEL: func @dense_array_attr 631func.func @dense_array_attr() attributes { 632// CHECK-SAME: emptyf32attr = array<f32>, 633 emptyf32attr = array<f32>, 634// CHECK-SAME: emptyf64attr = array<f64>, 635 emptyf64attr = array<f64>, 636// CHECK-SAME: emptyi16attr = array<i16>, 637 emptyi16attr = array<i16>, 638// CHECK-SAME: emptyi1attr = array<i1>, 639 emptyi1attr = array<i1>, 640// CHECK-SAME: emptyi32attr = array<i32>, 641 emptyi32attr = array<i32>, 642// CHECK-SAME: emptyi64attr = array<i64>, 643 emptyi64attr = array<i64>, 644// CHECK-SAME: emptyi8attr = array<i8>, 645 emptyi8attr = array<i8>, 646// CHECK-SAME: f32attr = array<f32: 1.024000e+03, 4.530000e+02, -6.435000e+03>, 647 f32attr = array<f32: 1024., 453., -6435.>, 648// CHECK-SAME: f64attr = array<f64: -1.420000e+02>, 649 f64attr = array<f64: -142.>, 650// CHECK-SAME: i16attr = array<i16: 3, 5, -4, 10>, 651 i16attr = array<i16: 3, 5, -4, 10>, 652// CHECK-SAME: i1attr = array<i1: true, false, true>, 653 i1attr = array<i1: true, false, true>, 654// CHECK-SAME: i32attr = array<i32: 1024, 453, -6435>, 655 i32attr = array<i32: 1024, 453, -6435>, 656// CHECK-SAME: i64attr = array<i64: -142>, 657 i64attr = array<i64: -142>, 658// CHECK-SAME: i8attr = array<i8: 1, -2, 3> 659 i8attr = array<i8: 1, -2, 3> 660 } { 661// CHECK: test.dense_array_attr 662 test.dense_array_attr 663// CHECK-SAME: i1attr = [true, false, true] 664 i1attr = [true, false, true] 665// CHECK-SAME: i8attr = [1, -2, 3] 666 i8attr = [1, -2, 3] 667// CHECK-SAME: i16attr = [3, 5, -4, 10] 668 i16attr = [3, 5, -4, 10] 669// CHECK-SAME: i32attr = [1024, 453, -6435] 670 i32attr = [1024, 453, -6435] 671// CHECK-SAME: i64attr = [-142] 672 i64attr = [-142] 673// CHECK-SAME: f32attr = [1.024000e+03, 4.530000e+02, -6.435000e+03] 674 f32attr = [1024., 453., -6435.] 675// CHECK-SAME: f64attr = [-1.420000e+02] 676 f64attr = [-142.] 677// CHECK-SAME: emptyattr = [] 678 emptyattr = [] 679 680 // CHECK: array.sizes 681 // CHECK-SAME: i0 = array<i0: 0, 0> 682 // CHECK-SAME: ui0 = array<ui0: 0, 0> 683 // CHECK-SAME: si0 = array<si0: 0, 0> 684 // CHECK-SAME: i24 = array<i24: -42, 42, 8388607> 685 // CHECK-SAME: ui24 = array<ui24: 16777215> 686 // CHECK-SAME: si24 = array<si24: -8388608> 687 // CHECK-SAME: bf16 = array<bf16: 1.2{{[0-9]+}}e+00, 3.4{{[0-9]+}}e+00> 688 // CHECK-SAME: f16 = array<f16: 1.{{[0-9]+}}e+00, 3.{{[0-9]+}}e+00> 689 "array.sizes"() { 690 x0_i0 = array<i0: 0, 0>, 691 x1_ui0 = array<ui0: 0, 0>, 692 x2_si0 = array<si0: 0, 0>, 693 x3_i24 = array<i24: -42, 42, 8388607>, 694 x4_ui24 = array<ui24: 16777215>, 695 x5_si24 = array<si24: -8388608>, 696 x6_bf16 = array<bf16: 1.2, 3.4>, 697 x7_f16 = array<f16: 1., 3.> 698 }: () -> () 699 700 return 701} 702 703// ----- 704 705func.func @test_invalid_bitwidth_type() { 706 // expected-error @below{{element type bitwidth must be a multiple of 8}} 707 "foo"() {tf32attr = array<tf32: 1024.0>} : () -> () 708 return 709} 710 711// ----- 712 713func.func @testConfinedDenseArrayAttr() { 714 "test.confined_dense_array_attr"() { 715 i64attr = array<i64: 0, 2, 3>, 716 i32attr = array<i32: 1>, 717 emptyattr = array<i16> 718 } : () -> () 719 func.return 720} 721 722// ----- 723 724func.func @testConfinedDenseArrayAttrDuplicateValues() { 725 // expected-error@+1{{'test.confined_dense_array_attr' op attribute 'i64attr' failed to satisfy constraint: i64 dense array attribute should be in increasing order}} 726 "test.confined_dense_array_attr"() { 727 emptyattr = array<i16>, 728 i32attr = array<i32: 1, 1>, 729 i64attr = array<i64: 0, 2, 2> 730 } : () -> () 731 func.return 732} 733 734// ----- 735 736func.func @testConfinedDenseArrayAttrDecreasingOrder() { 737 // expected-error@+1{{'test.confined_dense_array_attr' op attribute 'i32attr' failed to satisfy constraint: i32 dense array attribute should be in non-decreasing order}} 738 "test.confined_dense_array_attr"() { 739 emptyattr = array<i16>, 740 i32attr = array<i32: 1, 0>, 741 i64attr = array<i64: 0, 2, 3> 742 } : () -> () 743 func.return 744} 745 746// ----- 747 748func.func @testConfinedStrictlyPositiveDenseArrayAttr() { 749 "test.confined_strictly_positive_attr"() { 750 i8attr = array<i8: 2, 3>, 751 i16attr = array<i16: 20, 30>, 752 i32attr = array<i32: 1>, 753 i64attr = array<i64: 1, 2, 3>, 754 f32attr = array<f32: 1.1, 2.1>, 755 f64attr = array<f64: 2.1, 3.1>, 756 emptyattr = array<i16> 757 } : () -> () 758 func.return 759} 760 761// ----- 762 763func.func @testConfinedStrictlyPositiveDenseArrayAttr() { 764 // expected-error@+1{{'test.confined_strictly_positive_attr' op attribute 'i64attr' failed to satisfy constraint: i64 dense array attribute whose value is positive}} 765 "test.confined_strictly_positive_attr"() { 766 i8attr = array<i8: 2, 3>, 767 i16attr = array<i16: 20, 30>, 768 i32attr = array<i32: 1>, 769 i64attr = array<i64: 0, 2, 3>, 770 f32attr = array<f32: 1.1, 2.1>, 771 f64attr = array<f64: 2.1, 3.1>, 772 emptyattr = array<i16> 773 } : () -> () 774 func.return 775} 776 777// ----- 778 779func.func @testConfinedNonNegativeDenseArrayAttr() { 780 "test.confined_non_negative_attr"() { 781 i8attr = array<i8: 0, 3>, 782 i16attr = array<i16: 0, 30>, 783 i32attr = array<i32: 1>, 784 i64attr = array<i64: 1, 0, 3>, 785 f32attr = array<f32: 0.0, 2.1>, 786 f64attr = array<f64: 0.0, 3.1>, 787 emptyattr = array<i16> 788 } : () -> () 789 func.return 790} 791 792// ----- 793 794func.func @testConfinedNonNegativeDenseArrayAttr() { 795 // expected-error@+1{{'test.confined_non_negative_attr' op attribute 'i64attr' failed to satisfy constraint: i64 dense array attribute whose value is non-negative}} 796 "test.confined_non_negative_attr"() { 797 i8attr = array<i8: 0, 3>, 798 i16attr = array<i16: 0, 30>, 799 i32attr = array<i32: 1>, 800 i64attr = array<i64: -1, 0, 3>, 801 f32attr = array<f32: 0.0, 2.1>, 802 f64attr = array<f64: 0.0, 3.1>, 803 emptyattr = array<i16> 804 } : () -> () 805 func.return 806} 807 808// ----- 809 810//===----------------------------------------------------------------------===// 811// Test SymbolRefAttr 812//===----------------------------------------------------------------------===// 813 814func.func @fn() { return } 815 816// CHECK: test.symbol_ref_attr 817"test.symbol_ref_attr"() {symbol = @fn} : () -> () 818 819// ----- 820 821//===----------------------------------------------------------------------===// 822// Test IntElementsAttr 823//===----------------------------------------------------------------------===// 824 825func.func @correct_int_elements_attr_pass() { 826 "test.int_elements_attr"() { 827 // CHECK: any_i32_attr = dense<5> : tensor<1x2x3x4xui32>, 828 any_i32_attr = dense<5> : tensor<1x2x3x4xui32>, 829 i32_attr = dense<5> : tensor<6xi32> 830 } : () -> () 831 832 "test.int_elements_attr"() { 833 // CHECK: any_i32_attr = dense<5> : tensor<1x2x3x4xsi32>, 834 any_i32_attr = dense<5> : tensor<1x2x3x4xsi32>, 835 i32_attr = dense<5> : tensor<6xi32> 836 } : () -> () 837 838 "test.int_elements_attr"() { 839 // CHECK: any_i32_attr = dense<5> : tensor<1x2x3x4xi32>, 840 any_i32_attr = dense<5> : tensor<1x2x3x4xi32>, 841 i32_attr = dense<5> : tensor<6xi32> 842 } : () -> () 843 844 "test.index_elements_attr"() { 845 // CHECK: any_index_attr = dense<5> : tensor<1x2x3x4xindex>, 846 any_index_attr = dense<5> : tensor<1x2x3x4xindex>, 847 index_attr = dense<5> : tensor<6xindex> 848 } : () -> () 849 850 "test.hex_index_elements_attr"() { 851 // CHECK: hex_index_attr = dense<"0x00000C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000080C0000000000001A150000000000005078000000000000B659010000000000ECBC010000000000FEC5010000000000342902000000000046320200000000007C950200000000008E9E020000000000C401030000000000D60A0300000000000C6E0300000000001E7703000000000054DA03000000000066E30300000000009C46040000000000AE4F040000000000E4B2040000000000F6BB0400000000002C1F050000000000628100000000000098E40000000000000E0C00000000000020150000000000005678000000000000BC59010000000000F2BC01000000000004C60100000000003A290200000000004C320200000000008295020000000000949E020000000000CA01030000000000DC0A030000000000126E03000000000024770300000000005ADA0300000000006CE3030000000000A246040000000000B44F040000000000EAB2040000000000FCBB040000000000321F05000000000068810000000000009EE40000000000"> : tensor<23x5xindex> 852 hex_index_attr = dense<"0x00000C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000080C0000000000001A150000000000005078000000000000B659010000000000ECBC010000000000FEC5010000000000342902000000000046320200000000007C950200000000008E9E020000000000C401030000000000D60A0300000000000C6E0300000000001E7703000000000054DA03000000000066E30300000000009C46040000000000AE4F040000000000E4B2040000000000F6BB0400000000002C1F050000000000628100000000000098E40000000000000E0C00000000000020150000000000005678000000000000BC59010000000000F2BC01000000000004C60100000000003A290200000000004C320200000000008295020000000000949E020000000000CA01030000000000DC0A030000000000126E03000000000024770300000000005ADA0300000000006CE3030000000000A246040000000000B44F040000000000EAB2040000000000FCBB040000000000321F05000000000068810000000000009EE40000000000"> : tensor<23x5xindex> 853 } : () -> () 854 855 return 856} 857 858// ----- 859 860func.func @wrong_int_elements_attr_type_fail() { 861 // expected-error @+1 {{'any_i32_attr' failed to satisfy constraint: 32-bit integer elements attribute}} 862 "test.int_elements_attr"() { 863 any_i32_attr = dense<5.0> : tensor<1x2x3x4xf32>, 864 i32_attr = dense<5> : tensor<6xi32> 865 } : () -> () 866 return 867} 868 869// ----- 870 871func.func @wrong_int_elements_attr_signedness_fail() { 872 // expected-error @+1 {{'i32_attr' failed to satisfy constraint: 32-bit signless integer elements attribute}} 873 "test.int_elements_attr"() { 874 any_i32_attr = dense<5> : tensor<1x2x3x4xi32>, 875 i32_attr = dense<5> : tensor<6xsi32> 876 } : () -> () 877 return 878} 879 880// ----- 881 882//===----------------------------------------------------------------------===// 883// Test Ranked IntElementsAttr 884//===----------------------------------------------------------------------===// 885 886func.func @correct_type_pass() { 887 "test.ranked_int_elements_attr"() { 888 // CHECK: matrix_i64_attr = dense<6> : tensor<4x8xi64> 889 // CHECK: vector_i32_attr = dense<5> : tensor<2xi32> 890 matrix_i64_attr = dense<6> : tensor<4x8xi64>, 891 vector_i32_attr = dense<5> : tensor<2xi32> 892 } : () -> () 893 return 894} 895 896// ----- 897 898func.func @wrong_element_type_fail() { 899 // expected-error @+1 {{failed to satisfy constraint: 32-bit signless int elements attribute of shape [2]}} 900 "test.ranked_int_elements_attr"() { 901 matrix_i64_attr = dense<6> : tensor<4x8xi64>, 902 vector_i32_attr = dense<5> : tensor<2xi64> 903 } : () -> () 904 return 905} 906 907// ----- 908 909func.func @wrong_shape_fail() { 910 // expected-error @+1 {{failed to satisfy constraint: 64-bit signless int elements attribute of shape [4, 8]}} 911 "test.ranked_int_elements_attr"() { 912 matrix_i64_attr = dense<6> : tensor<4xi64>, 913 vector_i32_attr = dense<5> : tensor<2xi32> 914 } : () -> () 915 return 916} 917 918// ----- 919 920func.func @wrong_shape_fail() { 921 // expected-error @+1 {{failed to satisfy constraint: 32-bit signless int elements attribute of shape [2]}} 922 "test.ranked_int_elements_attr"() { 923 matrix_i64_attr = dense<6> : tensor<4x8xi64>, 924 vector_i32_attr = dense<5> : tensor<i32> 925 } : () -> () 926 return 927} 928 929// ----- 930 931//===----------------------------------------------------------------------===// 932// Test DefaultValuedAttr Printing 933//===----------------------------------------------------------------------===// 934 935// CHECK-LABEL: @default_value_printing 936func.func @default_value_printing(%arg0 : i32) { 937 // The attribute SHOULD NOT be printed because it is equal to the default 938 // CHECK: test.default_value_print %arg0 939 "test.default_value_print"(%arg0) {"value_with_default" = 0 : i32} : (i32) -> () 940 // The attribute SHOULD be printed because it is not equal to the default 941 // CHECK: test.default_value_print {value_with_default = 1 : i32} %arg0 942 "test.default_value_print"(%arg0) {"value_with_default" = 1 : i32} : (i32) -> () 943 return 944} 945 946// ----- 947 948func.func @type_attr_of_fail() { 949 // expected-error @below {{failed to satisfy constraint: type attribute of 64-bit signless integer}} 950 test.type_attr_of i32 951 return 952} 953