Recommit [NFC] Better encapsulation of llvm::Optional Storage
[llvm-complete.git] / include / llvm / Support / MachineValueType.h
blob7651b28a63380cdf2c1847ea0efcf0c0f4342b0d
1 //===- Support/MachineValueType.h - Machine-Level types ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the set of machine-level target independent types which
10 // legal values in the code generator use.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_MACHINEVALUETYPE_H
15 #define LLVM_SUPPORT_MACHINEVALUETYPE_H
17 #include "llvm/ADT/iterator_range.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/MathExtras.h"
20 #include <cassert>
22 namespace llvm {
24 class Type;
26 /// 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.
29 class MVT {
30 public:
31 enum SimpleValueType : uint8_t {
32 // Simple value types that aren't explicitly part of this enumeration
33 // are considered extended value types.
34 INVALID_SIMPLE_VALUE_TYPE = 0,
36 // If you change this numbering, you must change the values in
37 // ValueTypes.td as well!
38 Other = 1, // This is a non-standard value
39 i1 = 2, // This is a 1 bit integer value
40 i8 = 3, // This is an 8 bit integer value
41 i16 = 4, // This is a 16 bit integer value
42 i32 = 5, // This is a 32 bit integer value
43 i64 = 6, // This is a 64 bit integer value
44 i128 = 7, // This is a 128 bit integer value
46 FIRST_INTEGER_VALUETYPE = i1,
47 LAST_INTEGER_VALUETYPE = i128,
49 f16 = 8, // This is a 16 bit floating point value
50 f32 = 9, // This is a 32 bit floating point value
51 f64 = 10, // This is a 64 bit floating point value
52 f80 = 11, // This is a 80 bit floating point value
53 f128 = 12, // This is a 128 bit floating point value
54 ppcf128 = 13, // This is a PPC 128-bit floating point value
56 FIRST_FP_VALUETYPE = f16,
57 LAST_FP_VALUETYPE = ppcf128,
59 v1i1 = 14, // 1 x i1
60 v2i1 = 15, // 2 x i1
61 v4i1 = 16, // 4 x i1
62 v8i1 = 17, // 8 x i1
63 v16i1 = 18, // 16 x i1
64 v32i1 = 19, // 32 x i1
65 v64i1 = 20, // 64 x i1
66 v128i1 = 21, // 128 x i1
67 v512i1 = 22, // 512 x i1
68 v1024i1 = 23, // 1024 x i1
70 v1i8 = 24, // 1 x i8
71 v2i8 = 25, // 2 x i8
72 v4i8 = 26, // 4 x i8
73 v8i8 = 27, // 8 x i8
74 v16i8 = 28, // 16 x i8
75 v32i8 = 29, // 32 x i8
76 v64i8 = 30, // 64 x i8
77 v128i8 = 31, //128 x i8
78 v256i8 = 32, //256 x i8
80 v1i16 = 33, // 1 x i16
81 v2i16 = 34, // 2 x i16
82 v4i16 = 35, // 4 x i16
83 v8i16 = 36, // 8 x i16
84 v16i16 = 37, // 16 x i16
85 v32i16 = 38, // 32 x i16
86 v64i16 = 39, // 64 x i16
87 v128i16 = 40, //128 x i16
89 v1i32 = 41, // 1 x i32
90 v2i32 = 42, // 2 x i32
91 v4i32 = 43, // 4 x i32
92 v8i32 = 44, // 8 x i32
93 v16i32 = 45, // 16 x i32
94 v32i32 = 46, // 32 x i32
95 v64i32 = 47, // 64 x i32
97 v1i64 = 48, // 1 x i64
98 v2i64 = 49, // 2 x i64
99 v4i64 = 50, // 4 x i64
100 v8i64 = 51, // 8 x i64
101 v16i64 = 52, // 16 x i64
102 v32i64 = 53, // 32 x i64
104 v1i128 = 54, // 1 x i128
106 // Scalable integer types
107 nxv1i1 = 55, // n x 1 x i1
108 nxv2i1 = 56, // n x 2 x i1
109 nxv4i1 = 57, // n x 4 x i1
110 nxv8i1 = 58, // n x 8 x i1
111 nxv16i1 = 59, // n x 16 x i1
112 nxv32i1 = 60, // n x 32 x i1
114 nxv1i8 = 61, // n x 1 x i8
115 nxv2i8 = 62, // n x 2 x i8
116 nxv4i8 = 63, // n x 4 x i8
117 nxv8i8 = 64, // n x 8 x i8
118 nxv16i8 = 65, // n x 16 x i8
119 nxv32i8 = 66, // n x 32 x i8
121 nxv1i16 = 67, // n x 1 x i16
122 nxv2i16 = 68, // n x 2 x i16
123 nxv4i16 = 69, // n x 4 x i16
124 nxv8i16 = 70, // n x 8 x i16
125 nxv16i16 = 71, // n x 16 x i16
126 nxv32i16 = 72, // n x 32 x i16
128 nxv1i32 = 73, // n x 1 x i32
129 nxv2i32 = 74, // n x 2 x i32
130 nxv4i32 = 75, // n x 4 x i32
131 nxv8i32 = 76, // n x 8 x i32
132 nxv16i32 = 77, // n x 16 x i32
133 nxv32i32 = 78, // n x 32 x i32
135 nxv1i64 = 79, // n x 1 x i64
136 nxv2i64 = 80, // n x 2 x i64
137 nxv4i64 = 81, // n x 4 x i64
138 nxv8i64 = 82, // n x 8 x i64
139 nxv16i64 = 83, // n x 16 x i64
140 nxv32i64 = 84, // n x 32 x i64
142 FIRST_INTEGER_VECTOR_VALUETYPE = v1i1,
143 LAST_INTEGER_VECTOR_VALUETYPE = nxv32i64,
145 FIRST_INTEGER_SCALABLE_VALUETYPE = nxv1i1,
146 LAST_INTEGER_SCALABLE_VALUETYPE = nxv32i64,
148 v2f16 = 85, // 2 x f16
149 v4f16 = 86, // 4 x f16
150 v8f16 = 87, // 8 x f16
151 v1f32 = 88, // 1 x f32
152 v2f32 = 89, // 2 x f32
153 v4f32 = 90, // 4 x f32
154 v8f32 = 91, // 8 x f32
155 v16f32 = 92, // 16 x f32
156 v1f64 = 93, // 1 x f64
157 v2f64 = 94, // 2 x f64
158 v4f64 = 95, // 4 x f64
159 v8f64 = 96, // 8 x f64
161 nxv2f16 = 97, // n x 2 x f16
162 nxv4f16 = 98, // n x 4 x f16
163 nxv8f16 = 99, // n x 8 x f16
164 nxv1f32 = 100, // n x 1 x f32
165 nxv2f32 = 101, // n x 2 x f32
166 nxv4f32 = 102, // n x 4 x f32
167 nxv8f32 = 103, // n x 8 x f32
168 nxv16f32 = 104, // n x 16 x f32
169 nxv1f64 = 105, // n x 1 x f64
170 nxv2f64 = 106, // n x 2 x f64
171 nxv4f64 = 107, // n x 4 x f64
172 nxv8f64 = 108, // n x 8 x f64
174 FIRST_FP_VECTOR_VALUETYPE = v2f16,
175 LAST_FP_VECTOR_VALUETYPE = nxv8f64,
177 FIRST_FP_SCALABLE_VALUETYPE = nxv2f16,
178 LAST_FP_SCALABLE_VALUETYPE = nxv8f64,
180 FIRST_VECTOR_VALUETYPE = v1i1,
181 LAST_VECTOR_VALUETYPE = nxv8f64,
183 x86mmx = 109, // This is an X86 MMX value
185 Glue = 110, // This glues nodes together during pre-RA sched
187 isVoid = 111, // This has no value
189 Untyped = 112, // This value takes a register, but has
190 // unspecified type. The register class
191 // will be determined by the opcode.
193 ExceptRef = 113, // WebAssembly's except_ref type
195 FIRST_VALUETYPE = 1, // This is always the beginning of the list.
196 LAST_VALUETYPE = 114, // This always remains at the end of the list.
198 // This is the current maximum for LAST_VALUETYPE.
199 // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
200 // This value must be a multiple of 32.
201 MAX_ALLOWED_VALUETYPE = 128,
203 // A value of type llvm::TokenTy
204 token = 248,
206 // This is MDNode or MDString.
207 Metadata = 249,
209 // An int value the size of the pointer of the current
210 // target to any address space. This must only be used internal to
211 // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
212 iPTRAny = 250,
214 // A vector with any length and element size. This is used
215 // for intrinsics that have overloadings based on vector types.
216 // This is only for tblgen's consumption!
217 vAny = 251,
219 // Any floating-point or vector floating-point value. This is used
220 // for intrinsics that have overloadings based on floating-point types.
221 // This is only for tblgen's consumption!
222 fAny = 252,
224 // An integer or vector integer value of any bit width. This is
225 // used for intrinsics that have overloadings based on integer bit widths.
226 // This is only for tblgen's consumption!
227 iAny = 253,
229 // An int value the size of the pointer of the current
230 // target. This should only be used internal to tblgen!
231 iPTR = 254,
233 // Any type. This is used for intrinsics that have overloadings.
234 // This is only for tblgen's consumption!
235 Any = 255
238 SimpleValueType SimpleTy = INVALID_SIMPLE_VALUE_TYPE;
240 // A class to represent the number of elements in a vector
242 // For fixed-length vectors, the total number of elements is equal to 'Min'
243 // For scalable vectors, the total number of elements is a multiple of 'Min'
244 class ElementCount {
245 public:
246 unsigned Min;
247 bool Scalable;
249 ElementCount(unsigned Min, bool Scalable)
250 : Min(Min), Scalable(Scalable) {}
252 ElementCount operator*(unsigned RHS) {
253 return { Min * RHS, Scalable };
256 ElementCount& operator*=(unsigned RHS) {
257 Min *= RHS;
258 return *this;
261 ElementCount operator/(unsigned RHS) {
262 return { Min / RHS, Scalable };
265 ElementCount& operator/=(unsigned RHS) {
266 Min /= RHS;
267 return *this;
270 bool operator==(const ElementCount& RHS) {
271 return Min == RHS.Min && Scalable == RHS.Scalable;
275 constexpr MVT() = default;
276 constexpr MVT(SimpleValueType SVT) : SimpleTy(SVT) {}
278 bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; }
279 bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; }
280 bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
281 bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
282 bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
283 bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
285 /// Return true if this is a valid simple valuetype.
286 bool isValid() const {
287 return (SimpleTy >= MVT::FIRST_VALUETYPE &&
288 SimpleTy < MVT::LAST_VALUETYPE);
291 /// Return true if this is a FP or a vector FP type.
292 bool isFloatingPoint() const {
293 return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
294 SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
295 (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE &&
296 SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE));
299 /// Return true if this is an integer or a vector integer type.
300 bool isInteger() const {
301 return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
302 SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
303 (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE &&
304 SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE));
307 /// Return true if this is an integer, not including vectors.
308 bool isScalarInteger() const {
309 return (SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
310 SimpleTy <= MVT::LAST_INTEGER_VALUETYPE);
313 /// Return true if this is a vector value type.
314 bool isVector() const {
315 return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
316 SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
319 /// Return true if this is a vector value type where the
320 /// runtime length is machine dependent
321 bool isScalableVector() const {
322 return ((SimpleTy >= MVT::FIRST_INTEGER_SCALABLE_VALUETYPE &&
323 SimpleTy <= MVT::LAST_INTEGER_SCALABLE_VALUETYPE) ||
324 (SimpleTy >= MVT::FIRST_FP_SCALABLE_VALUETYPE &&
325 SimpleTy <= MVT::LAST_FP_SCALABLE_VALUETYPE));
328 /// Return true if this is a 16-bit vector type.
329 bool is16BitVector() const {
330 return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 ||
331 SimpleTy == MVT::v16i1);
334 /// Return true if this is a 32-bit vector type.
335 bool is32BitVector() const {
336 return (SimpleTy == MVT::v32i1 || SimpleTy == MVT::v4i8 ||
337 SimpleTy == MVT::v2i16 || SimpleTy == MVT::v1i32 ||
338 SimpleTy == MVT::v2f16 || SimpleTy == MVT::v1f32);
341 /// Return true if this is a 64-bit vector type.
342 bool is64BitVector() const {
343 return (SimpleTy == MVT::v64i1 || SimpleTy == MVT::v8i8 ||
344 SimpleTy == MVT::v4i16 || SimpleTy == MVT::v2i32 ||
345 SimpleTy == MVT::v1i64 || SimpleTy == MVT::v4f16 ||
346 SimpleTy == MVT::v2f32 || SimpleTy == MVT::v1f64);
349 /// Return true if this is a 128-bit vector type.
350 bool is128BitVector() const {
351 return (SimpleTy == MVT::v128i1 || SimpleTy == MVT::v16i8 ||
352 SimpleTy == MVT::v8i16 || SimpleTy == MVT::v4i32 ||
353 SimpleTy == MVT::v2i64 || SimpleTy == MVT::v1i128 ||
354 SimpleTy == MVT::v8f16 || SimpleTy == MVT::v4f32 ||
355 SimpleTy == MVT::v2f64);
358 /// Return true if this is a 256-bit vector type.
359 bool is256BitVector() const {
360 return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64 ||
361 SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
362 SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
365 /// Return true if this is a 512-bit vector type.
366 bool is512BitVector() const {
367 return (SimpleTy == MVT::v16f32 || SimpleTy == MVT::v8f64 ||
368 SimpleTy == MVT::v512i1 || SimpleTy == MVT::v64i8 ||
369 SimpleTy == MVT::v32i16 || SimpleTy == MVT::v16i32 ||
370 SimpleTy == MVT::v8i64);
373 /// Return true if this is a 1024-bit vector type.
374 bool is1024BitVector() const {
375 return (SimpleTy == MVT::v1024i1 || SimpleTy == MVT::v128i8 ||
376 SimpleTy == MVT::v64i16 || SimpleTy == MVT::v32i32 ||
377 SimpleTy == MVT::v16i64);
380 /// Return true if this is a 2048-bit vector type.
381 bool is2048BitVector() const {
382 return (SimpleTy == MVT::v256i8 || SimpleTy == MVT::v128i16 ||
383 SimpleTy == MVT::v64i32 || SimpleTy == MVT::v32i64);
386 /// Return true if this is an overloaded type for TableGen.
387 bool isOverloaded() const {
388 return (SimpleTy==MVT::Any ||
389 SimpleTy==MVT::iAny || SimpleTy==MVT::fAny ||
390 SimpleTy==MVT::vAny || SimpleTy==MVT::iPTRAny);
393 /// Returns true if the given vector is a power of 2.
394 bool isPow2VectorType() const {
395 unsigned NElts = getVectorNumElements();
396 return !(NElts & (NElts - 1));
399 /// Widens the length of the given vector MVT up to the nearest power of 2
400 /// and returns that type.
401 MVT getPow2VectorType() const {
402 if (isPow2VectorType())
403 return *this;
405 unsigned NElts = getVectorNumElements();
406 unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
407 return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
410 /// If this is a vector, return the element type, otherwise return this.
411 MVT getScalarType() const {
412 return isVector() ? getVectorElementType() : *this;
415 MVT getVectorElementType() const {
416 switch (SimpleTy) {
417 default:
418 llvm_unreachable("Not a vector MVT!");
419 case v1i1:
420 case v2i1:
421 case v4i1:
422 case v8i1:
423 case v16i1:
424 case v32i1:
425 case v64i1:
426 case v128i1:
427 case v512i1:
428 case v1024i1:
429 case nxv1i1:
430 case nxv2i1:
431 case nxv4i1:
432 case nxv8i1:
433 case nxv16i1:
434 case nxv32i1: return i1;
435 case v1i8:
436 case v2i8:
437 case v4i8:
438 case v8i8:
439 case v16i8:
440 case v32i8:
441 case v64i8:
442 case v128i8:
443 case v256i8:
444 case nxv1i8:
445 case nxv2i8:
446 case nxv4i8:
447 case nxv8i8:
448 case nxv16i8:
449 case nxv32i8: return i8;
450 case v1i16:
451 case v2i16:
452 case v4i16:
453 case v8i16:
454 case v16i16:
455 case v32i16:
456 case v64i16:
457 case v128i16:
458 case nxv1i16:
459 case nxv2i16:
460 case nxv4i16:
461 case nxv8i16:
462 case nxv16i16:
463 case nxv32i16: return i16;
464 case v1i32:
465 case v2i32:
466 case v4i32:
467 case v8i32:
468 case v16i32:
469 case v32i32:
470 case v64i32:
471 case nxv1i32:
472 case nxv2i32:
473 case nxv4i32:
474 case nxv8i32:
475 case nxv16i32:
476 case nxv32i32: return i32;
477 case v1i64:
478 case v2i64:
479 case v4i64:
480 case v8i64:
481 case v16i64:
482 case v32i64:
483 case nxv1i64:
484 case nxv2i64:
485 case nxv4i64:
486 case nxv8i64:
487 case nxv16i64:
488 case nxv32i64: return i64;
489 case v1i128: return i128;
490 case v2f16:
491 case v4f16:
492 case v8f16:
493 case nxv2f16:
494 case nxv4f16:
495 case nxv8f16: return f16;
496 case v1f32:
497 case v2f32:
498 case v4f32:
499 case v8f32:
500 case v16f32:
501 case nxv1f32:
502 case nxv2f32:
503 case nxv4f32:
504 case nxv8f32:
505 case nxv16f32: return f32;
506 case v1f64:
507 case v2f64:
508 case v4f64:
509 case v8f64:
510 case nxv1f64:
511 case nxv2f64:
512 case nxv4f64:
513 case nxv8f64: return f64;
517 unsigned getVectorNumElements() const {
518 switch (SimpleTy) {
519 default:
520 llvm_unreachable("Not a vector MVT!");
521 case v1024i1: return 1024;
522 case v512i1: return 512;
523 case v256i8: return 256;
524 case v128i1:
525 case v128i8:
526 case v128i16: return 128;
527 case v64i1:
528 case v64i8:
529 case v64i16:
530 case v64i32: return 64;
531 case v32i1:
532 case v32i8:
533 case v32i16:
534 case v32i32:
535 case v32i64:
536 case nxv32i1:
537 case nxv32i8:
538 case nxv32i16:
539 case nxv32i32:
540 case nxv32i64: return 32;
541 case v16i1:
542 case v16i8:
543 case v16i16:
544 case v16i32:
545 case v16i64:
546 case v16f32:
547 case nxv16i1:
548 case nxv16i8:
549 case nxv16i16:
550 case nxv16i32:
551 case nxv16i64:
552 case nxv16f32: return 16;
553 case v8i1:
554 case v8i8:
555 case v8i16:
556 case v8i32:
557 case v8i64:
558 case v8f16:
559 case v8f32:
560 case v8f64:
561 case nxv8i1:
562 case nxv8i8:
563 case nxv8i16:
564 case nxv8i32:
565 case nxv8i64:
566 case nxv8f16:
567 case nxv8f32:
568 case nxv8f64: return 8;
569 case v4i1:
570 case v4i8:
571 case v4i16:
572 case v4i32:
573 case v4i64:
574 case v4f16:
575 case v4f32:
576 case v4f64:
577 case nxv4i1:
578 case nxv4i8:
579 case nxv4i16:
580 case nxv4i32:
581 case nxv4i64:
582 case nxv4f16:
583 case nxv4f32:
584 case nxv4f64: return 4;
585 case v2i1:
586 case v2i8:
587 case v2i16:
588 case v2i32:
589 case v2i64:
590 case v2f16:
591 case v2f32:
592 case v2f64:
593 case nxv2i1:
594 case nxv2i8:
595 case nxv2i16:
596 case nxv2i32:
597 case nxv2i64:
598 case nxv2f16:
599 case nxv2f32:
600 case nxv2f64: return 2;
601 case v1i1:
602 case v1i8:
603 case v1i16:
604 case v1i32:
605 case v1i64:
606 case v1i128:
607 case v1f32:
608 case v1f64:
609 case nxv1i1:
610 case nxv1i8:
611 case nxv1i16:
612 case nxv1i32:
613 case nxv1i64:
614 case nxv1f32:
615 case nxv1f64: return 1;
619 MVT::ElementCount getVectorElementCount() const {
620 return { getVectorNumElements(), isScalableVector() };
623 unsigned getSizeInBits() const {
624 switch (SimpleTy) {
625 default:
626 llvm_unreachable("getSizeInBits called on extended MVT.");
627 case Other:
628 llvm_unreachable("Value type is non-standard value, Other.");
629 case iPTR:
630 llvm_unreachable("Value type size is target-dependent. Ask TLI.");
631 case iPTRAny:
632 case iAny:
633 case fAny:
634 case vAny:
635 case Any:
636 llvm_unreachable("Value type is overloaded.");
637 case token:
638 llvm_unreachable("Token type is a sentinel that cannot be used "
639 "in codegen and has no size");
640 case Metadata:
641 llvm_unreachable("Value type is metadata.");
642 case i1:
643 case v1i1:
644 case nxv1i1: return 1;
645 case v2i1:
646 case nxv2i1: return 2;
647 case v4i1:
648 case nxv4i1: return 4;
649 case i8 :
650 case v1i8:
651 case v8i1:
652 case nxv1i8:
653 case nxv8i1: return 8;
654 case i16 :
655 case f16:
656 case v16i1:
657 case v2i8:
658 case v1i16:
659 case nxv16i1:
660 case nxv2i8:
661 case nxv1i16: return 16;
662 case f32 :
663 case i32 :
664 case v32i1:
665 case v4i8:
666 case v2i16:
667 case v2f16:
668 case v1f32:
669 case v1i32:
670 case nxv32i1:
671 case nxv4i8:
672 case nxv2i16:
673 case nxv1i32:
674 case nxv2f16:
675 case nxv1f32: return 32;
676 case x86mmx:
677 case f64 :
678 case i64 :
679 case v64i1:
680 case v8i8:
681 case v4i16:
682 case v2i32:
683 case v1i64:
684 case v4f16:
685 case v2f32:
686 case v1f64:
687 case nxv8i8:
688 case nxv4i16:
689 case nxv2i32:
690 case nxv1i64:
691 case nxv4f16:
692 case nxv2f32:
693 case nxv1f64: return 64;
694 case f80 : return 80;
695 case f128:
696 case ppcf128:
697 case i128:
698 case v128i1:
699 case v16i8:
700 case v8i16:
701 case v4i32:
702 case v2i64:
703 case v1i128:
704 case v8f16:
705 case v4f32:
706 case v2f64:
707 case nxv16i8:
708 case nxv8i16:
709 case nxv4i32:
710 case nxv2i64:
711 case nxv8f16:
712 case nxv4f32:
713 case nxv2f64: return 128;
714 case v32i8:
715 case v16i16:
716 case v8i32:
717 case v4i64:
718 case v8f32:
719 case v4f64:
720 case nxv32i8:
721 case nxv16i16:
722 case nxv8i32:
723 case nxv4i64:
724 case nxv8f32:
725 case nxv4f64: return 256;
726 case v512i1:
727 case v64i8:
728 case v32i16:
729 case v16i32:
730 case v8i64:
731 case v16f32:
732 case v8f64:
733 case nxv32i16:
734 case nxv16i32:
735 case nxv8i64:
736 case nxv16f32:
737 case nxv8f64: return 512;
738 case v1024i1:
739 case v128i8:
740 case v64i16:
741 case v32i32:
742 case v16i64:
743 case nxv32i32:
744 case nxv16i64: return 1024;
745 case v256i8:
746 case v128i16:
747 case v64i32:
748 case v32i64:
749 case nxv32i64: return 2048;
750 case ExceptRef: return 0; // opaque type
754 unsigned getScalarSizeInBits() const {
755 return getScalarType().getSizeInBits();
758 /// Return the number of bytes overwritten by a store of the specified value
759 /// type.
760 unsigned getStoreSize() const {
761 return (getSizeInBits() + 7) / 8;
764 /// Return the number of bits overwritten by a store of the specified value
765 /// type.
766 unsigned getStoreSizeInBits() const {
767 return getStoreSize() * 8;
770 /// Return true if this has more bits than VT.
771 bool bitsGT(MVT VT) const {
772 return getSizeInBits() > VT.getSizeInBits();
775 /// Return true if this has no less bits than VT.
776 bool bitsGE(MVT VT) const {
777 return getSizeInBits() >= VT.getSizeInBits();
780 /// Return true if this has less bits than VT.
781 bool bitsLT(MVT VT) const {
782 return getSizeInBits() < VT.getSizeInBits();
785 /// Return true if this has no more bits than VT.
786 bool bitsLE(MVT VT) const {
787 return getSizeInBits() <= VT.getSizeInBits();
790 static MVT getFloatingPointVT(unsigned BitWidth) {
791 switch (BitWidth) {
792 default:
793 llvm_unreachable("Bad bit width!");
794 case 16:
795 return MVT::f16;
796 case 32:
797 return MVT::f32;
798 case 64:
799 return MVT::f64;
800 case 80:
801 return MVT::f80;
802 case 128:
803 return MVT::f128;
807 static MVT getIntegerVT(unsigned BitWidth) {
808 switch (BitWidth) {
809 default:
810 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
811 case 1:
812 return MVT::i1;
813 case 8:
814 return MVT::i8;
815 case 16:
816 return MVT::i16;
817 case 32:
818 return MVT::i32;
819 case 64:
820 return MVT::i64;
821 case 128:
822 return MVT::i128;
826 static MVT getVectorVT(MVT VT, unsigned NumElements) {
827 switch (VT.SimpleTy) {
828 default:
829 break;
830 case MVT::i1:
831 if (NumElements == 1) return MVT::v1i1;
832 if (NumElements == 2) return MVT::v2i1;
833 if (NumElements == 4) return MVT::v4i1;
834 if (NumElements == 8) return MVT::v8i1;
835 if (NumElements == 16) return MVT::v16i1;
836 if (NumElements == 32) return MVT::v32i1;
837 if (NumElements == 64) return MVT::v64i1;
838 if (NumElements == 128) return MVT::v128i1;
839 if (NumElements == 512) return MVT::v512i1;
840 if (NumElements == 1024) return MVT::v1024i1;
841 break;
842 case MVT::i8:
843 if (NumElements == 1) return MVT::v1i8;
844 if (NumElements == 2) return MVT::v2i8;
845 if (NumElements == 4) return MVT::v4i8;
846 if (NumElements == 8) return MVT::v8i8;
847 if (NumElements == 16) return MVT::v16i8;
848 if (NumElements == 32) return MVT::v32i8;
849 if (NumElements == 64) return MVT::v64i8;
850 if (NumElements == 128) return MVT::v128i8;
851 if (NumElements == 256) return MVT::v256i8;
852 break;
853 case MVT::i16:
854 if (NumElements == 1) return MVT::v1i16;
855 if (NumElements == 2) return MVT::v2i16;
856 if (NumElements == 4) return MVT::v4i16;
857 if (NumElements == 8) return MVT::v8i16;
858 if (NumElements == 16) return MVT::v16i16;
859 if (NumElements == 32) return MVT::v32i16;
860 if (NumElements == 64) return MVT::v64i16;
861 if (NumElements == 128) return MVT::v128i16;
862 break;
863 case MVT::i32:
864 if (NumElements == 1) return MVT::v1i32;
865 if (NumElements == 2) return MVT::v2i32;
866 if (NumElements == 4) return MVT::v4i32;
867 if (NumElements == 8) return MVT::v8i32;
868 if (NumElements == 16) return MVT::v16i32;
869 if (NumElements == 32) return MVT::v32i32;
870 if (NumElements == 64) return MVT::v64i32;
871 break;
872 case MVT::i64:
873 if (NumElements == 1) return MVT::v1i64;
874 if (NumElements == 2) return MVT::v2i64;
875 if (NumElements == 4) return MVT::v4i64;
876 if (NumElements == 8) return MVT::v8i64;
877 if (NumElements == 16) return MVT::v16i64;
878 if (NumElements == 32) return MVT::v32i64;
879 break;
880 case MVT::i128:
881 if (NumElements == 1) return MVT::v1i128;
882 break;
883 case MVT::f16:
884 if (NumElements == 2) return MVT::v2f16;
885 if (NumElements == 4) return MVT::v4f16;
886 if (NumElements == 8) return MVT::v8f16;
887 break;
888 case MVT::f32:
889 if (NumElements == 1) return MVT::v1f32;
890 if (NumElements == 2) return MVT::v2f32;
891 if (NumElements == 4) return MVT::v4f32;
892 if (NumElements == 8) return MVT::v8f32;
893 if (NumElements == 16) return MVT::v16f32;
894 break;
895 case MVT::f64:
896 if (NumElements == 1) return MVT::v1f64;
897 if (NumElements == 2) return MVT::v2f64;
898 if (NumElements == 4) return MVT::v4f64;
899 if (NumElements == 8) return MVT::v8f64;
900 break;
902 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
905 static MVT getScalableVectorVT(MVT VT, unsigned NumElements) {
906 switch(VT.SimpleTy) {
907 default:
908 break;
909 case MVT::i1:
910 if (NumElements == 1) return MVT::nxv1i1;
911 if (NumElements == 2) return MVT::nxv2i1;
912 if (NumElements == 4) return MVT::nxv4i1;
913 if (NumElements == 8) return MVT::nxv8i1;
914 if (NumElements == 16) return MVT::nxv16i1;
915 if (NumElements == 32) return MVT::nxv32i1;
916 break;
917 case MVT::i8:
918 if (NumElements == 1) return MVT::nxv1i8;
919 if (NumElements == 2) return MVT::nxv2i8;
920 if (NumElements == 4) return MVT::nxv4i8;
921 if (NumElements == 8) return MVT::nxv8i8;
922 if (NumElements == 16) return MVT::nxv16i8;
923 if (NumElements == 32) return MVT::nxv32i8;
924 break;
925 case MVT::i16:
926 if (NumElements == 1) return MVT::nxv1i16;
927 if (NumElements == 2) return MVT::nxv2i16;
928 if (NumElements == 4) return MVT::nxv4i16;
929 if (NumElements == 8) return MVT::nxv8i16;
930 if (NumElements == 16) return MVT::nxv16i16;
931 if (NumElements == 32) return MVT::nxv32i16;
932 break;
933 case MVT::i32:
934 if (NumElements == 1) return MVT::nxv1i32;
935 if (NumElements == 2) return MVT::nxv2i32;
936 if (NumElements == 4) return MVT::nxv4i32;
937 if (NumElements == 8) return MVT::nxv8i32;
938 if (NumElements == 16) return MVT::nxv16i32;
939 if (NumElements == 32) return MVT::nxv32i32;
940 break;
941 case MVT::i64:
942 if (NumElements == 1) return MVT::nxv1i64;
943 if (NumElements == 2) return MVT::nxv2i64;
944 if (NumElements == 4) return MVT::nxv4i64;
945 if (NumElements == 8) return MVT::nxv8i64;
946 if (NumElements == 16) return MVT::nxv16i64;
947 if (NumElements == 32) return MVT::nxv32i64;
948 break;
949 case MVT::f16:
950 if (NumElements == 2) return MVT::nxv2f16;
951 if (NumElements == 4) return MVT::nxv4f16;
952 if (NumElements == 8) return MVT::nxv8f16;
953 break;
954 case MVT::f32:
955 if (NumElements == 1) return MVT::nxv1f32;
956 if (NumElements == 2) return MVT::nxv2f32;
957 if (NumElements == 4) return MVT::nxv4f32;
958 if (NumElements == 8) return MVT::nxv8f32;
959 if (NumElements == 16) return MVT::nxv16f32;
960 break;
961 case MVT::f64:
962 if (NumElements == 1) return MVT::nxv1f64;
963 if (NumElements == 2) return MVT::nxv2f64;
964 if (NumElements == 4) return MVT::nxv4f64;
965 if (NumElements == 8) return MVT::nxv8f64;
966 break;
968 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
971 static MVT getVectorVT(MVT VT, unsigned NumElements, bool IsScalable) {
972 if (IsScalable)
973 return getScalableVectorVT(VT, NumElements);
974 return getVectorVT(VT, NumElements);
977 static MVT getVectorVT(MVT VT, MVT::ElementCount EC) {
978 if (EC.Scalable)
979 return getScalableVectorVT(VT, EC.Min);
980 return getVectorVT(VT, EC.Min);
983 /// Return the value type corresponding to the specified type. This returns
984 /// all pointers as iPTR. If HandleUnknown is true, unknown types are
985 /// returned as Other, otherwise they are invalid.
986 static MVT getVT(Type *Ty, bool HandleUnknown = false);
988 private:
989 /// A simple iterator over the MVT::SimpleValueType enum.
990 struct mvt_iterator {
991 SimpleValueType VT;
993 mvt_iterator(SimpleValueType VT) : VT(VT) {}
995 MVT operator*() const { return VT; }
996 bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
998 mvt_iterator& operator++() {
999 VT = (MVT::SimpleValueType)((int)VT + 1);
1000 assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
1001 "MVT iterator overflowed.");
1002 return *this;
1006 /// A range of the MVT::SimpleValueType enum.
1007 using mvt_range = iterator_range<mvt_iterator>;
1009 public:
1010 /// SimpleValueType Iteration
1011 /// @{
1012 static mvt_range all_valuetypes() {
1013 return mvt_range(MVT::FIRST_VALUETYPE, MVT::LAST_VALUETYPE);
1016 static mvt_range integer_valuetypes() {
1017 return mvt_range(MVT::FIRST_INTEGER_VALUETYPE,
1018 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VALUETYPE + 1));
1021 static mvt_range fp_valuetypes() {
1022 return mvt_range(MVT::FIRST_FP_VALUETYPE,
1023 (MVT::SimpleValueType)(MVT::LAST_FP_VALUETYPE + 1));
1026 static mvt_range vector_valuetypes() {
1027 return mvt_range(MVT::FIRST_VECTOR_VALUETYPE,
1028 (MVT::SimpleValueType)(MVT::LAST_VECTOR_VALUETYPE + 1));
1031 static mvt_range integer_vector_valuetypes() {
1032 return mvt_range(
1033 MVT::FIRST_INTEGER_VECTOR_VALUETYPE,
1034 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VECTOR_VALUETYPE + 1));
1037 static mvt_range fp_vector_valuetypes() {
1038 return mvt_range(
1039 MVT::FIRST_FP_VECTOR_VALUETYPE,
1040 (MVT::SimpleValueType)(MVT::LAST_FP_VECTOR_VALUETYPE + 1));
1043 static mvt_range integer_scalable_vector_valuetypes() {
1044 return mvt_range(MVT::FIRST_INTEGER_SCALABLE_VALUETYPE,
1045 (MVT::SimpleValueType)(MVT::LAST_INTEGER_SCALABLE_VALUETYPE + 1));
1048 static mvt_range fp_scalable_vector_valuetypes() {
1049 return mvt_range(MVT::FIRST_FP_SCALABLE_VALUETYPE,
1050 (MVT::SimpleValueType)(MVT::LAST_FP_SCALABLE_VALUETYPE + 1));
1052 /// @}
1055 } // end namespace llvm
1057 #endif // LLVM_CODEGEN_MACHINEVALUETYPE_H