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 // iAny - An integer or vector integer value of any bit width. This is
71 // used for intrinsics that have overloadings based on integer bit widths.
72 // This is only for tblgen's consumption!
75 // iPTR - An int value the size of the pointer of the current
76 // target. This should only be used internal to tblgen!
80 /// MVT::ValueType - This type holds low-level value types. Valid values
81 /// include any of the values in the SimpleValueType enum, or any value
82 /// returned from a function in the MVT namespace that has a ValueType
83 /// return type. Any value type equal to one of the SimpleValueType enum
84 /// values is a "simple" value type. All other value types are "extended".
86 /// Note that simple doesn't necessary mean legal for the target machine.
87 /// All legal value types must be simple, but often there are some simple
88 /// value types that are not legal.
91 /// Currently extended types are always vector types. Extended types are
92 /// encoded by having the first SimpleTypeBits bits encode the vector
93 /// element type (which must be a scalar type) and the remaining upper
94 /// bits encode the vector length, offset by one.
95 typedef uint32_t ValueType;
97 static const int SimpleTypeBits = 8;
99 static const uint32_t SimpleTypeMask =
100 (~uint32_t(0) << (32 - SimpleTypeBits)) >> (32 - SimpleTypeBits);
102 /// MVT::isExtendedVT - Test if the given ValueType is extended
103 /// (as opposed to being simple).
104 static inline bool isExtendedVT(ValueType VT) {
105 return VT > SimpleTypeMask;
108 /// MVT::isInteger - Return true if this is an integer, or a vector integer
110 static inline bool isInteger(ValueType VT) {
111 ValueType SVT = VT & SimpleTypeMask;
112 return (SVT >= i1 && SVT <= i128) || (SVT >= v8i8 && SVT <= v2i64);
115 /// MVT::isFloatingPoint - Return true if this is an FP, or a vector FP type.
116 static inline bool isFloatingPoint(ValueType VT) {
117 ValueType SVT = VT & SimpleTypeMask;
118 return (SVT >= f32 && SVT <= ppcf128) || (SVT >= v2f32 && SVT <= v2f64);
121 /// MVT::isVector - Return true if this is a vector value type.
122 static inline bool isVector(ValueType VT) {
123 return (VT >= FIRST_VECTOR_VALUETYPE && VT <= LAST_VECTOR_VALUETYPE) ||
127 /// MVT::getVectorElementType - Given a vector type, return the type of
129 static inline ValueType getVectorElementType(ValueType VT) {
132 if (isExtendedVT(VT))
133 return VT & SimpleTypeMask;
134 assert(0 && "Invalid vector type!");
136 case v16i8: return i8;
138 case v8i16: return i16;
141 case v4i32: return i32;
143 case v2i64: return i64;
146 case v4f32: return f32;
147 case v2f64: return f64;
151 /// MVT::getVectorNumElements - Given a vector type, return the
152 /// number of elements it contains.
153 static inline unsigned getVectorNumElements(ValueType VT) {
156 if (isExtendedVT(VT))
157 return ((VT & ~SimpleTypeMask) >> SimpleTypeBits) - 1;
158 assert(0 && "Invalid vector type!");
159 case v16i8: return 16;
161 case v8i16: return 8;
164 case v4f32: return 4;
166 case v3f32: return 3;
170 case v2f64: return 2;
171 case v1i64: return 1;
175 /// MVT::getSizeInBits - Return the size of the specified value type
178 static inline unsigned getSizeInBits(ValueType VT) {
181 if (isExtendedVT(VT))
182 return getSizeInBits(getVectorElementType(VT)) *
183 getVectorNumElements(VT);
184 assert(0 && "ValueType has no known size!");
185 case MVT::i1 : return 1;
186 case MVT::i8 : return 8;
187 case MVT::i16 : return 16;
189 case MVT::i32 : return 32;
196 case MVT::v2f32: return 64;
197 case MVT::f80 : return 80;
199 case MVT::v3f32: return 96;
208 case MVT::v2f64: return 128;
212 /// MVT::getVectorType - Returns the ValueType that represents a vector
213 /// NumElements in length, where each element is of type VT.
215 static inline ValueType getVectorType(ValueType VT, unsigned NumElements) {
220 if (NumElements == 8) return MVT::v8i8;
221 if (NumElements == 16) return MVT::v16i8;
224 if (NumElements == 4) return MVT::v4i16;
225 if (NumElements == 8) return MVT::v8i16;
228 if (NumElements == 2) return MVT::v2i32;
229 if (NumElements == 3) return MVT::v3i32;
230 if (NumElements == 4) return MVT::v4i32;
233 if (NumElements == 1) return MVT::v1i64;
234 if (NumElements == 2) return MVT::v2i64;
237 if (NumElements == 2) return MVT::v2f32;
238 if (NumElements == 3) return MVT::v3f32;
239 if (NumElements == 4) return MVT::v4f32;
242 if (NumElements == 2) return MVT::v2f64;
245 ValueType Result = VT | ((NumElements + 1) << SimpleTypeBits);
246 assert(getVectorElementType(Result) == VT &&
247 "Bad vector element type!");
248 assert(getVectorNumElements(Result) == NumElements &&
249 "Bad vector length!");
253 /// MVT::getIntVectorWithNumElements - Return any integer vector type that has
254 /// the specified number of elements.
255 static inline ValueType getIntVectorWithNumElements(unsigned NumElts) {
257 default: return getVectorType(i8, NumElts);
258 case 1: return v1i64;
259 case 2: return v2i32;
260 case 3: return v3i32;
261 case 4: return v4i16;
263 case 16: return v16i8;
268 /// MVT::getIntVTBitMask - Return an integer with 1's every place there are
269 /// bits in the specified integer value type.
270 static inline uint64_t getIntVTBitMask(ValueType VT) {
271 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
272 return ~uint64_t(0UL) >> (64-getSizeInBits(VT));
274 /// MVT::getIntVTSignBit - Return an integer with a 1 in the position of the
275 /// sign bit for the specified integer value type.
276 static inline uint64_t getIntVTSignBit(ValueType VT) {
277 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
278 return uint64_t(1UL) << (getSizeInBits(VT)-1);
281 /// MVT::getValueTypeString - This function returns value type as a string,
283 std::string getValueTypeString(ValueType VT);
285 /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
286 /// to the specified ValueType. For integer types, this returns an unsigned
287 /// type. Note that this will abort for types that cannot be represented.
288 const Type *getTypeForValueType(ValueType VT);
290 /// MVT::getValueType - Return the value type corresponding to the specified
291 /// type. This returns all pointers as MVT::iPTR. If HandleUnknown is true,
292 /// unknown types are returned as Other, otherwise they are invalid.
293 ValueType getValueType(const Type *Ty, bool HandleUnknown = false);
296 } // End llvm namespace