1 //===- CodeGen/MachineValueType.h - Machine-Level types ---------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines the set of machine-level target independent types which 11 // legal values in the code generator use. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_CODEGEN_MACHINEVALUETYPE_H 16 #define LLVM_CODEGEN_MACHINEVALUETYPE_H 17 18 #include "llvm/ADT/iterator_range.h" 19 #include "llvm/Support/ErrorHandling.h" 20 #include "llvm/Support/MathExtras.h" 21 22 namespace llvm { 23 24 class Type; 25 26 /// MVT - Machine Value Type. Every type that is supported natively by some 27 /// processor targeted by LLVM occurs here. This means that any legal value 28 /// type can be represented by an MVT. 29 class MVT { 30 public: 31 enum SimpleValueType : int8_t { 32 // INVALID_SIMPLE_VALUE_TYPE - Simple value types less than zero are 33 // considered extended value types. 34 INVALID_SIMPLE_VALUE_TYPE = -1, 35 36 // If you change this numbering, you must change the values in 37 // ValueTypes.td as well! 38 Other = 0, // This is a non-standard value 39 i1 = 1, // This is a 1 bit integer value 40 i8 = 2, // This is an 8 bit integer value 41 i16 = 3, // This is a 16 bit integer value 42 i32 = 4, // This is a 32 bit integer value 43 i64 = 5, // This is a 64 bit integer value 44 i128 = 6, // This is a 128 bit integer value 45 46 FIRST_INTEGER_VALUETYPE = i1, 47 LAST_INTEGER_VALUETYPE = i128, 48 49 f16 = 7, // This is a 16 bit floating point value 50 f32 = 8, // This is a 32 bit floating point value 51 f64 = 9, // This is a 64 bit floating point value 52 f80 = 10, // This is a 80 bit floating point value 53 f128 = 11, // This is a 128 bit floating point value 54 ppcf128 = 12, // This is a PPC 128-bit floating point value 55 56 FIRST_FP_VALUETYPE = f16, 57 LAST_FP_VALUETYPE = ppcf128, 58 59 v2i1 = 13, // 2 x i1 60 v4i1 = 14, // 4 x i1 61 v8i1 = 15, // 8 x i1 62 v16i1 = 16, // 16 x i1 63 v32i1 = 17, // 32 x i1 64 v64i1 = 18, // 64 x i1 65 v512i1 = 19, // 512 x i1 66 v1024i1 = 20, // 1024 x i1 67 68 v1i8 = 21, // 1 x i8 69 v2i8 = 22, // 2 x i8 70 v4i8 = 23, // 4 x i8 71 v8i8 = 24, // 8 x i8 72 v16i8 = 25, // 16 x i8 73 v32i8 = 26, // 32 x i8 74 v64i8 = 27, // 64 x i8 75 v128i8 = 28, //128 x i8 76 v256i8 = 29, //256 x i8 77 78 v1i16 = 30, // 1 x i16 79 v2i16 = 31, // 2 x i16 80 v4i16 = 32, // 4 x i16 81 v8i16 = 33, // 8 x i16 82 v16i16 = 34, // 16 x i16 83 v32i16 = 35, // 32 x i16 84 v64i16 = 36, // 64 x i16 85 v128i16 = 37, //128 x i16 86 87 v1i32 = 38, // 1 x i32 88 v2i32 = 39, // 2 x i32 89 v4i32 = 40, // 4 x i32 90 v8i32 = 41, // 8 x i32 91 v16i32 = 42, // 16 x i32 92 v32i32 = 43, // 32 x i32 93 v64i32 = 44, // 64 x i32 94 95 v1i64 = 45, // 1 x i64 96 v2i64 = 46, // 2 x i64 97 v4i64 = 47, // 4 x i64 98 v8i64 = 48, // 8 x i64 99 v16i64 = 49, // 16 x i64 100 v32i64 = 50, // 32 x i64 101 102 v1i128 = 51, // 1 x i128 103 104 FIRST_INTEGER_VECTOR_VALUETYPE = v2i1, 105 LAST_INTEGER_VECTOR_VALUETYPE = v1i128, 106 107 v2f16 = 52, // 2 x f16 108 v4f16 = 53, // 4 x f16 109 v8f16 = 54, // 8 x f16 110 v1f32 = 55, // 1 x f32 111 v2f32 = 56, // 2 x f32 112 v4f32 = 57, // 4 x f32 113 v8f32 = 58, // 8 x f32 114 v16f32 = 59, // 16 x f32 115 v1f64 = 60, // 1 x f64 116 v2f64 = 61, // 2 x f64 117 v4f64 = 62, // 4 x f64 118 v8f64 = 63, // 8 x f64 119 120 FIRST_FP_VECTOR_VALUETYPE = v2f16, 121 LAST_FP_VECTOR_VALUETYPE = v8f64, 122 123 FIRST_VECTOR_VALUETYPE = v2i1, 124 LAST_VECTOR_VALUETYPE = v8f64, 125 126 x86mmx = 64, // This is an X86 MMX value 127 128 Glue = 65, // This glues nodes together during pre-RA sched 129 130 isVoid = 66, // This has no value 131 132 Untyped = 67, // This value takes a register, but has 133 // unspecified type. The register class 134 // will be determined by the opcode. 135 136 FIRST_VALUETYPE = 0, // This is always the beginning of the list. 137 LAST_VALUETYPE = 68, // This always remains at the end of the list. 138 139 // This is the current maximum for LAST_VALUETYPE. 140 // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors 141 // This value must be a multiple of 32. 142 MAX_ALLOWED_VALUETYPE = 96, 143 144 // Token - A value of type llvm::TokenTy 145 token = 120, 146 147 // Metadata - This is MDNode or MDString. 148 Metadata = 121, 149 150 // iPTRAny - An int value the size of the pointer of the current 151 // target to any address space. This must only be used internal to 152 // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR. 153 iPTRAny = 122, 154 155 // vAny - A vector with any length and element size. This is used 156 // for intrinsics that have overloadings based on vector types. 157 // This is only for tblgen's consumption! 158 vAny = 123, 159 160 // fAny - Any floating-point or vector floating-point value. This is used 161 // for intrinsics that have overloadings based on floating-point types. 162 // This is only for tblgen's consumption! 163 fAny = 124, 164 165 // iAny - An integer or vector integer value of any bit width. This is 166 // used for intrinsics that have overloadings based on integer bit widths. 167 // This is only for tblgen's consumption! 168 iAny = 125, 169 170 // iPTR - An int value the size of the pointer of the current 171 // target. This should only be used internal to tblgen! 172 iPTR = 126, 173 174 // Any - Any type. This is used for intrinsics that have overloadings. 175 // This is only for tblgen's consumption! 176 Any = 127 177 }; 178 179 SimpleValueType SimpleTy; 180 MVT()181 LLVM_CONSTEXPR MVT() : SimpleTy(INVALID_SIMPLE_VALUE_TYPE) {} MVT(SimpleValueType SVT)182 LLVM_CONSTEXPR MVT(SimpleValueType SVT) : SimpleTy(SVT) { } 183 184 bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; } 185 bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; } 186 bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; } 187 bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; } 188 bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; } 189 bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; } 190 191 /// isValid - Return true if this is a valid simple valuetype. isValid()192 bool isValid() const { 193 return (SimpleTy >= MVT::FIRST_VALUETYPE && 194 SimpleTy < MVT::LAST_VALUETYPE); 195 } 196 197 /// isFloatingPoint - Return true if this is a FP, or a vector FP type. isFloatingPoint()198 bool isFloatingPoint() const { 199 return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE && 200 SimpleTy <= MVT::LAST_FP_VALUETYPE) || 201 (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE && 202 SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE)); 203 } 204 205 /// isInteger - Return true if this is an integer, or a vector integer type. isInteger()206 bool isInteger() const { 207 return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE && 208 SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) || 209 (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE && 210 SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE)); 211 } 212 213 /// isScalarInteger - Return true if this is an integer, not including 214 /// vectors. isScalarInteger()215 bool isScalarInteger() const { 216 return (SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE && 217 SimpleTy <= MVT::LAST_INTEGER_VALUETYPE); 218 } 219 220 /// isVector - Return true if this is a vector value type. isVector()221 bool isVector() const { 222 return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE && 223 SimpleTy <= MVT::LAST_VECTOR_VALUETYPE); 224 } 225 226 /// is16BitVector - Return true if this is a 16-bit vector type. is16BitVector()227 bool is16BitVector() const { 228 return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 || 229 SimpleTy == MVT::v16i1); 230 } 231 232 /// is32BitVector - Return true if this is a 32-bit vector type. is32BitVector()233 bool is32BitVector() const { 234 return (SimpleTy == MVT::v4i8 || SimpleTy == MVT::v2i16 || 235 SimpleTy == MVT::v1i32 || SimpleTy == MVT::v2f16 || 236 SimpleTy == MVT::v1f32); 237 } 238 239 /// is64BitVector - Return true if this is a 64-bit vector type. is64BitVector()240 bool is64BitVector() const { 241 return (SimpleTy == MVT::v8i8 || SimpleTy == MVT::v4i16 || 242 SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 || 243 SimpleTy == MVT::v4f16 || SimpleTy == MVT::v2f32 || 244 SimpleTy == MVT::v1f64); 245 } 246 247 /// is128BitVector - Return true if this is a 128-bit vector type. is128BitVector()248 bool is128BitVector() const { 249 return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 || 250 SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 || 251 SimpleTy == MVT::v1i128 || SimpleTy == MVT::v8f16 || 252 SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64); 253 } 254 255 /// is256BitVector - Return true if this is a 256-bit vector type. is256BitVector()256 bool is256BitVector() const { 257 return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64 || 258 SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 || 259 SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64); 260 } 261 262 /// is512BitVector - Return true if this is a 512-bit vector type. is512BitVector()263 bool is512BitVector() const { 264 return (SimpleTy == MVT::v16f32 || SimpleTy == MVT::v8f64 || 265 SimpleTy == MVT::v512i1 || SimpleTy == MVT::v64i8 || 266 SimpleTy == MVT::v32i16 || SimpleTy == MVT::v16i32 || 267 SimpleTy == MVT::v8i64); 268 } 269 270 /// is1024BitVector - Return true if this is a 1024-bit vector type. is1024BitVector()271 bool is1024BitVector() const { 272 return (SimpleTy == MVT::v1024i1 || SimpleTy == MVT::v128i8 || 273 SimpleTy == MVT::v64i16 || SimpleTy == MVT::v32i32 || 274 SimpleTy == MVT::v16i64); 275 } 276 277 /// is2048BitVector - Return true if this is a 1024-bit vector type. is2048BitVector()278 bool is2048BitVector() const { 279 return (SimpleTy == MVT::v256i8 || SimpleTy == MVT::v128i16 || 280 SimpleTy == MVT::v64i32 || SimpleTy == MVT::v32i64); 281 } 282 283 /// isOverloaded - Return true if this is an overloaded type for TableGen. isOverloaded()284 bool isOverloaded() const { 285 return (SimpleTy==MVT::Any || 286 SimpleTy==MVT::iAny || SimpleTy==MVT::fAny || 287 SimpleTy==MVT::vAny || SimpleTy==MVT::iPTRAny); 288 } 289 290 /// isPow2VectorType - Returns true if the given vector is a power of 2. isPow2VectorType()291 bool isPow2VectorType() const { 292 unsigned NElts = getVectorNumElements(); 293 return !(NElts & (NElts - 1)); 294 } 295 296 /// getPow2VectorType - Widens the length of the given vector MVT up to 297 /// the nearest power of 2 and returns that type. getPow2VectorType()298 MVT getPow2VectorType() const { 299 if (isPow2VectorType()) 300 return *this; 301 302 unsigned NElts = getVectorNumElements(); 303 unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts); 304 return MVT::getVectorVT(getVectorElementType(), Pow2NElts); 305 } 306 307 /// getScalarType - If this is a vector type, return the element type, 308 /// otherwise return this. getScalarType()309 MVT getScalarType() const { 310 return isVector() ? getVectorElementType() : *this; 311 } 312 getVectorElementType()313 MVT getVectorElementType() const { 314 switch (SimpleTy) { 315 default: 316 llvm_unreachable("Not a vector MVT!"); 317 case v2i1: 318 case v4i1: 319 case v8i1: 320 case v16i1: 321 case v32i1: 322 case v64i1: 323 case v512i1: 324 case v1024i1: return i1; 325 case v1i8: 326 case v2i8: 327 case v4i8: 328 case v8i8: 329 case v16i8: 330 case v32i8: 331 case v64i8: 332 case v128i8: 333 case v256i8: return i8; 334 case v1i16: 335 case v2i16: 336 case v4i16: 337 case v8i16: 338 case v16i16: 339 case v32i16: 340 case v64i16: 341 case v128i16: return i16; 342 case v1i32: 343 case v2i32: 344 case v4i32: 345 case v8i32: 346 case v16i32: 347 case v32i32: 348 case v64i32: return i32; 349 case v1i64: 350 case v2i64: 351 case v4i64: 352 case v8i64: 353 case v16i64: 354 case v32i64: return i64; 355 case v1i128: return i128; 356 case v2f16: 357 case v4f16: 358 case v8f16: return f16; 359 case v1f32: 360 case v2f32: 361 case v4f32: 362 case v8f32: 363 case v16f32: return f32; 364 case v1f64: 365 case v2f64: 366 case v4f64: 367 case v8f64: return f64; 368 } 369 } 370 getVectorNumElements()371 unsigned getVectorNumElements() const { 372 switch (SimpleTy) { 373 default: 374 llvm_unreachable("Not a vector MVT!"); 375 case v1024i1: return 1024; 376 case v512i1: return 512; 377 case v256i8: return 256; 378 case v128i8: 379 case v128i16: return 128; 380 case v64i1: 381 case v64i8: 382 case v64i16: 383 case v64i32: return 64; 384 case v32i1: 385 case v32i8: 386 case v32i16: 387 case v32i32: 388 case v32i64: return 32; 389 case v16i1: 390 case v16i8: 391 case v16i16: 392 case v16i32: 393 case v16i64: 394 case v16f32: return 16; 395 case v8i1: 396 case v8i8: 397 case v8i16: 398 case v8i32: 399 case v8i64: 400 case v8f16: 401 case v8f32: 402 case v8f64: return 8; 403 case v4i1: 404 case v4i8: 405 case v4i16: 406 case v4i32: 407 case v4i64: 408 case v4f16: 409 case v4f32: 410 case v4f64: return 4; 411 case v2i1: 412 case v2i8: 413 case v2i16: 414 case v2i32: 415 case v2i64: 416 case v2f16: 417 case v2f32: 418 case v2f64: return 2; 419 case v1i8: 420 case v1i16: 421 case v1i32: 422 case v1i64: 423 case v1i128: 424 case v1f32: 425 case v1f64: return 1; 426 } 427 } 428 getSizeInBits()429 unsigned getSizeInBits() const { 430 switch (SimpleTy) { 431 default: 432 llvm_unreachable("getSizeInBits called on extended MVT."); 433 case Other: 434 llvm_unreachable("Value type is non-standard value, Other."); 435 case iPTR: 436 llvm_unreachable("Value type size is target-dependent. Ask TLI."); 437 case iPTRAny: 438 case iAny: 439 case fAny: 440 case vAny: 441 case Any: 442 llvm_unreachable("Value type is overloaded."); 443 case token: 444 llvm_unreachable("Token type is a sentinel that cannot be used " 445 "in codegen and has no size"); 446 case Metadata: 447 llvm_unreachable("Value type is metadata."); 448 case i1 : return 1; 449 case v2i1: return 2; 450 case v4i1: return 4; 451 case i8 : 452 case v1i8: 453 case v8i1: return 8; 454 case i16 : 455 case f16: 456 case v16i1: 457 case v2i8: 458 case v1i16: return 16; 459 case f32 : 460 case i32 : 461 case v32i1: 462 case v4i8: 463 case v2i16: 464 case v2f16: 465 case v1f32: 466 case v1i32: return 32; 467 case x86mmx: 468 case f64 : 469 case i64 : 470 case v64i1: 471 case v8i8: 472 case v4i16: 473 case v2i32: 474 case v1i64: 475 case v4f16: 476 case v2f32: 477 case v1f64: return 64; 478 case f80 : return 80; 479 case f128: 480 case ppcf128: 481 case i128: 482 case v16i8: 483 case v8i16: 484 case v4i32: 485 case v2i64: 486 case v1i128: 487 case v8f16: 488 case v4f32: 489 case v2f64: return 128; 490 case v32i8: 491 case v16i16: 492 case v8i32: 493 case v4i64: 494 case v8f32: 495 case v4f64: return 256; 496 case v512i1: 497 case v64i8: 498 case v32i16: 499 case v16i32: 500 case v8i64: 501 case v16f32: 502 case v8f64: return 512; 503 case v1024i1: 504 case v128i8: 505 case v64i16: 506 case v32i32: 507 case v16i64: return 1024; 508 case v256i8: 509 case v128i16: 510 case v64i32: 511 case v32i64: return 2048; 512 } 513 } 514 getScalarSizeInBits()515 unsigned getScalarSizeInBits() const { 516 return getScalarType().getSizeInBits(); 517 } 518 519 /// getStoreSize - Return the number of bytes overwritten by a store 520 /// of the specified value type. getStoreSize()521 unsigned getStoreSize() const { 522 return (getSizeInBits() + 7) / 8; 523 } 524 525 /// getStoreSizeInBits - Return the number of bits overwritten by a store 526 /// of the specified value type. getStoreSizeInBits()527 unsigned getStoreSizeInBits() const { 528 return getStoreSize() * 8; 529 } 530 531 /// Return true if this has more bits than VT. bitsGT(MVT VT)532 bool bitsGT(MVT VT) const { 533 return getSizeInBits() > VT.getSizeInBits(); 534 } 535 536 /// Return true if this has no less bits than VT. bitsGE(MVT VT)537 bool bitsGE(MVT VT) const { 538 return getSizeInBits() >= VT.getSizeInBits(); 539 } 540 541 /// Return true if this has less bits than VT. bitsLT(MVT VT)542 bool bitsLT(MVT VT) const { 543 return getSizeInBits() < VT.getSizeInBits(); 544 } 545 546 /// Return true if this has no more bits than VT. bitsLE(MVT VT)547 bool bitsLE(MVT VT) const { 548 return getSizeInBits() <= VT.getSizeInBits(); 549 } 550 551 getFloatingPointVT(unsigned BitWidth)552 static MVT getFloatingPointVT(unsigned BitWidth) { 553 switch (BitWidth) { 554 default: 555 llvm_unreachable("Bad bit width!"); 556 case 16: 557 return MVT::f16; 558 case 32: 559 return MVT::f32; 560 case 64: 561 return MVT::f64; 562 case 80: 563 return MVT::f80; 564 case 128: 565 return MVT::f128; 566 } 567 } 568 getIntegerVT(unsigned BitWidth)569 static MVT getIntegerVT(unsigned BitWidth) { 570 switch (BitWidth) { 571 default: 572 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE); 573 case 1: 574 return MVT::i1; 575 case 8: 576 return MVT::i8; 577 case 16: 578 return MVT::i16; 579 case 32: 580 return MVT::i32; 581 case 64: 582 return MVT::i64; 583 case 128: 584 return MVT::i128; 585 } 586 } 587 getVectorVT(MVT VT,unsigned NumElements)588 static MVT getVectorVT(MVT VT, unsigned NumElements) { 589 switch (VT.SimpleTy) { 590 default: 591 break; 592 case MVT::i1: 593 if (NumElements == 2) return MVT::v2i1; 594 if (NumElements == 4) return MVT::v4i1; 595 if (NumElements == 8) return MVT::v8i1; 596 if (NumElements == 16) return MVT::v16i1; 597 if (NumElements == 32) return MVT::v32i1; 598 if (NumElements == 64) return MVT::v64i1; 599 if (NumElements == 512) return MVT::v512i1; 600 if (NumElements == 1024) return MVT::v1024i1; 601 break; 602 case MVT::i8: 603 if (NumElements == 1) return MVT::v1i8; 604 if (NumElements == 2) return MVT::v2i8; 605 if (NumElements == 4) return MVT::v4i8; 606 if (NumElements == 8) return MVT::v8i8; 607 if (NumElements == 16) return MVT::v16i8; 608 if (NumElements == 32) return MVT::v32i8; 609 if (NumElements == 64) return MVT::v64i8; 610 if (NumElements == 128) return MVT::v128i8; 611 if (NumElements == 256) return MVT::v256i8; 612 break; 613 case MVT::i16: 614 if (NumElements == 1) return MVT::v1i16; 615 if (NumElements == 2) return MVT::v2i16; 616 if (NumElements == 4) return MVT::v4i16; 617 if (NumElements == 8) return MVT::v8i16; 618 if (NumElements == 16) return MVT::v16i16; 619 if (NumElements == 32) return MVT::v32i16; 620 if (NumElements == 64) return MVT::v64i16; 621 if (NumElements == 128) return MVT::v128i16; 622 break; 623 case MVT::i32: 624 if (NumElements == 1) return MVT::v1i32; 625 if (NumElements == 2) return MVT::v2i32; 626 if (NumElements == 4) return MVT::v4i32; 627 if (NumElements == 8) return MVT::v8i32; 628 if (NumElements == 16) return MVT::v16i32; 629 if (NumElements == 32) return MVT::v32i32; 630 if (NumElements == 64) return MVT::v64i32; 631 break; 632 case MVT::i64: 633 if (NumElements == 1) return MVT::v1i64; 634 if (NumElements == 2) return MVT::v2i64; 635 if (NumElements == 4) return MVT::v4i64; 636 if (NumElements == 8) return MVT::v8i64; 637 if (NumElements == 16) return MVT::v16i64; 638 if (NumElements == 32) return MVT::v32i64; 639 break; 640 case MVT::i128: 641 if (NumElements == 1) return MVT::v1i128; 642 break; 643 case MVT::f16: 644 if (NumElements == 2) return MVT::v2f16; 645 if (NumElements == 4) return MVT::v4f16; 646 if (NumElements == 8) return MVT::v8f16; 647 break; 648 case MVT::f32: 649 if (NumElements == 1) return MVT::v1f32; 650 if (NumElements == 2) return MVT::v2f32; 651 if (NumElements == 4) return MVT::v4f32; 652 if (NumElements == 8) return MVT::v8f32; 653 if (NumElements == 16) return MVT::v16f32; 654 break; 655 case MVT::f64: 656 if (NumElements == 1) return MVT::v1f64; 657 if (NumElements == 2) return MVT::v2f64; 658 if (NumElements == 4) return MVT::v4f64; 659 if (NumElements == 8) return MVT::v8f64; 660 break; 661 } 662 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE); 663 } 664 665 /// Return the value type corresponding to the specified type. This returns 666 /// all pointers as iPTR. If HandleUnknown is true, unknown types are 667 /// returned as Other, otherwise they are invalid. 668 static MVT getVT(Type *Ty, bool HandleUnknown = false); 669 670 private: 671 /// A simple iterator over the MVT::SimpleValueType enum. 672 struct mvt_iterator { 673 SimpleValueType VT; mvt_iteratormvt_iterator674 mvt_iterator(SimpleValueType VT) : VT(VT) {} 675 MVT operator*() const { return VT; } 676 bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; } 677 mvt_iterator& operator++() { 678 VT = (MVT::SimpleValueType)((int)VT + 1); 679 assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE && 680 "MVT iterator overflowed."); 681 return *this; 682 } 683 }; 684 /// A range of the MVT::SimpleValueType enum. 685 typedef iterator_range<mvt_iterator> mvt_range; 686 687 public: 688 /// SimpleValueType Iteration 689 /// @{ all_valuetypes()690 static mvt_range all_valuetypes() { 691 return mvt_range(MVT::FIRST_VALUETYPE, MVT::LAST_VALUETYPE); 692 } integer_valuetypes()693 static mvt_range integer_valuetypes() { 694 return mvt_range(MVT::FIRST_INTEGER_VALUETYPE, 695 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VALUETYPE + 1)); 696 } fp_valuetypes()697 static mvt_range fp_valuetypes() { 698 return mvt_range(MVT::FIRST_FP_VALUETYPE, 699 (MVT::SimpleValueType)(MVT::LAST_FP_VALUETYPE + 1)); 700 } vector_valuetypes()701 static mvt_range vector_valuetypes() { 702 return mvt_range(MVT::FIRST_VECTOR_VALUETYPE, 703 (MVT::SimpleValueType)(MVT::LAST_VECTOR_VALUETYPE + 1)); 704 } integer_vector_valuetypes()705 static mvt_range integer_vector_valuetypes() { 706 return mvt_range( 707 MVT::FIRST_INTEGER_VECTOR_VALUETYPE, 708 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VECTOR_VALUETYPE + 1)); 709 } fp_vector_valuetypes()710 static mvt_range fp_vector_valuetypes() { 711 return mvt_range( 712 MVT::FIRST_FP_VECTOR_VALUETYPE, 713 (MVT::SimpleValueType)(MVT::LAST_FP_VECTOR_VALUETYPE + 1)); 714 } 715 /// @} 716 }; 717 718 } // End llvm namespace 719 720 #endif 721