1 //===- CodeGen/ValueTypes.h - Low-Level Target independ. types --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CODEGEN_VALUETYPES_H
17 #define LLVM_CODEGEN_VALUETYPES_H
21 #include "llvm/Support/DataTypes.h"
26 /// MVT namespace - This namespace defines the SimpleValueType enum, which
27 /// contains the various low-level value types, and the ValueType typedef.
29 namespace MVT { // MVT = Machine Value Types
30 enum SimpleValueType {
31 // If you change this numbering, you must change the values in ValueTypes.td
33 Other = 0, // This is a non-standard value
34 i1 = 1, // This is a 1 bit integer value
35 i8 = 2, // This is an 8 bit integer value
36 i16 = 3, // This is a 16 bit integer value
37 i32 = 4, // This is a 32 bit integer value
38 i64 = 5, // This is a 64 bit integer value
39 i128 = 6, // This is a 128 bit integer value
41 f32 = 7, // This is a 32 bit floating point value
42 f64 = 8, // This is a 64 bit floating point value
43 f80 = 9, // This is a 80 bit floating point value
44 f128 = 10, // This is a 128 bit floating point value
45 Flag = 11, // This is a condition code or machine flag.
47 isVoid = 12, // This has no value
50 v4i16 = 14, // 4 x i16
51 v2i32 = 15, // 2 x i32
52 v1i64 = 16, // 1 x i64
53 v16i8 = 17, // 16 x i8
54 v8i16 = 18, // 8 x i16
55 v4i32 = 19, // 4 x i32
56 v2i64 = 20, // 2 x i64
58 v2f32 = 21, // 2 x f32
59 v4f32 = 22, // 4 x f32
60 v2f64 = 23, // 2 x f64
61 FIRST_VECTOR_VALUETYPE = v8i8,
62 LAST_VECTOR_VALUETYPE = v2f64,
64 LAST_VALUETYPE = 24, // This always remains at the end of the list.
66 // iAny - An integer value of any bit width. This is used for intrinsics
67 // that have overloadings based on integer bit widths. This is only for
68 // tblgen's consumption!
71 // iPTR - An int value the size of the pointer of the current
72 // target. This should only be used internal to tblgen!
76 /// MVT::ValueType - This type holds low-level value types. Valid values
77 /// include any of the values in the SimpleValueType enum, or any value
78 /// returned from a function in the MVT namespace that has a ValueType
79 /// return type. Any value type equal to one of the SimpleValueType enum
80 /// values is a "simple" value type. All other value types are "extended".
82 /// Note that simple doesn't necessary mean legal for the target machine.
83 /// All legal value types must be simple, but often there are some simple
84 /// value types that are not legal.
85 typedef uint32_t ValueType;
87 static const int SimpleTypeBits = 8;
89 static const uint32_t SimpleTypeMask =
90 (~uint32_t(0) << (32 - SimpleTypeBits)) >> (32 - SimpleTypeBits);
92 /// MVT::isExtendedValueType - Test if the given ValueType is extended
93 /// (as opposed to being simple).
94 static inline bool isExtendedValueType(ValueType VT) {
95 return VT & ~SimpleTypeMask;
98 /// MVT::isInteger - Return true if this is an integer, or a vector integer
100 static inline bool isInteger(ValueType VT) {
101 ValueType SVT = VT & SimpleTypeMask;
102 return (SVT >= i1 && SVT <= i128) || (SVT >= v8i8 && SVT <= v2i64);
105 /// MVT::isFloatingPoint - Return true if this is an FP, or a vector FP type.
106 static inline bool isFloatingPoint(ValueType VT) {
107 ValueType SVT = VT & SimpleTypeMask;
108 return (SVT >= f32 && SVT <= f128) || (SVT >= v2f32 && SVT <= v2f64);
111 /// MVT::isVector - Return true if this is a vector value type.
112 static inline bool isVector(ValueType VT) {
113 return (VT >= FIRST_VECTOR_VALUETYPE && VT <= LAST_VECTOR_VALUETYPE) ||
114 isExtendedValueType(VT);
117 /// MVT::getVectorElementType - Given a vector type, return the type of
119 static inline ValueType getVectorElementType(ValueType VT) {
122 if (isExtendedValueType(VT))
123 return VT & SimpleTypeMask;
124 assert(0 && "Invalid vector type!");
126 case v16i8: return i8;
128 case v8i16: return i16;
130 case v4i32: return i32;
132 case v2i64: return i64;
134 case v4f32: return f32;
135 case v2f64: return f64;
139 /// MVT::getVectorNumElements - Given a vector type, return the
140 /// number of elements it contains.
141 static inline unsigned getVectorNumElements(ValueType VT) {
144 if (isExtendedValueType(VT))
145 return ((VT & ~SimpleTypeMask) >> SimpleTypeBits) - 1;
146 assert(0 && "Invalid vector type!");
147 case v16i8: return 16;
149 case v8i16: return 8;
152 case v4f32: return 4;
156 case v2f64: return 2;
157 case v1i64: return 1;
161 /// MVT::getSizeInBits - Return the size of the specified value type
164 static inline unsigned getSizeInBits(ValueType VT) {
167 if (isExtendedValueType(VT))
168 return getSizeInBits(getVectorElementType(VT)) *
169 getVectorNumElements(VT);
170 assert(0 && "ValueType has no known size!");
171 case MVT::i1 : return 1;
172 case MVT::i8 : return 8;
173 case MVT::i16 : return 16;
175 case MVT::i32 : return 32;
182 case MVT::v2f32: return 64;
183 case MVT::f80 : return 80;
191 case MVT::v2f64: return 128;
195 /// MVT::getVectorType - Returns the ValueType that represents a vector
196 /// NumElements in length, where each element is of type VT.
198 static inline ValueType getVectorType(ValueType VT, unsigned NumElements) {
203 if (NumElements == 8) return MVT::v8i8;
204 if (NumElements == 16) return MVT::v16i8;
207 if (NumElements == 4) return MVT::v4i16;
208 if (NumElements == 8) return MVT::v8i16;
211 if (NumElements == 2) return MVT::v2i32;
212 if (NumElements == 4) return MVT::v4i32;
215 if (NumElements == 1) return MVT::v1i64;
216 if (NumElements == 2) return MVT::v2i64;
219 if (NumElements == 2) return MVT::v2f32;
220 if (NumElements == 4) return MVT::v4f32;
223 if (NumElements == 2) return MVT::v2f64;
226 ValueType Result = VT | ((NumElements + 1) << SimpleTypeBits);
227 assert(getVectorElementType(Result) == VT &&
228 "Bad vector element type!");
229 assert(getVectorNumElements(Result) == NumElements &&
230 "Bad vector length!");
234 /// MVT::getIntVectorWithNumElements - Return any integer vector type that has
235 /// the specified number of elements.
236 static inline ValueType getIntVectorWithNumElements(unsigned NumElts) {
238 default: return getVectorType(i8, NumElts);
239 case 1: return v1i64;
240 case 2: return v2i32;
241 case 4: return v4i16;
243 case 16: return v16i8;
248 /// MVT::getIntVTBitMask - Return an integer with 1's every place there are
249 /// bits in the specified integer value type.
250 static inline uint64_t getIntVTBitMask(ValueType VT) {
251 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
252 return ~uint64_t(0UL) >> (64-getSizeInBits(VT));
254 /// MVT::getIntVTSignBit - Return an integer with a 1 in the position of the
255 /// sign bit for the specified integer value type.
256 static inline uint64_t getIntVTSignBit(ValueType VT) {
257 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
258 return uint64_t(1UL) << (getSizeInBits(VT)-1);
261 /// MVT::getValueTypeString - This function returns value type as a string,
263 std::string getValueTypeString(ValueType VT);
265 /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
266 /// to the specified ValueType. For integer types, this returns an unsigned
267 /// type. Note that this will abort for types that cannot be represented.
268 const Type *getTypeForValueType(ValueType VT);
270 /// MVT::getValueType - Return the value type corresponding to the specified
271 /// type. This returns all pointers as MVT::iPTR. If HandleUnknown is true,
272 /// unknown types are returned as Other, otherwise they are invalid.
273 ValueType getValueType(const Type *Ty, bool HandleUnknown = false);
276 } // End llvm namespace