Home | History | Annotate | Download | only in CodeGen
      1 //===- CodeGen/ValueTypes.h - Low-Level Target independ. 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 low-level target independent types which various
     11 // values in the code generator are.  This allows the target specific behavior
     12 // of instructions to be described to target independent passes.
     13 //
     14 //===----------------------------------------------------------------------===//
     15 
     16 #ifndef LLVM_CODEGEN_VALUETYPES_H
     17 #define LLVM_CODEGEN_VALUETYPES_H
     18 
     19 #include "llvm/Support/DataTypes.h"
     20 #include "llvm/Support/ErrorHandling.h"
     21 #include "llvm/Support/MathExtras.h"
     22 #include <cassert>
     23 #include <string>
     24 
     25 namespace llvm {
     26   class Type;
     27   class LLVMContext;
     28   struct EVT;
     29 
     30   /// MVT - Machine Value Type.  Every type that is supported natively by some
     31   /// processor targeted by LLVM occurs here.  This means that any legal value
     32   /// type can be represented by a MVT.
     33   class MVT {
     34   public:
     35     enum SimpleValueType {
     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       v2i8           =  13,   //  2 x i8
     60       v4i8           =  14,   //  4 x i8
     61       v8i8           =  15,   //  8 x i8
     62       v16i8          =  16,   // 16 x i8
     63       v32i8          =  17,   // 32 x i8
     64       v2i16          =  18,   //  2 x i16
     65       v4i16          =  19,   //  4 x i16
     66       v8i16          =  20,   //  8 x i16
     67       v16i16         =  21,   // 16 x i16
     68       v2i32          =  22,   //  2 x i32
     69       v4i32          =  23,   //  4 x i32
     70       v8i32          =  24,   //  8 x i32
     71       v16i32         =  25,   // 16 x i32
     72       v1i64          =  26,   //  1 x i64
     73       v2i64          =  27,   //  2 x i64
     74       v4i64          =  28,   //  4 x i64
     75       v8i64          =  29,   //  8 x i64
     76       v16i64         =  30,   // 16 x i64
     77 
     78       v2f16          =  31,   //  2 x f16
     79       v2f32          =  32,   //  2 x f32
     80       v4f32          =  33,   //  4 x f32
     81       v8f32          =  34,   //  8 x f32
     82       v2f64          =  35,   //  2 x f64
     83       v4f64          =  36,   //  4 x f64
     84 
     85       FIRST_VECTOR_VALUETYPE = v2i8,
     86       LAST_VECTOR_VALUETYPE  = v4f64,
     87       FIRST_INTEGER_VECTOR_VALUETYPE = v2i8,
     88       LAST_INTEGER_VECTOR_VALUETYPE = v16i64,
     89       FIRST_FP_VECTOR_VALUETYPE = v2f16,
     90       LAST_FP_VECTOR_VALUETYPE = v4f64,
     91 
     92       x86mmx         =  37,   // This is an X86 MMX value
     93 
     94       Glue           =  38,   // This glues nodes together during pre-RA sched
     95 
     96       isVoid         =  39,   // This has no value
     97 
     98       Untyped        =  40,   // This value takes a register, but has
     99                               // unspecified type.  The register class
    100                               // will be determined by the opcode.
    101 
    102       LAST_VALUETYPE =  41,   // This always remains at the end of the list.
    103 
    104       // This is the current maximum for LAST_VALUETYPE.
    105       // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
    106       // This value must be a multiple of 32.
    107       MAX_ALLOWED_VALUETYPE = 64,
    108 
    109       // Metadata - This is MDNode or MDString.
    110       Metadata       = 250,
    111 
    112       // iPTRAny - An int value the size of the pointer of the current
    113       // target to any address space. This must only be used internal to
    114       // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
    115       iPTRAny        = 251,
    116 
    117       // vAny - A vector with any length and element size. This is used
    118       // for intrinsics that have overloadings based on vector types.
    119       // This is only for tblgen's consumption!
    120       vAny           = 252,
    121 
    122       // fAny - Any floating-point or vector floating-point value. This is used
    123       // for intrinsics that have overloadings based on floating-point types.
    124       // This is only for tblgen's consumption!
    125       fAny           = 253,
    126 
    127       // iAny - An integer or vector integer value of any bit width. This is
    128       // used for intrinsics that have overloadings based on integer bit widths.
    129       // This is only for tblgen's consumption!
    130       iAny           = 254,
    131 
    132       // iPTR - An int value the size of the pointer of the current
    133       // target.  This should only be used internal to tblgen!
    134       iPTR           = 255,
    135 
    136       // LastSimpleValueType - The greatest valid SimpleValueType value.
    137       LastSimpleValueType = 255,
    138 
    139       // INVALID_SIMPLE_VALUE_TYPE - Simple value types greater than or equal
    140       // to this are considered extended value types.
    141       INVALID_SIMPLE_VALUE_TYPE = LastSimpleValueType + 1
    142     };
    143 
    144     SimpleValueType SimpleTy;
    145 
    146     MVT() : SimpleTy((SimpleValueType)(INVALID_SIMPLE_VALUE_TYPE)) {}
    147     MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
    148 
    149     bool operator>(const MVT& S)  const { return SimpleTy >  S.SimpleTy; }
    150     bool operator<(const MVT& S)  const { return SimpleTy <  S.SimpleTy; }
    151     bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
    152     bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
    153     bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
    154     bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
    155 
    156     /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
    157     bool isFloatingPoint() const {
    158       return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
    159                SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
    160               (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE &&
    161                SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE));
    162     }
    163 
    164     /// isInteger - Return true if this is an integer, or a vector integer type.
    165     bool isInteger() const {
    166       return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
    167                SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
    168               (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE &&
    169                SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE));
    170     }
    171 
    172     /// isVector - Return true if this is a vector value type.
    173     bool isVector() const {
    174       return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
    175               SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
    176     }
    177 
    178     /// is64BitVector - Return true if this is a 64-bit vector type.
    179     bool is64BitVector() const {
    180       return (SimpleTy == MVT::v8i8  || SimpleTy == MVT::v4i16 ||
    181               SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
    182               SimpleTy == MVT::v2f32);
    183     }
    184 
    185     /// is128BitVector - Return true if this is a 128-bit vector type.
    186     bool is128BitVector() const {
    187       return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
    188               SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 ||
    189               SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64);
    190     }
    191 
    192     /// is256BitVector - Return true if this is a 256-bit vector type.
    193     bool is256BitVector() const {
    194       return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64  ||
    195               SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
    196               SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
    197     }
    198 
    199     /// is512BitVector - Return true if this is a 512-bit vector type.
    200     bool is512BitVector() const {
    201       return (SimpleTy == MVT::v8i64 || SimpleTy == MVT::v16i32);
    202     }
    203 
    204     /// is1024BitVector - Return true if this is a 1024-bit vector type.
    205     bool is1024BitVector() const {
    206       return (SimpleTy == MVT::v16i64);
    207     }
    208 
    209     /// isPow2VectorType - Returns true if the given vector is a power of 2.
    210     bool isPow2VectorType() const {
    211       unsigned NElts = getVectorNumElements();
    212       return !(NElts & (NElts - 1));
    213     }
    214 
    215     /// getPow2VectorType - Widens the length of the given vector MVT up to
    216     /// the nearest power of 2 and returns that type.
    217     MVT getPow2VectorType() const {
    218       if (isPow2VectorType())
    219         return *this;
    220 
    221       unsigned NElts = getVectorNumElements();
    222       unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
    223       return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
    224     }
    225 
    226     /// getScalarType - If this is a vector type, return the element type,
    227     /// otherwise return this.
    228     MVT getScalarType() const {
    229       return isVector() ? getVectorElementType() : *this;
    230     }
    231 
    232     MVT getVectorElementType() const {
    233       switch (SimpleTy) {
    234       default:
    235         llvm_unreachable("Not a vector MVT!");
    236       case v2i8 :
    237       case v4i8 :
    238       case v8i8 :
    239       case v16i8:
    240       case v32i8: return i8;
    241       case v2i16:
    242       case v4i16:
    243       case v8i16:
    244       case v16i16: return i16;
    245       case v2i32:
    246       case v4i32:
    247       case v8i32:
    248       case v16i32: return i32;
    249       case v1i64:
    250       case v2i64:
    251       case v4i64:
    252       case v8i64:
    253       case v16i64: return i64;
    254       case v2f16: return f16;
    255       case v2f32:
    256       case v4f32:
    257       case v8f32: return f32;
    258       case v2f64:
    259       case v4f64: return f64;
    260       }
    261     }
    262 
    263     unsigned getVectorNumElements() const {
    264       switch (SimpleTy) {
    265       default:
    266         llvm_unreachable("Not a vector MVT!");
    267       case v32i8: return 32;
    268       case v16i8:
    269       case v16i16:
    270       case v16i32:
    271       case v16i64:return 16;
    272       case v8i8 :
    273       case v8i16:
    274       case v8i32:
    275       case v8i64:
    276       case v8f32: return 8;
    277       case v4i8:
    278       case v4i16:
    279       case v4i32:
    280       case v4i64:
    281       case v4f32:
    282       case v4f64: return 4;
    283       case v2i8:
    284       case v2i16:
    285       case v2i32:
    286       case v2i64:
    287       case v2f16:
    288       case v2f32:
    289       case v2f64: return 2;
    290       case v1i64: return 1;
    291       }
    292     }
    293 
    294     unsigned getSizeInBits() const {
    295       switch (SimpleTy) {
    296       case iPTR:
    297         llvm_unreachable("Value type size is target-dependent. Ask TLI.");
    298       case iPTRAny:
    299       case iAny:
    300       case fAny:
    301         llvm_unreachable("Value type is overloaded.");
    302       default:
    303         llvm_unreachable("getSizeInBits called on extended MVT.");
    304       case i1  :  return 1;
    305       case i8  :  return 8;
    306       case i16 :
    307       case f16:
    308       case v2i8:  return 16;
    309       case f32 :
    310       case i32 :
    311       case v4i8:
    312       case v2i16:
    313       case v2f16: return 32;
    314       case x86mmx:
    315       case f64 :
    316       case i64 :
    317       case v8i8:
    318       case v4i16:
    319       case v2i32:
    320       case v1i64:
    321       case v2f32: return 64;
    322       case f80 :  return 80;
    323       case f128:
    324       case ppcf128:
    325       case i128:
    326       case v16i8:
    327       case v8i16:
    328       case v4i32:
    329       case v2i64:
    330       case v4f32:
    331       case v2f64: return 128;
    332       case v32i8:
    333       case v16i16:
    334       case v8i32:
    335       case v4i64:
    336       case v8f32:
    337       case v4f64: return 256;
    338       case v16i32:
    339       case v8i64: return 512;
    340       case v16i64:return 1024;
    341       }
    342     }
    343 
    344     /// getStoreSize - Return the number of bytes overwritten by a store
    345     /// of the specified value type.
    346     unsigned getStoreSize() const {
    347       return (getSizeInBits() + 7) / 8;
    348     }
    349 
    350     /// getStoreSizeInBits - Return the number of bits overwritten by a store
    351     /// of the specified value type.
    352     unsigned getStoreSizeInBits() const {
    353       return getStoreSize() * 8;
    354     }
    355 
    356     static MVT getFloatingPointVT(unsigned BitWidth) {
    357       switch (BitWidth) {
    358       default:
    359         llvm_unreachable("Bad bit width!");
    360       case 16:
    361         return MVT::f16;
    362       case 32:
    363         return MVT::f32;
    364       case 64:
    365         return MVT::f64;
    366       case 80:
    367         return MVT::f80;
    368       case 128:
    369         return MVT::f128;
    370       }
    371     }
    372 
    373     static MVT getIntegerVT(unsigned BitWidth) {
    374       switch (BitWidth) {
    375       default:
    376         return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
    377       case 1:
    378         return MVT::i1;
    379       case 8:
    380         return MVT::i8;
    381       case 16:
    382         return MVT::i16;
    383       case 32:
    384         return MVT::i32;
    385       case 64:
    386         return MVT::i64;
    387       case 128:
    388         return MVT::i128;
    389       }
    390     }
    391 
    392     static MVT getVectorVT(MVT VT, unsigned NumElements) {
    393       switch (VT.SimpleTy) {
    394       default:
    395         break;
    396       case MVT::i8:
    397         if (NumElements == 2)  return MVT::v2i8;
    398         if (NumElements == 4)  return MVT::v4i8;
    399         if (NumElements == 8)  return MVT::v8i8;
    400         if (NumElements == 16) return MVT::v16i8;
    401         if (NumElements == 32) return MVT::v32i8;
    402         break;
    403       case MVT::i16:
    404         if (NumElements == 2)  return MVT::v2i16;
    405         if (NumElements == 4)  return MVT::v4i16;
    406         if (NumElements == 8)  return MVT::v8i16;
    407         if (NumElements == 16) return MVT::v16i16;
    408         break;
    409       case MVT::i32:
    410         if (NumElements == 2)  return MVT::v2i32;
    411         if (NumElements == 4)  return MVT::v4i32;
    412         if (NumElements == 8)  return MVT::v8i32;
    413         if (NumElements == 16) return MVT::v16i32;
    414         break;
    415       case MVT::i64:
    416         if (NumElements == 1)  return MVT::v1i64;
    417         if (NumElements == 2)  return MVT::v2i64;
    418         if (NumElements == 4)  return MVT::v4i64;
    419         if (NumElements == 8)  return MVT::v8i64;
    420         if (NumElements == 16) return MVT::v16i64;
    421         break;
    422       case MVT::f16:
    423         if (NumElements == 2)  return MVT::v2f16;
    424         break;
    425       case MVT::f32:
    426         if (NumElements == 2)  return MVT::v2f32;
    427         if (NumElements == 4)  return MVT::v4f32;
    428         if (NumElements == 8)  return MVT::v8f32;
    429         break;
    430       case MVT::f64:
    431         if (NumElements == 2)  return MVT::v2f64;
    432         if (NumElements == 4)  return MVT::v4f64;
    433         break;
    434       }
    435       return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
    436     }
    437   };
    438 
    439 
    440   /// EVT - Extended Value Type.  Capable of holding value types which are not
    441   /// native for any processor (such as the i12345 type), as well as the types
    442   /// a MVT can represent.
    443   struct EVT {
    444   private:
    445     MVT V;
    446     Type *LLVMTy;
    447 
    448   public:
    449     EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)),
    450             LLVMTy(0) {}
    451     EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(0) { }
    452     EVT(MVT S) : V(S), LLVMTy(0) {}
    453 
    454     bool operator==(EVT VT) const {
    455       return !(*this != VT);
    456     }
    457     bool operator!=(EVT VT) const {
    458       if (V.SimpleTy != VT.V.SimpleTy)
    459         return true;
    460       if (V.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
    461         return LLVMTy != VT.LLVMTy;
    462       return false;
    463     }
    464 
    465     /// getFloatingPointVT - Returns the EVT that represents a floating point
    466     /// type with the given number of bits.  There are two floating point types
    467     /// with 128 bits - this returns f128 rather than ppcf128.
    468     static EVT getFloatingPointVT(unsigned BitWidth) {
    469       return MVT::getFloatingPointVT(BitWidth);
    470     }
    471 
    472     /// getIntegerVT - Returns the EVT that represents an integer with the given
    473     /// number of bits.
    474     static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) {
    475       MVT M = MVT::getIntegerVT(BitWidth);
    476       if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
    477         return M;
    478       return getExtendedIntegerVT(Context, BitWidth);
    479     }
    480 
    481     /// getVectorVT - Returns the EVT that represents a vector NumElements in
    482     /// length, where each element is of type VT.
    483     static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements) {
    484       MVT M = MVT::getVectorVT(VT.V, NumElements);
    485       if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
    486         return M;
    487       return getExtendedVectorVT(Context, VT, NumElements);
    488     }
    489 
    490     /// changeVectorElementTypeToInteger - Return a vector with the same number
    491     /// of elements as this vector, but with the element type converted to an
    492     /// integer type with the same bitwidth.
    493     EVT changeVectorElementTypeToInteger() const {
    494       if (!isSimple())
    495         return changeExtendedVectorElementTypeToInteger();
    496       MVT EltTy = getSimpleVT().getVectorElementType();
    497       unsigned BitWidth = EltTy.getSizeInBits();
    498       MVT IntTy = MVT::getIntegerVT(BitWidth);
    499       MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements());
    500       assert(VecTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
    501              "Simple vector VT not representable by simple integer vector VT!");
    502       return VecTy;
    503     }
    504 
    505     /// isSimple - Test if the given EVT is simple (as opposed to being
    506     /// extended).
    507     bool isSimple() const {
    508       return V.SimpleTy <= MVT::LastSimpleValueType;
    509     }
    510 
    511     /// isExtended - Test if the given EVT is extended (as opposed to
    512     /// being simple).
    513     bool isExtended() const {
    514       return !isSimple();
    515     }
    516 
    517     /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
    518     bool isFloatingPoint() const {
    519       return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
    520     }
    521 
    522     /// isInteger - Return true if this is an integer, or a vector integer type.
    523     bool isInteger() const {
    524       return isSimple() ? V.isInteger() : isExtendedInteger();
    525     }
    526 
    527     /// isVector - Return true if this is a vector value type.
    528     bool isVector() const {
    529       return isSimple() ? V.isVector() : isExtendedVector();
    530     }
    531 
    532     /// is64BitVector - Return true if this is a 64-bit vector type.
    533     bool is64BitVector() const {
    534       return isSimple() ? V.is64BitVector() : isExtended64BitVector();
    535     }
    536 
    537     /// is128BitVector - Return true if this is a 128-bit vector type.
    538     bool is128BitVector() const {
    539       return isSimple() ? V.is128BitVector() : isExtended128BitVector();
    540     }
    541 
    542     /// is256BitVector - Return true if this is a 256-bit vector type.
    543     bool is256BitVector() const {
    544       return isSimple() ? V.is256BitVector() : isExtended256BitVector();
    545     }
    546 
    547     /// is512BitVector - Return true if this is a 512-bit vector type.
    548     bool is512BitVector() const {
    549       return isSimple() ? V.is512BitVector() : isExtended512BitVector();
    550     }
    551 
    552     /// is1024BitVector - Return true if this is a 1024-bit vector type.
    553     bool is1024BitVector() const {
    554       return isSimple() ? V.is1024BitVector() : isExtended1024BitVector();
    555     }
    556 
    557     /// isOverloaded - Return true if this is an overloaded type for TableGen.
    558     bool isOverloaded() const {
    559       return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
    560     }
    561 
    562     /// isByteSized - Return true if the bit size is a multiple of 8.
    563     bool isByteSized() const {
    564       return (getSizeInBits() & 7) == 0;
    565     }
    566 
    567     /// isRound - Return true if the size is a power-of-two number of bytes.
    568     bool isRound() const {
    569       unsigned BitSize = getSizeInBits();
    570       return BitSize >= 8 && !(BitSize & (BitSize - 1));
    571     }
    572 
    573     /// bitsEq - Return true if this has the same number of bits as VT.
    574     bool bitsEq(EVT VT) const {
    575       if (EVT::operator==(VT)) return true;
    576       return getSizeInBits() == VT.getSizeInBits();
    577     }
    578 
    579     /// bitsGT - Return true if this has more bits than VT.
    580     bool bitsGT(EVT VT) const {
    581       if (EVT::operator==(VT)) return false;
    582       return getSizeInBits() > VT.getSizeInBits();
    583     }
    584 
    585     /// bitsGE - Return true if this has no less bits than VT.
    586     bool bitsGE(EVT VT) const {
    587       if (EVT::operator==(VT)) return true;
    588       return getSizeInBits() >= VT.getSizeInBits();
    589     }
    590 
    591     /// bitsLT - Return true if this has less bits than VT.
    592     bool bitsLT(EVT VT) const {
    593       if (EVT::operator==(VT)) return false;
    594       return getSizeInBits() < VT.getSizeInBits();
    595     }
    596 
    597     /// bitsLE - Return true if this has no more bits than VT.
    598     bool bitsLE(EVT VT) const {
    599       if (EVT::operator==(VT)) return true;
    600       return getSizeInBits() <= VT.getSizeInBits();
    601     }
    602 
    603 
    604     /// getSimpleVT - Return the SimpleValueType held in the specified
    605     /// simple EVT.
    606     MVT getSimpleVT() const {
    607       assert(isSimple() && "Expected a SimpleValueType!");
    608       return V;
    609     }
    610 
    611     /// getScalarType - If this is a vector type, return the element type,
    612     /// otherwise return this.
    613     EVT getScalarType() const {
    614       return isVector() ? getVectorElementType() : *this;
    615     }
    616 
    617     /// getVectorElementType - Given a vector type, return the type of
    618     /// each element.
    619     EVT getVectorElementType() const {
    620       assert(isVector() && "Invalid vector type!");
    621       if (isSimple())
    622         return V.getVectorElementType();
    623       return getExtendedVectorElementType();
    624     }
    625 
    626     /// getVectorNumElements - Given a vector type, return the number of
    627     /// elements it contains.
    628     unsigned getVectorNumElements() const {
    629       assert(isVector() && "Invalid vector type!");
    630       if (isSimple())
    631         return V.getVectorNumElements();
    632       return getExtendedVectorNumElements();
    633     }
    634 
    635     /// getSizeInBits - Return the size of the specified value type in bits.
    636     unsigned getSizeInBits() const {
    637       if (isSimple())
    638         return V.getSizeInBits();
    639       return getExtendedSizeInBits();
    640     }
    641 
    642     /// getStoreSize - Return the number of bytes overwritten by a store
    643     /// of the specified value type.
    644     unsigned getStoreSize() const {
    645       return (getSizeInBits() + 7) / 8;
    646     }
    647 
    648     /// getStoreSizeInBits - Return the number of bits overwritten by a store
    649     /// of the specified value type.
    650     unsigned getStoreSizeInBits() const {
    651       return getStoreSize() * 8;
    652     }
    653 
    654     /// getRoundIntegerType - Rounds the bit-width of the given integer EVT up
    655     /// to the nearest power of two (and at least to eight), and returns the
    656     /// integer EVT with that number of bits.
    657     EVT getRoundIntegerType(LLVMContext &Context) const {
    658       assert(isInteger() && !isVector() && "Invalid integer type!");
    659       unsigned BitWidth = getSizeInBits();
    660       if (BitWidth <= 8)
    661         return EVT(MVT::i8);
    662       return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
    663     }
    664 
    665     /// getHalfSizedIntegerVT - Finds the smallest simple value type that is
    666     /// greater than or equal to half the width of this EVT. If no simple
    667     /// value type can be found, an extended integer value type of half the
    668     /// size (rounded up) is returned.
    669     EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
    670       assert(isInteger() && !isVector() && "Invalid integer type!");
    671       unsigned EVTSize = getSizeInBits();
    672       for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
    673           IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) {
    674         EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
    675         if (HalfVT.getSizeInBits() * 2 >= EVTSize)
    676           return HalfVT;
    677       }
    678       return getIntegerVT(Context, (EVTSize + 1) / 2);
    679     }
    680 
    681     /// isPow2VectorType - Returns true if the given vector is a power of 2.
    682     bool isPow2VectorType() const {
    683       unsigned NElts = getVectorNumElements();
    684       return !(NElts & (NElts - 1));
    685     }
    686 
    687     /// getPow2VectorType - Widens the length of the given vector EVT up to
    688     /// the nearest power of 2 and returns that type.
    689     EVT getPow2VectorType(LLVMContext &Context) const {
    690       if (!isPow2VectorType()) {
    691         unsigned NElts = getVectorNumElements();
    692         unsigned Pow2NElts = 1 <<  Log2_32_Ceil(NElts);
    693         return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts);
    694       }
    695       else {
    696         return *this;
    697       }
    698     }
    699 
    700     /// getEVTString - This function returns value type as a string,
    701     /// e.g. "i32".
    702     std::string getEVTString() const;
    703 
    704     /// getTypeForEVT - This method returns an LLVM type corresponding to the
    705     /// specified EVT.  For integer types, this returns an unsigned type.  Note
    706     /// that this will abort for types that cannot be represented.
    707     Type *getTypeForEVT(LLVMContext &Context) const;
    708 
    709     /// getEVT - Return the value type corresponding to the specified type.
    710     /// This returns all pointers as iPTR.  If HandleUnknown is true, unknown
    711     /// types are returned as Other, otherwise they are invalid.
    712     static EVT getEVT(Type *Ty, bool HandleUnknown = false);
    713 
    714     intptr_t getRawBits() {
    715       if (isSimple())
    716         return V.SimpleTy;
    717       else
    718         return (intptr_t)(LLVMTy);
    719     }
    720 
    721     /// compareRawBits - A meaningless but well-behaved order, useful for
    722     /// constructing containers.
    723     struct compareRawBits {
    724       bool operator()(EVT L, EVT R) const {
    725         if (L.V.SimpleTy == R.V.SimpleTy)
    726           return L.LLVMTy < R.LLVMTy;
    727         else
    728           return L.V.SimpleTy < R.V.SimpleTy;
    729       }
    730     };
    731 
    732   private:
    733     // Methods for handling the Extended-type case in functions above.
    734     // These are all out-of-line to prevent users of this header file
    735     // from having a dependency on Type.h.
    736     EVT changeExtendedVectorElementTypeToInteger() const;
    737     static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
    738     static EVT getExtendedVectorVT(LLVMContext &C, EVT VT,
    739                                    unsigned NumElements);
    740     bool isExtendedFloatingPoint() const;
    741     bool isExtendedInteger() const;
    742     bool isExtendedVector() const;
    743     bool isExtended64BitVector() const;
    744     bool isExtended128BitVector() const;
    745     bool isExtended256BitVector() const;
    746     bool isExtended512BitVector() const;
    747     bool isExtended1024BitVector() const;
    748     EVT getExtendedVectorElementType() const;
    749     unsigned getExtendedVectorNumElements() const;
    750     unsigned getExtendedSizeInBits() const;
    751   };
    752 
    753 } // End llvm namespace
    754 
    755 #endif
    756