brintos

brintos / llvm-project-archived public Read only

0
0
Text · 31.9 KiB · edb7357 Raw
957 lines · plain
1// RUN: mlir-opt %s -split-input-file -allow-unregistered-dialect -verify-diagnostics | FileCheck %s2 3//===----------------------------------------------------------------------===//4// Test AnyAttrOf attributes5//===----------------------------------------------------------------------===//6 7func.func @any_attr_of_pass() {8  "test.any_attr_of_i32_str"() {9    // CHECK: attr = 3 : i3210    attr = 3 : i3211  } : () -> ()12 13  "test.any_attr_of_i32_str"() {14    // CHECK: attr = "string_data"15    attr = "string_data"16  } : () -> ()17 18  return19}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 : i6427  } : () -> ()28 29  return30}31 32// -----33 34//===----------------------------------------------------------------------===//35// Test float attributes36//===----------------------------------------------------------------------===//37 38func.func @float_attrs_pass() {39  "test.float_attrs"() {40    // CHECK: float_attr = 2.000000e+00 : f4E2M1FN41    float_attr = 2. : f4E2M1FN42  } : () -> ()43  "test.float_attrs"() {44    // CHECK: float_attr = 2.000000e+00 : f6E2M3FN45    float_attr = 2. : f6E2M3FN46  } : () -> ()47  "test.float_attrs"() {48    // CHECK: float_attr = 2.000000e+00 : f6E3M2FN49    float_attr = 2. : f6E3M2FN50  } : () -> ()51  "test.float_attrs"() {52    // CHECK: float_attr = 2.000000e+00 : f8E5M253    float_attr = 2. : f8E5M254  } : () -> ()55  "test.float_attrs"() {56    // CHECK: float_attr = 2.000000e+00 : f8E4M357    float_attr = 2. : f8E4M358  } : () -> ()59  "test.float_attrs"() {60    // CHECK: float_attr = 2.000000e+00 : f8E4M3FN61    float_attr = 2. : f8E4M3FN62  } : () -> ()63  "test.float_attrs"() {64    // CHECK: float_attr = 2.000000e+00 : f8E5M2FNUZ65    float_attr = 2. : f8E5M2FNUZ66  } : () -> ()67  "test.float_attrs"() {68    // CHECK: float_attr = 2.000000e+00 : f8E4M3FNUZ69    float_attr = 2. : f8E4M3FNUZ70  } : () -> ()71  "test.float_attrs"() {72    // CHECK: float_attr = 2.000000e+00 : f8E4M3B11FNUZ73    float_attr = 2. : f8E4M3B11FNUZ74  } : () -> ()75  "test.float_attrs"() {76    // CHECK: float_attr = 2.000000e+00 : f8E3M477    float_attr = 2. : f8E3M478  } : () -> ()79  "test.float_attrs"() {80    // CHECK: float_attr = 2.000000e+00 : f8E8M0FNU81    float_attr = 2. : f8E8M0FNU82  } : () -> ()83  "test.float_attrs"() {84    // CHECK: float_attr = 2.000000e+00 : f1685    float_attr = 2. : f1686  } : () -> ()87  "test.float_attrs"() {88    // CHECK: float_attr = 2.000000e+00 : bf1689    float_attr = 2. : bf1690  } : () -> ()91  "test.float_attrs"() {92    // CHECK: float_attr = 2.000000e+00 : tf3293    float_attr = 2. : tf3294  } : () -> ()95  "test.float_attrs"() {96    // CHECK: float_attr = 2.000000e+00 : f3297    float_attr = 2. : f3298  } : () -> ()99  "test.float_attrs"() {100    // CHECK: float_attr = 2.000000e+00 : f64101    float_attr = 2. : f64102  } : () -> ()103  "test.float_attrs"() {104    // CHECK: float_attr = 2.000000e+00 : f80105    float_attr = 2. : f80106  } : () -> ()107  "test.float_attrs"() {108    // CHECK: float_attr = 2.000000e+00 : f128109    float_attr = 2. : f128110  } : () -> ()111  return112}113 114//===----------------------------------------------------------------------===//115// Test integer attributes116//===----------------------------------------------------------------------===//117 118func.func @int_attrs_pass() {119  "test.int_attrs"() {120    // CHECK: any_i32_attr = 5 : ui32121    any_i32_attr = 5 : ui32,122    // CHECK-SAME: index_attr = 8 : index123    index_attr = 8 : index,124    // CHECK-SAME: si32_attr = 7 : si32125    si32_attr = 7 : si32,126    // CHECK-SAME: ui32_attr = 6 : ui32127    ui32_attr = 6 : ui32128  } : () -> ()129 130  "test.int_attrs"() {131    // CHECK: any_i32_attr = 5 : si32132    any_i32_attr = 5 : si32,133    index_attr = 8 : index,134    si32_attr = 7 : si32,135    ui32_attr = 6 : ui32136  } : () -> ()137 138  "test.int_attrs"() {139    // CHECK: any_i32_attr = 5 : i32140    any_i32_attr = 5 : i32,141    index_attr = 8 : index,142    si32_attr = 7 : si32,143    ui32_attr = 6 : ui32144  } : () -> ()145 146  return147}148 149// -----150 151//===----------------------------------------------------------------------===//152// Check that the maximum and minimum integer attribute values are153// representable and preserved during a round-trip.154//===----------------------------------------------------------------------===//155 156func.func @int_attrs_pass() {157  "test.in_range_attrs"() {158    // CHECK: attr_00 = -128 : i8159    attr_00 = -128 : i8,160    // CHECK-SAME: attr_01 = 127 : i8161    attr_01 = 127 : i8,162    // CHECK-SAME: attr_02 = -128 : si8163    attr_02 = -128 : si8,164    // CHECK-SAME: attr_03 = 127 : si8165    attr_03 = 127 : si8,166    // CHECK-SAME: attr_04 = 255 : ui8167    attr_04 = 255 : ui8,168    // CHECK-SAME: attr_05 = -32768 : i16169    attr_05 = -32768 : i16,170    // CHECK-SAME: attr_06 = 32767 : i16171    attr_06 = 32767 : i16,172    // CHECK-SAME: attr_07 = -32768 : si16173    attr_07 = -32768 : si16,174    // CHECK-SAME: attr_08 = 32767 : si16175    attr_08 = 32767 : si16,176    // CHECK-SAME: attr_09 = 65535 : ui16177    attr_09 = 65535 : ui16,178    // CHECK-SAME: attr_10 = -2147483647 : i32179    attr_10 = -2147483647 : i32,180    // CHECK-SAME: attr_11 = 2147483646 : i32181    attr_11 = 2147483646 : i32,182    // CHECK-SAME: attr_12 = -2147483647 : si32183    attr_12 = -2147483647 : si32,184    // CHECK-SAME: attr_13 = 2147483646 : si32185    attr_13 = 2147483646 : si32,186    // CHECK-SAME: attr_14 = 4294967295 : ui32187    attr_14 = 4294967295 : ui32,188    // CHECK-SAME: attr_15 = -9223372036854775808 : i64189    attr_15 = -9223372036854775808 : i64,190    // CHECK-SAME: attr_16 = 9223372036854775807 : i64191    attr_16 = 9223372036854775807 : i64,192    // CHECK-SAME: attr_17 = -9223372036854775808 : si64193    attr_17 = -9223372036854775808 : si64,194    // CHECK-SAME: attr_18 = 9223372036854775807 : si64195    attr_18 = 9223372036854775807 : si64,196    // CHECK-SAME: attr_19 = 18446744073709551615 : ui64197    attr_19 = 18446744073709551615 : ui64,198    // CHECK-SAME: attr_20 = 1 : ui1199    attr_20 = 1 : ui1,200    // CHECK-SAME: attr_21 = -1 : si1201    attr_21 = -1 : si1,202    // CHECK-SAME: attr_22 = 79228162514264337593543950335 : ui96203    attr_22 = 79228162514264337593543950335 : ui96,204    // CHECK-SAME: attr_23 = -39614081257132168796771975168 : si96205    attr_23 = -39614081257132168796771975168 : si96206  } : () -> ()207 208  return209}210 211// -----212 213//===----------------------------------------------------------------------===//214// Check that positive values larger than 2^n-1 for signless integers215// are mapped to their negative signed counterpart. This behaviour is216// undocumented in the language specification, but it is what the217// parser currently does.218//===----------------------------------------------------------------------===//219 220func.func @int_attrs_pass() {221  "test.i8_attr"() {222    // CHECK: attr_00 = -1 : i8223    attr_00 = 255 : i8,224    // CHECK-SAME: attr_01 = -1 : i16225    attr_01 = 65535 : i16,226    // CHECK-SAME: attr_02 = -1 : i32227    attr_02 = 4294967295 : i32,228    // CHECK-SAME: attr_03 = -1 : i64229    attr_03 = 18446744073709551615 : i64230  } : () -> ()231  return232}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 that239// are good to verify.240//===----------------------------------------------------------------------===//241 242func.func @int0_attrs_pass() {243  "test.i0_attr"() {244    // CHECK: attr_00 = 0 : i0245    attr_00 = 0 : i0,246    // CHECK: attr_01 = 0 : si0247    attr_01 = 0 : si0,248    // CHECK: attr_02 = 0 : ui0249    attr_02 = 0 : ui0,250    // CHECK: attr_03 = 0 : i0251    attr_03 = 0x0000 : i0,252    // CHECK: attr_04 = 0 : si0253    attr_04 = 0x0000 : si0,254    // CHECK: attr_05 = 0 : ui0255    attr_05 = 0x0000 : ui0256  } : () -> ()257  return258}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 : i0266  } : () -> ()267  return268}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 : i0276  } : () -> ()277  return278}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 : ui32289  } : () -> ()290  return291}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 : si32302  } : () -> ()303  return304}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 : index315  } : () -> ()316  return317}318 319// -----320 321//===----------------------------------------------------------------------===//322// Test Non-negative Int Attr323//===----------------------------------------------------------------------===//324 325func.func @non_negative_int_attr_pass() {326  // CHECK: test.non_negative_int_attr327  "test.non_negative_int_attr"() {i32attr = 5 : i32, i64attr = 10 : i64} : () -> ()328  // CHECK: test.non_negative_int_attr329  "test.non_negative_int_attr"() {i32attr = 0 : i32, i64attr = 0 : i64} : () -> ()330  return331}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  return339}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  return347}348 349// -----350 351//===----------------------------------------------------------------------===//352// Test Positive Int Attr353//===----------------------------------------------------------------------===//354 355func.func @positive_int_attr_pass() {356  // CHECK: test.positive_int_attr357  "test.positive_int_attr"() {i32attr = 5 : i32, i64attr = 10 : i64} : () -> ()358  return359}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  return367}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  return375}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  return383}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  return391}392 393// -----394 395//===----------------------------------------------------------------------===//396// Test TypeArrayAttr397//===----------------------------------------------------------------------===//398 399func.func @correct_type_array_attr_pass() {400  // CHECK: test.type_array_attr401  "test.type_array_attr"() {attr = [i32, f32]} : () -> ()402  return403}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  return411}412 413// -----414 415//===----------------------------------------------------------------------===//416// Test StringAttr with custom type417//===----------------------------------------------------------------------===//418 419// CHECK-LABEL: func @string_attr_custom_type_valid420func.func @string_attr_custom_type_valid() {421  // CHECK: "string_data" : i64422  test.string_attr_with_type "string_data" : i64423  return424}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" : f32431  return432}433 434// -----435 436// CHECK-LABEL: func @string_attr_custom_mixed_type437func.func @string_attr_custom_mixed_type() {438  // CHECK: "string_data" : i64439  test.string_attr_with_mixed_type "string_data" : i64440  // CHECK: 42 : i64441  test.string_attr_with_mixed_type 42 : i64442  return443}444 445// -----446 447//===----------------------------------------------------------------------===//448// Test I32EnumAttr449//===----------------------------------------------------------------------===//450 451// CHECK-LABEL: func @allowed_cases_pass452func.func @allowed_cases_pass() {453  // CHECK: test.i32_enum_attr454  %0 = "test.i32_enum_attr"() {attr = 5: i32} : () -> i32455  // CHECK: test.i32_enum_attr456  %1 = "test.i32_enum_attr"() {attr = 10: i32} : () -> i32457  // CHECK: test.i32_enum_attr458  %2 = "test.i32_enum_attr"() {attr = 2147483648: i32} : () -> i32459  // CHECK: test.i32_enum_attr460  %3 = "test.i32_enum_attr"() {attr = 4294967295: i32} : () -> i32461  return462}463 464// -----465 466func.func @disallowed_case7_fail() {467  // expected-error @+1 {{allowed 32-bit signless integer cases: 5, 10}}468  %0 = "test.i32_enum_attr"() {attr = 7: i32} : () -> i32469  return470}471 472// -----473 474func.func @disallowed_case7_fail() {475  // expected-error @+1 {{allowed 32-bit signless integer cases: 5, 10}}476  %0 = "test.i32_enum_attr"() {attr = 5: i64} : () -> i32477  return478}479 480// -----481 482//===----------------------------------------------------------------------===//483// Test I64EnumAttr484//===----------------------------------------------------------------------===//485 486// CHECK-LABEL: func @allowed_cases_pass487func.func @allowed_cases_pass() {488  // CHECK: test.i64_enum_attr489  %0 = "test.i64_enum_attr"() {attr = 5: i64} : () -> i32490  // CHECK: test.i64_enum_attr491  %1 = "test.i64_enum_attr"() {attr = 10: i64} : () -> i32492  return493}494 495// -----496 497func.func @disallowed_case7_fail() {498  // expected-error @+1 {{allowed 64-bit signless integer cases: 5, 10}}499  %0 = "test.i64_enum_attr"() {attr = 7: i64} : () -> i32500  return501}502 503// -----504 505func.func @disallowed_case7_fail() {506  // expected-error @+1 {{allowed 64-bit signless integer cases: 5, 10}}507  %0 = "test.i64_enum_attr"() {attr = 5: i32} : () -> i32508  return509}510 511// -----512 513//===----------------------------------------------------------------------===//514// Test BitEnumAttr515//===----------------------------------------------------------------------===//516 517// CHECK-LABEL: func @allowed_cases_pass518func.func @allowed_cases_pass() {519  // CHECK: test.op_with_bit_enum <read, write>520  "test.op_with_bit_enum"() {value = #test.bit_enum<read, write>} : () -> ()521  // CHECK: test.op_with_bit_enum <read, execute>522  test.op_with_bit_enum <read,execute>523  return524}525 526// -----527 528// CHECK-LABEL: func @allowed_cases_pass529func.func @allowed_cases_pass() {530  // CHECK: test.op_with_bit_enum_vbar <user | group>531  "test.op_with_bit_enum_vbar"() {532    value = #test.bit_enum_vbar<user|group>533  } : () -> ()534  // CHECK: test.op_with_bit_enum_vbar <user | group | other>535  test.op_with_bit_enum_vbar <user | group | other>536  return537}538 539// -----540 541func.func @disallowed_case_sticky_fail() {542  // expected-error@+2 {{expected one of [read, write, execute] for a test bit enum, got: sticky}}543  // expected-error@+1 {{failed to parse TestBitEnumAttr}}544  "test.op_with_bit_enum"() {value = #test.bit_enum<sticky>} : () -> ()545}546 547// -----548 549//===----------------------------------------------------------------------===//550// Test FloatElementsAttr551//===----------------------------------------------------------------------===//552 553func.func @correct_type_pass() {554  "test.float_elements_attr"() {555    // CHECK: scalar_f32_attr = dense<5.000000e+00> : tensor<2xf32>556    // CHECK: tensor_f64_attr = dense<6.000000e+00> : tensor<4x8xf64>557    scalar_f32_attr = dense<5.0> : tensor<2xf32>,558    tensor_f64_attr = dense<6.0> : tensor<4x8xf64>559  } : () -> ()560  return561}562 563// -----564 565func.func @wrong_element_type_pass() {566  // expected-error @+1 {{failed to satisfy constraint: 32-bit float elements attribute of shape [2]}}567  "test.float_elements_attr"() {568    scalar_f32_attr = dense<5.0> : tensor<2xf64>,569    tensor_f64_attr = dense<6.0> : tensor<4x8xf64>570  } : () -> ()571  return572}573 574// -----575 576func.func @correct_type_pass() {577  // expected-error @+1 {{failed to satisfy constraint: 64-bit float elements attribute of shape [4, 8]}}578  "test.float_elements_attr"() {579    scalar_f32_attr = dense<5.0> : tensor<2xf32>,580    tensor_f64_attr = dense<6.0> : tensor<4xf64>581  } : () -> ()582  return583}584 585// -----586 587func.func @tf32_elements_attr() {588  // CHECK: "foo"() {attr = dense<4.000000e+00> : tensor<tf32>} : () -> ()589  "foo"() {attr = dense<4.0> : tensor<tf32>} : () -> ()590  return591}592 593// -----594 595//===----------------------------------------------------------------------===//596// Test StringElementsAttr597//===----------------------------------------------------------------------===//598 599func.func @simple_scalar_example() {600  "test.string_elements_attr"() {601    // CHECK: dense<"example">602    scalar_string_attr = dense<"example"> : tensor<2x!unknown<"">>603  } : () -> ()604  return605}606 607// -----608 609func.func @escape_string_example() {610  "test.string_elements_attr"() {611    // CHECK: dense<"new\0Aline">612    scalar_string_attr = dense<"new\nline"> : tensor<2x!unknown<"">>613  } : () -> ()614  return615}616 617// -----618 619func.func @simple_scalar_example() {620  "test.string_elements_attr"() {621    // CHECK: dense<["example1", "example2"]>622    scalar_string_attr = dense<["example1", "example2"]> : tensor<2x!unknown<"">>623  } : () -> ()624  return625}626 627 628// -----629 630//===----------------------------------------------------------------------===//631// Test DenseArrayAttr632//===----------------------------------------------------------------------===//633 634// CHECK-LABEL: func @dense_array_attr635func.func @dense_array_attr() attributes {636// CHECK-SAME: emptyf32attr = array<f32>,637               emptyf32attr = array<f32>,638// CHECK-SAME: emptyf64attr = array<f64>,639               emptyf64attr = array<f64>,640// CHECK-SAME: emptyi16attr = array<i16>,641               emptyi16attr = array<i16>,642// CHECK-SAME: emptyi1attr = array<i1>,643               emptyi1attr = array<i1>,644// CHECK-SAME: emptyi32attr = array<i32>,645               emptyi32attr = array<i32>,646// CHECK-SAME: emptyi64attr = array<i64>,647               emptyi64attr = array<i64>,648// CHECK-SAME: emptyi8attr = array<i8>,649               emptyi8attr = array<i8>,650// CHECK-SAME: f32attr = array<f32: 1.024000e+03, 4.530000e+02, -6.435000e+03>,651               f32attr = array<f32: 1024., 453., -6435.>,652// CHECK-SAME: f64attr = array<f64: -1.420000e+02>,653               f64attr = array<f64: -142.>,654// CHECK-SAME: i16attr = array<i16: 3, 5, -4, 10>,655               i16attr = array<i16: 3, 5, -4, 10>,656// CHECK-SAME: i1attr = array<i1: true, false, true>,657               i1attr = array<i1: true, false, true>,658// CHECK-SAME: i32attr = array<i32: 1024, 453, -6435>,659               i32attr = array<i32: 1024, 453, -6435>,660// CHECK-SAME: i64attr = array<i64: -142>,661               i64attr = array<i64: -142>,662// CHECK-SAME: i8attr = array<i8: 1, -2, 3>663               i8attr = array<i8: 1, -2, 3>664 } {665// CHECK:  test.dense_array_attr666  test.dense_array_attr667// CHECK-SAME: i1attr = [true, false, true]668               i1attr = [true, false, true]669// CHECK-SAME: i8attr = [1, -2, 3]670               i8attr = [1, -2, 3]671// CHECK-SAME: i16attr = [3, 5, -4, 10]672               i16attr = [3, 5, -4, 10]673// CHECK-SAME: i32attr = [1024, 453, -6435]674               i32attr = [1024, 453, -6435]675// CHECK-SAME: i64attr = [-142]676               i64attr = [-142]677// CHECK-SAME: f32attr = [1.024000e+03, 4.530000e+02, -6.435000e+03]678               f32attr = [1024., 453., -6435.]679// CHECK-SAME: f64attr = [-1.420000e+02]680               f64attr = [-142.]681// CHECK-SAME: emptyattr = []682               emptyattr = []683 684  // CHECK: array.sizes685  // CHECK-SAME: i0 = array<i0: 0, 0>686  // CHECK-SAME: ui0 = array<ui0: 0, 0>687  // CHECK-SAME: si0 = array<si0: 0, 0>688  // CHECK-SAME: i24 = array<i24: -42, 42, 8388607>689  // CHECK-SAME: ui24 = array<ui24: 16777215>690  // CHECK-SAME: si24 = array<si24: -8388608>691  // CHECK-SAME: bf16 = array<bf16: 1.2{{[0-9]+}}e+00, 3.4{{[0-9]+}}e+00>692  // CHECK-SAME: f16 = array<f16: 1.{{[0-9]+}}e+00, 3.{{[0-9]+}}e+00>693  "array.sizes"() {694    x0_i0 = array<i0: 0, 0>,695    x1_ui0 = array<ui0: 0, 0>,696    x2_si0 = array<si0: 0, 0>,697    x3_i24 = array<i24: -42, 42, 8388607>,698    x4_ui24 = array<ui24: 16777215>,699    x5_si24 = array<si24: -8388608>,700    x6_bf16 = array<bf16: 1.2, 3.4>,701    x7_f16 = array<f16: 1., 3.>702  }: () -> ()703 704  return705}706 707// -----708 709func.func @test_invalid_bitwidth_type() {710  // expected-error @below{{element type bitwidth must be a multiple of 8}}711  "foo"() {tf32attr = array<tf32: 1024.0>} : () -> ()712  return713}714 715// -----716 717func.func @testConfinedDenseArrayAttr() {718  "test.confined_dense_array_attr"() {719    i64attr = array<i64: 0, 2, 3>,720    i32attr = array<i32: 1>,721    emptyattr = array<i16>722  } : () -> ()723  func.return724}725 726// -----727 728func.func @testConfinedDenseArrayAttrDuplicateValues() {729  // expected-error@+1{{'test.confined_dense_array_attr' op attribute 'i64attr' failed to satisfy constraint: i64 dense array attribute should be in increasing order}}730  "test.confined_dense_array_attr"() {731    emptyattr = array<i16>,732    i32attr = array<i32: 1, 1>,733    i64attr = array<i64: 0, 2, 2>734  } : () -> ()735  func.return736}737 738// -----739 740func.func @testConfinedDenseArrayAttrDecreasingOrder() {741  // 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}}742  "test.confined_dense_array_attr"() {743    emptyattr = array<i16>,744    i32attr = array<i32: 1, 0>,745    i64attr = array<i64: 0, 2, 3>746  } : () -> ()747  func.return748}749 750// -----751 752func.func @testConfinedStrictlyPositiveDenseArrayAttr() {753  "test.confined_strictly_positive_attr"() {754    i8attr = array<i8: 2, 3>,755    i16attr = array<i16: 20, 30>,756    i32attr = array<i32: 1>,757    i64attr = array<i64: 1, 2, 3>,758    f32attr = array<f32: 1.1, 2.1>,759    f64attr = array<f64: 2.1, 3.1>,760    emptyattr = array<i16>761  } : () -> ()762  func.return763}764 765// -----766 767func.func @testConfinedStrictlyPositiveDenseArrayAttr() {768  // expected-error@+1{{'test.confined_strictly_positive_attr' op attribute 'i64attr' failed to satisfy constraint: i64 dense array attribute whose value is positive}}769  "test.confined_strictly_positive_attr"() {770    i8attr = array<i8: 2, 3>,771    i16attr = array<i16: 20, 30>,772    i32attr = array<i32: 1>,773    i64attr = array<i64: 0, 2, 3>,774    f32attr = array<f32: 1.1, 2.1>,775    f64attr = array<f64: 2.1, 3.1>,776    emptyattr = array<i16>777  } : () -> ()778  func.return779}780 781// -----782 783func.func @testConfinedNonNegativeDenseArrayAttr() {784  "test.confined_non_negative_attr"() {785    i8attr = array<i8: 0, 3>,786    i16attr = array<i16: 0, 30>,787    i32attr = array<i32: 1>,788    i64attr = array<i64: 1, 0, 3>,789    f32attr = array<f32: 0.0, 2.1>,790    f64attr = array<f64: 0.0, 3.1>,791    emptyattr = array<i16>792  } : () -> ()793  func.return794}795 796// -----797 798func.func @testConfinedNonNegativeDenseArrayAttr() {799  // expected-error@+1{{'test.confined_non_negative_attr' op attribute 'i64attr' failed to satisfy constraint: i64 dense array attribute whose value is non-negative}}800  "test.confined_non_negative_attr"() {801    i8attr = array<i8: 0, 3>,802    i16attr = array<i16: 0, 30>,803    i32attr = array<i32: 1>,804    i64attr = array<i64: -1, 0, 3>,805    f32attr = array<f32: 0.0, 2.1>,806    f64attr = array<f64: 0.0, 3.1>,807    emptyattr = array<i16>808  } : () -> ()809  func.return810}811 812// -----813 814//===----------------------------------------------------------------------===//815// Test SymbolRefAttr816//===----------------------------------------------------------------------===//817 818func.func @fn() { return }819 820// CHECK: test.symbol_ref_attr821"test.symbol_ref_attr"() {symbol = @fn} : () -> ()822 823// -----824 825//===----------------------------------------------------------------------===//826// Test IntElementsAttr827//===----------------------------------------------------------------------===//828 829func.func @correct_int_elements_attr_pass() {830  "test.int_elements_attr"() {831    // CHECK: any_i32_attr = dense<5> : tensor<1x2x3x4xui32>,832    any_i32_attr = dense<5> : tensor<1x2x3x4xui32>,833    i32_attr = dense<5> : tensor<6xi32>834  } : () -> ()835 836  "test.int_elements_attr"() {837    // CHECK: any_i32_attr = dense<5> : tensor<1x2x3x4xsi32>,838    any_i32_attr = dense<5> : tensor<1x2x3x4xsi32>,839    i32_attr = dense<5> : tensor<6xi32>840  } : () -> ()841 842  "test.int_elements_attr"() {843    // CHECK: any_i32_attr = dense<5> : tensor<1x2x3x4xi32>,844    any_i32_attr = dense<5> : tensor<1x2x3x4xi32>,845    i32_attr = dense<5> : tensor<6xi32>846  } : () -> ()847 848  "test.index_elements_attr"() {849    // CHECK: any_index_attr = dense<5> : tensor<1x2x3x4xindex>,850    any_index_attr = dense<5> : tensor<1x2x3x4xindex>,851    index_attr = dense<5> : tensor<6xindex>852  } : () -> ()853 854  "test.hex_index_elements_attr"() {855    // CHECK: hex_index_attr = dense<"0x00000C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000080C0000000000001A150000000000005078000000000000B659010000000000ECBC010000000000FEC5010000000000342902000000000046320200000000007C950200000000008E9E020000000000C401030000000000D60A0300000000000C6E0300000000001E7703000000000054DA03000000000066E30300000000009C46040000000000AE4F040000000000E4B2040000000000F6BB0400000000002C1F050000000000628100000000000098E40000000000000E0C00000000000020150000000000005678000000000000BC59010000000000F2BC01000000000004C60100000000003A290200000000004C320200000000008295020000000000949E020000000000CA01030000000000DC0A030000000000126E03000000000024770300000000005ADA0300000000006CE3030000000000A246040000000000B44F040000000000EAB2040000000000FCBB040000000000321F05000000000068810000000000009EE40000000000"> : tensor<23x5xindex>856    hex_index_attr = dense<"0x00000C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000080C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000100C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000180C000000000000080C0000000000001A150000000000005078000000000000B659010000000000ECBC010000000000FEC5010000000000342902000000000046320200000000007C950200000000008E9E020000000000C401030000000000D60A0300000000000C6E0300000000001E7703000000000054DA03000000000066E30300000000009C46040000000000AE4F040000000000E4B2040000000000F6BB0400000000002C1F050000000000628100000000000098E40000000000000E0C00000000000020150000000000005678000000000000BC59010000000000F2BC01000000000004C60100000000003A290200000000004C320200000000008295020000000000949E020000000000CA01030000000000DC0A030000000000126E03000000000024770300000000005ADA0300000000006CE3030000000000A246040000000000B44F040000000000EAB2040000000000FCBB040000000000321F05000000000068810000000000009EE40000000000"> : tensor<23x5xindex>857  } : () -> ()858 859  return860}861 862// -----863 864func.func @wrong_int_elements_attr_type_fail() {865  // expected-error @+1 {{'any_i32_attr' failed to satisfy constraint: 32-bit integer elements attribute}}866  "test.int_elements_attr"() {867    any_i32_attr = dense<5.0> : tensor<1x2x3x4xf32>,868    i32_attr = dense<5> : tensor<6xi32>869  } : () -> ()870  return871}872 873// -----874 875func.func @wrong_int_elements_attr_signedness_fail() {876  // expected-error @+1 {{'i32_attr' failed to satisfy constraint: 32-bit signless integer elements attribute}}877  "test.int_elements_attr"() {878    any_i32_attr = dense<5> : tensor<1x2x3x4xi32>,879    i32_attr = dense<5> : tensor<6xsi32>880  } : () -> ()881  return882}883 884// -----885 886//===----------------------------------------------------------------------===//887// Test Ranked IntElementsAttr888//===----------------------------------------------------------------------===//889 890func.func @correct_type_pass() {891  "test.ranked_int_elements_attr"() {892    // CHECK: matrix_i64_attr = dense<6> : tensor<4x8xi64>893    // CHECK: vector_i32_attr = dense<5> : tensor<2xi32>894    matrix_i64_attr = dense<6> : tensor<4x8xi64>,895    vector_i32_attr = dense<5> : tensor<2xi32>896  } : () -> ()897  return898}899 900// -----901 902func.func @wrong_element_type_fail() {903  // expected-error @+1 {{failed to satisfy constraint: 32-bit signless int elements attribute of shape [2]}}904  "test.ranked_int_elements_attr"() {905    matrix_i64_attr = dense<6> : tensor<4x8xi64>,906    vector_i32_attr = dense<5> : tensor<2xi64>907  } : () -> ()908  return909}910 911// -----912 913func.func @wrong_shape_fail() {914  // expected-error @+1 {{failed to satisfy constraint: 64-bit signless int elements attribute of shape [4, 8]}}915  "test.ranked_int_elements_attr"() {916    matrix_i64_attr = dense<6> : tensor<4xi64>,917    vector_i32_attr = dense<5> : tensor<2xi32>918  } : () -> ()919  return920}921 922// -----923 924func.func @wrong_shape_fail() {925  // expected-error @+1 {{failed to satisfy constraint: 32-bit signless int elements attribute of shape [2]}}926  "test.ranked_int_elements_attr"() {927    matrix_i64_attr = dense<6> : tensor<4x8xi64>,928    vector_i32_attr = dense<5> : tensor<i32>929  } : () -> ()930  return931}932 933// -----934 935//===----------------------------------------------------------------------===//936// Test DefaultValuedAttr Printing937//===----------------------------------------------------------------------===//938 939// CHECK-LABEL: @default_value_printing940func.func @default_value_printing(%arg0 : i32) {941  // The attribute SHOULD NOT be printed because it is equal to the default942  // CHECK: test.default_value_print %arg0943  "test.default_value_print"(%arg0) {"value_with_default" = 0 : i32} : (i32) -> ()944  // The attribute SHOULD be printed because it is not equal to the default945  // CHECK: test.default_value_print {value_with_default = 1 : i32} %arg0946  "test.default_value_print"(%arg0) {"value_with_default" = 1 : i32} : (i32) -> ()947  return948}949 950// -----951 952func.func @type_attr_of_fail() {953    // expected-error @below {{failed to satisfy constraint: type attribute of 64-bit signless integer}}954    test.type_attr_of i32955    return956}957