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
65 v512i1 = 19, // 512 x i1
66 v1024i1 = 20, // 1024 x i1
72 v16i8 = 25, // 16 x i8
73 v32i8 = 26, // 32 x i8
74 v64i8 = 27, // 64 x i8
75 v128i8 = 28, //128 x i8
76 v256i8 = 29, //256 x i8
78 v1i16 = 30, // 1 x i16
79 v2i16 = 31, // 2 x i16
80 v4i16 = 32, // 4 x i16
81 v8i16 = 33, // 8 x i16
82 v16i16 = 34, // 16 x i16
83 v32i16 = 35, // 32 x i16
84 v64i16 = 36, // 64 x i16
85 v128i16 = 37, //128 x i16
87 v1i32 = 38, // 1 x i32
88 v2i32 = 39, // 2 x i32
89 v4i32 = 40, // 4 x i32
90 v8i32 = 41, // 8 x i32
91 v16i32 = 42, // 16 x i32
92 v32i32 = 43, // 32 x i32
93 v64i32 = 44, // 64 x i32
95 v1i64 = 45, // 1 x i64
96 v2i64 = 46, // 2 x i64
97 v4i64 = 47, // 4 x i64
98 v8i64 = 48, // 8 x i64
99 v16i64 = 49, // 16 x i64
100 v32i64 = 50, // 32 x i64
102 v1i128 = 51, // 1 x i128
104 FIRST_INTEGER_VECTOR_VALUETYPE = v2i1,
105 LAST_INTEGER_VECTOR_VALUETYPE = v1i128,
107 v2f16 = 52, // 2 x f16
108 v4f16 = 53, // 4 x f16
109 v8f16 = 54, // 8 x f16
110 v1f32 = 55, // 1 x f32
111 v2f32 = 56, // 2 x f32
112 v4f32 = 57, // 4 x f32
113 v8f32 = 58, // 8 x f32
114 v16f32 = 59, // 16 x f32
115 v1f64 = 60, // 1 x f64
116 v2f64 = 61, // 2 x f64
117 v4f64 = 62, // 4 x f64
118 v8f64 = 63, // 8 x f64
120 FIRST_FP_VECTOR_VALUETYPE = v2f16,
121 LAST_FP_VECTOR_VALUETYPE = v8f64,
123 FIRST_VECTOR_VALUETYPE = v2i1,
124 LAST_VECTOR_VALUETYPE = v8f64,
126 x86mmx = 64, // This is an X86 MMX value
128 Glue = 65, // This glues nodes together during pre-RA sched
130 isVoid = 66, // This has no value
132 Untyped = 67, // This value takes a register, but has
133 // unspecified type. The register class
134 // will be determined by the opcode.
136 FIRST_VALUETYPE = 0, // This is always the beginning of the list.
137 LAST_VALUETYPE = 68, // This always remains at the end of the list.
139 // This is the current maximum for LAST_VALUETYPE.
140 // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
141 // This value must be a multiple of 32.
142 MAX_ALLOWED_VALUETYPE = 96,
144 // Token - A value of type llvm::TokenTy
147 // Metadata - This is MDNode or MDString.
150 // iPTRAny - An int value the size of the pointer of the current
151 // target to any address space. This must only be used internal to
152 // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
155 // vAny - A vector with any length and element size. This is used
156 // for intrinsics that have overloadings based on vector types.
157 // This is only for tblgen's consumption!
160 // fAny - Any floating-point or vector floating-point value. This is used
161 // for intrinsics that have overloadings based on floating-point types.
162 // This is only for tblgen's consumption!
165 // iAny - An integer or vector integer value of any bit width. This is
166 // used for intrinsics that have overloadings based on integer bit widths.
167 // This is only for tblgen's consumption!
170 // iPTR - An int value the size of the pointer of the current
171 // target. This should only be used internal to tblgen!
174 // Any - Any type. This is used for intrinsics that have overloadings.
175 // This is only for tblgen's consumption!
179 SimpleValueType SimpleTy;
181 LLVM_CONSTEXPR MVT() : SimpleTy(INVALID_SIMPLE_VALUE_TYPE) {}
182 LLVM_CONSTEXPR MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
184 bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; }
185 bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; }
186 bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
187 bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
188 bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
189 bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
191 /// isValid - Return true if this is a valid simple valuetype.
192 bool isValid() const {
193 return (SimpleTy >= MVT::FIRST_VALUETYPE &&
194 SimpleTy < MVT::LAST_VALUETYPE);
197 /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
198 bool isFloatingPoint() const {
199 return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
200 SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
201 (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE &&
202 SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE));
205 /// isInteger - Return true if this is an integer, or a vector integer type.
206 bool isInteger() const {
207 return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
208 SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
209 (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE &&
210 SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE));
213 /// isVector - Return true if this is a vector value type.
214 bool isVector() const {
215 return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
216 SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
219 /// is16BitVector - Return true if this is a 16-bit vector type.
220 bool is16BitVector() const {
221 return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 ||
222 SimpleTy == MVT::v16i1);
225 /// is32BitVector - Return true if this is a 32-bit vector type.
226 bool is32BitVector() const {
227 return (SimpleTy == MVT::v4i8 || SimpleTy == MVT::v2i16 ||
228 SimpleTy == MVT::v1i32 || SimpleTy == MVT::v2f16 ||
229 SimpleTy == MVT::v1f32);
232 /// is64BitVector - Return true if this is a 64-bit vector type.
233 bool is64BitVector() const {
234 return (SimpleTy == MVT::v8i8 || SimpleTy == MVT::v4i16 ||
235 SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
236 SimpleTy == MVT::v4f16 || SimpleTy == MVT::v2f32 ||
237 SimpleTy == MVT::v1f64);
240 /// is128BitVector - Return true if this is a 128-bit vector type.
241 bool is128BitVector() const {
242 return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
243 SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 ||
244 SimpleTy == MVT::v1i128 || SimpleTy == MVT::v8f16 ||
245 SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64);
248 /// is256BitVector - Return true if this is a 256-bit vector type.
249 bool is256BitVector() const {
250 return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64 ||
251 SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
252 SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
255 /// is512BitVector - Return true if this is a 512-bit vector type.
256 bool is512BitVector() const {
257 return (SimpleTy == MVT::v16f32 || SimpleTy == MVT::v8f64 ||
258 SimpleTy == MVT::v512i1 || SimpleTy == MVT::v64i8 ||
259 SimpleTy == MVT::v32i16 || SimpleTy == MVT::v16i32 ||
260 SimpleTy == MVT::v8i64);
263 /// is1024BitVector - Return true if this is a 1024-bit vector type.
264 bool is1024BitVector() const {
265 return (SimpleTy == MVT::v1024i1 || SimpleTy == MVT::v128i8 ||
266 SimpleTy == MVT::v64i16 || SimpleTy == MVT::v32i32 ||
267 SimpleTy == MVT::v16i64);
270 /// is2048BitVector - Return true if this is a 1024-bit vector type.
271 bool is2048BitVector() const {
272 return (SimpleTy == MVT::v256i8 || SimpleTy == MVT::v128i16 ||
273 SimpleTy == MVT::v64i32 || SimpleTy == MVT::v32i64);
276 /// isOverloaded - Return true if this is an overloaded type for TableGen.
277 bool isOverloaded() const {
278 return (SimpleTy==MVT::Any ||
279 SimpleTy==MVT::iAny || SimpleTy==MVT::fAny ||
280 SimpleTy==MVT::vAny || SimpleTy==MVT::iPTRAny);
283 /// isPow2VectorType - Returns true if the given vector is a power of 2.
284 bool isPow2VectorType() const {
285 unsigned NElts = getVectorNumElements();
286 return !(NElts & (NElts - 1));
289 /// getPow2VectorType - Widens the length of the given vector MVT up to
290 /// the nearest power of 2 and returns that type.
291 MVT getPow2VectorType() const {
292 if (isPow2VectorType())
295 unsigned NElts = getVectorNumElements();
296 unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
297 return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
300 /// getScalarType - If this is a vector type, return the element type,
301 /// otherwise return this.
302 MVT getScalarType() const {
303 return isVector() ? getVectorElementType() : *this;
306 MVT getVectorElementType() const {
309 llvm_unreachable("Not a vector MVT!");
317 case v1024i1: return i1;
326 case v256i8: return i8;
334 case v128i16: return i16;
341 case v64i32: return i32;
347 case v32i64: return i64;
348 case v1i128: return i128;
351 case v8f16: return f16;
356 case v16f32: return f32;
360 case v8f64: return f64;
364 unsigned getVectorNumElements() const {
367 llvm_unreachable("Not a vector MVT!");
368 case v1024i1: return 1024;
369 case v512i1: return 512;
370 case v256i8: return 256;
372 case v128i16: return 128;
376 case v64i32: return 64;
381 case v32i64: return 32;
387 case v16f32: return 16;
395 case v8f64: return 8;
403 case v4f64: return 4;
411 case v2f64: return 2;
418 case v1f64: return 1;
422 unsigned getSizeInBits() const {
425 llvm_unreachable("getSizeInBits called on extended MVT.");
427 llvm_unreachable("Value type is non-standard value, Other.");
429 llvm_unreachable("Value type size is target-dependent. Ask TLI.");
435 llvm_unreachable("Value type is overloaded.");
437 llvm_unreachable("Token type is a sentinel that cannot be used "
438 "in codegen and has no size");
440 llvm_unreachable("Value type is metadata.");
451 case v1i16: return 16;
459 case v1i32: return 32;
470 case v1f64: return 64;
471 case f80 : return 80;
482 case v2f64: return 128;
488 case v4f64: return 256;
495 case v8f64: return 512;
500 case v16i64: return 1024;
504 case v32i64: return 2048;
508 unsigned getScalarSizeInBits() const {
509 return getScalarType().getSizeInBits();
512 /// getStoreSize - Return the number of bytes overwritten by a store
513 /// of the specified value type.
514 unsigned getStoreSize() const {
515 return (getSizeInBits() + 7) / 8;
518 /// getStoreSizeInBits - Return the number of bits overwritten by a store
519 /// of the specified value type.
520 unsigned getStoreSizeInBits() const {
521 return getStoreSize() * 8;
524 /// Return true if this has more bits than VT.
525 bool bitsGT(MVT VT) const {
526 return getSizeInBits() > VT.getSizeInBits();
529 /// Return true if this has no less bits than VT.
530 bool bitsGE(MVT VT) const {
531 return getSizeInBits() >= VT.getSizeInBits();
534 /// Return true if this has less bits than VT.
535 bool bitsLT(MVT VT) const {
536 return getSizeInBits() < VT.getSizeInBits();
539 /// Return true if this has no more bits than VT.
540 bool bitsLE(MVT VT) const {
541 return getSizeInBits() <= VT.getSizeInBits();
545 static MVT getFloatingPointVT(unsigned BitWidth) {
548 llvm_unreachable("Bad bit width!");
562 static MVT getIntegerVT(unsigned BitWidth) {
565 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
581 static MVT getVectorVT(MVT VT, unsigned NumElements) {
582 switch (VT.SimpleTy) {
586 if (NumElements == 2) return MVT::v2i1;
587 if (NumElements == 4) return MVT::v4i1;
588 if (NumElements == 8) return MVT::v8i1;
589 if (NumElements == 16) return MVT::v16i1;
590 if (NumElements == 32) return MVT::v32i1;
591 if (NumElements == 64) return MVT::v64i1;
592 if (NumElements == 512) return MVT::v512i1;
593 if (NumElements == 1024) return MVT::v1024i1;
596 if (NumElements == 1) return MVT::v1i8;
597 if (NumElements == 2) return MVT::v2i8;
598 if (NumElements == 4) return MVT::v4i8;
599 if (NumElements == 8) return MVT::v8i8;
600 if (NumElements == 16) return MVT::v16i8;
601 if (NumElements == 32) return MVT::v32i8;
602 if (NumElements == 64) return MVT::v64i8;
603 if (NumElements == 128) return MVT::v128i8;
604 if (NumElements == 256) return MVT::v256i8;
607 if (NumElements == 1) return MVT::v1i16;
608 if (NumElements == 2) return MVT::v2i16;
609 if (NumElements == 4) return MVT::v4i16;
610 if (NumElements == 8) return MVT::v8i16;
611 if (NumElements == 16) return MVT::v16i16;
612 if (NumElements == 32) return MVT::v32i16;
613 if (NumElements == 64) return MVT::v64i16;
614 if (NumElements == 128) return MVT::v128i16;
617 if (NumElements == 1) return MVT::v1i32;
618 if (NumElements == 2) return MVT::v2i32;
619 if (NumElements == 4) return MVT::v4i32;
620 if (NumElements == 8) return MVT::v8i32;
621 if (NumElements == 16) return MVT::v16i32;
622 if (NumElements == 32) return MVT::v32i32;
623 if (NumElements == 64) return MVT::v64i32;
626 if (NumElements == 1) return MVT::v1i64;
627 if (NumElements == 2) return MVT::v2i64;
628 if (NumElements == 4) return MVT::v4i64;
629 if (NumElements == 8) return MVT::v8i64;
630 if (NumElements == 16) return MVT::v16i64;
631 if (NumElements == 32) return MVT::v32i64;
634 if (NumElements == 1) return MVT::v1i128;
637 if (NumElements == 2) return MVT::v2f16;
638 if (NumElements == 4) return MVT::v4f16;
639 if (NumElements == 8) return MVT::v8f16;
642 if (NumElements == 1) return MVT::v1f32;
643 if (NumElements == 2) return MVT::v2f32;
644 if (NumElements == 4) return MVT::v4f32;
645 if (NumElements == 8) return MVT::v8f32;
646 if (NumElements == 16) return MVT::v16f32;
649 if (NumElements == 1) return MVT::v1f64;
650 if (NumElements == 2) return MVT::v2f64;
651 if (NumElements == 4) return MVT::v4f64;
652 if (NumElements == 8) return MVT::v8f64;
655 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
658 /// Return the value type corresponding to the specified type. This returns
659 /// all pointers as iPTR. If HandleUnknown is true, unknown types are
660 /// returned as Other, otherwise they are invalid.
661 static MVT getVT(Type *Ty, bool HandleUnknown = false);
664 /// A simple iterator over the MVT::SimpleValueType enum.
665 struct mvt_iterator {
667 mvt_iterator(SimpleValueType VT) : VT(VT) {}
668 MVT operator*() const { return VT; }
669 bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
670 mvt_iterator& operator++() {
671 VT = (MVT::SimpleValueType)((int)VT + 1);
672 assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
673 "MVT iterator overflowed.");
677 /// A range of the MVT::SimpleValueType enum.
678 typedef iterator_range<mvt_iterator> mvt_range;
681 /// SimpleValueType Iteration
683 static mvt_range all_valuetypes() {
684 return mvt_range(MVT::FIRST_VALUETYPE, MVT::LAST_VALUETYPE);
686 static mvt_range integer_valuetypes() {
687 return mvt_range(MVT::FIRST_INTEGER_VALUETYPE,
688 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VALUETYPE + 1));
690 static mvt_range fp_valuetypes() {
691 return mvt_range(MVT::FIRST_FP_VALUETYPE,
692 (MVT::SimpleValueType)(MVT::LAST_FP_VALUETYPE + 1));
694 static mvt_range vector_valuetypes() {
695 return mvt_range(MVT::FIRST_VECTOR_VALUETYPE,
696 (MVT::SimpleValueType)(MVT::LAST_VECTOR_VALUETYPE + 1));
698 static mvt_range integer_vector_valuetypes() {
700 MVT::FIRST_INTEGER_VECTOR_VALUETYPE,
701 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VECTOR_VALUETYPE + 1));
703 static mvt_range fp_vector_valuetypes() {
705 MVT::FIRST_FP_VECTOR_VALUETYPE,
706 (MVT::SimpleValueType)(MVT::LAST_FP_VECTOR_VALUETYPE + 1));
711 } // End llvm namespace