LLVM API Documentation

ValueTypes.h
Go to the documentation of this file.
00001 //===- CodeGen/ValueTypes.h - Low-Level Target independ. types --*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the set of low-level target independent types which various
00011 // values in the code generator are.  This allows the target specific behavior
00012 // of instructions to be described to target independent passes.
00013 //
00014 //===----------------------------------------------------------------------===//
00015 
00016 #ifndef LLVM_CODEGEN_VALUETYPES_H
00017 #define LLVM_CODEGEN_VALUETYPES_H
00018 
00019 #include "llvm/Support/DataTypes.h"
00020 #include "llvm/Support/ErrorHandling.h"
00021 #include "llvm/Support/MathExtras.h"
00022 #include <cassert>
00023 #include <string>
00024 
00025 namespace llvm {
00026   class Type;
00027   class LLVMContext;
00028   struct EVT;
00029 
00030   /// MVT - Machine Value Type.  Every type that is supported natively by some
00031   /// processor targeted by LLVM occurs here.  This means that any legal value
00032   /// type can be represented by a MVT.
00033   class MVT {
00034   public:
00035     enum SimpleValueType {
00036       // INVALID_SIMPLE_VALUE_TYPE - Simple value types less than zero are
00037       // considered extended value types.
00038       INVALID_SIMPLE_VALUE_TYPE = -1,
00039 
00040       // If you change this numbering, you must change the values in
00041       // ValueTypes.td as well!
00042       Other          =   0,   // This is a non-standard value
00043       i1             =   1,   // This is a 1 bit integer value
00044       i8             =   2,   // This is an 8 bit integer value
00045       i16            =   3,   // This is a 16 bit integer value
00046       i32            =   4,   // This is a 32 bit integer value
00047       i64            =   5,   // This is a 64 bit integer value
00048       i128           =   6,   // This is a 128 bit integer value
00049 
00050       FIRST_INTEGER_VALUETYPE = i1,
00051       LAST_INTEGER_VALUETYPE  = i128,
00052 
00053       f16            =   7,   // This is a 16 bit floating point value
00054       f32            =   8,   // This is a 32 bit floating point value
00055       f64            =   9,   // This is a 64 bit floating point value
00056       f80            =  10,   // This is a 80 bit floating point value
00057       f128           =  11,   // This is a 128 bit floating point value
00058       ppcf128        =  12,   // This is a PPC 128-bit floating point value
00059 
00060       FIRST_FP_VALUETYPE = f16,
00061       LAST_FP_VALUETYPE  = ppcf128,
00062 
00063       v2i1           =  13,   //  2 x i1
00064       v4i1           =  14,   //  4 x i1
00065       v8i1           =  15,   //  8 x i1
00066       v16i1          =  16,   // 16 x i1
00067       v32i1          =  17,   // 32 x i1
00068       v64i1          =  18,   // 64 x i1
00069 
00070       v2i8           =  19,   //  2 x i8
00071       v4i8           =  20,   //  4 x i8
00072       v8i8           =  21,   //  8 x i8
00073       v16i8          =  22,   // 16 x i8
00074       v32i8          =  23,   // 32 x i8
00075       v64i8          =  24,   // 64 x i8
00076       v1i16          =  25,   //  1 x i16
00077       v2i16          =  26,   //  2 x i16
00078       v4i16          =  27,   //  4 x i16
00079       v8i16          =  28,   //  8 x i16
00080       v16i16         =  29,   // 16 x i16
00081       v32i16         =  30,   // 32 x i16
00082       v1i32          =  31,   //  1 x i32
00083       v2i32          =  32,   //  2 x i32
00084       v4i32          =  33,   //  4 x i32
00085       v8i32          =  34,   //  8 x i32
00086       v16i32         =  35,   // 16 x i32
00087       v1i64          =  36,   //  1 x i64
00088       v2i64          =  37,   //  2 x i64
00089       v4i64          =  38,   //  4 x i64
00090       v8i64          =  39,   //  8 x i64
00091       v16i64         =  40,   // 16 x i64
00092 
00093       FIRST_INTEGER_VECTOR_VALUETYPE = v2i1,
00094       LAST_INTEGER_VECTOR_VALUETYPE = v16i64,
00095 
00096       v2f16          =  41,   //  2 x f16
00097       v2f32          =  42,   //  2 x f32
00098       v4f32          =  43,   //  4 x f32
00099       v8f32          =  44,   //  8 x f32
00100       v16f32         =  45,   // 16 x f32
00101       v2f64          =  46,   //  2 x f64
00102       v4f64          =  47,   //  4 x f64
00103       v8f64          =  48,   //  8 x f64
00104 
00105       FIRST_FP_VECTOR_VALUETYPE = v2f16,
00106       LAST_FP_VECTOR_VALUETYPE = v8f64,
00107 
00108       FIRST_VECTOR_VALUETYPE = v2i1,
00109       LAST_VECTOR_VALUETYPE  = v8f64,
00110 
00111       x86mmx         =  49,   // This is an X86 MMX value
00112 
00113       Glue           =  50,   // This glues nodes together during pre-RA sched
00114 
00115       isVoid         =  51,   // This has no value
00116 
00117       Untyped        =  52,   // This value takes a register, but has
00118                               // unspecified type.  The register class
00119                               // will be determined by the opcode.
00120 
00121       LAST_VALUETYPE =  53,   // This always remains at the end of the list.
00122 
00123       // This is the current maximum for LAST_VALUETYPE.
00124       // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
00125       // This value must be a multiple of 32.
00126       MAX_ALLOWED_VALUETYPE = 64,
00127 
00128       // Metadata - This is MDNode or MDString.
00129       Metadata       = 250,
00130 
00131       // iPTRAny - An int value the size of the pointer of the current
00132       // target to any address space. This must only be used internal to
00133       // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
00134       iPTRAny        = 251,
00135 
00136       // vAny - A vector with any length and element size. This is used
00137       // for intrinsics that have overloadings based on vector types.
00138       // This is only for tblgen's consumption!
00139       vAny           = 252,
00140 
00141       // fAny - Any floating-point or vector floating-point value. This is used
00142       // for intrinsics that have overloadings based on floating-point types.
00143       // This is only for tblgen's consumption!
00144       fAny           = 253,
00145 
00146       // iAny - An integer or vector integer value of any bit width. This is
00147       // used for intrinsics that have overloadings based on integer bit widths.
00148       // This is only for tblgen's consumption!
00149       iAny           = 254,
00150 
00151       // iPTR - An int value the size of the pointer of the current
00152       // target.  This should only be used internal to tblgen!
00153       iPTR           = 255
00154     };
00155 
00156     SimpleValueType SimpleTy;
00157 
00158     MVT() : SimpleTy((SimpleValueType)(INVALID_SIMPLE_VALUE_TYPE)) {}
00159     MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
00160 
00161     bool operator>(const MVT& S)  const { return SimpleTy >  S.SimpleTy; }
00162     bool operator<(const MVT& S)  const { return SimpleTy <  S.SimpleTy; }
00163     bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
00164     bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
00165     bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
00166     bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
00167 
00168     /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
00169     bool isFloatingPoint() const {
00170       return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
00171                SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
00172               (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE &&
00173                SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE));
00174     }
00175 
00176     /// isInteger - Return true if this is an integer, or a vector integer type.
00177     bool isInteger() const {
00178       return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
00179                SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
00180               (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE &&
00181                SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE));
00182     }
00183 
00184     /// isVector - Return true if this is a vector value type.
00185     bool isVector() const {
00186       return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
00187               SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
00188     }
00189 
00190     /// is16BitVector - Return true if this is a 16-bit vector type.
00191     bool is16BitVector() const {
00192       return (SimpleTy == MVT::v2i8  || SimpleTy == MVT::v1i16 ||
00193               SimpleTy == MVT::v16i1);
00194     }
00195 
00196     /// is32BitVector - Return true if this is a 32-bit vector type.
00197     bool is32BitVector() const {
00198       return (SimpleTy == MVT::v4i8  || SimpleTy == MVT::v2i16 ||
00199               SimpleTy == MVT::v1i32);
00200     }
00201 
00202     /// is64BitVector - Return true if this is a 64-bit vector type.
00203     bool is64BitVector() const {
00204       return (SimpleTy == MVT::v8i8  || SimpleTy == MVT::v4i16 ||
00205               SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
00206               SimpleTy == MVT::v2f32);
00207     }
00208 
00209     /// is128BitVector - Return true if this is a 128-bit vector type.
00210     bool is128BitVector() const {
00211       return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
00212               SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 ||
00213               SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64);
00214     }
00215 
00216     /// is256BitVector - Return true if this is a 256-bit vector type.
00217     bool is256BitVector() const {
00218       return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64  ||
00219               SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
00220               SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
00221     }
00222 
00223     /// is512BitVector - Return true if this is a 512-bit vector type.
00224     bool is512BitVector() const {
00225       return (SimpleTy == MVT::v8f64 || SimpleTy == MVT::v16f32 ||
00226               SimpleTy == MVT::v64i8 || SimpleTy == MVT::v32i16 ||
00227               SimpleTy == MVT::v8i64 || SimpleTy == MVT::v16i32);
00228     }
00229 
00230     /// is1024BitVector - Return true if this is a 1024-bit vector type.
00231     bool is1024BitVector() const {
00232       return (SimpleTy == MVT::v16i64);
00233     }
00234 
00235     /// isPow2VectorType - Returns true if the given vector is a power of 2.
00236     bool isPow2VectorType() const {
00237       unsigned NElts = getVectorNumElements();
00238       return !(NElts & (NElts - 1));
00239     }
00240 
00241     /// getPow2VectorType - Widens the length of the given vector MVT up to
00242     /// the nearest power of 2 and returns that type.
00243     MVT getPow2VectorType() const {
00244       if (isPow2VectorType())
00245         return *this;
00246 
00247       unsigned NElts = getVectorNumElements();
00248       unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
00249       return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
00250     }
00251 
00252     /// getScalarType - If this is a vector type, return the element type,
00253     /// otherwise return this.
00254     MVT getScalarType() const {
00255       return isVector() ? getVectorElementType() : *this;
00256     }
00257 
00258     MVT getVectorElementType() const {
00259       switch (SimpleTy) {
00260       default:
00261         llvm_unreachable("Not a vector MVT!");
00262       case v2i1 :
00263       case v4i1 :
00264       case v8i1 :
00265       case v16i1 :
00266       case v32i1 :
00267       case v64i1: return i1;
00268       case v2i8 :
00269       case v4i8 :
00270       case v8i8 :
00271       case v16i8:
00272       case v32i8:
00273       case v64i8: return i8;
00274       case v1i16:
00275       case v2i16:
00276       case v4i16:
00277       case v8i16:
00278       case v16i16:
00279       case v32i16: return i16;
00280       case v1i32:
00281       case v2i32:
00282       case v4i32:
00283       case v8i32:
00284       case v16i32: return i32;
00285       case v1i64:
00286       case v2i64:
00287       case v4i64:
00288       case v8i64:
00289       case v16i64: return i64;
00290       case v2f16: return f16;
00291       case v2f32:
00292       case v4f32:
00293       case v8f32:
00294       case v16f32: return f32;
00295       case v2f64:
00296       case v4f64:
00297       case v8f64: return f64;
00298       }
00299     }
00300 
00301     unsigned getVectorNumElements() const {
00302       switch (SimpleTy) {
00303       default:
00304         llvm_unreachable("Not a vector MVT!");
00305       case v32i1:
00306       case v32i8:
00307       case v32i16: return 32;
00308       case v64i1:
00309       case v64i8: return 64;
00310       case v16i1:
00311       case v16i8:
00312       case v16i16:
00313       case v16i32:
00314       case v16i64:
00315       case v16f32: return 16;
00316       case v8i1 :
00317       case v8i8 :
00318       case v8i16:
00319       case v8i32:
00320       case v8i64:
00321       case v8f32:
00322       case v8f64: return 8;
00323       case v4i1:
00324       case v4i8:
00325       case v4i16:
00326       case v4i32:
00327       case v4i64:
00328       case v4f32:
00329       case v4f64: return 4;
00330       case v2i1:
00331       case v2i8:
00332       case v2i16:
00333       case v2i32:
00334       case v2i64:
00335       case v2f16:
00336       case v2f32:
00337       case v2f64: return 2;
00338       case v1i16:
00339       case v1i32:
00340       case v1i64: return 1;
00341       }
00342     }
00343 
00344     unsigned getSizeInBits() const {
00345       switch (SimpleTy) {
00346       case iPTR:
00347         llvm_unreachable("Value type size is target-dependent. Ask TLI.");
00348       case iPTRAny:
00349       case iAny:
00350       case fAny:
00351       case vAny:
00352         llvm_unreachable("Value type is overloaded.");
00353       case Metadata:
00354         llvm_unreachable("Value type is metadata.");
00355       default:
00356         llvm_unreachable("getSizeInBits called on extended MVT.");
00357       case i1  :  return 1;
00358       case v2i1:  return 2;
00359       case v4i1:  return 4;
00360       case i8  :
00361       case v8i1: return 8;
00362       case i16 :
00363       case f16:
00364       case v16i1:
00365       case v2i8:
00366       case v1i16: return 16;
00367       case f32 :
00368       case i32 :
00369       case v32i1:
00370       case v4i8:
00371       case v2i16:
00372       case v2f16:
00373       case v1i32: return 32;
00374       case x86mmx:
00375       case f64 :
00376       case i64 :
00377       case v64i1:
00378       case v8i8:
00379       case v4i16:
00380       case v2i32:
00381       case v1i64:
00382       case v2f32: return 64;
00383       case f80 :  return 80;
00384       case f128:
00385       case ppcf128:
00386       case i128:
00387       case v16i8:
00388       case v8i16:
00389       case v4i32:
00390       case v2i64:
00391       case v4f32:
00392       case v2f64: return 128;
00393       case v32i8:
00394       case v16i16:
00395       case v8i32:
00396       case v4i64:
00397       case v8f32:
00398       case v4f64: return 256;
00399       case v64i8:
00400       case v32i16:
00401       case v16i32:
00402       case v8i64:
00403       case v16f32:
00404       case v8f64: return 512;
00405       case v16i64:return 1024;
00406       }
00407     }
00408 
00409     /// getStoreSize - Return the number of bytes overwritten by a store
00410     /// of the specified value type.
00411     unsigned getStoreSize() const {
00412       return (getSizeInBits() + 7) / 8;
00413     }
00414 
00415     /// getStoreSizeInBits - Return the number of bits overwritten by a store
00416     /// of the specified value type.
00417     unsigned getStoreSizeInBits() const {
00418       return getStoreSize() * 8;
00419     }
00420 
00421     /// Return true if this has more bits than VT.
00422     bool bitsGT(MVT VT) const {
00423       return getSizeInBits() > VT.getSizeInBits();
00424     }
00425 
00426     /// Return true if this has no less bits than VT.
00427     bool bitsGE(MVT VT) const {
00428       return getSizeInBits() >= VT.getSizeInBits();
00429     }
00430 
00431     /// Return true if this has less bits than VT.
00432     bool bitsLT(MVT VT) const {
00433       return getSizeInBits() < VT.getSizeInBits();
00434     }
00435 
00436     /// Return true if this has no more bits than VT.
00437     bool bitsLE(MVT VT) const {
00438       return getSizeInBits() <= VT.getSizeInBits();
00439     }
00440 
00441 
00442     static MVT getFloatingPointVT(unsigned BitWidth) {
00443       switch (BitWidth) {
00444       default:
00445         llvm_unreachable("Bad bit width!");
00446       case 16:
00447         return MVT::f16;
00448       case 32:
00449         return MVT::f32;
00450       case 64:
00451         return MVT::f64;
00452       case 80:
00453         return MVT::f80;
00454       case 128:
00455         return MVT::f128;
00456       }
00457     }
00458 
00459     static MVT getIntegerVT(unsigned BitWidth) {
00460       switch (BitWidth) {
00461       default:
00462         return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
00463       case 1:
00464         return MVT::i1;
00465       case 8:
00466         return MVT::i8;
00467       case 16:
00468         return MVT::i16;
00469       case 32:
00470         return MVT::i32;
00471       case 64:
00472         return MVT::i64;
00473       case 128:
00474         return MVT::i128;
00475       }
00476     }
00477 
00478     static MVT getVectorVT(MVT VT, unsigned NumElements) {
00479       switch (VT.SimpleTy) {
00480       default:
00481         break;
00482       case MVT::i1:
00483         if (NumElements == 2)  return MVT::v2i1;
00484         if (NumElements == 4)  return MVT::v4i1;
00485         if (NumElements == 8)  return MVT::v8i1;
00486         if (NumElements == 16) return MVT::v16i1;
00487         if (NumElements == 32) return MVT::v32i1;
00488         if (NumElements == 64) return MVT::v64i1;
00489         break;
00490       case MVT::i8:
00491         if (NumElements == 2)  return MVT::v2i8;
00492         if (NumElements == 4)  return MVT::v4i8;
00493         if (NumElements == 8)  return MVT::v8i8;
00494         if (NumElements == 16) return MVT::v16i8;
00495         if (NumElements == 32) return MVT::v32i8;
00496         if (NumElements == 64) return MVT::v64i8;
00497         break;
00498       case MVT::i16:
00499         if (NumElements == 1)  return MVT::v1i16;
00500         if (NumElements == 2)  return MVT::v2i16;
00501         if (NumElements == 4)  return MVT::v4i16;
00502         if (NumElements == 8)  return MVT::v8i16;
00503         if (NumElements == 16) return MVT::v16i16;
00504         if (NumElements == 32) return MVT::v32i16;
00505         break;
00506       case MVT::i32:
00507         if (NumElements == 1)  return MVT::v1i32;
00508         if (NumElements == 2)  return MVT::v2i32;
00509         if (NumElements == 4)  return MVT::v4i32;
00510         if (NumElements == 8)  return MVT::v8i32;
00511         if (NumElements == 16) return MVT::v16i32;
00512         break;
00513       case MVT::i64:
00514         if (NumElements == 1)  return MVT::v1i64;
00515         if (NumElements == 2)  return MVT::v2i64;
00516         if (NumElements == 4)  return MVT::v4i64;
00517         if (NumElements == 8)  return MVT::v8i64;
00518         if (NumElements == 16) return MVT::v16i64;
00519         break;
00520       case MVT::f16:
00521         if (NumElements == 2)  return MVT::v2f16;
00522         break;
00523       case MVT::f32:
00524         if (NumElements == 2)  return MVT::v2f32;
00525         if (NumElements == 4)  return MVT::v4f32;
00526         if (NumElements == 8)  return MVT::v8f32;
00527         if (NumElements == 16) return MVT::v16f32;
00528         break;
00529       case MVT::f64:
00530         if (NumElements == 2)  return MVT::v2f64;
00531         if (NumElements == 4)  return MVT::v4f64;
00532         if (NumElements == 8)  return MVT::v8f64;
00533         break;
00534       }
00535       return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
00536     }
00537 
00538     /// Return the value type corresponding to the specified type.  This returns
00539     /// all pointers as iPTR.  If HandleUnknown is true, unknown types are
00540     /// returned as Other, otherwise they are invalid.
00541     static MVT getVT(Type *Ty, bool HandleUnknown = false);
00542 
00543   };
00544 
00545 
00546   /// EVT - Extended Value Type.  Capable of holding value types which are not
00547   /// native for any processor (such as the i12345 type), as well as the types
00548   /// a MVT can represent.
00549   struct EVT {
00550   private:
00551     MVT V;
00552     Type *LLVMTy;
00553 
00554   public:
00555     EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)),
00556             LLVMTy(0) {}
00557     EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(0) { }
00558     EVT(MVT S) : V(S), LLVMTy(0) {}
00559 
00560     bool operator==(EVT VT) const {
00561       return !(*this != VT);
00562     }
00563     bool operator!=(EVT VT) const {
00564       if (V.SimpleTy != VT.V.SimpleTy)
00565         return true;
00566       if (V.SimpleTy < 0)
00567         return LLVMTy != VT.LLVMTy;
00568       return false;
00569     }
00570 
00571     /// getFloatingPointVT - Returns the EVT that represents a floating point
00572     /// type with the given number of bits.  There are two floating point types
00573     /// with 128 bits - this returns f128 rather than ppcf128.
00574     static EVT getFloatingPointVT(unsigned BitWidth) {
00575       return MVT::getFloatingPointVT(BitWidth);
00576     }
00577 
00578     /// getIntegerVT - Returns the EVT that represents an integer with the given
00579     /// number of bits.
00580     static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) {
00581       MVT M = MVT::getIntegerVT(BitWidth);
00582       if (M.SimpleTy >= 0)
00583         return M;
00584       return getExtendedIntegerVT(Context, BitWidth);
00585     }
00586 
00587     /// getVectorVT - Returns the EVT that represents a vector NumElements in
00588     /// length, where each element is of type VT.
00589     static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements) {
00590       MVT M = MVT::getVectorVT(VT.V, NumElements);
00591       if (M.SimpleTy >= 0)
00592         return M;
00593       return getExtendedVectorVT(Context, VT, NumElements);
00594     }
00595 
00596     /// changeVectorElementTypeToInteger - Return a vector with the same number
00597     /// of elements as this vector, but with the element type converted to an
00598     /// integer type with the same bitwidth.
00599     EVT changeVectorElementTypeToInteger() const {
00600       if (!isSimple())
00601         return changeExtendedVectorElementTypeToInteger();
00602       MVT EltTy = getSimpleVT().getVectorElementType();
00603       unsigned BitWidth = EltTy.getSizeInBits();
00604       MVT IntTy = MVT::getIntegerVT(BitWidth);
00605       MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements());
00606       assert(VecTy.SimpleTy >= 0 &&
00607              "Simple vector VT not representable by simple integer vector VT!");
00608       return VecTy;
00609     }
00610 
00611     /// isSimple - Test if the given EVT is simple (as opposed to being
00612     /// extended).
00613     bool isSimple() const {
00614       return V.SimpleTy >= 0;
00615     }
00616 
00617     /// isExtended - Test if the given EVT is extended (as opposed to
00618     /// being simple).
00619     bool isExtended() const {
00620       return !isSimple();
00621     }
00622 
00623     /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
00624     bool isFloatingPoint() const {
00625       return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
00626     }
00627 
00628     /// isInteger - Return true if this is an integer, or a vector integer type.
00629     bool isInteger() const {
00630       return isSimple() ? V.isInteger() : isExtendedInteger();
00631     }
00632 
00633     /// isVector - Return true if this is a vector value type.
00634     bool isVector() const {
00635       return isSimple() ? V.isVector() : isExtendedVector();
00636     }
00637 
00638     /// is16BitVector - Return true if this is a 16-bit vector type.
00639     bool is16BitVector() const {
00640       return isSimple() ? V.is16BitVector() : isExtended16BitVector();
00641     }
00642 
00643     /// is32BitVector - Return true if this is a 32-bit vector type.
00644     bool is32BitVector() const {
00645       return isSimple() ? V.is32BitVector() : isExtended32BitVector();
00646     }
00647 
00648     /// is64BitVector - Return true if this is a 64-bit vector type.
00649     bool is64BitVector() const {
00650       return isSimple() ? V.is64BitVector() : isExtended64BitVector();
00651     }
00652 
00653     /// is128BitVector - Return true if this is a 128-bit vector type.
00654     bool is128BitVector() const {
00655       return isSimple() ? V.is128BitVector() : isExtended128BitVector();
00656     }
00657 
00658     /// is256BitVector - Return true if this is a 256-bit vector type.
00659     bool is256BitVector() const {
00660       return isSimple() ? V.is256BitVector() : isExtended256BitVector();
00661     }
00662 
00663     /// is512BitVector - Return true if this is a 512-bit vector type.
00664     bool is512BitVector() const {
00665       return isSimple() ? V.is512BitVector() : isExtended512BitVector();
00666     }
00667 
00668     /// is1024BitVector - Return true if this is a 1024-bit vector type.
00669     bool is1024BitVector() const {
00670       return isSimple() ? V.is1024BitVector() : isExtended1024BitVector();
00671     }
00672 
00673     /// isOverloaded - Return true if this is an overloaded type for TableGen.
00674     bool isOverloaded() const {
00675       return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
00676     }
00677 
00678     /// isByteSized - Return true if the bit size is a multiple of 8.
00679     bool isByteSized() const {
00680       return (getSizeInBits() & 7) == 0;
00681     }
00682 
00683     /// isRound - Return true if the size is a power-of-two number of bytes.
00684     bool isRound() const {
00685       unsigned BitSize = getSizeInBits();
00686       return BitSize >= 8 && !(BitSize & (BitSize - 1));
00687     }
00688 
00689     /// bitsEq - Return true if this has the same number of bits as VT.
00690     bool bitsEq(EVT VT) const {
00691       if (EVT::operator==(VT)) return true;
00692       return getSizeInBits() == VT.getSizeInBits();
00693     }
00694 
00695     /// bitsGT - Return true if this has more bits than VT.
00696     bool bitsGT(EVT VT) const {
00697       if (EVT::operator==(VT)) return false;
00698       return getSizeInBits() > VT.getSizeInBits();
00699     }
00700 
00701     /// bitsGE - Return true if this has no less bits than VT.
00702     bool bitsGE(EVT VT) const {
00703       if (EVT::operator==(VT)) return true;
00704       return getSizeInBits() >= VT.getSizeInBits();
00705     }
00706 
00707     /// bitsLT - Return true if this has less bits than VT.
00708     bool bitsLT(EVT VT) const {
00709       if (EVT::operator==(VT)) return false;
00710       return getSizeInBits() < VT.getSizeInBits();
00711     }
00712 
00713     /// bitsLE - Return true if this has no more bits than VT.
00714     bool bitsLE(EVT VT) const {
00715       if (EVT::operator==(VT)) return true;
00716       return getSizeInBits() <= VT.getSizeInBits();
00717     }
00718 
00719 
00720     /// getSimpleVT - Return the SimpleValueType held in the specified
00721     /// simple EVT.
00722     MVT getSimpleVT() const {
00723       assert(isSimple() && "Expected a SimpleValueType!");
00724       return V;
00725     }
00726 
00727     /// getScalarType - If this is a vector type, return the element type,
00728     /// otherwise return this.
00729     EVT getScalarType() const {
00730       return isVector() ? getVectorElementType() : *this;
00731     }
00732 
00733     /// getVectorElementType - Given a vector type, return the type of
00734     /// each element.
00735     EVT getVectorElementType() const {
00736       assert(isVector() && "Invalid vector type!");
00737       if (isSimple())
00738         return V.getVectorElementType();
00739       return getExtendedVectorElementType();
00740     }
00741 
00742     /// getVectorNumElements - Given a vector type, return the number of
00743     /// elements it contains.
00744     unsigned getVectorNumElements() const {
00745       assert(isVector() && "Invalid vector type!");
00746       if (isSimple())
00747         return V.getVectorNumElements();
00748       return getExtendedVectorNumElements();
00749     }
00750 
00751     /// getSizeInBits - Return the size of the specified value type in bits.
00752     unsigned getSizeInBits() const {
00753       if (isSimple())
00754         return V.getSizeInBits();
00755       return getExtendedSizeInBits();
00756     }
00757 
00758     /// getStoreSize - Return the number of bytes overwritten by a store
00759     /// of the specified value type.
00760     unsigned getStoreSize() const {
00761       return (getSizeInBits() + 7) / 8;
00762     }
00763 
00764     /// getStoreSizeInBits - Return the number of bits overwritten by a store
00765     /// of the specified value type.
00766     unsigned getStoreSizeInBits() const {
00767       return getStoreSize() * 8;
00768     }
00769 
00770     /// getRoundIntegerType - Rounds the bit-width of the given integer EVT up
00771     /// to the nearest power of two (and at least to eight), and returns the
00772     /// integer EVT with that number of bits.
00773     EVT getRoundIntegerType(LLVMContext &Context) const {
00774       assert(isInteger() && !isVector() && "Invalid integer type!");
00775       unsigned BitWidth = getSizeInBits();
00776       if (BitWidth <= 8)
00777         return EVT(MVT::i8);
00778       return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
00779     }
00780 
00781     /// getHalfSizedIntegerVT - Finds the smallest simple value type that is
00782     /// greater than or equal to half the width of this EVT. If no simple
00783     /// value type can be found, an extended integer value type of half the
00784     /// size (rounded up) is returned.
00785     EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
00786       assert(isInteger() && !isVector() && "Invalid integer type!");
00787       unsigned EVTSize = getSizeInBits();
00788       for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
00789           IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) {
00790         EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
00791         if (HalfVT.getSizeInBits() * 2 >= EVTSize)
00792           return HalfVT;
00793       }
00794       return getIntegerVT(Context, (EVTSize + 1) / 2);
00795     }
00796 
00797     /// isPow2VectorType - Returns true if the given vector is a power of 2.
00798     bool isPow2VectorType() const {
00799       unsigned NElts = getVectorNumElements();
00800       return !(NElts & (NElts - 1));
00801     }
00802 
00803     /// getPow2VectorType - Widens the length of the given vector EVT up to
00804     /// the nearest power of 2 and returns that type.
00805     EVT getPow2VectorType(LLVMContext &Context) const {
00806       if (!isPow2VectorType()) {
00807         unsigned NElts = getVectorNumElements();
00808         unsigned Pow2NElts = 1 <<  Log2_32_Ceil(NElts);
00809         return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts);
00810       }
00811       else {
00812         return *this;
00813       }
00814     }
00815 
00816     /// getEVTString - This function returns value type as a string,
00817     /// e.g. "i32".
00818     std::string getEVTString() const;
00819 
00820     /// getTypeForEVT - This method returns an LLVM type corresponding to the
00821     /// specified EVT.  For integer types, this returns an unsigned type.  Note
00822     /// that this will abort for types that cannot be represented.
00823     Type *getTypeForEVT(LLVMContext &Context) const;
00824 
00825     /// getEVT - Return the value type corresponding to the specified type.
00826     /// This returns all pointers as iPTR.  If HandleUnknown is true, unknown
00827     /// types are returned as Other, otherwise they are invalid.
00828     static EVT getEVT(Type *Ty, bool HandleUnknown = false);
00829 
00830     intptr_t getRawBits() const {
00831       if (isSimple())
00832         return V.SimpleTy;
00833       else
00834         return (intptr_t)(LLVMTy);
00835     }
00836 
00837     /// compareRawBits - A meaningless but well-behaved order, useful for
00838     /// constructing containers.
00839     struct compareRawBits {
00840       bool operator()(EVT L, EVT R) const {
00841         if (L.V.SimpleTy == R.V.SimpleTy)
00842           return L.LLVMTy < R.LLVMTy;
00843         else
00844           return L.V.SimpleTy < R.V.SimpleTy;
00845       }
00846     };
00847 
00848   private:
00849     // Methods for handling the Extended-type case in functions above.
00850     // These are all out-of-line to prevent users of this header file
00851     // from having a dependency on Type.h.
00852     EVT changeExtendedVectorElementTypeToInteger() const;
00853     static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
00854     static EVT getExtendedVectorVT(LLVMContext &C, EVT VT,
00855                                    unsigned NumElements);
00856     bool isExtendedFloatingPoint() const;
00857     bool isExtendedInteger() const;
00858     bool isExtendedVector() const;
00859     bool isExtended16BitVector() const;
00860     bool isExtended32BitVector() const;
00861     bool isExtended64BitVector() const;
00862     bool isExtended128BitVector() const;
00863     bool isExtended256BitVector() const;
00864     bool isExtended512BitVector() const;
00865     bool isExtended1024BitVector() const;
00866     EVT getExtendedVectorElementType() const;
00867     unsigned getExtendedVectorNumElements() const;
00868     unsigned getExtendedSizeInBits() const;
00869   };
00870 
00871 } // End llvm namespace
00872 
00873 #endif