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
20 #include "llvm/Support/DataTypes.h"
25 /// MVT namespace - This namespace defines the ValueType enum, which contains
26 /// the various low-level value types.
28 namespace MVT { // MVT = Machine Value Types
30 // If you change this numbering, you must change the values in ValueTypes.td
32 Other = 0, // This is a non-standard value
33 i1 = 1, // This is a 1 bit integer value
34 i8 = 2, // This is an 8 bit integer value
35 i16 = 3, // This is a 16 bit integer value
36 i32 = 4, // This is a 32 bit integer value
37 i64 = 5, // This is a 64 bit integer value
38 i128 = 6, // This is a 128 bit integer value
40 f32 = 7, // This is a 32 bit floating point value
41 f64 = 8, // This is a 64 bit floating point value
42 f80 = 9, // This is a 80 bit floating point value
43 f128 = 10, // This is a 128 bit floating point value
44 Flag = 11, // This is a condition code or machine flag.
46 isVoid = 12, // This has no value
48 Vector = 13, // This is an abstract vector type, which will
49 // be expanded into a target vector type, or scalars
50 // if no matching vector type is available.
53 v4i16 = 15, // 4 x i16
54 v2i32 = 16, // 2 x i32
55 v1i64 = 17, // 1 x i64
56 v16i8 = 18, // 16 x i8
57 v8i16 = 19, // 8 x i16
58 v4i32 = 20, // 4 x i32
59 v2i64 = 21, // 2 x i64
61 v2f32 = 22, // 2 x f32
62 v4f32 = 23, // 4 x f32
63 v2f64 = 24, // 2 x f64
64 FIRST_VECTOR_VALUETYPE = v8i8,
65 LAST_VECTOR_VALUETYPE = v2f64,
67 LAST_VALUETYPE = 25, // This always remains at the end of the list.
69 // iAny - An integer value of any bit width. This is used for intrinsics
70 // that have overloadings based on integer bit widths. This is only for
71 // tblgen's consumption!
74 // iPTR - An int value the size of the pointer of the current
75 // target. This should only be used internal to tblgen!
79 /// MVT::isInteger - Return true if this is a simple integer, or a packed
80 /// vector integer type.
81 static inline bool isInteger(ValueType VT) {
82 return (VT >= i1 && VT <= i128) || (VT >= v8i8 && VT <= v2i64);
85 /// MVT::isFloatingPoint - Return true if this is a simple FP, or a packed
87 static inline bool isFloatingPoint(ValueType VT) {
88 return (VT >= f32 && VT <= f128) || (VT >= v2f32 && VT <= v2f64);
91 /// MVT::isVector - Return true if this is a packed vector type (i.e. not
93 static inline bool isVector(ValueType VT) {
94 return VT >= FIRST_VECTOR_VALUETYPE && VT <= LAST_VECTOR_VALUETYPE;
97 /// MVT::getSizeInBits - Return the size of the specified value type in bits.
99 static inline unsigned getSizeInBits(ValueType VT) {
101 default: assert(0 && "ValueType has no known size!");
102 case MVT::i1 : return 1;
103 case MVT::i8 : return 8;
104 case MVT::i16 : return 16;
106 case MVT::i32 : return 32;
113 case MVT::v2f32: return 64;
114 case MVT::f80 : return 80;
122 case MVT::v2f64: return 128;
126 /// MVT::getVectorType - Returns the ValueType that represents a vector
127 /// NumElements in length, where each element is of type VT. If there is no
128 /// ValueType that represents this vector, a ValueType of Other is returned.
130 ValueType getVectorType(ValueType VT, unsigned NumElements);
132 /// MVT::getVectorElementType - Given a packed vector type, return the type of
134 static inline ValueType getVectorElementType(ValueType VT) {
136 default: assert(0 && "Invalid vector type!");
138 case v16i8: return i8;
140 case v8i16: return i16;
142 case v4i32: return i32;
144 case v2i64: return i64;
146 case v4f32: return f32;
147 case v2f64: return f64;
151 /// MVT::getVectorNumElements - Given a packed vector type, return the number
152 /// of elements it contains.
153 static inline unsigned getVectorNumElements(ValueType VT) {
155 default: assert(0 && "Invalid vector type!");
156 case v16i8: return 16;
158 case v8i16: return 8;
161 case v4f32: return 4;
165 case v2f64: return 2;
166 case v1i64: return 1;
170 /// MVT::getIntVectorWithNumElements - Return any integer vector type that has
171 /// the specified number of elements.
172 static inline ValueType getIntVectorWithNumElements(unsigned NumElts) {
174 default: assert(0 && "Invalid vector type!");
175 case 1: return v1i64;
176 case 2: return v2i32;
177 case 4: return v4i16;
179 case 16: return v16i8;
184 /// MVT::getIntVTBitMask - Return an integer with 1's every place there are
185 /// bits in the specified integer value type.
186 static inline uint64_t getIntVTBitMask(ValueType VT) {
187 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
188 return ~uint64_t(0UL) >> (64-getSizeInBits(VT));
190 /// MVT::getIntVTSignBit - Return an integer with a 1 in the position of the
191 /// sign bit for the specified integer value type.
192 static inline uint64_t getIntVTSignBit(ValueType VT) {
193 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
194 return uint64_t(1UL) << (getSizeInBits(VT)-1);
197 /// MVT::getValueTypeString - This function returns value type as a string,
199 const char *getValueTypeString(ValueType VT);
201 /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
202 /// to the specified ValueType. For integer types, this returns an unsigned
203 /// type. Note that this will abort for types that cannot be represented.
204 const Type *getTypeForValueType(ValueType VT);
206 /// MVT::getValueType - Return the value type corresponding to the specified
207 /// type. This returns all vectors as MVT::Vector and all pointers as
208 /// MVT::iPTR. If HandleUnknown is true, unknown types are returned as Other,
209 /// otherwise they are invalid.
210 ValueType getValueType(const Type *Ty, bool HandleUnknown = false);
213 } // End llvm namespace