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 // Metadata - This is MDNode or MDString.
134 // iPTRAny - An int value the size of the pointer of the current
135 // target to any address space. This must only be used internal to
136 // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
139 // vAny - A vector with any length and element size. This is used
140 // for intrinsics that have overloadings based on vector types.
141 // This is only for tblgen's consumption!
144 // fAny - Any floating-point or vector floating-point value. This is used
145 // for intrinsics that have overloadings based on floating-point types.
146 // This is only for tblgen's consumption!
149 // iAny - An integer or vector integer value of any bit width. This is
150 // used for intrinsics that have overloadings based on integer bit widths.
151 // This is only for tblgen's consumption!
154 // iPTR - An int value the size of the pointer of the current
155 // target. This should only be used internal to tblgen!
158 // Any - Any type. This is used for intrinsics that have overloadings.
159 // This is only for tblgen's consumption!
163 SimpleValueType SimpleTy;
165 LLVM_CONSTEXPR MVT() : SimpleTy(INVALID_SIMPLE_VALUE_TYPE) {}
166 LLVM_CONSTEXPR MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
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; }
173 bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
175 /// isValid - Return true if this is a valid simple valuetype.
176 bool isValid() const {
177 return (SimpleTy >= MVT::FIRST_VALUETYPE &&
178 SimpleTy < MVT::LAST_VALUETYPE);
181 /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
182 bool isFloatingPoint() const {
183 return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
184 SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
185 (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE &&
186 SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE));
189 /// isInteger - Return true if this is an integer, or a vector integer type.
190 bool isInteger() const {
191 return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
192 SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
193 (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE &&
194 SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE));
197 /// isVector - Return true if this is a vector value type.
198 bool isVector() const {
199 return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
200 SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
203 /// is16BitVector - Return true if this is a 16-bit vector type.
204 bool is16BitVector() const {
205 return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 ||
206 SimpleTy == MVT::v16i1);
209 /// is32BitVector - Return true if this is a 32-bit vector type.
210 bool is32BitVector() const {
211 return (SimpleTy == MVT::v4i8 || SimpleTy == MVT::v2i16 ||
212 SimpleTy == MVT::v1i32 || SimpleTy == MVT::v2f16 ||
213 SimpleTy == MVT::v1f32);
216 /// is64BitVector - Return true if this is a 64-bit vector type.
217 bool is64BitVector() const {
218 return (SimpleTy == MVT::v8i8 || SimpleTy == MVT::v4i16 ||
219 SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
220 SimpleTy == MVT::v4f16 || SimpleTy == MVT::v2f32 ||
221 SimpleTy == MVT::v1f64);
224 /// is128BitVector - Return true if this is a 128-bit vector type.
225 bool is128BitVector() const {
226 return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
227 SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 ||
228 SimpleTy == MVT::v1i128 || SimpleTy == MVT::v8f16 ||
229 SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64);
232 /// is256BitVector - Return true if this is a 256-bit vector type.
233 bool is256BitVector() const {
234 return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64 ||
235 SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
236 SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
239 /// is512BitVector - Return true if this is a 512-bit vector type.
240 bool is512BitVector() const {
241 return (SimpleTy == MVT::v8f64 || SimpleTy == MVT::v16f32 ||
242 SimpleTy == MVT::v64i8 || SimpleTy == MVT::v32i16 ||
243 SimpleTy == MVT::v8i64 || SimpleTy == MVT::v16i32);
246 /// is1024BitVector - Return true if this is a 1024-bit vector type.
247 bool is1024BitVector() const {
248 return (SimpleTy == MVT::v16i64);
251 /// isOverloaded - Return true if this is an overloaded type for TableGen.
252 bool isOverloaded() const {
253 return (SimpleTy==MVT::Any ||
254 SimpleTy==MVT::iAny || SimpleTy==MVT::fAny ||
255 SimpleTy==MVT::vAny || SimpleTy==MVT::iPTRAny);
258 /// isPow2VectorType - Returns true if the given vector is a power of 2.
259 bool isPow2VectorType() const {
260 unsigned NElts = getVectorNumElements();
261 return !(NElts & (NElts - 1));
264 /// getPow2VectorType - Widens the length of the given vector MVT up to
265 /// the nearest power of 2 and returns that type.
266 MVT getPow2VectorType() const {
267 if (isPow2VectorType())
270 unsigned NElts = getVectorNumElements();
271 unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
272 return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
275 /// getScalarType - If this is a vector type, return the element type,
276 /// otherwise return this.
277 MVT getScalarType() const {
278 return isVector() ? getVectorElementType() : *this;
281 MVT getVectorElementType() const {
284 llvm_unreachable("Not a vector MVT!");
290 case v64i1: return i1;
297 case v64i8: return i8;
303 case v32i16: return i16;
308 case v16i32: return i32;
313 case v16i64: return i64;
314 case v1i128: return i128;
317 case v8f16: return f16;
322 case v16f32: return f32;
326 case v8f64: return f64;
330 unsigned getVectorNumElements() const {
333 llvm_unreachable("Not a vector MVT!");
336 case v32i16: return 32;
338 case v64i8: return 64;
344 case v16f32: return 16;
352 case v8f64: return 8;
360 case v4f64: return 4;
368 case v2f64: return 2;
375 case v1f64: return 1;
379 unsigned getSizeInBits() const {
382 llvm_unreachable("getSizeInBits called on extended MVT.");
384 llvm_unreachable("Value type is non-standard value, Other.");
386 llvm_unreachable("Value type size is target-dependent. Ask TLI.");
392 llvm_unreachable("Value type is overloaded.");
394 llvm_unreachable("Value type is metadata.");
405 case v1i16: return 16;
413 case v1i32: return 32;
424 case v1f64: return 64;
425 case f80 : return 80;
436 case v2f64: return 128;
442 case v4f64: return 256;
448 case v8f64: return 512;
449 case v16i64:return 1024;
453 unsigned getScalarSizeInBits() const {
454 return getScalarType().getSizeInBits();
457 /// getStoreSize - Return the number of bytes overwritten by a store
458 /// of the specified value type.
459 unsigned getStoreSize() const {
460 return (getSizeInBits() + 7) / 8;
463 /// getStoreSizeInBits - Return the number of bits overwritten by a store
464 /// of the specified value type.
465 unsigned getStoreSizeInBits() const {
466 return getStoreSize() * 8;
469 /// Return true if this has more bits than VT.
470 bool bitsGT(MVT VT) const {
471 return getSizeInBits() > VT.getSizeInBits();
474 /// Return true if this has no less bits than VT.
475 bool bitsGE(MVT VT) const {
476 return getSizeInBits() >= VT.getSizeInBits();
479 /// Return true if this has less bits than VT.
480 bool bitsLT(MVT VT) const {
481 return getSizeInBits() < VT.getSizeInBits();
484 /// Return true if this has no more bits than VT.
485 bool bitsLE(MVT VT) const {
486 return getSizeInBits() <= VT.getSizeInBits();
490 static MVT getFloatingPointVT(unsigned BitWidth) {
493 llvm_unreachable("Bad bit width!");
507 static MVT getIntegerVT(unsigned BitWidth) {
510 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
526 static MVT getVectorVT(MVT VT, unsigned NumElements) {
527 switch (VT.SimpleTy) {
531 if (NumElements == 2) return MVT::v2i1;
532 if (NumElements == 4) return MVT::v4i1;
533 if (NumElements == 8) return MVT::v8i1;
534 if (NumElements == 16) return MVT::v16i1;
535 if (NumElements == 32) return MVT::v32i1;
536 if (NumElements == 64) return MVT::v64i1;
539 if (NumElements == 1) return MVT::v1i8;
540 if (NumElements == 2) return MVT::v2i8;
541 if (NumElements == 4) return MVT::v4i8;
542 if (NumElements == 8) return MVT::v8i8;
543 if (NumElements == 16) return MVT::v16i8;
544 if (NumElements == 32) return MVT::v32i8;
545 if (NumElements == 64) return MVT::v64i8;
548 if (NumElements == 1) return MVT::v1i16;
549 if (NumElements == 2) return MVT::v2i16;
550 if (NumElements == 4) return MVT::v4i16;
551 if (NumElements == 8) return MVT::v8i16;
552 if (NumElements == 16) return MVT::v16i16;
553 if (NumElements == 32) return MVT::v32i16;
556 if (NumElements == 1) return MVT::v1i32;
557 if (NumElements == 2) return MVT::v2i32;
558 if (NumElements == 4) return MVT::v4i32;
559 if (NumElements == 8) return MVT::v8i32;
560 if (NumElements == 16) return MVT::v16i32;
563 if (NumElements == 1) return MVT::v1i64;
564 if (NumElements == 2) return MVT::v2i64;
565 if (NumElements == 4) return MVT::v4i64;
566 if (NumElements == 8) return MVT::v8i64;
567 if (NumElements == 16) return MVT::v16i64;
570 if (NumElements == 1) return MVT::v1i128;
573 if (NumElements == 2) return MVT::v2f16;
574 if (NumElements == 4) return MVT::v4f16;
575 if (NumElements == 8) return MVT::v8f16;
578 if (NumElements == 1) return MVT::v1f32;
579 if (NumElements == 2) return MVT::v2f32;
580 if (NumElements == 4) return MVT::v4f32;
581 if (NumElements == 8) return MVT::v8f32;
582 if (NumElements == 16) return MVT::v16f32;
585 if (NumElements == 1) return MVT::v1f64;
586 if (NumElements == 2) return MVT::v2f64;
587 if (NumElements == 4) return MVT::v4f64;
588 if (NumElements == 8) return MVT::v8f64;
591 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
594 /// Return the value type corresponding to the specified type. This returns
595 /// all pointers as iPTR. If HandleUnknown is true, unknown types are
596 /// returned as Other, otherwise they are invalid.
597 static MVT getVT(Type *Ty, bool HandleUnknown = false);
600 /// A simple iterator over the MVT::SimpleValueType enum.
601 struct mvt_iterator {
603 mvt_iterator(SimpleValueType VT) : VT(VT) {}
604 MVT operator*() const { return VT; }
605 bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
606 mvt_iterator& operator++() {
607 VT = (MVT::SimpleValueType)((int)VT + 1);
608 assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
609 "MVT iterator overflowed.");
613 /// A range of the MVT::SimpleValueType enum.
614 typedef iterator_range<mvt_iterator> mvt_range;
617 /// SimpleValueType Iteration
619 static mvt_range all_valuetypes() {
620 return mvt_range(MVT::FIRST_VALUETYPE, MVT::LAST_VALUETYPE);
622 static mvt_range integer_valuetypes() {
623 return mvt_range(MVT::FIRST_INTEGER_VALUETYPE,
624 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VALUETYPE + 1));
626 static mvt_range fp_valuetypes() {
627 return mvt_range(MVT::FIRST_FP_VALUETYPE,
628 (MVT::SimpleValueType)(MVT::LAST_FP_VALUETYPE + 1));
630 static mvt_range vector_valuetypes() {
631 return mvt_range(MVT::FIRST_VECTOR_VALUETYPE,
632 (MVT::SimpleValueType)(MVT::LAST_VECTOR_VALUETYPE + 1));
634 static mvt_range integer_vector_valuetypes() {
636 MVT::FIRST_INTEGER_VECTOR_VALUETYPE,
637 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VECTOR_VALUETYPE + 1));
639 static mvt_range fp_vector_valuetypes() {
641 MVT::FIRST_FP_VECTOR_VALUETYPE,
642 (MVT::SimpleValueType)(MVT::LAST_FP_VECTOR_VALUETYPE + 1));
647 } // End llvm namespace