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