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 // iPTR - An int value the size of the pointer of the current
70 // target. This should only be used internal to tblgen!
74 /// MVT::isInteger - Return true if this is a simple integer, or a packed
75 /// vector integer type.
76 static inline bool isInteger(ValueType VT) {
77 return (VT >= i1 && VT <= i128) || (VT >= v8i8 && VT <= v2i64);
80 /// MVT::isFloatingPoint - Return true if this is a simple FP, or a packed
82 static inline bool isFloatingPoint(ValueType VT) {
83 return (VT >= f32 && VT <= f128) || (VT >= v4f32 && VT <= v2f64);
86 /// MVT::isVector - Return true if this is a packed vector type (i.e. not
88 static inline bool isVector(ValueType VT) {
89 return VT >= FIRST_VECTOR_VALUETYPE && VT <= LAST_VECTOR_VALUETYPE;
92 /// MVT::getSizeInBits - Return the size of the specified value type in bits.
94 static inline unsigned getSizeInBits(ValueType VT) {
96 default: assert(0 && "ValueType has no known size!");
97 case MVT::i1 : return 1;
98 case MVT::i8 : return 8;
99 case MVT::i16 : return 16;
101 case MVT::i32 : return 32;
108 case MVT::v2f32: return 64;
109 case MVT::f80 : return 80;
117 case MVT::v2f64: return 128;
121 /// MVT::getVectorType - Returns the ValueType that represents a vector
122 /// NumElements in length, where each element is of type VT. If there is no
123 /// ValueType that represents this vector, a ValueType of Other is returned.
125 ValueType getVectorType(ValueType VT, unsigned NumElements);
127 /// MVT::getVectorBaseType - Given a packed vector type, return the type of
129 static inline ValueType getVectorBaseType(ValueType VT) {
131 default: assert(0 && "Invalid vector type!");
133 case v16i8: return i8;
135 case v8i16: return i16;
137 case v4i32: return i32;
139 case v2i64: return i64;
141 case v4f32: return f32;
142 case v2f64: return f64;
146 /// MVT::getVectorNumElements - Given a packed vector type, return the number
147 /// of elements it contains.
148 static inline unsigned getVectorNumElements(ValueType VT) {
150 default: assert(0 && "Invalid vector type!");
151 case v16i8: return 16;
153 case v8i16: return 8;
156 case v4f32: return 4;
160 case v2f64: return 2;
161 case v1i64: return 1;
165 /// MVT::getIntVectorWithNumElements - Return any integer vector type that has
166 /// the specified number of elements.
167 static inline ValueType getIntVectorWithNumElements(unsigned NumElts) {
169 default: assert(0 && "Invalid vector type!");
170 case 1: return v1i64;
171 case 2: return v2i32;
172 case 4: return v4i16;
174 case 16: return v16i8;
179 /// MVT::getIntVTBitMask - Return an integer with 1's every place there are
180 /// bits in the specified integer value type.
181 static inline uint64_t getIntVTBitMask(ValueType VT) {
182 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
183 return ~uint64_t(0UL) >> (64-getSizeInBits(VT));
185 /// MVT::getIntVTSignBit - Return an integer with a 1 in the position of the
186 /// sign bit for the specified integer value type.
187 static inline uint64_t getIntVTSignBit(ValueType VT) {
188 assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
189 return uint64_t(1UL) << (getSizeInBits(VT)-1);
192 /// MVT::getValueTypeString - This function returns value type as a string,
194 const char *getValueTypeString(ValueType VT);
196 /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
197 /// to the specified ValueType. For integer types, this returns an unsigned
198 /// type. Note that this will abort for types that cannot be represented.
199 const Type *getTypeForValueType(ValueType VT);
202 } // End llvm namespace