Home | History | Annotate | Download | only in CodeGen
      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 {
     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          = 249,
    146 
    147       // Metadata - This is MDNode or MDString.
    148       Metadata       = 250,
    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        = 251,
    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           = 252,
    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           = 253,
    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           = 254,
    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           = 255,
    173 
    174       // Any - Any type. This is used for intrinsics that have overloadings.
    175       // This is only for tblgen's consumption!
    176       Any            = 256
    177     };
    178 
    179     SimpleValueType SimpleTy;
    180 
    181     LLVM_CONSTEXPR MVT() : SimpleTy(INVALID_SIMPLE_VALUE_TYPE) {}
    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.
    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.
    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.
    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     /// isVector - Return true if this is a vector value type.
    214     bool isVector() const {
    215       return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
    216               SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
    217     }
    218 
    219     /// is16BitVector - Return true if this is a 16-bit vector type.
    220     bool is16BitVector() const {
    221       return (SimpleTy == MVT::v2i8  || SimpleTy == MVT::v1i16 ||
    222               SimpleTy == MVT::v16i1);
    223     }
    224 
    225     /// is32BitVector - Return true if this is a 32-bit vector type.
    226     bool is32BitVector() const {
    227       return (SimpleTy == MVT::v4i8  || SimpleTy == MVT::v2i16 ||
    228               SimpleTy == MVT::v1i32 || SimpleTy == MVT::v2f16 ||
    229               SimpleTy == MVT::v1f32);
    230     }
    231 
    232     /// is64BitVector - Return true if this is a 64-bit vector type.
    233     bool is64BitVector() const {
    234       return (SimpleTy == MVT::v8i8  || SimpleTy == MVT::v4i16 ||
    235               SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
    236               SimpleTy == MVT::v4f16 || SimpleTy == MVT::v2f32 ||
    237               SimpleTy == MVT::v1f64);
    238     }
    239 
    240     /// is128BitVector - Return true if this is a 128-bit vector type.
    241     bool is128BitVector() const {
    242       return (SimpleTy == MVT::v16i8  || SimpleTy == MVT::v8i16 ||
    243               SimpleTy == MVT::v4i32  || SimpleTy == MVT::v2i64 ||
    244               SimpleTy == MVT::v1i128 || SimpleTy == MVT::v8f16 ||
    245               SimpleTy == MVT::v4f32  || SimpleTy == MVT::v2f64);
    246     }
    247 
    248     /// is256BitVector - Return true if this is a 256-bit vector type.
    249     bool is256BitVector() const {
    250       return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64  ||
    251               SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
    252               SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
    253     }
    254 
    255     /// is512BitVector - Return true if this is a 512-bit vector type.
    256     bool is512BitVector() const {
    257       return (SimpleTy == MVT::v16f32 || SimpleTy == MVT::v8f64  ||
    258               SimpleTy == MVT::v512i1 || SimpleTy == MVT::v64i8  ||
    259               SimpleTy == MVT::v32i16 || SimpleTy == MVT::v16i32 ||
    260               SimpleTy == MVT::v8i64);
    261     }
    262 
    263     /// is1024BitVector - Return true if this is a 1024-bit vector type.
    264     bool is1024BitVector() const {
    265       return (SimpleTy == MVT::v1024i1 || SimpleTy == MVT::v128i8 ||
    266               SimpleTy == MVT::v64i16  || SimpleTy == MVT::v32i32 ||
    267               SimpleTy == MVT::v16i64);
    268     }
    269 
    270     /// is2048BitVector - Return true if this is a 1024-bit vector type.
    271     bool is2048BitVector() const {
    272       return (SimpleTy == MVT::v256i8 || SimpleTy == MVT::v128i16 ||
    273               SimpleTy == MVT::v64i32 || SimpleTy == MVT::v32i64);
    274     }
    275 
    276     /// isOverloaded - Return true if this is an overloaded type for TableGen.
    277     bool isOverloaded() const {
    278       return (SimpleTy==MVT::Any  ||
    279               SimpleTy==MVT::iAny || SimpleTy==MVT::fAny ||
    280               SimpleTy==MVT::vAny || SimpleTy==MVT::iPTRAny);
    281     }
    282 
    283     /// isPow2VectorType - Returns true if the given vector is a power of 2.
    284     bool isPow2VectorType() const {
    285       unsigned NElts = getVectorNumElements();
    286       return !(NElts & (NElts - 1));
    287     }
    288 
    289     /// getPow2VectorType - Widens the length of the given vector MVT up to
    290     /// the nearest power of 2 and returns that type.
    291     MVT getPow2VectorType() const {
    292       if (isPow2VectorType())
    293         return *this;
    294 
    295       unsigned NElts = getVectorNumElements();
    296       unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
    297       return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
    298     }
    299 
    300     /// getScalarType - If this is a vector type, return the element type,
    301     /// otherwise return this.
    302     MVT getScalarType() const {
    303       return isVector() ? getVectorElementType() : *this;
    304     }
    305 
    306     MVT getVectorElementType() const {
    307       switch (SimpleTy) {
    308       default:
    309         llvm_unreachable("Not a vector MVT!");
    310       case v2i1:
    311       case v4i1:
    312       case v8i1:
    313       case v16i1:
    314       case v32i1:
    315       case v64i1:
    316       case v512i1:
    317       case v1024i1: return i1;
    318       case v1i8:
    319       case v2i8:
    320       case v4i8:
    321       case v8i8:
    322       case v16i8:
    323       case v32i8:
    324       case v64i8:
    325       case v128i8:
    326       case v256i8: return i8;
    327       case v1i16:
    328       case v2i16:
    329       case v4i16:
    330       case v8i16:
    331       case v16i16:
    332       case v32i16:
    333       case v64i16:
    334       case v128i16: return i16;
    335       case v1i32:
    336       case v2i32:
    337       case v4i32:
    338       case v8i32:
    339       case v16i32:
    340       case v32i32:
    341       case v64i32: return i32;
    342       case v1i64:
    343       case v2i64:
    344       case v4i64:
    345       case v8i64:
    346       case v16i64:
    347       case v32i64: return i64;
    348       case v1i128: return i128;
    349       case v2f16:
    350       case v4f16:
    351       case v8f16: return f16;
    352       case v1f32:
    353       case v2f32:
    354       case v4f32:
    355       case v8f32:
    356       case v16f32: return f32;
    357       case v1f64:
    358       case v2f64:
    359       case v4f64:
    360       case v8f64: return f64;
    361       }
    362     }
    363 
    364     unsigned getVectorNumElements() const {
    365       switch (SimpleTy) {
    366       default:
    367         llvm_unreachable("Not a vector MVT!");
    368       case v1024i1: return 1024;
    369       case v512i1: return 512;
    370       case v256i8: return 256;
    371       case v128i8:
    372       case v128i16: return 128;
    373       case v64i1:
    374       case v64i8:
    375       case v64i16:
    376       case v64i32: return 64;
    377       case v32i1:
    378       case v32i8:
    379       case v32i16:
    380       case v32i32:
    381       case v32i64: return 32;
    382       case v16i1:
    383       case v16i8:
    384       case v16i16:
    385       case v16i32:
    386       case v16i64:
    387       case v16f32: return 16;
    388       case v8i1:
    389       case v8i8:
    390       case v8i16:
    391       case v8i32:
    392       case v8i64:
    393       case v8f16:
    394       case v8f32:
    395       case v8f64: return 8;
    396       case v4i1:
    397       case v4i8:
    398       case v4i16:
    399       case v4i32:
    400       case v4i64:
    401       case v4f16:
    402       case v4f32:
    403       case v4f64: return 4;
    404       case v2i1:
    405       case v2i8:
    406       case v2i16:
    407       case v2i32:
    408       case v2i64:
    409       case v2f16:
    410       case v2f32:
    411       case v2f64: return 2;
    412       case v1i8:
    413       case v1i16:
    414       case v1i32:
    415       case v1i64:
    416       case v1i128:
    417       case v1f32:
    418       case v1f64: return 1;
    419       }
    420     }
    421 
    422     unsigned getSizeInBits() const {
    423       switch (SimpleTy) {
    424       default:
    425         llvm_unreachable("getSizeInBits called on extended MVT.");
    426       case Other:
    427         llvm_unreachable("Value type is non-standard value, Other.");
    428       case iPTR:
    429         llvm_unreachable("Value type size is target-dependent. Ask TLI.");
    430       case iPTRAny:
    431       case iAny:
    432       case fAny:
    433       case vAny:
    434       case Any:
    435         llvm_unreachable("Value type is overloaded.");
    436       case token:
    437         llvm_unreachable("Token type is a sentinel that cannot be used "
    438                          "in codegen and has no size");
    439       case Metadata:
    440         llvm_unreachable("Value type is metadata.");
    441       case i1  :  return 1;
    442       case v2i1:  return 2;
    443       case v4i1:  return 4;
    444       case i8  :
    445       case v1i8:
    446       case v8i1: return 8;
    447       case i16 :
    448       case f16:
    449       case v16i1:
    450       case v2i8:
    451       case v1i16: return 16;
    452       case f32 :
    453       case i32 :
    454       case v32i1:
    455       case v4i8:
    456       case v2i16:
    457       case v2f16:
    458       case v1f32:
    459       case v1i32: return 32;
    460       case x86mmx:
    461       case f64 :
    462       case i64 :
    463       case v64i1:
    464       case v8i8:
    465       case v4i16:
    466       case v2i32:
    467       case v1i64:
    468       case v4f16:
    469       case v2f32:
    470       case v1f64: return 64;
    471       case f80 :  return 80;
    472       case f128:
    473       case ppcf128:
    474       case i128:
    475       case v16i8:
    476       case v8i16:
    477       case v4i32:
    478       case v2i64:
    479       case v1i128:
    480       case v8f16:
    481       case v4f32:
    482       case v2f64: return 128;
    483       case v32i8:
    484       case v16i16:
    485       case v8i32:
    486       case v4i64:
    487       case v8f32:
    488       case v4f64: return 256;
    489       case v512i1:
    490       case v64i8:
    491       case v32i16:
    492       case v16i32:
    493       case v8i64:
    494       case v16f32:
    495       case v8f64: return 512;
    496       case v1024i1:
    497       case v128i8:
    498       case v64i16:
    499       case v32i32:
    500       case v16i64: return 1024;
    501       case v256i8:
    502       case v128i16:
    503       case v64i32:
    504       case v32i64: return 2048;
    505       }
    506     }
    507 
    508     unsigned getScalarSizeInBits() const {
    509       return getScalarType().getSizeInBits();
    510     }
    511 
    512     /// getStoreSize - Return the number of bytes overwritten by a store
    513     /// of the specified value type.
    514     unsigned getStoreSize() const {
    515       return (getSizeInBits() + 7) / 8;
    516     }
    517 
    518     /// getStoreSizeInBits - Return the number of bits overwritten by a store
    519     /// of the specified value type.
    520     unsigned getStoreSizeInBits() const {
    521       return getStoreSize() * 8;
    522     }
    523 
    524     /// Return true if this has more bits than VT.
    525     bool bitsGT(MVT VT) const {
    526       return getSizeInBits() > VT.getSizeInBits();
    527     }
    528 
    529     /// Return true if this has no less bits than VT.
    530     bool bitsGE(MVT VT) const {
    531       return getSizeInBits() >= VT.getSizeInBits();
    532     }
    533 
    534     /// Return true if this has less bits than VT.
    535     bool bitsLT(MVT VT) const {
    536       return getSizeInBits() < VT.getSizeInBits();
    537     }
    538 
    539     /// Return true if this has no more bits than VT.
    540     bool bitsLE(MVT VT) const {
    541       return getSizeInBits() <= VT.getSizeInBits();
    542     }
    543 
    544 
    545     static MVT getFloatingPointVT(unsigned BitWidth) {
    546       switch (BitWidth) {
    547       default:
    548         llvm_unreachable("Bad bit width!");
    549       case 16:
    550         return MVT::f16;
    551       case 32:
    552         return MVT::f32;
    553       case 64:
    554         return MVT::f64;
    555       case 80:
    556         return MVT::f80;
    557       case 128:
    558         return MVT::f128;
    559       }
    560     }
    561 
    562     static MVT getIntegerVT(unsigned BitWidth) {
    563       switch (BitWidth) {
    564       default:
    565         return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
    566       case 1:
    567         return MVT::i1;
    568       case 8:
    569         return MVT::i8;
    570       case 16:
    571         return MVT::i16;
    572       case 32:
    573         return MVT::i32;
    574       case 64:
    575         return MVT::i64;
    576       case 128:
    577         return MVT::i128;
    578       }
    579     }
    580 
    581     static MVT getVectorVT(MVT VT, unsigned NumElements) {
    582       switch (VT.SimpleTy) {
    583       default:
    584         break;
    585       case MVT::i1:
    586         if (NumElements == 2)    return MVT::v2i1;
    587         if (NumElements == 4)    return MVT::v4i1;
    588         if (NumElements == 8)    return MVT::v8i1;
    589         if (NumElements == 16)   return MVT::v16i1;
    590         if (NumElements == 32)   return MVT::v32i1;
    591         if (NumElements == 64)   return MVT::v64i1;
    592         if (NumElements == 512)  return MVT::v512i1;
    593         if (NumElements == 1024) return MVT::v1024i1;
    594         break;
    595       case MVT::i8:
    596         if (NumElements == 1)   return MVT::v1i8;
    597         if (NumElements == 2)   return MVT::v2i8;
    598         if (NumElements == 4)   return MVT::v4i8;
    599         if (NumElements == 8)   return MVT::v8i8;
    600         if (NumElements == 16)  return MVT::v16i8;
    601         if (NumElements == 32)  return MVT::v32i8;
    602         if (NumElements == 64)  return MVT::v64i8;
    603         if (NumElements == 128) return MVT::v128i8;
    604         if (NumElements == 256) return MVT::v256i8;
    605         break;
    606       case MVT::i16:
    607         if (NumElements == 1)   return MVT::v1i16;
    608         if (NumElements == 2)   return MVT::v2i16;
    609         if (NumElements == 4)   return MVT::v4i16;
    610         if (NumElements == 8)   return MVT::v8i16;
    611         if (NumElements == 16)  return MVT::v16i16;
    612         if (NumElements == 32)  return MVT::v32i16;
    613         if (NumElements == 64)  return MVT::v64i16;
    614         if (NumElements == 128) return MVT::v128i16;
    615         break;
    616       case MVT::i32:
    617         if (NumElements == 1)  return MVT::v1i32;
    618         if (NumElements == 2)  return MVT::v2i32;
    619         if (NumElements == 4)  return MVT::v4i32;
    620         if (NumElements == 8)  return MVT::v8i32;
    621         if (NumElements == 16) return MVT::v16i32;
    622         if (NumElements == 32) return MVT::v32i32;
    623         if (NumElements == 64) return MVT::v64i32;
    624         break;
    625       case MVT::i64:
    626         if (NumElements == 1)  return MVT::v1i64;
    627         if (NumElements == 2)  return MVT::v2i64;
    628         if (NumElements == 4)  return MVT::v4i64;
    629         if (NumElements == 8)  return MVT::v8i64;
    630         if (NumElements == 16) return MVT::v16i64;
    631         if (NumElements == 32) return MVT::v32i64;
    632         break;
    633       case MVT::i128:
    634         if (NumElements == 1)  return MVT::v1i128;
    635         break;
    636       case MVT::f16:
    637         if (NumElements == 2)  return MVT::v2f16;
    638         if (NumElements == 4)  return MVT::v4f16;
    639         if (NumElements == 8)  return MVT::v8f16;
    640         break;
    641       case MVT::f32:
    642         if (NumElements == 1)  return MVT::v1f32;
    643         if (NumElements == 2)  return MVT::v2f32;
    644         if (NumElements == 4)  return MVT::v4f32;
    645         if (NumElements == 8)  return MVT::v8f32;
    646         if (NumElements == 16) return MVT::v16f32;
    647         break;
    648       case MVT::f64:
    649         if (NumElements == 1)  return MVT::v1f64;
    650         if (NumElements == 2)  return MVT::v2f64;
    651         if (NumElements == 4)  return MVT::v4f64;
    652         if (NumElements == 8)  return MVT::v8f64;
    653         break;
    654       }
    655       return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
    656     }
    657 
    658     /// Return the value type corresponding to the specified type.  This returns
    659     /// all pointers as iPTR.  If HandleUnknown is true, unknown types are
    660     /// returned as Other, otherwise they are invalid.
    661     static MVT getVT(Type *Ty, bool HandleUnknown = false);
    662 
    663   private:
    664     /// A simple iterator over the MVT::SimpleValueType enum.
    665     struct mvt_iterator {
    666       SimpleValueType VT;
    667       mvt_iterator(SimpleValueType VT) : VT(VT) {}
    668       MVT operator*() const { return VT; }
    669       bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
    670       mvt_iterator& operator++() {
    671         VT = (MVT::SimpleValueType)((int)VT + 1);
    672         assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
    673                "MVT iterator overflowed.");
    674         return *this;
    675       }
    676     };
    677     /// A range of the MVT::SimpleValueType enum.
    678     typedef iterator_range<mvt_iterator> mvt_range;
    679 
    680   public:
    681     /// SimpleValueType Iteration
    682     /// @{
    683     static mvt_range all_valuetypes() {
    684       return mvt_range(MVT::FIRST_VALUETYPE, MVT::LAST_VALUETYPE);
    685     }
    686     static mvt_range integer_valuetypes() {
    687       return mvt_range(MVT::FIRST_INTEGER_VALUETYPE,
    688                        (MVT::SimpleValueType)(MVT::LAST_INTEGER_VALUETYPE + 1));
    689     }
    690     static mvt_range fp_valuetypes() {
    691       return mvt_range(MVT::FIRST_FP_VALUETYPE,
    692                        (MVT::SimpleValueType)(MVT::LAST_FP_VALUETYPE + 1));
    693     }
    694     static mvt_range vector_valuetypes() {
    695       return mvt_range(MVT::FIRST_VECTOR_VALUETYPE,
    696                        (MVT::SimpleValueType)(MVT::LAST_VECTOR_VALUETYPE + 1));
    697     }
    698     static mvt_range integer_vector_valuetypes() {
    699       return mvt_range(
    700           MVT::FIRST_INTEGER_VECTOR_VALUETYPE,
    701           (MVT::SimpleValueType)(MVT::LAST_INTEGER_VECTOR_VALUETYPE + 1));
    702     }
    703     static mvt_range fp_vector_valuetypes() {
    704       return mvt_range(
    705           MVT::FIRST_FP_VECTOR_VALUETYPE,
    706           (MVT::SimpleValueType)(MVT::LAST_FP_VECTOR_VALUETYPE + 1));
    707     }
    708     /// @}
    709   };
    710 
    711 } // End llvm namespace
    712 
    713 #endif
    714