| 1 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
| 2 | |* *| |
| 3 | |* Enum Utility Declarations *| |
| 4 | |* *| |
| 5 | |* Automatically generated file, do not edit! *| |
| 6 | |* From: TestEnumDefs.td *| |
| 7 | |* *| |
| 8 | \*===----------------------------------------------------------------------===*/ |
| 9 | |
| 10 | // Multi-result op kinds |
| 11 | enum class MultiResultOpEnum : uint64_t { |
| 12 | kind1 = 1, |
| 13 | kind2 = 2, |
| 14 | kind3 = 3, |
| 15 | kind4 = 4, |
| 16 | kind5 = 5, |
| 17 | kind6 = 6, |
| 18 | }; |
| 19 | |
| 20 | ::std::optional<MultiResultOpEnum> symbolizeMultiResultOpEnum(uint64_t); |
| 21 | ::llvm::StringRef stringifyMultiResultOpEnum(MultiResultOpEnum); |
| 22 | ::std::optional<MultiResultOpEnum> symbolizeMultiResultOpEnum(::llvm::StringRef); |
| 23 | inline constexpr unsigned getMaxEnumValForMultiResultOpEnum() { |
| 24 | return 6; |
| 25 | } |
| 26 | |
| 27 | |
| 28 | inline ::llvm::StringRef stringifyEnum(MultiResultOpEnum enumValue) { |
| 29 | return stringifyMultiResultOpEnum(enumValue); |
| 30 | } |
| 31 | |
| 32 | template <typename EnumType> |
| 33 | ::std::optional<EnumType> symbolizeEnum(::llvm::StringRef); |
| 34 | |
| 35 | template <> |
| 36 | inline ::std::optional<MultiResultOpEnum> symbolizeEnum<MultiResultOpEnum>(::llvm::StringRef str) { |
| 37 | return symbolizeMultiResultOpEnum(str); |
| 38 | } |
| 39 | |
| 40 | class MultiResultOpEnumAttr : public ::mlir::IntegerAttr { |
| 41 | public: |
| 42 | using ValueType = MultiResultOpEnum; |
| 43 | using ::mlir::IntegerAttr::IntegerAttr; |
| 44 | static bool classof(::mlir::Attribute attr); |
| 45 | static MultiResultOpEnumAttr get(::mlir::MLIRContext *context, MultiResultOpEnum val); |
| 46 | MultiResultOpEnum getValue() const; |
| 47 | }; |
| 48 | |
| 49 | namespace mlir { |
| 50 | template <typename T, typename> |
| 51 | struct FieldParser; |
| 52 | |
| 53 | template<> |
| 54 | struct FieldParser<::MultiResultOpEnum, ::MultiResultOpEnum> { |
| 55 | template <typename ParserT> |
| 56 | static FailureOr<::MultiResultOpEnum> parse(ParserT &parser) { |
| 57 | // Parse the keyword/string containing the enum. |
| 58 | std::string enumKeyword; |
| 59 | auto loc = parser.getCurrentLocation(); |
| 60 | if (failed(parser.parseOptionalKeywordOrString(&enumKeyword))) |
| 61 | return parser.emitError(loc, "expected keyword for Multi-result op kinds" ); |
| 62 | |
| 63 | // Symbolize the keyword. |
| 64 | if (::std::optional<::MultiResultOpEnum> attr = ::symbolizeEnum<::MultiResultOpEnum>(str: enumKeyword)) |
| 65 | return *attr; |
| 66 | return parser.emitError(loc, "expected one of [kind1, kind2, kind3, kind4, kind5, kind6] for Multi-result op kinds, got: " ) << enumKeyword; |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | /// Support for std::optional, useful in attribute/type definition where the enum is |
| 71 | /// used as: |
| 72 | /// |
| 73 | /// let parameters = (ins OptionalParameter<"std::optional<TheEnumName>">:$value); |
| 74 | template<> |
| 75 | struct FieldParser<std::optional<::MultiResultOpEnum>, std::optional<::MultiResultOpEnum>> { |
| 76 | template <typename ParserT> |
| 77 | static FailureOr<std::optional<::MultiResultOpEnum>> parse(ParserT &parser) { |
| 78 | // Parse the keyword/string containing the enum. |
| 79 | std::string enumKeyword; |
| 80 | auto loc = parser.getCurrentLocation(); |
| 81 | if (failed(parser.parseOptionalKeywordOrString(&enumKeyword))) |
| 82 | return std::optional<::MultiResultOpEnum>{}; |
| 83 | |
| 84 | // Symbolize the keyword. |
| 85 | if (::std::optional<::MultiResultOpEnum> attr = ::symbolizeEnum<::MultiResultOpEnum>(str: enumKeyword)) |
| 86 | return attr; |
| 87 | return parser.emitError(loc, "expected one of [kind1, kind2, kind3, kind4, kind5, kind6] for Multi-result op kinds, got: " ) << enumKeyword; |
| 88 | } |
| 89 | }; |
| 90 | } // namespace mlir |
| 91 | |
| 92 | namespace llvm { |
| 93 | inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, ::MultiResultOpEnum value) { |
| 94 | auto valueStr = stringifyEnum(enumValue: value); |
| 95 | return p << valueStr; |
| 96 | } |
| 97 | } // namespace llvm |
| 98 | |
| 99 | namespace llvm { |
| 100 | template<> struct DenseMapInfo<::MultiResultOpEnum> { |
| 101 | using StorageInfo = ::llvm::DenseMapInfo<uint64_t>; |
| 102 | |
| 103 | static inline ::MultiResultOpEnum getEmptyKey() { |
| 104 | return static_cast<::MultiResultOpEnum>(StorageInfo::getEmptyKey()); |
| 105 | } |
| 106 | |
| 107 | static inline ::MultiResultOpEnum getTombstoneKey() { |
| 108 | return static_cast<::MultiResultOpEnum>(StorageInfo::getTombstoneKey()); |
| 109 | } |
| 110 | |
| 111 | static unsigned getHashValue(const ::MultiResultOpEnum &val) { |
| 112 | return StorageInfo::getHashValue(Val: static_cast<uint64_t>(val)); |
| 113 | } |
| 114 | |
| 115 | static bool isEqual(const ::MultiResultOpEnum &lhs, const ::MultiResultOpEnum &rhs) { |
| 116 | return lhs == rhs; |
| 117 | } |
| 118 | }; |
| 119 | } |
| 120 | |
| 121 | // allowed 32-bit signless integer cases: 5, 10, 2147483648, 4294967295 |
| 122 | enum class SomeI32Enum : uint32_t { |
| 123 | case5 = 5, |
| 124 | case10 = 10, |
| 125 | caseSignedMaxPlusOne = 2147483648, |
| 126 | caseUnsignedMax = 4294967295, |
| 127 | }; |
| 128 | |
| 129 | ::std::optional<SomeI32Enum> symbolizeSomeI32Enum(uint32_t); |
| 130 | ::llvm::StringRef stringifySomeI32Enum(SomeI32Enum); |
| 131 | ::std::optional<SomeI32Enum> symbolizeSomeI32Enum(::llvm::StringRef); |
| 132 | inline constexpr unsigned getMaxEnumValForSomeI32Enum() { |
| 133 | return 4294967295; |
| 134 | } |
| 135 | |
| 136 | |
| 137 | inline ::llvm::StringRef stringifyEnum(SomeI32Enum enumValue) { |
| 138 | return stringifySomeI32Enum(enumValue); |
| 139 | } |
| 140 | |
| 141 | template <typename EnumType> |
| 142 | ::std::optional<EnumType> symbolizeEnum(::llvm::StringRef); |
| 143 | |
| 144 | template <> |
| 145 | inline ::std::optional<SomeI32Enum> symbolizeEnum<SomeI32Enum>(::llvm::StringRef str) { |
| 146 | return symbolizeSomeI32Enum(str); |
| 147 | } |
| 148 | |
| 149 | class SomeI32EnumAttr : public ::mlir::IntegerAttr { |
| 150 | public: |
| 151 | using ValueType = SomeI32Enum; |
| 152 | using ::mlir::IntegerAttr::IntegerAttr; |
| 153 | static bool classof(::mlir::Attribute attr); |
| 154 | static SomeI32EnumAttr get(::mlir::MLIRContext *context, SomeI32Enum val); |
| 155 | SomeI32Enum getValue() const; |
| 156 | }; |
| 157 | |
| 158 | namespace mlir { |
| 159 | template <typename T, typename> |
| 160 | struct FieldParser; |
| 161 | |
| 162 | template<> |
| 163 | struct FieldParser<::SomeI32Enum, ::SomeI32Enum> { |
| 164 | template <typename ParserT> |
| 165 | static FailureOr<::SomeI32Enum> parse(ParserT &parser) { |
| 166 | // Parse the keyword/string containing the enum. |
| 167 | std::string enumKeyword; |
| 168 | auto loc = parser.getCurrentLocation(); |
| 169 | if (failed(parser.parseOptionalKeywordOrString(&enumKeyword))) |
| 170 | return parser.emitError(loc, "expected keyword for allowed 32-bit signless integer cases: 5, 10, 2147483648, 4294967295" ); |
| 171 | |
| 172 | // Symbolize the keyword. |
| 173 | if (::std::optional<::SomeI32Enum> attr = ::symbolizeEnum<::SomeI32Enum>(str: enumKeyword)) |
| 174 | return *attr; |
| 175 | return parser.emitError(loc, "expected one of [case5, case10, caseSignedMaxPlusOne, caseUnsignedMax] for allowed 32-bit signless integer cases: 5, 10, 2147483648, 4294967295, got: " ) << enumKeyword; |
| 176 | } |
| 177 | }; |
| 178 | |
| 179 | /// Support for std::optional, useful in attribute/type definition where the enum is |
| 180 | /// used as: |
| 181 | /// |
| 182 | /// let parameters = (ins OptionalParameter<"std::optional<TheEnumName>">:$value); |
| 183 | template<> |
| 184 | struct FieldParser<std::optional<::SomeI32Enum>, std::optional<::SomeI32Enum>> { |
| 185 | template <typename ParserT> |
| 186 | static FailureOr<std::optional<::SomeI32Enum>> parse(ParserT &parser) { |
| 187 | // Parse the keyword/string containing the enum. |
| 188 | std::string enumKeyword; |
| 189 | auto loc = parser.getCurrentLocation(); |
| 190 | if (failed(parser.parseOptionalKeywordOrString(&enumKeyword))) |
| 191 | return std::optional<::SomeI32Enum>{}; |
| 192 | |
| 193 | // Symbolize the keyword. |
| 194 | if (::std::optional<::SomeI32Enum> attr = ::symbolizeEnum<::SomeI32Enum>(str: enumKeyword)) |
| 195 | return attr; |
| 196 | return parser.emitError(loc, "expected one of [case5, case10, caseSignedMaxPlusOne, caseUnsignedMax] for allowed 32-bit signless integer cases: 5, 10, 2147483648, 4294967295, got: " ) << enumKeyword; |
| 197 | } |
| 198 | }; |
| 199 | } // namespace mlir |
| 200 | |
| 201 | namespace llvm { |
| 202 | inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, ::SomeI32Enum value) { |
| 203 | auto valueStr = stringifyEnum(enumValue: value); |
| 204 | return p << valueStr; |
| 205 | } |
| 206 | } // namespace llvm |
| 207 | |
| 208 | namespace llvm { |
| 209 | template<> struct DenseMapInfo<::SomeI32Enum> { |
| 210 | using StorageInfo = ::llvm::DenseMapInfo<uint32_t>; |
| 211 | |
| 212 | static inline ::SomeI32Enum getEmptyKey() { |
| 213 | return static_cast<::SomeI32Enum>(StorageInfo::getEmptyKey()); |
| 214 | } |
| 215 | |
| 216 | static inline ::SomeI32Enum getTombstoneKey() { |
| 217 | return static_cast<::SomeI32Enum>(StorageInfo::getTombstoneKey()); |
| 218 | } |
| 219 | |
| 220 | static unsigned getHashValue(const ::SomeI32Enum &val) { |
| 221 | return StorageInfo::getHashValue(Val: static_cast<uint32_t>(val)); |
| 222 | } |
| 223 | |
| 224 | static bool isEqual(const ::SomeI32Enum &lhs, const ::SomeI32Enum &rhs) { |
| 225 | return lhs == rhs; |
| 226 | } |
| 227 | }; |
| 228 | } |
| 229 | |
| 230 | // allowed 64-bit signless integer cases: 5, 10 |
| 231 | enum class SomeI64Enum : uint64_t { |
| 232 | case5 = 5, |
| 233 | case10 = 10, |
| 234 | }; |
| 235 | |
| 236 | ::std::optional<SomeI64Enum> symbolizeSomeI64Enum(uint64_t); |
| 237 | ::llvm::StringRef stringifySomeI64Enum(SomeI64Enum); |
| 238 | ::std::optional<SomeI64Enum> symbolizeSomeI64Enum(::llvm::StringRef); |
| 239 | inline constexpr unsigned getMaxEnumValForSomeI64Enum() { |
| 240 | return 10; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | inline ::llvm::StringRef stringifyEnum(SomeI64Enum enumValue) { |
| 245 | return stringifySomeI64Enum(enumValue); |
| 246 | } |
| 247 | |
| 248 | template <typename EnumType> |
| 249 | ::std::optional<EnumType> symbolizeEnum(::llvm::StringRef); |
| 250 | |
| 251 | template <> |
| 252 | inline ::std::optional<SomeI64Enum> symbolizeEnum<SomeI64Enum>(::llvm::StringRef str) { |
| 253 | return symbolizeSomeI64Enum(str); |
| 254 | } |
| 255 | |
| 256 | class SomeI64EnumAttr : public ::mlir::IntegerAttr { |
| 257 | public: |
| 258 | using ValueType = SomeI64Enum; |
| 259 | using ::mlir::IntegerAttr::IntegerAttr; |
| 260 | static bool classof(::mlir::Attribute attr); |
| 261 | static SomeI64EnumAttr get(::mlir::MLIRContext *context, SomeI64Enum val); |
| 262 | SomeI64Enum getValue() const; |
| 263 | }; |
| 264 | |
| 265 | namespace mlir { |
| 266 | template <typename T, typename> |
| 267 | struct FieldParser; |
| 268 | |
| 269 | template<> |
| 270 | struct FieldParser<::SomeI64Enum, ::SomeI64Enum> { |
| 271 | template <typename ParserT> |
| 272 | static FailureOr<::SomeI64Enum> parse(ParserT &parser) { |
| 273 | // Parse the keyword/string containing the enum. |
| 274 | std::string enumKeyword; |
| 275 | auto loc = parser.getCurrentLocation(); |
| 276 | if (failed(parser.parseOptionalKeywordOrString(&enumKeyword))) |
| 277 | return parser.emitError(loc, "expected keyword for allowed 64-bit signless integer cases: 5, 10" ); |
| 278 | |
| 279 | // Symbolize the keyword. |
| 280 | if (::std::optional<::SomeI64Enum> attr = ::symbolizeEnum<::SomeI64Enum>(str: enumKeyword)) |
| 281 | return *attr; |
| 282 | return parser.emitError(loc, "expected one of [case5, case10] for allowed 64-bit signless integer cases: 5, 10, got: " ) << enumKeyword; |
| 283 | } |
| 284 | }; |
| 285 | |
| 286 | /// Support for std::optional, useful in attribute/type definition where the enum is |
| 287 | /// used as: |
| 288 | /// |
| 289 | /// let parameters = (ins OptionalParameter<"std::optional<TheEnumName>">:$value); |
| 290 | template<> |
| 291 | struct FieldParser<std::optional<::SomeI64Enum>, std::optional<::SomeI64Enum>> { |
| 292 | template <typename ParserT> |
| 293 | static FailureOr<std::optional<::SomeI64Enum>> parse(ParserT &parser) { |
| 294 | // Parse the keyword/string containing the enum. |
| 295 | std::string enumKeyword; |
| 296 | auto loc = parser.getCurrentLocation(); |
| 297 | if (failed(parser.parseOptionalKeywordOrString(&enumKeyword))) |
| 298 | return std::optional<::SomeI64Enum>{}; |
| 299 | |
| 300 | // Symbolize the keyword. |
| 301 | if (::std::optional<::SomeI64Enum> attr = ::symbolizeEnum<::SomeI64Enum>(str: enumKeyword)) |
| 302 | return attr; |
| 303 | return parser.emitError(loc, "expected one of [case5, case10] for allowed 64-bit signless integer cases: 5, 10, got: " ) << enumKeyword; |
| 304 | } |
| 305 | }; |
| 306 | } // namespace mlir |
| 307 | |
| 308 | namespace llvm { |
| 309 | inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, ::SomeI64Enum value) { |
| 310 | auto valueStr = stringifyEnum(enumValue: value); |
| 311 | return p << valueStr; |
| 312 | } |
| 313 | } // namespace llvm |
| 314 | |
| 315 | namespace llvm { |
| 316 | template<> struct DenseMapInfo<::SomeI64Enum> { |
| 317 | using StorageInfo = ::llvm::DenseMapInfo<uint64_t>; |
| 318 | |
| 319 | static inline ::SomeI64Enum getEmptyKey() { |
| 320 | return static_cast<::SomeI64Enum>(StorageInfo::getEmptyKey()); |
| 321 | } |
| 322 | |
| 323 | static inline ::SomeI64Enum getTombstoneKey() { |
| 324 | return static_cast<::SomeI64Enum>(StorageInfo::getTombstoneKey()); |
| 325 | } |
| 326 | |
| 327 | static unsigned getHashValue(const ::SomeI64Enum &val) { |
| 328 | return StorageInfo::getHashValue(Val: static_cast<uint64_t>(val)); |
| 329 | } |
| 330 | |
| 331 | static bool isEqual(const ::SomeI64Enum &lhs, const ::SomeI64Enum &rhs) { |
| 332 | return lhs == rhs; |
| 333 | } |
| 334 | }; |
| 335 | } |
| 336 | |
| 337 | namespace test { |
| 338 | // a test bit enum |
| 339 | enum class TestBitEnum : uint32_t { |
| 340 | Read = 1, |
| 341 | Write = 2, |
| 342 | Execute = 4, |
| 343 | }; |
| 344 | |
| 345 | ::std::optional<TestBitEnum> symbolizeTestBitEnum(uint32_t); |
| 346 | std::string stringifyTestBitEnum(TestBitEnum); |
| 347 | ::std::optional<TestBitEnum> symbolizeTestBitEnum(::llvm::StringRef); |
| 348 | |
| 349 | inline constexpr TestBitEnum operator|(TestBitEnum a, TestBitEnum b) { |
| 350 | return static_cast<TestBitEnum>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b)); |
| 351 | } |
| 352 | inline constexpr TestBitEnum operator&(TestBitEnum a, TestBitEnum b) { |
| 353 | return static_cast<TestBitEnum>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b)); |
| 354 | } |
| 355 | inline constexpr TestBitEnum operator^(TestBitEnum a, TestBitEnum b) { |
| 356 | return static_cast<TestBitEnum>(static_cast<uint32_t>(a) ^ static_cast<uint32_t>(b)); |
| 357 | } |
| 358 | inline constexpr TestBitEnum operator~(TestBitEnum bits) { |
| 359 | // Ensure only bits that can be present in the enum are set |
| 360 | return static_cast<TestBitEnum>(~static_cast<uint32_t>(bits) & static_cast<uint32_t>(7u)); |
| 361 | } |
| 362 | inline constexpr bool bitEnumContainsAll(TestBitEnum bits, TestBitEnum bit) { |
| 363 | return (bits & bit) == bit; |
| 364 | } |
| 365 | inline constexpr bool bitEnumContainsAny(TestBitEnum bits, TestBitEnum bit) { |
| 366 | return (static_cast<uint32_t>(bits) & static_cast<uint32_t>(bit)) != 0; |
| 367 | } |
| 368 | inline constexpr TestBitEnum bitEnumClear(TestBitEnum bits, TestBitEnum bit) { |
| 369 | return bits & ~bit; |
| 370 | } |
| 371 | inline constexpr TestBitEnum bitEnumSet(TestBitEnum bits, TestBitEnum bit, /*optional*/bool value=true) { |
| 372 | return value ? (bits | bit) : bitEnumClear(bits, bit); |
| 373 | } |
| 374 | |
| 375 | inline std::string stringifyEnum(TestBitEnum enumValue) { |
| 376 | return stringifyTestBitEnum(enumValue); |
| 377 | } |
| 378 | |
| 379 | template <typename EnumType> |
| 380 | ::std::optional<EnumType> symbolizeEnum(::llvm::StringRef); |
| 381 | |
| 382 | template <> |
| 383 | inline ::std::optional<TestBitEnum> symbolizeEnum<TestBitEnum>(::llvm::StringRef str) { |
| 384 | return symbolizeTestBitEnum(str); |
| 385 | } |
| 386 | } // namespace test |
| 387 | |
| 388 | namespace mlir { |
| 389 | template <typename T, typename> |
| 390 | struct FieldParser; |
| 391 | |
| 392 | template<> |
| 393 | struct FieldParser<test::TestBitEnum, test::TestBitEnum> { |
| 394 | template <typename ParserT> |
| 395 | static FailureOr<test::TestBitEnum> parse(ParserT &parser) { |
| 396 | test::TestBitEnum flags = {}; |
| 397 | do { |
| 398 | // Parse the keyword containing a part of the enum. |
| 399 | ::llvm::StringRef enumKeyword; |
| 400 | auto loc = parser.getCurrentLocation(); |
| 401 | if (failed(parser.parseOptionalKeyword(&enumKeyword))) { |
| 402 | return parser.emitError(loc, "expected keyword for a test bit enum" ); |
| 403 | } |
| 404 | |
| 405 | // Symbolize the keyword. |
| 406 | if (::std::optional<test::TestBitEnum> flag = test::symbolizeEnum<test::TestBitEnum>(str: enumKeyword)) { |
| 407 | flags = flags | *flag; |
| 408 | } else { |
| 409 | return parser.emitError(loc, "expected one of [read, write, execute] for a test bit enum, got: " ) << enumKeyword; |
| 410 | } |
| 411 | } while (::mlir::succeeded(Result: parser.parseOptionalComma())); |
| 412 | return flags; |
| 413 | } |
| 414 | }; |
| 415 | |
| 416 | /// Support for std::optional, useful in attribute/type definition where the enum is |
| 417 | /// used as: |
| 418 | /// |
| 419 | /// let parameters = (ins OptionalParameter<"std::optional<TheEnumName>">:$value); |
| 420 | template<> |
| 421 | struct FieldParser<std::optional<test::TestBitEnum>, std::optional<test::TestBitEnum>> { |
| 422 | template <typename ParserT> |
| 423 | static FailureOr<std::optional<test::TestBitEnum>> parse(ParserT &parser) { |
| 424 | test::TestBitEnum flags = {}; |
| 425 | bool firstIter = true; |
| 426 | do { |
| 427 | // Parse the keyword containing a part of the enum. |
| 428 | ::llvm::StringRef enumKeyword; |
| 429 | auto loc = parser.getCurrentLocation(); |
| 430 | if (failed(parser.parseOptionalKeyword(&enumKeyword))) { |
| 431 | if (firstIter) |
| 432 | return std::optional<test::TestBitEnum>{}; |
| 433 | return parser.emitError(loc, "expected keyword for a test bit enum after ', '" ); |
| 434 | } |
| 435 | firstIter = false; |
| 436 | |
| 437 | // Symbolize the keyword. |
| 438 | if (::std::optional<test::TestBitEnum> flag = test::symbolizeEnum<test::TestBitEnum>(str: enumKeyword)) { |
| 439 | flags = flags | *flag; |
| 440 | } else { |
| 441 | return parser.emitError(loc, "expected one of [read, write, execute] for a test bit enum, got: " ) << enumKeyword; |
| 442 | } |
| 443 | } while(::mlir::succeeded(Result: parser.parseOptionalComma())); |
| 444 | return std::optional<test::TestBitEnum>{flags}; |
| 445 | } |
| 446 | }; |
| 447 | } // namespace mlir |
| 448 | |
| 449 | namespace llvm { |
| 450 | inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, test::TestBitEnum value) { |
| 451 | auto valueStr = stringifyEnum(enumValue: value); |
| 452 | return p << valueStr; |
| 453 | } |
| 454 | } // namespace llvm |
| 455 | |
| 456 | namespace llvm { |
| 457 | template<> struct DenseMapInfo<test::TestBitEnum> { |
| 458 | using StorageInfo = ::llvm::DenseMapInfo<uint32_t>; |
| 459 | |
| 460 | static inline test::TestBitEnum getEmptyKey() { |
| 461 | return static_cast<test::TestBitEnum>(StorageInfo::getEmptyKey()); |
| 462 | } |
| 463 | |
| 464 | static inline test::TestBitEnum getTombstoneKey() { |
| 465 | return static_cast<test::TestBitEnum>(StorageInfo::getTombstoneKey()); |
| 466 | } |
| 467 | |
| 468 | static unsigned getHashValue(const test::TestBitEnum &val) { |
| 469 | return StorageInfo::getHashValue(Val: static_cast<uint32_t>(val)); |
| 470 | } |
| 471 | |
| 472 | static bool isEqual(const test::TestBitEnum &lhs, const test::TestBitEnum &rhs) { |
| 473 | return lhs == rhs; |
| 474 | } |
| 475 | }; |
| 476 | } |
| 477 | |
| 478 | namespace test { |
| 479 | // another test bit enum |
| 480 | enum class TestBitEnumVerticalBar : uint32_t { |
| 481 | User = 1, |
| 482 | Group = 2, |
| 483 | Other = 4, |
| 484 | }; |
| 485 | |
| 486 | ::std::optional<TestBitEnumVerticalBar> symbolizeTestBitEnumVerticalBar(uint32_t); |
| 487 | std::string stringifyTestBitEnumVerticalBar(TestBitEnumVerticalBar); |
| 488 | ::std::optional<TestBitEnumVerticalBar> symbolizeTestBitEnumVerticalBar(::llvm::StringRef); |
| 489 | |
| 490 | inline constexpr TestBitEnumVerticalBar operator|(TestBitEnumVerticalBar a, TestBitEnumVerticalBar b) { |
| 491 | return static_cast<TestBitEnumVerticalBar>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b)); |
| 492 | } |
| 493 | inline constexpr TestBitEnumVerticalBar operator&(TestBitEnumVerticalBar a, TestBitEnumVerticalBar b) { |
| 494 | return static_cast<TestBitEnumVerticalBar>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b)); |
| 495 | } |
| 496 | inline constexpr TestBitEnumVerticalBar operator^(TestBitEnumVerticalBar a, TestBitEnumVerticalBar b) { |
| 497 | return static_cast<TestBitEnumVerticalBar>(static_cast<uint32_t>(a) ^ static_cast<uint32_t>(b)); |
| 498 | } |
| 499 | inline constexpr TestBitEnumVerticalBar operator~(TestBitEnumVerticalBar bits) { |
| 500 | // Ensure only bits that can be present in the enum are set |
| 501 | return static_cast<TestBitEnumVerticalBar>(~static_cast<uint32_t>(bits) & static_cast<uint32_t>(7u)); |
| 502 | } |
| 503 | inline constexpr bool bitEnumContainsAll(TestBitEnumVerticalBar bits, TestBitEnumVerticalBar bit) { |
| 504 | return (bits & bit) == bit; |
| 505 | } |
| 506 | inline constexpr bool bitEnumContainsAny(TestBitEnumVerticalBar bits, TestBitEnumVerticalBar bit) { |
| 507 | return (static_cast<uint32_t>(bits) & static_cast<uint32_t>(bit)) != 0; |
| 508 | } |
| 509 | inline constexpr TestBitEnumVerticalBar bitEnumClear(TestBitEnumVerticalBar bits, TestBitEnumVerticalBar bit) { |
| 510 | return bits & ~bit; |
| 511 | } |
| 512 | inline constexpr TestBitEnumVerticalBar bitEnumSet(TestBitEnumVerticalBar bits, TestBitEnumVerticalBar bit, /*optional*/bool value=true) { |
| 513 | return value ? (bits | bit) : bitEnumClear(bits, bit); |
| 514 | } |
| 515 | |
| 516 | inline std::string stringifyEnum(TestBitEnumVerticalBar enumValue) { |
| 517 | return stringifyTestBitEnumVerticalBar(enumValue); |
| 518 | } |
| 519 | |
| 520 | template <typename EnumType> |
| 521 | ::std::optional<EnumType> symbolizeEnum(::llvm::StringRef); |
| 522 | |
| 523 | template <> |
| 524 | inline ::std::optional<TestBitEnumVerticalBar> symbolizeEnum<TestBitEnumVerticalBar>(::llvm::StringRef str) { |
| 525 | return symbolizeTestBitEnumVerticalBar(str); |
| 526 | } |
| 527 | } // namespace test |
| 528 | |
| 529 | namespace mlir { |
| 530 | template <typename T, typename> |
| 531 | struct FieldParser; |
| 532 | |
| 533 | template<> |
| 534 | struct FieldParser<test::TestBitEnumVerticalBar, test::TestBitEnumVerticalBar> { |
| 535 | template <typename ParserT> |
| 536 | static FailureOr<test::TestBitEnumVerticalBar> parse(ParserT &parser) { |
| 537 | test::TestBitEnumVerticalBar flags = {}; |
| 538 | do { |
| 539 | // Parse the keyword containing a part of the enum. |
| 540 | ::llvm::StringRef enumKeyword; |
| 541 | auto loc = parser.getCurrentLocation(); |
| 542 | if (failed(parser.parseOptionalKeyword(&enumKeyword))) { |
| 543 | return parser.emitError(loc, "expected keyword for another test bit enum" ); |
| 544 | } |
| 545 | |
| 546 | // Symbolize the keyword. |
| 547 | if (::std::optional<test::TestBitEnumVerticalBar> flag = test::symbolizeEnum<test::TestBitEnumVerticalBar>(str: enumKeyword)) { |
| 548 | flags = flags | *flag; |
| 549 | } else { |
| 550 | return parser.emitError(loc, "expected one of [user, group, other] for another test bit enum, got: " ) << enumKeyword; |
| 551 | } |
| 552 | } while (::mlir::succeeded(Result: parser.parseOptionalVerticalBar())); |
| 553 | return flags; |
| 554 | } |
| 555 | }; |
| 556 | |
| 557 | /// Support for std::optional, useful in attribute/type definition where the enum is |
| 558 | /// used as: |
| 559 | /// |
| 560 | /// let parameters = (ins OptionalParameter<"std::optional<TheEnumName>">:$value); |
| 561 | template<> |
| 562 | struct FieldParser<std::optional<test::TestBitEnumVerticalBar>, std::optional<test::TestBitEnumVerticalBar>> { |
| 563 | template <typename ParserT> |
| 564 | static FailureOr<std::optional<test::TestBitEnumVerticalBar>> parse(ParserT &parser) { |
| 565 | test::TestBitEnumVerticalBar flags = {}; |
| 566 | bool firstIter = true; |
| 567 | do { |
| 568 | // Parse the keyword containing a part of the enum. |
| 569 | ::llvm::StringRef enumKeyword; |
| 570 | auto loc = parser.getCurrentLocation(); |
| 571 | if (failed(parser.parseOptionalKeyword(&enumKeyword))) { |
| 572 | if (firstIter) |
| 573 | return std::optional<test::TestBitEnumVerticalBar>{}; |
| 574 | return parser.emitError(loc, "expected keyword for another test bit enum after ' | '" ); |
| 575 | } |
| 576 | firstIter = false; |
| 577 | |
| 578 | // Symbolize the keyword. |
| 579 | if (::std::optional<test::TestBitEnumVerticalBar> flag = test::symbolizeEnum<test::TestBitEnumVerticalBar>(str: enumKeyword)) { |
| 580 | flags = flags | *flag; |
| 581 | } else { |
| 582 | return parser.emitError(loc, "expected one of [user, group, other] for another test bit enum, got: " ) << enumKeyword; |
| 583 | } |
| 584 | } while(::mlir::succeeded(Result: parser.parseOptionalVerticalBar())); |
| 585 | return std::optional<test::TestBitEnumVerticalBar>{flags}; |
| 586 | } |
| 587 | }; |
| 588 | } // namespace mlir |
| 589 | |
| 590 | namespace llvm { |
| 591 | inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, test::TestBitEnumVerticalBar value) { |
| 592 | auto valueStr = stringifyEnum(enumValue: value); |
| 593 | return p << valueStr; |
| 594 | } |
| 595 | } // namespace llvm |
| 596 | |
| 597 | namespace llvm { |
| 598 | template<> struct DenseMapInfo<test::TestBitEnumVerticalBar> { |
| 599 | using StorageInfo = ::llvm::DenseMapInfo<uint32_t>; |
| 600 | |
| 601 | static inline test::TestBitEnumVerticalBar getEmptyKey() { |
| 602 | return static_cast<test::TestBitEnumVerticalBar>(StorageInfo::getEmptyKey()); |
| 603 | } |
| 604 | |
| 605 | static inline test::TestBitEnumVerticalBar getTombstoneKey() { |
| 606 | return static_cast<test::TestBitEnumVerticalBar>(StorageInfo::getTombstoneKey()); |
| 607 | } |
| 608 | |
| 609 | static unsigned getHashValue(const test::TestBitEnumVerticalBar &val) { |
| 610 | return StorageInfo::getHashValue(Val: static_cast<uint32_t>(val)); |
| 611 | } |
| 612 | |
| 613 | static bool isEqual(const test::TestBitEnumVerticalBar &lhs, const test::TestBitEnumVerticalBar &rhs) { |
| 614 | return lhs == rhs; |
| 615 | } |
| 616 | }; |
| 617 | } |
| 618 | |
| 619 | namespace test { |
| 620 | // a test enum |
| 621 | enum class TestEnum : uint32_t { |
| 622 | First = 0, |
| 623 | Second = 1, |
| 624 | Third = 2, |
| 625 | }; |
| 626 | |
| 627 | ::std::optional<TestEnum> symbolizeTestEnum(uint32_t); |
| 628 | ::llvm::StringRef stringifyTestEnum(TestEnum); |
| 629 | ::std::optional<TestEnum> symbolizeTestEnum(::llvm::StringRef); |
| 630 | inline constexpr unsigned getMaxEnumValForTestEnum() { |
| 631 | return 2; |
| 632 | } |
| 633 | |
| 634 | |
| 635 | inline ::llvm::StringRef stringifyEnum(TestEnum enumValue) { |
| 636 | return stringifyTestEnum(enumValue); |
| 637 | } |
| 638 | |
| 639 | template <typename EnumType> |
| 640 | ::std::optional<EnumType> symbolizeEnum(::llvm::StringRef); |
| 641 | |
| 642 | template <> |
| 643 | inline ::std::optional<TestEnum> symbolizeEnum<TestEnum>(::llvm::StringRef str) { |
| 644 | return symbolizeTestEnum(str); |
| 645 | } |
| 646 | } // namespace test |
| 647 | |
| 648 | namespace mlir { |
| 649 | template <typename T, typename> |
| 650 | struct FieldParser; |
| 651 | |
| 652 | template<> |
| 653 | struct FieldParser<test::TestEnum, test::TestEnum> { |
| 654 | template <typename ParserT> |
| 655 | static FailureOr<test::TestEnum> parse(ParserT &parser) { |
| 656 | // Parse the keyword/string containing the enum. |
| 657 | std::string enumKeyword; |
| 658 | auto loc = parser.getCurrentLocation(); |
| 659 | if (failed(parser.parseOptionalKeywordOrString(&enumKeyword))) |
| 660 | return parser.emitError(loc, "expected keyword for a test enum" ); |
| 661 | |
| 662 | // Symbolize the keyword. |
| 663 | if (::std::optional<test::TestEnum> attr = test::symbolizeEnum<test::TestEnum>(str: enumKeyword)) |
| 664 | return *attr; |
| 665 | return parser.emitError(loc, "expected one of [first, second, third] for a test enum, got: " ) << enumKeyword; |
| 666 | } |
| 667 | }; |
| 668 | |
| 669 | /// Support for std::optional, useful in attribute/type definition where the enum is |
| 670 | /// used as: |
| 671 | /// |
| 672 | /// let parameters = (ins OptionalParameter<"std::optional<TheEnumName>">:$value); |
| 673 | template<> |
| 674 | struct FieldParser<std::optional<test::TestEnum>, std::optional<test::TestEnum>> { |
| 675 | template <typename ParserT> |
| 676 | static FailureOr<std::optional<test::TestEnum>> parse(ParserT &parser) { |
| 677 | // Parse the keyword/string containing the enum. |
| 678 | std::string enumKeyword; |
| 679 | auto loc = parser.getCurrentLocation(); |
| 680 | if (failed(parser.parseOptionalKeywordOrString(&enumKeyword))) |
| 681 | return std::optional<test::TestEnum>{}; |
| 682 | |
| 683 | // Symbolize the keyword. |
| 684 | if (::std::optional<test::TestEnum> attr = test::symbolizeEnum<test::TestEnum>(str: enumKeyword)) |
| 685 | return attr; |
| 686 | return parser.emitError(loc, "expected one of [first, second, third] for a test enum, got: " ) << enumKeyword; |
| 687 | } |
| 688 | }; |
| 689 | } // namespace mlir |
| 690 | |
| 691 | namespace llvm { |
| 692 | inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, test::TestEnum value) { |
| 693 | auto valueStr = stringifyEnum(enumValue: value); |
| 694 | return p << valueStr; |
| 695 | } |
| 696 | } // namespace llvm |
| 697 | |
| 698 | namespace llvm { |
| 699 | template<> struct DenseMapInfo<test::TestEnum> { |
| 700 | using StorageInfo = ::llvm::DenseMapInfo<uint32_t>; |
| 701 | |
| 702 | static inline test::TestEnum getEmptyKey() { |
| 703 | return static_cast<test::TestEnum>(StorageInfo::getEmptyKey()); |
| 704 | } |
| 705 | |
| 706 | static inline test::TestEnum getTombstoneKey() { |
| 707 | return static_cast<test::TestEnum>(StorageInfo::getTombstoneKey()); |
| 708 | } |
| 709 | |
| 710 | static unsigned getHashValue(const test::TestEnum &val) { |
| 711 | return StorageInfo::getHashValue(Val: static_cast<uint32_t>(val)); |
| 712 | } |
| 713 | |
| 714 | static bool isEqual(const test::TestEnum &lhs, const test::TestEnum &rhs) { |
| 715 | return lhs == rhs; |
| 716 | } |
| 717 | }; |
| 718 | } |
| 719 | |
| 720 | namespace test { |
| 721 | // allowed i32 cases: 0, 1 |
| 722 | enum class SimpleEnum : uint32_t { |
| 723 | a = 0, |
| 724 | b = 1, |
| 725 | }; |
| 726 | |
| 727 | ::std::optional<SimpleEnum> symbolizeSimpleEnum(uint32_t); |
| 728 | ::llvm::StringRef stringifySimpleEnum(SimpleEnum); |
| 729 | ::std::optional<SimpleEnum> symbolizeSimpleEnum(::llvm::StringRef); |
| 730 | inline constexpr unsigned getMaxEnumValForSimpleEnum() { |
| 731 | return 1; |
| 732 | } |
| 733 | |
| 734 | |
| 735 | inline ::llvm::StringRef stringifyEnum(SimpleEnum enumValue) { |
| 736 | return stringifySimpleEnum(enumValue); |
| 737 | } |
| 738 | |
| 739 | template <typename EnumType> |
| 740 | ::std::optional<EnumType> symbolizeEnum(::llvm::StringRef); |
| 741 | |
| 742 | template <> |
| 743 | inline ::std::optional<SimpleEnum> symbolizeEnum<SimpleEnum>(::llvm::StringRef str) { |
| 744 | return symbolizeSimpleEnum(str); |
| 745 | } |
| 746 | } // namespace test |
| 747 | |
| 748 | namespace mlir { |
| 749 | template <typename T, typename> |
| 750 | struct FieldParser; |
| 751 | |
| 752 | template<> |
| 753 | struct FieldParser<::test::SimpleEnum, ::test::SimpleEnum> { |
| 754 | template <typename ParserT> |
| 755 | static FailureOr<::test::SimpleEnum> parse(ParserT &parser) { |
| 756 | // Parse the keyword/string containing the enum. |
| 757 | std::string enumKeyword; |
| 758 | auto loc = parser.getCurrentLocation(); |
| 759 | if (failed(parser.parseOptionalKeywordOrString(&enumKeyword))) |
| 760 | return parser.emitError(loc, "expected keyword for allowed i32 cases: 0, 1" ); |
| 761 | |
| 762 | // Symbolize the keyword. |
| 763 | if (::std::optional<::test::SimpleEnum> attr = ::test::symbolizeEnum<::test::SimpleEnum>(str: enumKeyword)) |
| 764 | return *attr; |
| 765 | return parser.emitError(loc, "expected one of [a, b] for allowed i32 cases: 0, 1, got: " ) << enumKeyword; |
| 766 | } |
| 767 | }; |
| 768 | |
| 769 | /// Support for std::optional, useful in attribute/type definition where the enum is |
| 770 | /// used as: |
| 771 | /// |
| 772 | /// let parameters = (ins OptionalParameter<"std::optional<TheEnumName>">:$value); |
| 773 | template<> |
| 774 | struct FieldParser<std::optional<::test::SimpleEnum>, std::optional<::test::SimpleEnum>> { |
| 775 | template <typename ParserT> |
| 776 | static FailureOr<std::optional<::test::SimpleEnum>> parse(ParserT &parser) { |
| 777 | // Parse the keyword/string containing the enum. |
| 778 | std::string enumKeyword; |
| 779 | auto loc = parser.getCurrentLocation(); |
| 780 | if (failed(parser.parseOptionalKeywordOrString(&enumKeyword))) |
| 781 | return std::optional<::test::SimpleEnum>{}; |
| 782 | |
| 783 | // Symbolize the keyword. |
| 784 | if (::std::optional<::test::SimpleEnum> attr = ::test::symbolizeEnum<::test::SimpleEnum>(str: enumKeyword)) |
| 785 | return attr; |
| 786 | return parser.emitError(loc, "expected one of [a, b] for allowed i32 cases: 0, 1, got: " ) << enumKeyword; |
| 787 | } |
| 788 | }; |
| 789 | } // namespace mlir |
| 790 | |
| 791 | namespace llvm { |
| 792 | inline ::llvm::raw_ostream &operator<<(::llvm::raw_ostream &p, ::test::SimpleEnum value) { |
| 793 | auto valueStr = stringifyEnum(enumValue: value); |
| 794 | return p << valueStr; |
| 795 | } |
| 796 | } // namespace llvm |
| 797 | |
| 798 | namespace llvm { |
| 799 | template<> struct DenseMapInfo<::test::SimpleEnum> { |
| 800 | using StorageInfo = ::llvm::DenseMapInfo<uint32_t>; |
| 801 | |
| 802 | static inline ::test::SimpleEnum getEmptyKey() { |
| 803 | return static_cast<::test::SimpleEnum>(StorageInfo::getEmptyKey()); |
| 804 | } |
| 805 | |
| 806 | static inline ::test::SimpleEnum getTombstoneKey() { |
| 807 | return static_cast<::test::SimpleEnum>(StorageInfo::getTombstoneKey()); |
| 808 | } |
| 809 | |
| 810 | static unsigned getHashValue(const ::test::SimpleEnum &val) { |
| 811 | return StorageInfo::getHashValue(Val: static_cast<uint32_t>(val)); |
| 812 | } |
| 813 | |
| 814 | static bool isEqual(const ::test::SimpleEnum &lhs, const ::test::SimpleEnum &rhs) { |
| 815 | return lhs == rhs; |
| 816 | } |
| 817 | }; |
| 818 | } |
| 819 | |
| 820 | |