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
90 FIRST_INTEGER_VECTOR_VALUETYPE = v2i1,
91 LAST_INTEGER_VECTOR_VALUETYPE = v16i64,
93 v2f16 = 42, // 2 x f16
94 v4f16 = 43, // 4 x f16
95 v8f16 = 44, // 8 x f16
96 v1f32 = 45, // 1 x f32
97 v2f32 = 46, // 2 x f32
98 v4f32 = 47, // 4 x f32
99 v8f32 = 48, // 8 x f32
100 v16f32 = 49, // 16 x f32
101 v1f64 = 50, // 1 x f64
102 v2f64 = 51, // 2 x f64
103 v4f64 = 52, // 4 x f64
104 v8f64 = 53, // 8 x f64
106 FIRST_FP_VECTOR_VALUETYPE = v2f16,
107 LAST_FP_VECTOR_VALUETYPE = v8f64,
109 FIRST_VECTOR_VALUETYPE = v2i1,
110 LAST_VECTOR_VALUETYPE = v8f64,
112 x86mmx = 54, // This is an X86 MMX value
114 Glue = 55, // This glues nodes together during pre-RA sched
116 isVoid = 56, // This has no value
118 Untyped = 57, // This value takes a register, but has
119 // unspecified type. The register class
120 // will be determined by the opcode.
122 FIRST_VALUETYPE = 0, // This is always the beginning of the list.
123 LAST_VALUETYPE = 58, // This always remains at the end of the list.
125 // This is the current maximum for LAST_VALUETYPE.
126 // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
127 // This value must be a multiple of 32.
128 MAX_ALLOWED_VALUETYPE = 64,
130 // Metadata - This is MDNode or MDString.
133 // iPTRAny - An int value the size of the pointer of the current
134 // target to any address space. This must only be used internal to
135 // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
138 // vAny - A vector with any length and element size. This is used
139 // for intrinsics that have overloadings based on vector types.
140 // This is only for tblgen's consumption!
143 // fAny - Any floating-point or vector floating-point value. This is used
144 // for intrinsics that have overloadings based on floating-point types.
145 // This is only for tblgen's consumption!
148 // iAny - An integer or vector integer value of any bit width. This is
149 // used for intrinsics that have overloadings based on integer bit widths.
150 // This is only for tblgen's consumption!
153 // iPTR - An int value the size of the pointer of the current
154 // target. This should only be used internal to tblgen!
157 // Any - Any type. This is used for intrinsics that have overloadings.
158 // This is only for tblgen's consumption!
162 SimpleValueType SimpleTy;
164 LLVM_CONSTEXPR MVT() : SimpleTy(INVALID_SIMPLE_VALUE_TYPE) {}
165 LLVM_CONSTEXPR MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
167 bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; }
168 bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; }
169 bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
170 bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
171 bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
172 bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
174 /// isValid - Return true if this is a valid simple valuetype.
175 bool isValid() const {
176 return (SimpleTy >= MVT::FIRST_VALUETYPE &&
177 SimpleTy < MVT::LAST_VALUETYPE);
180 /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
181 bool isFloatingPoint() const {
182 return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
183 SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
184 (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE &&
185 SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE));
188 /// isInteger - Return true if this is an integer, or a vector integer type.
189 bool isInteger() const {
190 return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
191 SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
192 (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE &&
193 SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE));
196 /// isVector - Return true if this is a vector value type.
197 bool isVector() const {
198 return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
199 SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
202 /// is16BitVector - Return true if this is a 16-bit vector type.
203 bool is16BitVector() const {
204 return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 ||
205 SimpleTy == MVT::v16i1);
208 /// is32BitVector - Return true if this is a 32-bit vector type.
209 bool is32BitVector() const {
210 return (SimpleTy == MVT::v4i8 || SimpleTy == MVT::v2i16 ||
211 SimpleTy == MVT::v1i32 || SimpleTy == MVT::v2f16 ||
212 SimpleTy == MVT::v1f32);
215 /// is64BitVector - Return true if this is a 64-bit vector type.
216 bool is64BitVector() const {
217 return (SimpleTy == MVT::v8i8 || SimpleTy == MVT::v4i16 ||
218 SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
219 SimpleTy == MVT::v4f16 || SimpleTy == MVT::v2f32 ||
220 SimpleTy == MVT::v1f64);
223 /// is128BitVector - Return true if this is a 128-bit vector type.
224 bool is128BitVector() const {
225 return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
226 SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 ||
227 SimpleTy == MVT::v8f16 || SimpleTy == MVT::v4f32 ||
228 SimpleTy == MVT::v2f64);
231 /// is256BitVector - Return true if this is a 256-bit vector type.
232 bool is256BitVector() const {
233 return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64 ||
234 SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
235 SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
238 /// is512BitVector - Return true if this is a 512-bit vector type.
239 bool is512BitVector() const {
240 return (SimpleTy == MVT::v8f64 || SimpleTy == MVT::v16f32 ||
241 SimpleTy == MVT::v64i8 || SimpleTy == MVT::v32i16 ||
242 SimpleTy == MVT::v8i64 || SimpleTy == MVT::v16i32);
245 /// is1024BitVector - Return true if this is a 1024-bit vector type.
246 bool is1024BitVector() const {
247 return (SimpleTy == MVT::v16i64);
250 /// isOverloaded - Return true if this is an overloaded type for TableGen.
251 bool isOverloaded() const {
252 return (SimpleTy==MVT::Any ||
253 SimpleTy==MVT::iAny || SimpleTy==MVT::fAny ||
254 SimpleTy==MVT::vAny || SimpleTy==MVT::iPTRAny);
257 /// isPow2VectorType - Returns true if the given vector is a power of 2.
258 bool isPow2VectorType() const {
259 unsigned NElts = getVectorNumElements();
260 return !(NElts & (NElts - 1));
263 /// getPow2VectorType - Widens the length of the given vector MVT up to
264 /// the nearest power of 2 and returns that type.
265 MVT getPow2VectorType() const {
266 if (isPow2VectorType())
269 unsigned NElts = getVectorNumElements();
270 unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
271 return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
274 /// getScalarType - If this is a vector type, return the element type,
275 /// otherwise return this.
276 MVT getScalarType() const {
277 return isVector() ? getVectorElementType() : *this;
280 MVT getVectorElementType() const {
283 llvm_unreachable("Not a vector MVT!");
289 case v64i1: return i1;
296 case v64i8: return i8;
302 case v32i16: return i16;
307 case v16i32: return i32;
312 case v16i64: return i64;
315 case v8f16: return f16;
320 case v16f32: return f32;
324 case v8f64: return f64;
328 unsigned getVectorNumElements() const {
331 llvm_unreachable("Not a vector MVT!");
334 case v32i16: return 32;
336 case v64i8: return 64;
342 case v16f32: return 16;
350 case v8f64: return 8;
358 case v4f64: return 4;
366 case v2f64: return 2;
372 case v1f64: return 1;
376 unsigned getSizeInBits() const {
379 llvm_unreachable("getSizeInBits called on extended MVT.");
381 llvm_unreachable("Value type is non-standard value, Other.");
383 llvm_unreachable("Value type size is target-dependent. Ask TLI.");
389 llvm_unreachable("Value type is overloaded.");
391 llvm_unreachable("Value type is metadata.");
402 case v1i16: return 16;
410 case v1i32: return 32;
421 case v1f64: return 64;
422 case f80 : return 80;
432 case v2f64: return 128;
438 case v4f64: return 256;
444 case v8f64: return 512;
445 case v16i64:return 1024;
449 unsigned getScalarSizeInBits() const {
450 return getScalarType().getSizeInBits();
453 /// getStoreSize - Return the number of bytes overwritten by a store
454 /// of the specified value type.
455 unsigned getStoreSize() const {
456 return (getSizeInBits() + 7) / 8;
459 /// getStoreSizeInBits - Return the number of bits overwritten by a store
460 /// of the specified value type.
461 unsigned getStoreSizeInBits() const {
462 return getStoreSize() * 8;
465 /// Return true if this has more bits than VT.
466 bool bitsGT(MVT VT) const {
467 return getSizeInBits() > VT.getSizeInBits();
470 /// Return true if this has no less bits than VT.
471 bool bitsGE(MVT VT) const {
472 return getSizeInBits() >= VT.getSizeInBits();
475 /// Return true if this has less bits than VT.
476 bool bitsLT(MVT VT) const {
477 return getSizeInBits() < VT.getSizeInBits();
480 /// Return true if this has no more bits than VT.
481 bool bitsLE(MVT VT) const {
482 return getSizeInBits() <= VT.getSizeInBits();
486 static MVT getFloatingPointVT(unsigned BitWidth) {
489 llvm_unreachable("Bad bit width!");
503 static MVT getIntegerVT(unsigned BitWidth) {
506 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
522 static MVT getVectorVT(MVT VT, unsigned NumElements) {
523 switch (VT.SimpleTy) {
527 if (NumElements == 2) return MVT::v2i1;
528 if (NumElements == 4) return MVT::v4i1;
529 if (NumElements == 8) return MVT::v8i1;
530 if (NumElements == 16) return MVT::v16i1;
531 if (NumElements == 32) return MVT::v32i1;
532 if (NumElements == 64) return MVT::v64i1;
535 if (NumElements == 1) return MVT::v1i8;
536 if (NumElements == 2) return MVT::v2i8;
537 if (NumElements == 4) return MVT::v4i8;
538 if (NumElements == 8) return MVT::v8i8;
539 if (NumElements == 16) return MVT::v16i8;
540 if (NumElements == 32) return MVT::v32i8;
541 if (NumElements == 64) return MVT::v64i8;
544 if (NumElements == 1) return MVT::v1i16;
545 if (NumElements == 2) return MVT::v2i16;
546 if (NumElements == 4) return MVT::v4i16;
547 if (NumElements == 8) return MVT::v8i16;
548 if (NumElements == 16) return MVT::v16i16;
549 if (NumElements == 32) return MVT::v32i16;
552 if (NumElements == 1) return MVT::v1i32;
553 if (NumElements == 2) return MVT::v2i32;
554 if (NumElements == 4) return MVT::v4i32;
555 if (NumElements == 8) return MVT::v8i32;
556 if (NumElements == 16) return MVT::v16i32;
559 if (NumElements == 1) return MVT::v1i64;
560 if (NumElements == 2) return MVT::v2i64;
561 if (NumElements == 4) return MVT::v4i64;
562 if (NumElements == 8) return MVT::v8i64;
563 if (NumElements == 16) return MVT::v16i64;
566 if (NumElements == 2) return MVT::v2f16;
567 if (NumElements == 4) return MVT::v4f16;
568 if (NumElements == 8) return MVT::v8f16;
571 if (NumElements == 1) return MVT::v1f32;
572 if (NumElements == 2) return MVT::v2f32;
573 if (NumElements == 4) return MVT::v4f32;
574 if (NumElements == 8) return MVT::v8f32;
575 if (NumElements == 16) return MVT::v16f32;
578 if (NumElements == 1) return MVT::v1f64;
579 if (NumElements == 2) return MVT::v2f64;
580 if (NumElements == 4) return MVT::v4f64;
581 if (NumElements == 8) return MVT::v8f64;
584 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
587 /// Return the value type corresponding to the specified type. This returns
588 /// all pointers as iPTR. If HandleUnknown is true, unknown types are
589 /// returned as Other, otherwise they are invalid.
590 static MVT getVT(Type *Ty, bool HandleUnknown = false);
593 /// A simple iterator over the MVT::SimpleValueType enum.
594 struct mvt_iterator {
596 mvt_iterator(SimpleValueType VT) : VT(VT) {}
597 MVT operator*() const { return VT; }
598 bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
599 mvt_iterator& operator++() {
600 VT = (MVT::SimpleValueType)((int)VT + 1);
601 assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
602 "MVT iterator overflowed.");
606 /// A range of the MVT::SimpleValueType enum.
607 typedef iterator_range<mvt_iterator> mvt_range;
610 /// SimpleValueType Iteration
612 static mvt_range all_valuetypes() {
613 return mvt_range(MVT::FIRST_VALUETYPE, MVT::LAST_VALUETYPE);
615 static mvt_range integer_valuetypes() {
616 return mvt_range(MVT::FIRST_INTEGER_VALUETYPE,
617 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VALUETYPE + 1));
619 static mvt_range fp_valuetypes() {
620 return mvt_range(MVT::FIRST_FP_VALUETYPE,
621 (MVT::SimpleValueType)(MVT::LAST_FP_VALUETYPE + 1));
623 static mvt_range vector_valuetypes() {
624 return mvt_range(MVT::FIRST_VECTOR_VALUETYPE,
625 (MVT::SimpleValueType)(MVT::LAST_VECTOR_VALUETYPE + 1));
627 static mvt_range integer_vector_valuetypes() {
629 MVT::FIRST_INTEGER_VECTOR_VALUETYPE,
630 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VECTOR_VALUETYPE + 1));
632 static mvt_range fp_vector_valuetypes() {
634 MVT::FIRST_FP_VECTOR_VALUETYPE,
635 (MVT::SimpleValueType)(MVT::LAST_FP_VECTOR_VALUETYPE + 1));
640 } // End llvm namespace