1 //===- CodeGen/ValueTypes.h - Low-Level Target independ. types --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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"
22 #include "llvm/Support/MathExtras.h"
28 struct EVT { // EVT = Machine Value Type
30 enum SimpleValueType {
31 // If you change this numbering, you must change the values in
32 // ValueTypes.td as well!
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 FIRST_INTEGER_VALUETYPE = i1,
42 LAST_INTEGER_VALUETYPE = i128,
44 f32 = 7, // This is a 32 bit floating point value
45 f64 = 8, // This is a 64 bit floating point value
46 f80 = 9, // This is a 80 bit floating point value
47 f128 = 10, // This is a 128 bit floating point value
48 ppcf128 = 11, // This is a PPC 128-bit floating point value
49 Flag = 12, // This is a condition code or machine flag.
51 isVoid = 13, // This has no value
56 v16i8 = 17, // 16 x i8
57 v32i8 = 18, // 32 x i8
58 v2i16 = 19, // 2 x i16
59 v4i16 = 20, // 4 x i16
60 v8i16 = 21, // 8 x i16
61 v16i16 = 22, // 16 x i16
62 v2i32 = 23, // 2 x i32
63 v4i32 = 24, // 4 x i32
64 v8i32 = 25, // 8 x i32
65 v1i64 = 26, // 1 x i64
66 v2i64 = 27, // 2 x i64
67 v4i64 = 28, // 4 x i64
69 v2f32 = 29, // 2 x f32
70 v4f32 = 30, // 4 x f32
71 v8f32 = 31, // 8 x f32
72 v2f64 = 32, // 2 x f64
73 v4f64 = 33, // 4 x f64
75 FIRST_VECTOR_VALUETYPE = v2i8,
76 LAST_VECTOR_VALUETYPE = v4f64,
78 LAST_VALUETYPE = 34, // This always remains at the end of the list.
80 // This is the current maximum for LAST_VALUETYPE.
81 // EVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
82 // This value must be a multiple of 32.
83 MAX_ALLOWED_VALUETYPE = 64,
85 // Metadata - This is MDNode or MDString.
88 // iPTRAny - An int value the size of the pointer of the current
89 // target to any address space. This must only be used internal to
90 // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
93 // vAny - A vector with any length and element size. This is used
94 // for intrinsics that have overloadings based on vector types.
95 // This is only for tblgen's consumption!
98 // fAny - Any floating-point or vector floating-point value. This is used
99 // for intrinsics that have overloadings based on floating-point types.
100 // This is only for tblgen's consumption!
103 // iAny - An integer or vector integer value of any bit width. This is
104 // used for intrinsics that have overloadings based on integer bit widths.
105 // This is only for tblgen's consumption!
108 // iPTR - An int value the size of the pointer of the current
109 // target. This should only be used internal to tblgen!
112 // LastSimpleValueType - The greatest valid SimpleValueType value.
113 LastSimpleValueType = 255
117 /// This union holds low-level value types. Valid values include any of
118 /// the values in the SimpleValueType enum, or any value returned from one
119 /// of the EVT methods. Any value type equal to one of the SimpleValueType
120 /// enum values is a "simple" value type. All others are "extended".
122 /// Note that simple doesn't necessary mean legal for the target machine.
123 /// All legal value types must be simple, but often there are some simple
124 /// value types that are not legal.
133 EVT(SimpleValueType S) : V(S) {}
135 bool operator==(const EVT VT) const {
136 return getRawBits() == VT.getRawBits();
138 bool operator!=(const EVT VT) const {
139 return getRawBits() != VT.getRawBits();
142 /// getFloatingPointVT - Returns the EVT that represents a floating point
143 /// type with the given number of bits. There are two floating point types
144 /// with 128 bits - this returns f128 rather than ppcf128.
145 static EVT getFloatingPointVT(unsigned BitWidth) {
148 assert(false && "Bad bit width!");
160 /// getIntegerVT - Returns the EVT that represents an integer with the given
162 static EVT getIntegerVT(unsigned BitWidth) {
179 return getExtendedIntegerVT(BitWidth);
182 /// getVectorVT - Returns the EVT that represents a vector NumElements in
183 /// length, where each element is of type VT.
184 static EVT getVectorVT(EVT VT, unsigned NumElements) {
189 if (NumElements == 2) return v2i8;
190 if (NumElements == 4) return v4i8;
191 if (NumElements == 8) return v8i8;
192 if (NumElements == 16) return v16i8;
193 if (NumElements == 32) return v32i8;
196 if (NumElements == 2) return v2i16;
197 if (NumElements == 4) return v4i16;
198 if (NumElements == 8) return v8i16;
199 if (NumElements == 16) return v16i16;
202 if (NumElements == 2) return v2i32;
203 if (NumElements == 4) return v4i32;
204 if (NumElements == 8) return v8i32;
207 if (NumElements == 1) return v1i64;
208 if (NumElements == 2) return v2i64;
209 if (NumElements == 4) return v4i64;
212 if (NumElements == 2) return v2f32;
213 if (NumElements == 4) return v4f32;
214 if (NumElements == 8) return v8f32;
217 if (NumElements == 2) return v2f64;
218 if (NumElements == 4) return v4f64;
221 return getExtendedVectorVT(VT, NumElements);
224 /// getIntVectorWithNumElements - Return any integer vector type that has
225 /// the specified number of elements.
226 static EVT getIntVectorWithNumElements(unsigned NumElts) {
228 default: return getVectorVT(i8, NumElts);
229 case 1: return v1i64;
230 case 2: return v2i32;
231 case 4: return v4i16;
233 case 16: return v16i8;
237 /// isSimple - Test if the given EVT is simple (as opposed to being
239 bool isSimple() const {
240 return V <= LastSimpleValueType;
243 /// isExtended - Test if the given EVT is extended (as opposed to
245 bool isExtended() const {
249 /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
250 bool isFloatingPoint() const {
252 ((V >= f32 && V <= ppcf128) ||
253 (V >= v2f32 && V <= v4f64)) : isExtendedFloatingPoint();
256 /// isInteger - Return true if this is an integer, or a vector integer type.
257 bool isInteger() const {
259 ((V >= FIRST_INTEGER_VALUETYPE && V <= LAST_INTEGER_VALUETYPE) ||
260 (V >= v2i8 && V <= v4i64)) : isExtendedInteger();
263 /// isVector - Return true if this is a vector value type.
264 bool isVector() const {
266 (V >= FIRST_VECTOR_VALUETYPE && V <= LAST_VECTOR_VALUETYPE) :
270 /// is64BitVector - Return true if this is a 64-bit vector type.
271 bool is64BitVector() const {
273 (V==v8i8 || V==v4i16 || V==v2i32 || V==v1i64 || V==v2f32) :
274 isExtended64BitVector();
277 /// is128BitVector - Return true if this is a 128-bit vector type.
278 bool is128BitVector() const {
280 (V==v16i8 || V==v8i16 || V==v4i32 ||
281 V==v2i64 || V==v4f32 || V==v2f64) :
282 isExtended128BitVector();
285 /// is256BitVector - Return true if this is a 256-bit vector type.
286 inline bool is256BitVector() const {
288 (V==v8f32 || V==v4f64 || V==v32i8 || V==v16i16 || V==v8i32 ||
289 V==v4i64) : isExtended256BitVector();
292 /// isOverloaded - Return true if this is an overloaded type for TableGen.
293 bool isOverloaded() const {
294 return (V==iAny || V==fAny || V==vAny || V==iPTRAny);
297 /// isByteSized - Return true if the bit size is a multiple of 8.
298 bool isByteSized() const {
299 return (getSizeInBits() & 7) == 0;
302 /// isRound - Return true if the size is a power-of-two number of bytes.
303 bool isRound() const {
304 unsigned BitSize = getSizeInBits();
305 return BitSize >= 8 && !(BitSize & (BitSize - 1));
308 /// bitsEq - Return true if this has the same number of bits as VT.
309 bool bitsEq(EVT VT) const {
310 return getSizeInBits() == VT.getSizeInBits();
313 /// bitsGT - Return true if this has more bits than VT.
314 bool bitsGT(EVT VT) const {
315 return getSizeInBits() > VT.getSizeInBits();
318 /// bitsGE - Return true if this has no less bits than VT.
319 bool bitsGE(EVT VT) const {
320 return getSizeInBits() >= VT.getSizeInBits();
323 /// bitsLT - Return true if this has less bits than VT.
324 bool bitsLT(EVT VT) const {
325 return getSizeInBits() < VT.getSizeInBits();
328 /// bitsLE - Return true if this has no more bits than VT.
329 bool bitsLE(EVT VT) const {
330 return getSizeInBits() <= VT.getSizeInBits();
334 /// getSimpleVT - Return the SimpleValueType held in the specified
336 SimpleValueType getSimpleVT() const {
337 assert(isSimple() && "Expected a SimpleValueType!");
338 return SimpleValueType(V);
341 /// getVectorElementType - Given a vector type, return the type of
343 EVT getVectorElementType() const {
344 assert(isVector() && "Invalid vector type!");
347 return getExtendedVectorElementType();
352 case v32i8: return i8;
356 case v16i16: return i16;
359 case v8i32: return i32;
362 case v4i64: return i64;
365 case v8f32: return f32;
367 case v4f64: return f64;
371 /// getVectorNumElements - Given a vector type, return the number of
372 /// elements it contains.
373 unsigned getVectorNumElements() const {
374 assert(isVector() && "Invalid vector type!");
377 return getExtendedVectorNumElements();
378 case v32i8: return 32;
380 case v16i16: return 16;
384 case v8f32: return 8;
390 case v4f64: return 4;
396 case v2f64: return 2;
397 case v1i64: return 1;
401 /// getSizeInBits - Return the size of the specified value type in bits.
402 unsigned getSizeInBits() const {
405 assert(0 && "Value type size is target-dependent. Ask TLI.");
410 assert(0 && "Value type is overloaded.");
412 return getExtendedSizeInBits();
416 case v2i8: return 16;
420 case v2i16: return 32;
427 case v2f32: return 64;
428 case f80 : return 80;
437 case v2f64: return 128;
443 case v4f64: return 256;
447 /// getStoreSizeInBits - Return the number of bits overwritten by a store
448 /// of the specified value type.
449 unsigned getStoreSizeInBits() const {
450 return (getSizeInBits() + 7)/8*8;
453 /// getRoundIntegerType - Rounds the bit-width of the given integer EVT up
454 /// to the nearest power of two (and at least to eight), and returns the
455 /// integer EVT with that number of bits.
456 EVT getRoundIntegerType() const {
457 assert(isInteger() && !isVector() && "Invalid integer type!");
458 unsigned BitWidth = getSizeInBits();
462 return getIntegerVT(1 << Log2_32_Ceil(BitWidth));
465 /// isPow2VectorType - Retuns true if the given vector is a power of 2.
466 bool isPow2VectorType() const {
467 unsigned NElts = getVectorNumElements();
468 return !(NElts & (NElts - 1));
471 /// getPow2VectorType - Widens the length of the given vector EVT up to
472 /// the nearest power of 2 and returns that type.
473 EVT getPow2VectorType() const {
474 if (!isPow2VectorType()) {
475 unsigned NElts = getVectorNumElements();
476 unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
477 return EVT::getVectorVT(getVectorElementType(), Pow2NElts);
484 /// getEVTString - This function returns value type as a string,
486 std::string getEVTString() const;
488 /// getTypeForEVT - This method returns an LLVM type corresponding to the
489 /// specified EVT. For integer types, this returns an unsigned type. Note
490 /// that this will abort for types that cannot be represented.
491 const Type *getTypeForEVT() const;
493 /// getEVT - Return the value type corresponding to the specified type.
494 /// This returns all pointers as iPTR. If HandleUnknown is true, unknown
495 /// types are returned as Other, otherwise they are invalid.
496 static EVT getEVT(const Type *Ty, bool HandleUnknown = false);
498 /// getRawBits - Represent the type as a bunch of bits.
499 uintptr_t getRawBits() const { return V; }
501 /// compareRawBits - A meaningless but well-behaved order, useful for
502 /// constructing containers.
503 struct compareRawBits {
504 bool operator()(EVT L, EVT R) const {
505 return L.getRawBits() < R.getRawBits();
510 // Methods for handling the Extended-type case in functions above.
511 // These are all out-of-line to prevent users of this header file
512 // from having a dependency on Type.h.
513 static EVT getExtendedIntegerVT(unsigned BitWidth);
514 static EVT getExtendedVectorVT(EVT VT, unsigned NumElements);
515 bool isExtendedFloatingPoint() const;
516 bool isExtendedInteger() const;
517 bool isExtendedVector() const;
518 bool isExtended64BitVector() const;
519 bool isExtended128BitVector() const;
520 bool isExtended256BitVector() const;
521 EVT getExtendedVectorElementType() const;
522 unsigned getExtendedVectorNumElements() const;
523 unsigned getExtendedSizeInBits() const;
526 } // End llvm namespace