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.
87 /// Currently extended types are always vector types. Extended types are
88 /// encoded by having the first SimpleTypeBits bits encode the vector
89 /// element type (which must be a scalar type) and the remaining upper
90 /// bits encode the vector length, offset by one.
91 typedef uint32_t ValueType;
93 static const int SimpleTypeBits = 8;
95 static const uint32_t SimpleTypeMask =
96 (~uint32_t(0) << (32 - SimpleTypeBits)) >> (32 - SimpleTypeBits);
98 /// MVT::isExtendedValueType - Test if the given ValueType is extended
99 /// (as opposed to being simple).
100 static inline bool isExtendedValueType(ValueType VT) {
101 return VT > SimpleTypeMask;
104 /// MVT::isInteger - Return true if this is an integer, or a vector integer
106 static inline bool isInteger(ValueType VT) {
107 ValueType SVT = VT & SimpleTypeMask;
108 return (SVT >= i1 && SVT <= i128) || (SVT >= v8i8 && SVT <= v2i64);
111 /// MVT::isFloatingPoint - Return true if this is an FP, or a vector FP type.
112 static inline bool isFloatingPoint(ValueType VT) {
113 ValueType SVT = VT & SimpleTypeMask;
114 return (SVT >= f32 && SVT <= f128) || (SVT >= v2f32 && SVT <= v2f64);
117 /// MVT::isVector - Return true if this is a vector value type.
118 static inline bool isVector(ValueType VT) {
119 return (VT >= FIRST_VECTOR_VALUETYPE && VT <= LAST_VECTOR_VALUETYPE) ||
120 isExtendedValueType(VT);
123 /// MVT::getVectorElementType - Given a vector type, return the type of
125 static inline ValueType getVectorElementType(ValueType VT) {
128 if (isExtendedValueType(VT))
129 return VT & SimpleTypeMask;
130 assert(0 && "Invalid vector type!");
132 case v16i8: return i8;
134 case v8i16: return i16;
136 case v4i32: return i32;
138 case v2i64: return i64;
140 case v4f32: return f32;
141 case v2f64: return f64;
145 /// MVT::getVectorNumElements - Given a vector type, return the
146 /// number of elements it contains.
147 static inline unsigned getVectorNumElements(ValueType VT) {
150 if (isExtendedValueType(VT))
151 return ((VT & ~SimpleTypeMask) >> SimpleTypeBits) - 1;
152 assert(0 && "Invalid vector type!");
153 case v16i8: return 16;
155 case v8i16: return 8;
158 case v4f32: return 4;
162 case v2f64: return 2;
163 case v1i64: return 1;
167 /// MVT::getSizeInBits - Return the size of the specified value type
170 static inline unsigned getSizeInBits(ValueType VT) {
173 if (isExtendedValueType(VT))
174 return getSizeInBits(getVectorElementType(VT)) *
175 getVectorNumElements(VT);
176 assert(0 && "ValueType has no known size!");
177 case MVT::i1 : return 1;
178 case MVT::i8 : return 8;
179 case MVT::i16 : return 16;
181 case MVT::i32 : return 32;
188 case MVT::v2f32: return 64;
189 case MVT::f80 : return 80;
197 case MVT::v2f64: return 128;
201 /// MVT::getVectorType - Returns the ValueType that represents a vector
202 /// NumElements in length, where each element is of type VT.
204 static inline ValueType getVectorType(ValueType VT, unsigned NumElements) {
209 if (NumElements == 8) return MVT::v8i8;
210 if (NumElements == 16) return MVT::v16i8;
213 if (NumElements == 4) return MVT::v4i16;
214 if (NumElements == 8) return MVT::v8i16;
217 if (NumElements == 2) return MVT::v2i32;
218 if (NumElements == 4) return MVT::v4i32;
221 if (NumElements == 1) return MVT::v1i64;
222 if (NumElements == 2) return MVT::v2i64;
225 if (NumElements == 2) return MVT::v2f32;
226 if (NumElements == 4) return MVT::v4f32;
229 if (NumElements == 2) return MVT::v2f64;
232 ValueType Result = VT | ((NumElements + 1) << SimpleTypeBits);
233 assert(getVectorElementType(Result) == VT &&
234 "Bad vector element type!");
235 assert(getVectorNumElements(Result) == NumElements &&
236 "Bad vector length!");
240 /// MVT::getIntVectorWithNumElements - Return any integer vector type that has
241 /// the specified number of elements.
242 static inline ValueType getIntVectorWithNumElements(unsigned NumElts) {
244 default: return getVectorType(i8, NumElts);
245 case 1: return v1i64;
246 case 2: return v2i32;
247 case 4: return v4i16;
249 case 16: return v16i8;
254 /// MVT::getIntVTBitMask - Return an integer with 1's every place there are
255 /// bits in the specified integer value type.
256 static inline uint64_t getIntVTBitMask(ValueType VT) {
257 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
258 return ~uint64_t(0UL) >> (64-getSizeInBits(VT));
260 /// MVT::getIntVTSignBit - Return an integer with a 1 in the position of the
261 /// sign bit for the specified integer value type.
262 static inline uint64_t getIntVTSignBit(ValueType VT) {
263 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
264 return uint64_t(1UL) << (getSizeInBits(VT)-1);
267 /// MVT::getValueTypeString - This function returns value type as a string,
269 std::string getValueTypeString(ValueType VT);
271 /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
272 /// to the specified ValueType. For integer types, this returns an unsigned
273 /// type. Note that this will abort for types that cannot be represented.
274 const Type *getTypeForValueType(ValueType VT);
276 /// MVT::getValueType - Return the value type corresponding to the specified
277 /// type. This returns all pointers as MVT::iPTR. If HandleUnknown is true,
278 /// unknown types are returned as Other, otherwise they are invalid.
279 ValueType getValueType(const Type *Ty, bool HandleUnknown = false);
282 } // End llvm namespace