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 ValueType getVectorType(ValueType VT, unsigned NumElements); 00124 00125 /// MVT::getVectorBaseType - Given a packed vector type, return the type of 00126 /// each element. 00127 static inline ValueType getVectorBaseType(ValueType VT) { 00128 switch (VT) { 00129 default: assert(0 && "Invalid vector type!"); 00130 case v8i8 : 00131 case v16i8: return i8; 00132 case v4i16: 00133 case v8i16: return i16; 00134 case v2i32: 00135 case v4i32: return i32; 00136 case v2i64: return i64; 00137 case v2f32: 00138 case v4f32: return f32; 00139 case v2f64: return f64; 00140 } 00141 } 00142 00143 /// MVT::getVectorNumElements - Given a packed vector type, return the number 00144 /// of elements it contains. 00145 static inline unsigned getVectorNumElements(ValueType VT) { 00146 switch (VT) { 00147 default: assert(0 && "Invalid vector type!"); 00148 case v16i8: return 16; 00149 case v8i8 : 00150 case v8i16: return 8; 00151 case v4i16: 00152 case v4i32: 00153 case v4f32: return 4; 00154 case v2i32: 00155 case v2i64: 00156 case v2f32: 00157 case v2f64: return 2; 00158 } 00159 } 00160 00161 /// MVT::getIntVectorWithNumElements - Return any integer vector type that has 00162 /// the specified number of elements. 00163 static inline ValueType getIntVectorWithNumElements(unsigned NumElts) { 00164 switch (NumElts) { 00165 default: assert(0 && "Invalid vector type!"); 00166 case 2: return v2i32; 00167 case 4: return v4i16; 00168 case 8: return v8i8; 00169 case 16: return v16i8; 00170 } 00171 } 00172 00173 00174 /// MVT::getIntVTBitMask - Return an integer with 1's every place there are 00175 /// bits in the specified integer value type. 00176 static inline uint64_t getIntVTBitMask(ValueType VT) { 00177 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!"); 00178 return ~uint64_t(0UL) >> (64-getSizeInBits(VT)); 00179 } 00180 /// MVT::getIntVTSignBit - Return an integer with a 1 in the position of the 00181 /// sign bit for the specified integer value type. 00182 static inline uint64_t getIntVTSignBit(ValueType VT) { 00183 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!"); 00184 return uint64_t(1UL) << (getSizeInBits(VT)-1); 00185 } 00186 00187 /// MVT::getValueTypeString - This function returns value type as a string, 00188 /// e.g. "i32". 00189 const char *getValueTypeString(ValueType VT); 00190 00191 /// MVT::getTypeForValueType - This method returns an LLVM type corresponding 00192 /// to the specified ValueType. For integer types, this returns an unsigned 00193 /// type. Note that this will abort for types that cannot be represented. 00194 const Type *getTypeForValueType(ValueType VT); 00195 } 00196 00197 } // End llvm namespace 00198 00199 #endif