1 //===- CodeGen/MachineValueType.h - Machine-Level 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 machine-level target independent types which
11 // legal values in the code generator use.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_MACHINEVALUETYPE_H
16 #define LLVM_CODEGEN_MACHINEVALUETYPE_H
18 #include "llvm/ADT/iterator_range.h"
19 #include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/MathExtras.h"
26 /// MVT - Machine Value Type. Every type that is supported natively by some
27 /// processor targeted by LLVM occurs here. This means that any legal value
28 /// type can be represented by an MVT.
31 enum SimpleValueType {
32 // INVALID_SIMPLE_VALUE_TYPE - Simple value types less than zero are
33 // considered extended value types.
34 INVALID_SIMPLE_VALUE_TYPE = -1,
36 // If you change this numbering, you must change the values in
37 // ValueTypes.td as well!
38 Other = 0, // This is a non-standard value
39 i1 = 1, // This is a 1 bit integer value
40 i8 = 2, // This is an 8 bit integer value
41 i16 = 3, // This is a 16 bit integer value
42 i32 = 4, // This is a 32 bit integer value
43 i64 = 5, // This is a 64 bit integer value
44 i128 = 6, // This is a 128 bit integer value
46 FIRST_INTEGER_VALUETYPE = i1,
47 LAST_INTEGER_VALUETYPE = i128,
49 f16 = 7, // This is a 16 bit floating point value
50 f32 = 8, // This is a 32 bit floating point value
51 f64 = 9, // This is a 64 bit floating point value
52 f80 = 10, // This is a 80 bit floating point value
53 f128 = 11, // This is a 128 bit floating point value
54 ppcf128 = 12, // This is a PPC 128-bit floating point value
56 FIRST_FP_VALUETYPE = f16,
57 LAST_FP_VALUETYPE = ppcf128,
62 v16i1 = 16, // 16 x i1
63 v32i1 = 17, // 32 x i1
64 v64i1 = 18, // 64 x i1
70 v16i8 = 23, // 16 x i8
71 v32i8 = 24, // 32 x i8
72 v64i8 = 25, // 64 x i8
73 v1i16 = 26, // 1 x i16
74 v2i16 = 27, // 2 x i16
75 v4i16 = 28, // 4 x i16
76 v8i16 = 29, // 8 x i16
77 v16i16 = 30, // 16 x i16
78 v32i16 = 31, // 32 x i16
79 v1i32 = 32, // 1 x i32
80 v2i32 = 33, // 2 x i32
81 v4i32 = 34, // 4 x i32
82 v8i32 = 35, // 8 x i32
83 v16i32 = 36, // 16 x i32
84 v1i64 = 37, // 1 x i64
85 v2i64 = 38, // 2 x i64
86 v4i64 = 39, // 4 x i64
87 v8i64 = 40, // 8 x i64
88 v16i64 = 41, // 16 x i64
89 v1i128 = 42, // 1 x i128
91 FIRST_INTEGER_VECTOR_VALUETYPE = v2i1,
92 LAST_INTEGER_VECTOR_VALUETYPE = v1i128,
94 v2f16 = 43, // 2 x f16
95 v4f16 = 44, // 4 x f16
96 v8f16 = 45, // 8 x f16
97 v1f32 = 46, // 1 x f32
98 v2f32 = 47, // 2 x f32
99 v4f32 = 48, // 4 x f32
100 v8f32 = 49, // 8 x f32
101 v16f32 = 50, // 16 x f32
102 v1f64 = 51, // 1 x f64
103 v2f64 = 52, // 2 x f64
104 v4f64 = 53, // 4 x f64
105 v8f64 = 54, // 8 x f64
107 FIRST_FP_VECTOR_VALUETYPE = v2f16,
108 LAST_FP_VECTOR_VALUETYPE = v8f64,
110 FIRST_VECTOR_VALUETYPE = v2i1,
111 LAST_VECTOR_VALUETYPE = v8f64,
113 x86mmx = 55, // This is an X86 MMX value
115 Glue = 56, // This glues nodes together during pre-RA sched
117 isVoid = 57, // This has no value
119 Untyped = 58, // This value takes a register, but has
120 // unspecified type. The register class
121 // will be determined by the opcode.
123 FIRST_VALUETYPE = 0, // This is always the beginning of the list.
124 LAST_VALUETYPE = 59, // This always remains at the end of the list.
126 // This is the current maximum for LAST_VALUETYPE.
127 // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
128 // This value must be a multiple of 32.
129 MAX_ALLOWED_VALUETYPE = 64,
131 // Token - A value of type llvm::TokenTy
134 // Metadata - This is MDNode or MDString.
137 // iPTRAny - An int value the size of the pointer of the current
138 // target to any address space. This must only be used internal to
139 // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
142 // vAny - A vector with any length and element size. This is used
143 // for intrinsics that have overloadings based on vector types.
144 // This is only for tblgen's consumption!
147 // fAny - Any floating-point or vector floating-point value. This is used
148 // for intrinsics that have overloadings based on floating-point types.
149 // This is only for tblgen's consumption!
152 // iAny - An integer or vector integer value of any bit width. This is
153 // used for intrinsics that have overloadings based on integer bit widths.
154 // This is only for tblgen's consumption!
157 // iPTR - An int value the size of the pointer of the current
158 // target. This should only be used internal to tblgen!
161 // Any - Any type. This is used for intrinsics that have overloadings.
162 // This is only for tblgen's consumption!
166 SimpleValueType SimpleTy;
168 LLVM_CONSTEXPR MVT() : SimpleTy(INVALID_SIMPLE_VALUE_TYPE) {}
169 LLVM_CONSTEXPR MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
171 bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; }
172 bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; }
173 bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
174 bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
175 bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
176 bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
178 /// isValid - Return true if this is a valid simple valuetype.
179 bool isValid() const {
180 return (SimpleTy >= MVT::FIRST_VALUETYPE &&
181 SimpleTy < MVT::LAST_VALUETYPE);
184 /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
185 bool isFloatingPoint() const {
186 return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
187 SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
188 (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE &&
189 SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE));
192 /// isInteger - Return true if this is an integer, or a vector integer type.
193 bool isInteger() const {
194 return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
195 SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
196 (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE &&
197 SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE));
200 /// isVector - Return true if this is a vector value type.
201 bool isVector() const {
202 return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
203 SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
206 /// is16BitVector - Return true if this is a 16-bit vector type.
207 bool is16BitVector() const {
208 return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 ||
209 SimpleTy == MVT::v16i1);
212 /// is32BitVector - Return true if this is a 32-bit vector type.
213 bool is32BitVector() const {
214 return (SimpleTy == MVT::v4i8 || SimpleTy == MVT::v2i16 ||
215 SimpleTy == MVT::v1i32 || SimpleTy == MVT::v2f16 ||
216 SimpleTy == MVT::v1f32);
219 /// is64BitVector - Return true if this is a 64-bit vector type.
220 bool is64BitVector() const {
221 return (SimpleTy == MVT::v8i8 || SimpleTy == MVT::v4i16 ||
222 SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
223 SimpleTy == MVT::v4f16 || SimpleTy == MVT::v2f32 ||
224 SimpleTy == MVT::v1f64);
227 /// is128BitVector - Return true if this is a 128-bit vector type.
228 bool is128BitVector() const {
229 return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
230 SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 ||
231 SimpleTy == MVT::v1i128 || SimpleTy == MVT::v8f16 ||
232 SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64);
235 /// is256BitVector - Return true if this is a 256-bit vector type.
236 bool is256BitVector() const {
237 return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64 ||
238 SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
239 SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
242 /// is512BitVector - Return true if this is a 512-bit vector type.
243 bool is512BitVector() const {
244 return (SimpleTy == MVT::v8f64 || SimpleTy == MVT::v16f32 ||
245 SimpleTy == MVT::v64i8 || SimpleTy == MVT::v32i16 ||
246 SimpleTy == MVT::v8i64 || SimpleTy == MVT::v16i32);
249 /// is1024BitVector - Return true if this is a 1024-bit vector type.
250 bool is1024BitVector() const {
251 return (SimpleTy == MVT::v16i64);
254 /// isOverloaded - Return true if this is an overloaded type for TableGen.
255 bool isOverloaded() const {
256 return (SimpleTy==MVT::Any ||
257 SimpleTy==MVT::iAny || SimpleTy==MVT::fAny ||
258 SimpleTy==MVT::vAny || SimpleTy==MVT::iPTRAny);
261 /// isPow2VectorType - Returns true if the given vector is a power of 2.
262 bool isPow2VectorType() const {
263 unsigned NElts = getVectorNumElements();
264 return !(NElts & (NElts - 1));
267 /// getPow2VectorType - Widens the length of the given vector MVT up to
268 /// the nearest power of 2 and returns that type.
269 MVT getPow2VectorType() const {
270 if (isPow2VectorType())
273 unsigned NElts = getVectorNumElements();
274 unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
275 return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
278 /// getScalarType - If this is a vector type, return the element type,
279 /// otherwise return this.
280 MVT getScalarType() const {
281 return isVector() ? getVectorElementType() : *this;
284 MVT getVectorElementType() const {
287 llvm_unreachable("Not a vector MVT!");
293 case v64i1: return i1;
300 case v64i8: return i8;
306 case v32i16: return i16;
311 case v16i32: return i32;
316 case v16i64: return i64;
317 case v1i128: return i128;
320 case v8f16: return f16;
325 case v16f32: return f32;
329 case v8f64: return f64;
333 unsigned getVectorNumElements() const {
336 llvm_unreachable("Not a vector MVT!");
339 case v32i16: return 32;
341 case v64i8: return 64;
347 case v16f32: return 16;
355 case v8f64: return 8;
363 case v4f64: return 4;
371 case v2f64: return 2;
378 case v1f64: return 1;
382 unsigned getSizeInBits() const {
385 llvm_unreachable("getSizeInBits called on extended MVT.");
387 llvm_unreachable("Value type is non-standard value, Other.");
389 llvm_unreachable("Value type size is target-dependent. Ask TLI.");
395 llvm_unreachable("Value type is overloaded.");
397 llvm_unreachable("Token type is a sentinel that cannot be used "
398 "in codegen and has no size");
400 llvm_unreachable("Value type is metadata.");
411 case v1i16: return 16;
419 case v1i32: return 32;
430 case v1f64: return 64;
431 case f80 : return 80;
442 case v2f64: return 128;
448 case v4f64: return 256;
454 case v8f64: return 512;
455 case v16i64:return 1024;
459 unsigned getScalarSizeInBits() const {
460 return getScalarType().getSizeInBits();
463 /// getStoreSize - Return the number of bytes overwritten by a store
464 /// of the specified value type.
465 unsigned getStoreSize() const {
466 return (getSizeInBits() + 7) / 8;
469 /// getStoreSizeInBits - Return the number of bits overwritten by a store
470 /// of the specified value type.
471 unsigned getStoreSizeInBits() const {
472 return getStoreSize() * 8;
475 /// Return true if this has more bits than VT.
476 bool bitsGT(MVT VT) const {
477 return getSizeInBits() > VT.getSizeInBits();
480 /// Return true if this has no less bits than VT.
481 bool bitsGE(MVT VT) const {
482 return getSizeInBits() >= VT.getSizeInBits();
485 /// Return true if this has less bits than VT.
486 bool bitsLT(MVT VT) const {
487 return getSizeInBits() < VT.getSizeInBits();
490 /// Return true if this has no more bits than VT.
491 bool bitsLE(MVT VT) const {
492 return getSizeInBits() <= VT.getSizeInBits();
496 static MVT getFloatingPointVT(unsigned BitWidth) {
499 llvm_unreachable("Bad bit width!");
513 static MVT getIntegerVT(unsigned BitWidth) {
516 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
532 static MVT getVectorVT(MVT VT, unsigned NumElements) {
533 switch (VT.SimpleTy) {
537 if (NumElements == 2) return MVT::v2i1;
538 if (NumElements == 4) return MVT::v4i1;
539 if (NumElements == 8) return MVT::v8i1;
540 if (NumElements == 16) return MVT::v16i1;
541 if (NumElements == 32) return MVT::v32i1;
542 if (NumElements == 64) return MVT::v64i1;
545 if (NumElements == 1) return MVT::v1i8;
546 if (NumElements == 2) return MVT::v2i8;
547 if (NumElements == 4) return MVT::v4i8;
548 if (NumElements == 8) return MVT::v8i8;
549 if (NumElements == 16) return MVT::v16i8;
550 if (NumElements == 32) return MVT::v32i8;
551 if (NumElements == 64) return MVT::v64i8;
554 if (NumElements == 1) return MVT::v1i16;
555 if (NumElements == 2) return MVT::v2i16;
556 if (NumElements == 4) return MVT::v4i16;
557 if (NumElements == 8) return MVT::v8i16;
558 if (NumElements == 16) return MVT::v16i16;
559 if (NumElements == 32) return MVT::v32i16;
562 if (NumElements == 1) return MVT::v1i32;
563 if (NumElements == 2) return MVT::v2i32;
564 if (NumElements == 4) return MVT::v4i32;
565 if (NumElements == 8) return MVT::v8i32;
566 if (NumElements == 16) return MVT::v16i32;
569 if (NumElements == 1) return MVT::v1i64;
570 if (NumElements == 2) return MVT::v2i64;
571 if (NumElements == 4) return MVT::v4i64;
572 if (NumElements == 8) return MVT::v8i64;
573 if (NumElements == 16) return MVT::v16i64;
576 if (NumElements == 1) return MVT::v1i128;
579 if (NumElements == 2) return MVT::v2f16;
580 if (NumElements == 4) return MVT::v4f16;
581 if (NumElements == 8) return MVT::v8f16;
584 if (NumElements == 1) return MVT::v1f32;
585 if (NumElements == 2) return MVT::v2f32;
586 if (NumElements == 4) return MVT::v4f32;
587 if (NumElements == 8) return MVT::v8f32;
588 if (NumElements == 16) return MVT::v16f32;
591 if (NumElements == 1) return MVT::v1f64;
592 if (NumElements == 2) return MVT::v2f64;
593 if (NumElements == 4) return MVT::v4f64;
594 if (NumElements == 8) return MVT::v8f64;
597 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
600 /// Return the value type corresponding to the specified type. This returns
601 /// all pointers as iPTR. If HandleUnknown is true, unknown types are
602 /// returned as Other, otherwise they are invalid.
603 static MVT getVT(Type *Ty, bool HandleUnknown = false);
606 /// A simple iterator over the MVT::SimpleValueType enum.
607 struct mvt_iterator {
609 mvt_iterator(SimpleValueType VT) : VT(VT) {}
610 MVT operator*() const { return VT; }
611 bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
612 mvt_iterator& operator++() {
613 VT = (MVT::SimpleValueType)((int)VT + 1);
614 assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
615 "MVT iterator overflowed.");
619 /// A range of the MVT::SimpleValueType enum.
620 typedef iterator_range<mvt_iterator> mvt_range;
623 /// SimpleValueType Iteration
625 static mvt_range all_valuetypes() {
626 return mvt_range(MVT::FIRST_VALUETYPE, MVT::LAST_VALUETYPE);
628 static mvt_range integer_valuetypes() {
629 return mvt_range(MVT::FIRST_INTEGER_VALUETYPE,
630 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VALUETYPE + 1));
632 static mvt_range fp_valuetypes() {
633 return mvt_range(MVT::FIRST_FP_VALUETYPE,
634 (MVT::SimpleValueType)(MVT::LAST_FP_VALUETYPE + 1));
636 static mvt_range vector_valuetypes() {
637 return mvt_range(MVT::FIRST_VECTOR_VALUETYPE,
638 (MVT::SimpleValueType)(MVT::LAST_VECTOR_VALUETYPE + 1));
640 static mvt_range integer_vector_valuetypes() {
642 MVT::FIRST_INTEGER_VECTOR_VALUETYPE,
643 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VECTOR_VALUETYPE + 1));
645 static mvt_range fp_vector_valuetypes() {
647 MVT::FIRST_FP_VECTOR_VALUETYPE,
648 (MVT::SimpleValueType)(MVT::LAST_FP_VECTOR_VALUETYPE + 1));
653 } // End llvm namespace