LLVM API Documentation
00001 //===- CodeGen/ValueTypes.h - Low-Level Target independ. types --*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source 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 <cassert> 00020 #include "llvm/Support/DataTypes.h" 00021 00022 namespace llvm { 00023 class Type; 00024 00025 /// MVT namespace - This namespace defines the ValueType enum, which contains 00026 /// the various low-level value types. 00027 /// 00028 namespace MVT { // MVT = Machine Value Types 00029 enum ValueType { 00030 // If you change this numbering, you must change the values in ValueTypes.td 00031 // well! 00032 Other = 0, // This is a non-standard value 00033 i1 = 1, // This is a 1 bit integer value 00034 i8 = 2, // This is an 8 bit integer value 00035 i16 = 3, // This is a 16 bit integer value 00036 i32 = 4, // This is a 32 bit integer value 00037 i64 = 5, // This is a 64 bit integer value 00038 i128 = 6, // This is a 128 bit integer value 00039 00040 f32 = 7, // This is a 32 bit floating point value 00041 f64 = 8, // This is a 64 bit floating point value 00042 f80 = 9, // This is a 80 bit floating point value 00043 f128 = 10, // This is a 128 bit floating point value 00044 Flag = 11, // This is a condition code or machine flag. 00045 00046 isVoid = 12, // This has no value 00047 00048 Vector = 13, // This is an abstract vector type, which will 00049 // be expanded into a target vector type, or scalars 00050 // if no matching vector type is available. 00051 00052 v8i8 = 14, // 8 x i8 00053 v4i16 = 15, // 4 x i16 00054 v2i32 = 16, // 2 x i32 00055 v16i8 = 17, // 16 x i8 00056 v8i16 = 18, // 8 x i16 00057 v4i32 = 19, // 4 x i32 00058 v2i64 = 20, // 2 x i64 00059 00060 v2f32 = 21, // 2 x f32 00061 v4f32 = 22, // 4 x f32 00062 v2f64 = 23, // 2 x f64 00063 FIRST_VECTOR_VALUETYPE = v8i8, 00064 LAST_VECTOR_VALUETYPE = v2f64, 00065 00066 LAST_VALUETYPE = 24, // This always remains at the end of the list. 00067 00068 // iPTR - An int value the size of the pointer of the current 00069 // target. This should only be used internal to tblgen! 00070 iPTR = 255 00071 }; 00072 00073 /// MVT::isInteger - Return true if this is a simple integer, or a packed 00074 /// vector integer type. 00075 static inline bool isInteger(ValueType VT) { 00076 return (VT >= i1 && VT <= i128) || (VT >= v8i8 && VT <= v2i64); 00077 } 00078 00079 /// MVT::isFloatingPoint - Return true if this is a simple FP, or a packed 00080 /// vector FP type. 00081 static inline bool isFloatingPoint(ValueType VT) { 00082 return (VT >= f32 && VT <= f128) || (VT >= v4f32 && VT <= v2f64); 00083 } 00084 00085 /// MVT::isVector - Return true if this is a packed vector type (i.e. not 00086 /// MVT::Vector). 00087 static inline bool isVector(ValueType VT) { 00088 return VT >= FIRST_VECTOR_VALUETYPE && VT <= LAST_VECTOR_VALUETYPE; 00089 } 00090 00091 /// MVT::getSizeInBits - Return the size of the specified value type in bits. 00092 /// 00093 static inline unsigned getSizeInBits(ValueType VT) { 00094 switch (VT) { 00095 default: assert(0 && "ValueType has no known size!"); 00096 case MVT::i1 : return 1; 00097 case MVT::i8 : return 8; 00098 case MVT::i16 : return 16; 00099 case MVT::f32 : 00100 case MVT::i32 : return 32; 00101 case MVT::f64 : 00102 case MVT::i64 : 00103 case MVT::v8i8: 00104 case MVT::v4i16: 00105 case MVT::v2i32: 00106 case MVT::v2f32: return 64; 00107 case MVT::f80 : return 80; 00108 case MVT::f128: 00109 case MVT::i128: 00110 case MVT::v16i8: 00111 case MVT::v8i16: 00112 case MVT::v4i32: 00113 case MVT::v2i64: 00114 case MVT::v4f32: 00115 case MVT::v2f64: return 128; 00116 } 00117 } 00118 00119 /// MVT::getVectorType - Returns the ValueType that represents a vector 00120 /// NumElements in length, where each element is of type VT. If there is no 00121 /// ValueType that represents this vector, a ValueType of Other is returned. 00122 /// 00123 static inline ValueType getVectorType(ValueType VT, unsigned NumElements) { 00124 switch (VT) { 00125 default: 00126 break; 00127 case MVT::i8: 00128 if (NumElements == 8) return MVT::v8i8; 00129 if (NumElements == 16) return MVT::v16i8; 00130 break; 00131 case MVT::i16: 00132 if (NumElements == 4) return MVT::v4i16; 00133 if (NumElements == 8) return MVT::v8i16; 00134 break; 00135 case MVT::i32: 00136 if (NumElements == 2) return MVT::v2i32; 00137 if (NumElements == 4) return MVT::v4i32; 00138 break; 00139 case MVT::i64: 00140 if (NumElements == 2) return MVT::v2i64; 00141 break; 00142 case MVT::f32: 00143 if (NumElements == 2) return MVT::v2f32; 00144 if (NumElements == 4) return MVT::v4f32; 00145 break; 00146 case MVT::f64: 00147 if (NumElements == 2) return MVT::v2f64; 00148 break; 00149 } 00150 return MVT::Other; 00151 } 00152 00153 /// MVT::getVectorBaseType - Given a packed vector type, return the type of 00154 /// each element. 00155 static inline ValueType getVectorBaseType(ValueType VT) { 00156 switch (VT) { 00157 default: assert(0 && "Invalid vector type!"); 00158 case v8i8 : 00159 case v16i8: return i8; 00160 case v4i16: 00161 case v8i16: return i16; 00162 case v2i32: 00163 case v4i32: return i32; 00164 case v2i64: return i64; 00165 case v2f32: 00166 case v4f32: return f32; 00167 case v2f64: return f64; 00168 } 00169 } 00170 00171 /// MVT::getVectorNumElements - Given a packed vector type, return the number 00172 /// of elements it contains. 00173 static inline unsigned getVectorNumElements(ValueType VT) { 00174 switch (VT) { 00175 default: assert(0 && "Invalid vector type!"); 00176 case v16i8: return 16; 00177 case v8i8 : 00178 case v8i16: return 8; 00179 case v4i16: 00180 case v4i32: 00181 case v4f32: return 4; 00182 case v2i32: 00183 case v2i64: 00184 case v2f32: 00185 case v2f64: return 2; 00186 } 00187 } 00188 00189 /// MVT::getIntVectorWithNumElements - Return any integer vector type that has 00190 /// the specified number of elements. 00191 static inline ValueType getIntVectorWithNumElements(unsigned NumElts) { 00192 switch (NumElts) { 00193 default: assert(0 && "Invalid vector type!"); 00194 case 2: return v2i32; 00195 case 4: return v4i16; 00196 case 8: return v8i8; 00197 case 16: return v16i8; 00198 } 00199 } 00200 00201 00202 /// MVT::getIntVTBitMask - Return an integer with 1's every place there are 00203 /// bits in the specified integer value type. 00204 static inline uint64_t getIntVTBitMask(ValueType VT) { 00205 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!"); 00206 return ~0ULL >> (64-getSizeInBits(VT)); 00207 } 00208 /// MVT::getIntVTSignBit - Return an integer with a 1 in the position of the 00209 /// sign bit for the specified integer value type. 00210 static inline uint64_t getIntVTSignBit(ValueType VT) { 00211 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!"); 00212 return 1ULL << (getSizeInBits(VT)-1); 00213 } 00214 00215 /// MVT::getValueTypeString - This function returns value type as a string, 00216 /// e.g. "i32". 00217 const char *getValueTypeString(ValueType VT); 00218 00219 /// MVT::getTypeForValueType - This method returns an LLVM type corresponding 00220 /// to the specified ValueType. For integer types, this returns an unsigned 00221 /// type. Note that this will abort for types that cannot be represented. 00222 const Type *getTypeForValueType(ValueType VT); 00223 } 00224 00225 } // End llvm namespace 00226 00227 #endif