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 : int8_t {
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 constexpr MVT() : SimpleTy(INVALID_SIMPLE_VALUE_TYPE) {}
182 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 /// isScalarInteger - Return true if this is an integer, not including
215 bool isScalarInteger() const {
216 return (SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
217 SimpleTy <= MVT::LAST_INTEGER_VALUETYPE);
220 /// isVector - Return true if this is a vector value type.
221 bool isVector() const {
222 return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
223 SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
226 /// is16BitVector - Return true if this is a 16-bit vector type.
227 bool is16BitVector() const {
228 return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 ||
229 SimpleTy == MVT::v16i1);
232 /// is32BitVector - Return true if this is a 32-bit vector type.
233 bool is32BitVector() const {
234 return (SimpleTy == MVT::v4i8 || SimpleTy == MVT::v2i16 ||
235 SimpleTy == MVT::v1i32 || SimpleTy == MVT::v2f16 ||
236 SimpleTy == MVT::v1f32);
239 /// is64BitVector - Return true if this is a 64-bit vector type.
240 bool is64BitVector() const {
241 return (SimpleTy == MVT::v8i8 || SimpleTy == MVT::v4i16 ||
242 SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
243 SimpleTy == MVT::v4f16 || SimpleTy == MVT::v2f32 ||
244 SimpleTy == MVT::v1f64);
247 /// is128BitVector - Return true if this is a 128-bit vector type.
248 bool is128BitVector() const {
249 return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
250 SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 ||
251 SimpleTy == MVT::v1i128 || SimpleTy == MVT::v8f16 ||
252 SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64);
255 /// is256BitVector - Return true if this is a 256-bit vector type.
256 bool is256BitVector() const {
257 return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64 ||
258 SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
259 SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
262 /// is512BitVector - Return true if this is a 512-bit vector type.
263 bool is512BitVector() const {
264 return (SimpleTy == MVT::v16f32 || SimpleTy == MVT::v8f64 ||
265 SimpleTy == MVT::v512i1 || SimpleTy == MVT::v64i8 ||
266 SimpleTy == MVT::v32i16 || SimpleTy == MVT::v16i32 ||
267 SimpleTy == MVT::v8i64);
270 /// is1024BitVector - Return true if this is a 1024-bit vector type.
271 bool is1024BitVector() const {
272 return (SimpleTy == MVT::v1024i1 || SimpleTy == MVT::v128i8 ||
273 SimpleTy == MVT::v64i16 || SimpleTy == MVT::v32i32 ||
274 SimpleTy == MVT::v16i64);
277 /// is2048BitVector - Return true if this is a 1024-bit vector type.
278 bool is2048BitVector() const {
279 return (SimpleTy == MVT::v256i8 || SimpleTy == MVT::v128i16 ||
280 SimpleTy == MVT::v64i32 || SimpleTy == MVT::v32i64);
283 /// isOverloaded - Return true if this is an overloaded type for TableGen.
284 bool isOverloaded() const {
285 return (SimpleTy==MVT::Any ||
286 SimpleTy==MVT::iAny || SimpleTy==MVT::fAny ||
287 SimpleTy==MVT::vAny || SimpleTy==MVT::iPTRAny);
290 /// isPow2VectorType - Returns true if the given vector is a power of 2.
291 bool isPow2VectorType() const {
292 unsigned NElts = getVectorNumElements();
293 return !(NElts & (NElts - 1));
296 /// getPow2VectorType - Widens the length of the given vector MVT up to
297 /// the nearest power of 2 and returns that type.
298 MVT getPow2VectorType() const {
299 if (isPow2VectorType())
302 unsigned NElts = getVectorNumElements();
303 unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
304 return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
307 /// getScalarType - If this is a vector type, return the element type,
308 /// otherwise return this.
309 MVT getScalarType() const {
310 return isVector() ? getVectorElementType() : *this;
313 MVT getVectorElementType() const {
316 llvm_unreachable("Not a vector MVT!");
324 case v1024i1: return i1;
333 case v256i8: return i8;
341 case v128i16: return i16;
348 case v64i32: return i32;
354 case v32i64: return i64;
355 case v1i128: return i128;
358 case v8f16: return f16;
363 case v16f32: return f32;
367 case v8f64: return f64;
371 unsigned getVectorNumElements() const {
374 llvm_unreachable("Not a vector MVT!");
375 case v1024i1: return 1024;
376 case v512i1: return 512;
377 case v256i8: return 256;
379 case v128i16: return 128;
383 case v64i32: return 64;
388 case v32i64: return 32;
394 case v16f32: return 16;
402 case v8f64: return 8;
410 case v4f64: return 4;
418 case v2f64: return 2;
425 case v1f64: return 1;
429 unsigned getSizeInBits() const {
432 llvm_unreachable("getSizeInBits called on extended MVT.");
434 llvm_unreachable("Value type is non-standard value, Other.");
436 llvm_unreachable("Value type size is target-dependent. Ask TLI.");
442 llvm_unreachable("Value type is overloaded.");
444 llvm_unreachable("Token type is a sentinel that cannot be used "
445 "in codegen and has no size");
447 llvm_unreachable("Value type is metadata.");
458 case v1i16: return 16;
466 case v1i32: return 32;
477 case v1f64: return 64;
478 case f80 : return 80;
489 case v2f64: return 128;
495 case v4f64: return 256;
502 case v8f64: return 512;
507 case v16i64: return 1024;
511 case v32i64: return 2048;
515 unsigned getScalarSizeInBits() const {
516 return getScalarType().getSizeInBits();
519 /// getStoreSize - Return the number of bytes overwritten by a store
520 /// of the specified value type.
521 unsigned getStoreSize() const {
522 return (getSizeInBits() + 7) / 8;
525 /// getStoreSizeInBits - Return the number of bits overwritten by a store
526 /// of the specified value type.
527 unsigned getStoreSizeInBits() const {
528 return getStoreSize() * 8;
531 /// Return true if this has more bits than VT.
532 bool bitsGT(MVT VT) const {
533 return getSizeInBits() > VT.getSizeInBits();
536 /// Return true if this has no less bits than VT.
537 bool bitsGE(MVT VT) const {
538 return getSizeInBits() >= VT.getSizeInBits();
541 /// Return true if this has less bits than VT.
542 bool bitsLT(MVT VT) const {
543 return getSizeInBits() < VT.getSizeInBits();
546 /// Return true if this has no more bits than VT.
547 bool bitsLE(MVT VT) const {
548 return getSizeInBits() <= VT.getSizeInBits();
552 static MVT getFloatingPointVT(unsigned BitWidth) {
555 llvm_unreachable("Bad bit width!");
569 static MVT getIntegerVT(unsigned BitWidth) {
572 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
588 static MVT getVectorVT(MVT VT, unsigned NumElements) {
589 switch (VT.SimpleTy) {
593 if (NumElements == 2) return MVT::v2i1;
594 if (NumElements == 4) return MVT::v4i1;
595 if (NumElements == 8) return MVT::v8i1;
596 if (NumElements == 16) return MVT::v16i1;
597 if (NumElements == 32) return MVT::v32i1;
598 if (NumElements == 64) return MVT::v64i1;
599 if (NumElements == 512) return MVT::v512i1;
600 if (NumElements == 1024) return MVT::v1024i1;
603 if (NumElements == 1) return MVT::v1i8;
604 if (NumElements == 2) return MVT::v2i8;
605 if (NumElements == 4) return MVT::v4i8;
606 if (NumElements == 8) return MVT::v8i8;
607 if (NumElements == 16) return MVT::v16i8;
608 if (NumElements == 32) return MVT::v32i8;
609 if (NumElements == 64) return MVT::v64i8;
610 if (NumElements == 128) return MVT::v128i8;
611 if (NumElements == 256) return MVT::v256i8;
614 if (NumElements == 1) return MVT::v1i16;
615 if (NumElements == 2) return MVT::v2i16;
616 if (NumElements == 4) return MVT::v4i16;
617 if (NumElements == 8) return MVT::v8i16;
618 if (NumElements == 16) return MVT::v16i16;
619 if (NumElements == 32) return MVT::v32i16;
620 if (NumElements == 64) return MVT::v64i16;
621 if (NumElements == 128) return MVT::v128i16;
624 if (NumElements == 1) return MVT::v1i32;
625 if (NumElements == 2) return MVT::v2i32;
626 if (NumElements == 4) return MVT::v4i32;
627 if (NumElements == 8) return MVT::v8i32;
628 if (NumElements == 16) return MVT::v16i32;
629 if (NumElements == 32) return MVT::v32i32;
630 if (NumElements == 64) return MVT::v64i32;
633 if (NumElements == 1) return MVT::v1i64;
634 if (NumElements == 2) return MVT::v2i64;
635 if (NumElements == 4) return MVT::v4i64;
636 if (NumElements == 8) return MVT::v8i64;
637 if (NumElements == 16) return MVT::v16i64;
638 if (NumElements == 32) return MVT::v32i64;
641 if (NumElements == 1) return MVT::v1i128;
644 if (NumElements == 2) return MVT::v2f16;
645 if (NumElements == 4) return MVT::v4f16;
646 if (NumElements == 8) return MVT::v8f16;
649 if (NumElements == 1) return MVT::v1f32;
650 if (NumElements == 2) return MVT::v2f32;
651 if (NumElements == 4) return MVT::v4f32;
652 if (NumElements == 8) return MVT::v8f32;
653 if (NumElements == 16) return MVT::v16f32;
656 if (NumElements == 1) return MVT::v1f64;
657 if (NumElements == 2) return MVT::v2f64;
658 if (NumElements == 4) return MVT::v4f64;
659 if (NumElements == 8) return MVT::v8f64;
662 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
665 /// Return the value type corresponding to the specified type. This returns
666 /// all pointers as iPTR. If HandleUnknown is true, unknown types are
667 /// returned as Other, otherwise they are invalid.
668 static MVT getVT(Type *Ty, bool HandleUnknown = false);
671 /// A simple iterator over the MVT::SimpleValueType enum.
672 struct mvt_iterator {
674 mvt_iterator(SimpleValueType VT) : VT(VT) {}
675 MVT operator*() const { return VT; }
676 bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
677 mvt_iterator& operator++() {
678 VT = (MVT::SimpleValueType)((int)VT + 1);
679 assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
680 "MVT iterator overflowed.");
684 /// A range of the MVT::SimpleValueType enum.
685 typedef iterator_range<mvt_iterator> mvt_range;
688 /// SimpleValueType Iteration
690 static mvt_range all_valuetypes() {
691 return mvt_range(MVT::FIRST_VALUETYPE, MVT::LAST_VALUETYPE);
693 static mvt_range integer_valuetypes() {
694 return mvt_range(MVT::FIRST_INTEGER_VALUETYPE,
695 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VALUETYPE + 1));
697 static mvt_range fp_valuetypes() {
698 return mvt_range(MVT::FIRST_FP_VALUETYPE,
699 (MVT::SimpleValueType)(MVT::LAST_FP_VALUETYPE + 1));
701 static mvt_range vector_valuetypes() {
702 return mvt_range(MVT::FIRST_VECTOR_VALUETYPE,
703 (MVT::SimpleValueType)(MVT::LAST_VECTOR_VALUETYPE + 1));
705 static mvt_range integer_vector_valuetypes() {
707 MVT::FIRST_INTEGER_VECTOR_VALUETYPE,
708 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VECTOR_VALUETYPE + 1));
710 static mvt_range fp_vector_valuetypes() {
712 MVT::FIRST_FP_VECTOR_VALUETYPE,
713 (MVT::SimpleValueType)(MVT::LAST_FP_VECTOR_VALUETYPE + 1));
718 } // End llvm namespace