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