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 ppcf128 = 11, // This is a PPC 128-bit floating point value
46 Flag = 12, // This is a condition code or machine flag.
48 isVoid = 13, // This has no value
51 v4i16 = 15, // 4 x i16
52 v2i32 = 16, // 2 x i32
53 v1i64 = 17, // 1 x i64
54 v16i8 = 18, // 16 x i8
55 v8i16 = 19, // 8 x i16
56 v3i32 = 20, // 3 x i32
57 v4i32 = 21, // 4 x i32
58 v2i64 = 22, // 2 x i64
60 v2f32 = 23, // 2 x f32
61 v3f32 = 24, // 3 x f32
62 v4f32 = 25, // 4 x f32
63 v2f64 = 26, // 2 x f64
65 FIRST_VECTOR_VALUETYPE = v8i8,
66 LAST_VECTOR_VALUETYPE = v2f64,
68 LAST_VALUETYPE = 27, // This always remains at the end of the list.
70 // fAny - Any floating-point or vector floating-point value. This is used
71 // for intrinsics that have overloadings based on floating-point types.
72 // This is only for tblgen's consumption!
75 // iAny - An integer or vector integer value of any bit width. This is
76 // used for intrinsics that have overloadings based on integer bit widths.
77 // This is only for tblgen's consumption!
80 // iPTR - An int value the size of the pointer of the current
81 // target. This should only be used internal to tblgen!
85 /// MVT::ValueType - This type holds low-level value types. Valid values
86 /// include any of the values in the SimpleValueType enum, or any value
87 /// returned from a function in the MVT namespace that has a ValueType
88 /// return type. Any value type equal to one of the SimpleValueType enum
89 /// values is a "simple" value type. All other value types are "extended".
91 /// Note that simple doesn't necessary mean legal for the target machine.
92 /// All legal value types must be simple, but often there are some simple
93 /// value types that are not legal.
96 /// Currently extended types are always vector types. Extended types are
97 /// encoded by having the first SimpleTypeBits bits encode the vector
98 /// element type (which must be a scalar type) and the remaining upper
99 /// bits encode the vector length, offset by one.
100 typedef uint32_t ValueType;
102 static const int SimpleTypeBits = 8;
104 static const uint32_t SimpleTypeMask =
105 (~uint32_t(0) << (32 - SimpleTypeBits)) >> (32 - SimpleTypeBits);
107 /// MVT::isExtendedVT - Test if the given ValueType is extended
108 /// (as opposed to being simple).
109 static inline bool isExtendedVT(ValueType VT) {
110 return VT > SimpleTypeMask;
113 /// MVT::isInteger - Return true if this is an integer, or a vector integer
115 static inline bool isInteger(ValueType VT) {
116 ValueType SVT = VT & SimpleTypeMask;
117 return (SVT >= i1 && SVT <= i128) || (SVT >= v8i8 && SVT <= v2i64);
120 /// MVT::isFloatingPoint - Return true if this is an FP, or a vector FP type.
121 static inline bool isFloatingPoint(ValueType VT) {
122 ValueType SVT = VT & SimpleTypeMask;
123 return (SVT >= f32 && SVT <= ppcf128) || (SVT >= v2f32 && SVT <= v2f64);
126 /// MVT::isVector - Return true if this is a vector value type.
127 static inline bool isVector(ValueType VT) {
128 return (VT >= FIRST_VECTOR_VALUETYPE && VT <= LAST_VECTOR_VALUETYPE) ||
132 /// MVT::getVectorElementType - Given a vector type, return the type of
134 static inline ValueType getVectorElementType(ValueType VT) {
137 if (isExtendedVT(VT))
138 return VT & SimpleTypeMask;
139 assert(0 && "Invalid vector type!");
141 case v16i8: return i8;
143 case v8i16: return i16;
146 case v4i32: return i32;
148 case v2i64: return i64;
151 case v4f32: return f32;
152 case v2f64: return f64;
156 /// MVT::getVectorNumElements - Given a vector type, return the
157 /// number of elements it contains.
158 static inline unsigned getVectorNumElements(ValueType VT) {
161 if (isExtendedVT(VT))
162 return ((VT & ~SimpleTypeMask) >> SimpleTypeBits) - 1;
163 assert(0 && "Invalid vector type!");
164 case v16i8: return 16;
166 case v8i16: return 8;
169 case v4f32: return 4;
171 case v3f32: return 3;
175 case v2f64: return 2;
176 case v1i64: return 1;
180 /// MVT::getSizeInBits - Return the size of the specified value type
183 static inline unsigned getSizeInBits(ValueType VT) {
186 if (isExtendedVT(VT))
187 return getSizeInBits(getVectorElementType(VT)) *
188 getVectorNumElements(VT);
189 assert(0 && "ValueType has no known size!");
190 case MVT::i1 : return 1;
191 case MVT::i8 : return 8;
192 case MVT::i16 : return 16;
194 case MVT::i32 : return 32;
201 case MVT::v2f32: return 64;
202 case MVT::f80 : return 80;
204 case MVT::v3f32: return 96;
213 case MVT::v2f64: return 128;
217 /// MVT::getVectorType - Returns the ValueType that represents a vector
218 /// NumElements in length, where each element is of type VT.
220 static inline ValueType getVectorType(ValueType VT, unsigned NumElements) {
225 if (NumElements == 8) return MVT::v8i8;
226 if (NumElements == 16) return MVT::v16i8;
229 if (NumElements == 4) return MVT::v4i16;
230 if (NumElements == 8) return MVT::v8i16;
233 if (NumElements == 2) return MVT::v2i32;
234 if (NumElements == 3) return MVT::v3i32;
235 if (NumElements == 4) return MVT::v4i32;
238 if (NumElements == 1) return MVT::v1i64;
239 if (NumElements == 2) return MVT::v2i64;
242 if (NumElements == 2) return MVT::v2f32;
243 if (NumElements == 3) return MVT::v3f32;
244 if (NumElements == 4) return MVT::v4f32;
247 if (NumElements == 2) return MVT::v2f64;
250 ValueType Result = VT | ((NumElements + 1) << SimpleTypeBits);
251 assert(getVectorElementType(Result) == VT &&
252 "Bad vector element type!");
253 assert(getVectorNumElements(Result) == NumElements &&
254 "Bad vector length!");
258 /// MVT::getIntVectorWithNumElements - Return any integer vector type that has
259 /// the specified number of elements.
260 static inline ValueType getIntVectorWithNumElements(unsigned NumElts) {
262 default: return getVectorType(i8, NumElts);
263 case 1: return v1i64;
264 case 2: return v2i32;
265 case 3: return v3i32;
266 case 4: return v4i16;
268 case 16: return v16i8;
273 /// MVT::getIntVTBitMask - Return an integer with 1's every place there are
274 /// bits in the specified integer value type.
275 static inline uint64_t getIntVTBitMask(ValueType VT) {
276 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
277 return ~uint64_t(0UL) >> (64-getSizeInBits(VT));
279 /// MVT::getIntVTSignBit - Return an integer with a 1 in the position of the
280 /// sign bit for the specified integer value type.
281 static inline uint64_t getIntVTSignBit(ValueType VT) {
282 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
283 return uint64_t(1UL) << (getSizeInBits(VT)-1);
286 /// MVT::getValueTypeString - This function returns value type as a string,
288 std::string getValueTypeString(ValueType VT);
290 /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
291 /// to the specified ValueType. For integer types, this returns an unsigned
292 /// type. Note that this will abort for types that cannot be represented.
293 const Type *getTypeForValueType(ValueType VT);
295 /// MVT::getValueType - Return the value type corresponding to the specified
296 /// type. This returns all pointers as MVT::iPTR. If HandleUnknown is true,
297 /// unknown types are returned as Other, otherwise they are invalid.
298 ValueType getValueType(const Type *Ty, bool HandleUnknown = false);
301 } // End llvm namespace