[InstCombine] Signed saturation tests. NFC
[llvm-complete.git] / include / llvm / Support / MachineValueType.h
blob7f9f0b85c55e17dc185e46d8bda6c5d7b43050ef
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 "llvm/Support/TypeSize.h"
21 #include <cassert>
23 namespace llvm {
25 class Type;
27 /// Machine Value Type. Every type that is supported natively by some
28 /// processor targeted by LLVM occurs here. This means that any legal value
29 /// type can be represented by an MVT.
30 class MVT {
31 public:
32 enum SimpleValueType : uint8_t {
33 // Simple value types that aren't explicitly part of this enumeration
34 // are considered extended value types.
35 INVALID_SIMPLE_VALUE_TYPE = 0,
37 // If you change this numbering, you must change the values in
38 // ValueTypes.td as well!
39 Other = 1, // This is a non-standard value
40 i1 = 2, // This is a 1 bit integer value
41 i8 = 3, // This is an 8 bit integer value
42 i16 = 4, // This is a 16 bit integer value
43 i32 = 5, // This is a 32 bit integer value
44 i64 = 6, // This is a 64 bit integer value
45 i128 = 7, // This is a 128 bit integer value
47 FIRST_INTEGER_VALUETYPE = i1,
48 LAST_INTEGER_VALUETYPE = i128,
50 f16 = 8, // This is a 16 bit floating point value
51 f32 = 9, // This is a 32 bit floating point value
52 f64 = 10, // This is a 64 bit floating point value
53 f80 = 11, // This is a 80 bit floating point value
54 f128 = 12, // This is a 128 bit floating point value
55 ppcf128 = 13, // This is a PPC 128-bit floating point value
57 FIRST_FP_VALUETYPE = f16,
58 LAST_FP_VALUETYPE = ppcf128,
60 v1i1 = 14, // 1 x i1
61 v2i1 = 15, // 2 x i1
62 v4i1 = 16, // 4 x i1
63 v8i1 = 17, // 8 x i1
64 v16i1 = 18, // 16 x i1
65 v32i1 = 19, // 32 x i1
66 v64i1 = 20, // 64 x i1
67 v128i1 = 21, // 128 x i1
68 v256i1 = 22, // 256 x i1
69 v512i1 = 23, // 512 x i1
70 v1024i1 = 24, // 1024 x i1
72 v1i8 = 25, // 1 x i8
73 v2i8 = 26, // 2 x i8
74 v4i8 = 27, // 4 x i8
75 v8i8 = 28, // 8 x i8
76 v16i8 = 29, // 16 x i8
77 v32i8 = 30, // 32 x i8
78 v64i8 = 31, // 64 x i8
79 v128i8 = 32, //128 x i8
80 v256i8 = 33, //256 x i8
82 v1i16 = 34, // 1 x i16
83 v2i16 = 35, // 2 x i16
84 v3i16 = 36, // 3 x i16
85 v4i16 = 37, // 4 x i16
86 v8i16 = 38, // 8 x i16
87 v16i16 = 39, // 16 x i16
88 v32i16 = 40, // 32 x i16
89 v64i16 = 41, // 64 x i16
90 v128i16 = 42, //128 x i16
92 v1i32 = 43, // 1 x i32
93 v2i32 = 44, // 2 x i32
94 v3i32 = 45, // 3 x i32
95 v4i32 = 46, // 4 x i32
96 v5i32 = 47, // 5 x i32
97 v8i32 = 48, // 8 x i32
98 v16i32 = 49, // 16 x i32
99 v32i32 = 50, // 32 x i32
100 v64i32 = 51, // 64 x i32
101 v128i32 = 52, // 128 x i32
102 v256i32 = 53, // 256 x i32
103 v512i32 = 54, // 512 x i32
104 v1024i32 = 55, // 1024 x i32
105 v2048i32 = 56, // 2048 x i32
107 v1i64 = 57, // 1 x i64
108 v2i64 = 58, // 2 x i64
109 v4i64 = 59, // 4 x i64
110 v8i64 = 60, // 8 x i64
111 v16i64 = 61, // 16 x i64
112 v32i64 = 62, // 32 x i64
114 v1i128 = 63, // 1 x i128
116 FIRST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE = v1i1,
117 LAST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE = v1i128,
119 v2f16 = 64, // 2 x f16
120 v3f16 = 65, // 3 x f16
121 v4f16 = 66, // 4 x f16
122 v8f16 = 67, // 8 x f16
123 v16f16 = 68, // 16 x f16
124 v32f16 = 69, // 32 x f16
125 v1f32 = 70, // 1 x f32
126 v2f32 = 71, // 2 x f32
127 v3f32 = 72, // 3 x f32
128 v4f32 = 73, // 4 x f32
129 v5f32 = 74, // 5 x f32
130 v8f32 = 75, // 8 x f32
131 v16f32 = 76, // 16 x f32
132 v32f32 = 77, // 32 x f32
133 v64f32 = 78, // 64 x f32
134 v128f32 = 79, // 128 x f32
135 v256f32 = 80, // 256 x f32
136 v512f32 = 81, // 512 x f32
137 v1024f32 = 82, // 1024 x f32
138 v2048f32 = 83, // 2048 x f32
139 v1f64 = 84, // 1 x f64
140 v2f64 = 85, // 2 x f64
141 v4f64 = 86, // 4 x f64
142 v8f64 = 87, // 8 x f64
144 FIRST_FP_FIXEDLEN_VECTOR_VALUETYPE = v2f16,
145 LAST_FP_FIXEDLEN_VECTOR_VALUETYPE = v8f64,
147 FIRST_FIXEDLEN_VECTOR_VALUETYPE = v1i1,
148 LAST_FIXEDLEN_VECTOR_VALUETYPE = v8f64,
150 nxv1i1 = 88, // n x 1 x i1
151 nxv2i1 = 89, // n x 2 x i1
152 nxv4i1 = 90, // n x 4 x i1
153 nxv8i1 = 91, // n x 8 x i1
154 nxv16i1 = 92, // n x 16 x i1
155 nxv32i1 = 93, // n x 32 x i1
157 nxv1i8 = 94, // n x 1 x i8
158 nxv2i8 = 95, // n x 2 x i8
159 nxv4i8 = 96, // n x 4 x i8
160 nxv8i8 = 97, // n x 8 x i8
161 nxv16i8 = 98, // n x 16 x i8
162 nxv32i8 = 99, // n x 32 x i8
164 nxv1i16 = 100, // n x 1 x i16
165 nxv2i16 = 101, // n x 2 x i16
166 nxv4i16 = 102, // n x 4 x i16
167 nxv8i16 = 103, // n x 8 x i16
168 nxv16i16 = 104, // n x 16 x i16
169 nxv32i16 = 105, // n x 32 x i16
171 nxv1i32 = 106, // n x 1 x i32
172 nxv2i32 = 107, // n x 2 x i32
173 nxv4i32 = 108, // n x 4 x i32
174 nxv8i32 = 109, // n x 8 x i32
175 nxv16i32 = 110, // n x 16 x i32
176 nxv32i32 = 111, // n x 32 x i32
178 nxv1i64 = 112, // n x 1 x i64
179 nxv2i64 = 113, // n x 2 x i64
180 nxv4i64 = 114, // n x 4 x i64
181 nxv8i64 = 115, // n x 8 x i64
182 nxv16i64 = 116, // n x 16 x i64
183 nxv32i64 = 117, // n x 32 x i64
185 FIRST_INTEGER_SCALABLE_VECTOR_VALUETYPE = nxv1i1,
186 LAST_INTEGER_SCALABLE_VECTOR_VALUETYPE = nxv32i64,
188 nxv2f16 = 118, // n x 2 x f16
189 nxv4f16 = 119, // n x 4 x f16
190 nxv8f16 = 120, // n x 8 x f16
191 nxv1f32 = 121, // n x 1 x f32
192 nxv2f32 = 122, // n x 2 x f32
193 nxv4f32 = 123, // n x 4 x f32
194 nxv8f32 = 124, // n x 8 x f32
195 nxv16f32 = 125, // n x 16 x f32
196 nxv1f64 = 126, // n x 1 x f64
197 nxv2f64 = 127, // n x 2 x f64
198 nxv4f64 = 128, // n x 4 x f64
199 nxv8f64 = 129, // n x 8 x f64
201 FIRST_FP_SCALABLE_VECTOR_VALUETYPE = nxv2f16,
202 LAST_FP_SCALABLE_VECTOR_VALUETYPE = nxv8f64,
204 FIRST_SCALABLE_VECTOR_VALUETYPE = nxv1i1,
205 LAST_SCALABLE_VECTOR_VALUETYPE = nxv8f64,
207 FIRST_VECTOR_VALUETYPE = v1i1,
208 LAST_VECTOR_VALUETYPE = nxv8f64,
210 x86mmx = 130, // This is an X86 MMX value
212 Glue = 131, // This glues nodes together during pre-RA sched
214 isVoid = 132, // This has no value
216 Untyped = 133, // This value takes a register, but has
217 // unspecified type. The register class
218 // will be determined by the opcode.
220 exnref = 134, // WebAssembly's exnref type
222 FIRST_VALUETYPE = 1, // This is always the beginning of the list.
223 LAST_VALUETYPE = 135, // This always remains at the end of the list.
225 // This is the current maximum for LAST_VALUETYPE.
226 // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
227 // This value must be a multiple of 32.
228 MAX_ALLOWED_VALUETYPE = 160,
230 // A value of type llvm::TokenTy
231 token = 248,
233 // This is MDNode or MDString.
234 Metadata = 249,
236 // An int value the size of the pointer of the current
237 // target to any address space. This must only be used internal to
238 // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
239 iPTRAny = 250,
241 // A vector with any length and element size. This is used
242 // for intrinsics that have overloadings based on vector types.
243 // This is only for tblgen's consumption!
244 vAny = 251,
246 // Any floating-point or vector floating-point value. This is used
247 // for intrinsics that have overloadings based on floating-point types.
248 // This is only for tblgen's consumption!
249 fAny = 252,
251 // An integer or vector integer value of any bit width. This is
252 // used for intrinsics that have overloadings based on integer bit widths.
253 // This is only for tblgen's consumption!
254 iAny = 253,
256 // An int value the size of the pointer of the current
257 // target. This should only be used internal to tblgen!
258 iPTR = 254,
260 // Any type. This is used for intrinsics that have overloadings.
261 // This is only for tblgen's consumption!
262 Any = 255
265 SimpleValueType SimpleTy = INVALID_SIMPLE_VALUE_TYPE;
267 constexpr MVT() = default;
268 constexpr MVT(SimpleValueType SVT) : SimpleTy(SVT) {}
270 bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; }
271 bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; }
272 bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
273 bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
274 bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
275 bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
277 /// Return true if this is a valid simple valuetype.
278 bool isValid() const {
279 return (SimpleTy >= MVT::FIRST_VALUETYPE &&
280 SimpleTy < MVT::LAST_VALUETYPE);
283 /// Return true if this is a FP or a vector FP type.
284 bool isFloatingPoint() const {
285 return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
286 SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
287 (SimpleTy >= MVT::FIRST_FP_FIXEDLEN_VECTOR_VALUETYPE &&
288 SimpleTy <= MVT::LAST_FP_FIXEDLEN_VECTOR_VALUETYPE) ||
289 (SimpleTy >= MVT::FIRST_FP_SCALABLE_VECTOR_VALUETYPE &&
290 SimpleTy <= MVT::LAST_FP_SCALABLE_VECTOR_VALUETYPE));
293 /// Return true if this is an integer or a vector integer type.
294 bool isInteger() const {
295 return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
296 SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
297 (SimpleTy >= MVT::FIRST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE &&
298 SimpleTy <= MVT::LAST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE) ||
299 (SimpleTy >= MVT::FIRST_INTEGER_SCALABLE_VECTOR_VALUETYPE &&
300 SimpleTy <= MVT::LAST_INTEGER_SCALABLE_VECTOR_VALUETYPE));
303 /// Return true if this is an integer, not including vectors.
304 bool isScalarInteger() const {
305 return (SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
306 SimpleTy <= MVT::LAST_INTEGER_VALUETYPE);
309 /// Return true if this is a vector value type.
310 bool isVector() const {
311 return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
312 SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
315 /// Return true if this is a vector value type where the
316 /// runtime length is machine dependent
317 bool isScalableVector() const {
318 return (SimpleTy >= MVT::FIRST_SCALABLE_VECTOR_VALUETYPE &&
319 SimpleTy <= MVT::LAST_SCALABLE_VECTOR_VALUETYPE);
322 bool isFixedLengthVector() const {
323 return (SimpleTy >= MVT::FIRST_FIXEDLEN_VECTOR_VALUETYPE &&
324 SimpleTy <= MVT::LAST_FIXEDLEN_VECTOR_VALUETYPE);
327 /// Return true if this is a 16-bit vector type.
328 bool is16BitVector() const {
329 return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 ||
330 SimpleTy == MVT::v16i1);
333 /// Return true if this is a 32-bit vector type.
334 bool is32BitVector() const {
335 return (SimpleTy == MVT::v32i1 || SimpleTy == MVT::v4i8 ||
336 SimpleTy == MVT::v2i16 || SimpleTy == MVT::v1i32 ||
337 SimpleTy == MVT::v2f16 || SimpleTy == MVT::v1f32);
340 /// Return true if this is a 64-bit vector type.
341 bool is64BitVector() const {
342 return (SimpleTy == MVT::v64i1 || SimpleTy == MVT::v8i8 ||
343 SimpleTy == MVT::v4i16 || SimpleTy == MVT::v2i32 ||
344 SimpleTy == MVT::v1i64 || SimpleTy == MVT::v4f16 ||
345 SimpleTy == MVT::v2f32 || SimpleTy == MVT::v1f64);
348 /// Return true if this is a 128-bit vector type.
349 bool is128BitVector() const {
350 return (SimpleTy == MVT::v128i1 || SimpleTy == MVT::v16i8 ||
351 SimpleTy == MVT::v8i16 || SimpleTy == MVT::v4i32 ||
352 SimpleTy == MVT::v2i64 || SimpleTy == MVT::v1i128 ||
353 SimpleTy == MVT::v8f16 || SimpleTy == MVT::v4f32 ||
354 SimpleTy == MVT::v2f64);
357 /// Return true if this is a 256-bit vector type.
358 bool is256BitVector() const {
359 return (SimpleTy == MVT::v16f16 || SimpleTy == MVT::v8f32 ||
360 SimpleTy == MVT::v4f64 || SimpleTy == MVT::v32i8 ||
361 SimpleTy == MVT::v16i16 || SimpleTy == MVT::v8i32 ||
362 SimpleTy == MVT::v4i64 || SimpleTy == MVT::v256i1);
365 /// Return true if this is a 512-bit vector type.
366 bool is512BitVector() const {
367 return (SimpleTy == MVT::v32f16 || SimpleTy == MVT::v16f32 ||
368 SimpleTy == MVT::v8f64 || SimpleTy == MVT::v512i1 ||
369 SimpleTy == MVT::v64i8 || SimpleTy == MVT::v32i16 ||
370 SimpleTy == MVT::v16i32 || 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 /// Return a VT for a vector type with the same element type but
394 /// half the number of elements.
395 MVT getHalfNumVectorElementsVT() const {
396 MVT EltVT = getVectorElementType();
397 auto EltCnt = getVectorElementCount();
398 assert(!(EltCnt.Min & 1) && "Splitting vector, but not in half!");
399 return getVectorVT(EltVT, EltCnt / 2);
402 /// Returns true if the given vector is a power of 2.
403 bool isPow2VectorType() const {
404 unsigned NElts = getVectorNumElements();
405 return !(NElts & (NElts - 1));
408 /// Widens the length of the given vector MVT up to the nearest power of 2
409 /// and returns that type.
410 MVT getPow2VectorType() const {
411 if (isPow2VectorType())
412 return *this;
414 unsigned NElts = getVectorNumElements();
415 unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
416 return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
419 /// If this is a vector, return the element type, otherwise return this.
420 MVT getScalarType() const {
421 return isVector() ? getVectorElementType() : *this;
424 MVT getVectorElementType() const {
425 switch (SimpleTy) {
426 default:
427 llvm_unreachable("Not a vector MVT!");
428 case v1i1:
429 case v2i1:
430 case v4i1:
431 case v8i1:
432 case v16i1:
433 case v32i1:
434 case v64i1:
435 case v128i1:
436 case v256i1:
437 case v512i1:
438 case v1024i1:
439 case nxv1i1:
440 case nxv2i1:
441 case nxv4i1:
442 case nxv8i1:
443 case nxv16i1:
444 case nxv32i1: return i1;
445 case v1i8:
446 case v2i8:
447 case v4i8:
448 case v8i8:
449 case v16i8:
450 case v32i8:
451 case v64i8:
452 case v128i8:
453 case v256i8:
454 case nxv1i8:
455 case nxv2i8:
456 case nxv4i8:
457 case nxv8i8:
458 case nxv16i8:
459 case nxv32i8: return i8;
460 case v1i16:
461 case v2i16:
462 case v3i16:
463 case v4i16:
464 case v8i16:
465 case v16i16:
466 case v32i16:
467 case v64i16:
468 case v128i16:
469 case nxv1i16:
470 case nxv2i16:
471 case nxv4i16:
472 case nxv8i16:
473 case nxv16i16:
474 case nxv32i16: return i16;
475 case v1i32:
476 case v2i32:
477 case v3i32:
478 case v4i32:
479 case v5i32:
480 case v8i32:
481 case v16i32:
482 case v32i32:
483 case v64i32:
484 case v128i32:
485 case v256i32:
486 case v512i32:
487 case v1024i32:
488 case v2048i32:
489 case nxv1i32:
490 case nxv2i32:
491 case nxv4i32:
492 case nxv8i32:
493 case nxv16i32:
494 case nxv32i32: return i32;
495 case v1i64:
496 case v2i64:
497 case v4i64:
498 case v8i64:
499 case v16i64:
500 case v32i64:
501 case nxv1i64:
502 case nxv2i64:
503 case nxv4i64:
504 case nxv8i64:
505 case nxv16i64:
506 case nxv32i64: return i64;
507 case v1i128: return i128;
508 case v2f16:
509 case v3f16:
510 case v4f16:
511 case v8f16:
512 case v16f16:
513 case v32f16:
514 case nxv2f16:
515 case nxv4f16:
516 case nxv8f16: return f16;
517 case v1f32:
518 case v2f32:
519 case v3f32:
520 case v4f32:
521 case v5f32:
522 case v8f32:
523 case v16f32:
524 case v32f32:
525 case v64f32:
526 case v128f32:
527 case v256f32:
528 case v512f32:
529 case v1024f32:
530 case v2048f32:
531 case nxv1f32:
532 case nxv2f32:
533 case nxv4f32:
534 case nxv8f32:
535 case nxv16f32: return f32;
536 case v1f64:
537 case v2f64:
538 case v4f64:
539 case v8f64:
540 case nxv1f64:
541 case nxv2f64:
542 case nxv4f64:
543 case nxv8f64: return f64;
547 unsigned getVectorNumElements() const {
548 switch (SimpleTy) {
549 default:
550 llvm_unreachable("Not a vector MVT!");
551 case v2048i32:
552 case v2048f32: return 2048;
553 case v1024i1:
554 case v1024i32:
555 case v1024f32: return 1024;
556 case v512i1:
557 case v512i32:
558 case v512f32: return 512;
559 case v256i1:
560 case v256i8:
561 case v256i32:
562 case v256f32: return 256;
563 case v128i1:
564 case v128i8:
565 case v128i16:
566 case v128i32:
567 case v128f32: return 128;
568 case v64i1:
569 case v64i8:
570 case v64i16:
571 case v64i32:
572 case v64f32: return 64;
573 case v32i1:
574 case v32i8:
575 case v32i16:
576 case v32i32:
577 case v32i64:
578 case v32f16:
579 case v32f32:
580 case nxv32i1:
581 case nxv32i8:
582 case nxv32i16:
583 case nxv32i32:
584 case nxv32i64: return 32;
585 case v16i1:
586 case v16i8:
587 case v16i16:
588 case v16i32:
589 case v16i64:
590 case v16f16:
591 case v16f32:
592 case nxv16i1:
593 case nxv16i8:
594 case nxv16i16:
595 case nxv16i32:
596 case nxv16i64:
597 case nxv16f32: return 16;
598 case v8i1:
599 case v8i8:
600 case v8i16:
601 case v8i32:
602 case v8i64:
603 case v8f16:
604 case v8f32:
605 case v8f64:
606 case nxv8i1:
607 case nxv8i8:
608 case nxv8i16:
609 case nxv8i32:
610 case nxv8i64:
611 case nxv8f16:
612 case nxv8f32:
613 case nxv8f64: return 8;
614 case v5i32:
615 case v5f32: return 5;
616 case v4i1:
617 case v4i8:
618 case v4i16:
619 case v4i32:
620 case v4i64:
621 case v4f16:
622 case v4f32:
623 case v4f64:
624 case nxv4i1:
625 case nxv4i8:
626 case nxv4i16:
627 case nxv4i32:
628 case nxv4i64:
629 case nxv4f16:
630 case nxv4f32:
631 case nxv4f64: return 4;
632 case v3i16:
633 case v3i32:
634 case v3f16:
635 case v3f32: return 3;
636 case v2i1:
637 case v2i8:
638 case v2i16:
639 case v2i32:
640 case v2i64:
641 case v2f16:
642 case v2f32:
643 case v2f64:
644 case nxv2i1:
645 case nxv2i8:
646 case nxv2i16:
647 case nxv2i32:
648 case nxv2i64:
649 case nxv2f16:
650 case nxv2f32:
651 case nxv2f64: return 2;
652 case v1i1:
653 case v1i8:
654 case v1i16:
655 case v1i32:
656 case v1i64:
657 case v1i128:
658 case v1f32:
659 case v1f64:
660 case nxv1i1:
661 case nxv1i8:
662 case nxv1i16:
663 case nxv1i32:
664 case nxv1i64:
665 case nxv1f32:
666 case nxv1f64: return 1;
670 ElementCount getVectorElementCount() const {
671 return { getVectorNumElements(), isScalableVector() };
674 unsigned getSizeInBits() const {
675 switch (SimpleTy) {
676 default:
677 llvm_unreachable("getSizeInBits called on extended MVT.");
678 case Other:
679 llvm_unreachable("Value type is non-standard value, Other.");
680 case iPTR:
681 llvm_unreachable("Value type size is target-dependent. Ask TLI.");
682 case iPTRAny:
683 case iAny:
684 case fAny:
685 case vAny:
686 case Any:
687 llvm_unreachable("Value type is overloaded.");
688 case token:
689 llvm_unreachable("Token type is a sentinel that cannot be used "
690 "in codegen and has no size");
691 case Metadata:
692 llvm_unreachable("Value type is metadata.");
693 case i1:
694 case v1i1:
695 case nxv1i1: return 1;
696 case v2i1:
697 case nxv2i1: return 2;
698 case v4i1:
699 case nxv4i1: return 4;
700 case i8 :
701 case v1i8:
702 case v8i1:
703 case nxv1i8:
704 case nxv8i1: return 8;
705 case i16 :
706 case f16:
707 case v16i1:
708 case v2i8:
709 case v1i16:
710 case nxv16i1:
711 case nxv2i8:
712 case nxv1i16: return 16;
713 case f32 :
714 case i32 :
715 case v32i1:
716 case v4i8:
717 case v2i16:
718 case v2f16:
719 case v1f32:
720 case v1i32:
721 case nxv32i1:
722 case nxv4i8:
723 case nxv2i16:
724 case nxv1i32:
725 case nxv2f16:
726 case nxv1f32: return 32;
727 case v3i16:
728 case v3f16: return 48;
729 case x86mmx:
730 case f64 :
731 case i64 :
732 case v64i1:
733 case v8i8:
734 case v4i16:
735 case v2i32:
736 case v1i64:
737 case v4f16:
738 case v2f32:
739 case v1f64:
740 case nxv8i8:
741 case nxv4i16:
742 case nxv2i32:
743 case nxv1i64:
744 case nxv4f16:
745 case nxv2f32:
746 case nxv1f64: return 64;
747 case f80 : return 80;
748 case v3i32:
749 case v3f32: return 96;
750 case f128:
751 case ppcf128:
752 case i128:
753 case v128i1:
754 case v16i8:
755 case v8i16:
756 case v4i32:
757 case v2i64:
758 case v1i128:
759 case v8f16:
760 case v4f32:
761 case v2f64:
762 case nxv16i8:
763 case nxv8i16:
764 case nxv4i32:
765 case nxv2i64:
766 case nxv8f16:
767 case nxv4f32:
768 case nxv2f64: return 128;
769 case v5i32:
770 case v5f32: return 160;
771 case v256i1:
772 case v32i8:
773 case v16i16:
774 case v8i32:
775 case v4i64:
776 case v16f16:
777 case v8f32:
778 case v4f64:
779 case nxv32i8:
780 case nxv16i16:
781 case nxv8i32:
782 case nxv4i64:
783 case nxv8f32:
784 case nxv4f64: return 256;
785 case v512i1:
786 case v64i8:
787 case v32i16:
788 case v16i32:
789 case v8i64:
790 case v32f16:
791 case v16f32:
792 case v8f64:
793 case nxv32i16:
794 case nxv16i32:
795 case nxv8i64:
796 case nxv16f32:
797 case nxv8f64: return 512;
798 case v1024i1:
799 case v128i8:
800 case v64i16:
801 case v32i32:
802 case v16i64:
803 case v32f32:
804 case nxv32i32:
805 case nxv16i64: return 1024;
806 case v256i8:
807 case v128i16:
808 case v64i32:
809 case v32i64:
810 case v64f32:
811 case nxv32i64: return 2048;
812 case v128i32:
813 case v128f32: return 4096;
814 case v256i32:
815 case v256f32: return 8192;
816 case v512i32:
817 case v512f32: return 16384;
818 case v1024i32:
819 case v1024f32: return 32768;
820 case v2048i32:
821 case v2048f32: return 65536;
822 case exnref: return 0; // opaque type
826 unsigned getScalarSizeInBits() const {
827 return getScalarType().getSizeInBits();
830 /// Return the number of bytes overwritten by a store of the specified value
831 /// type.
832 unsigned getStoreSize() const {
833 return (getSizeInBits() + 7) / 8;
836 /// Return the number of bits overwritten by a store of the specified value
837 /// type.
838 unsigned getStoreSizeInBits() const {
839 return getStoreSize() * 8;
842 /// Return true if this has more bits than VT.
843 bool bitsGT(MVT VT) const {
844 return getSizeInBits() > VT.getSizeInBits();
847 /// Return true if this has no less bits than VT.
848 bool bitsGE(MVT VT) const {
849 return getSizeInBits() >= VT.getSizeInBits();
852 /// Return true if this has less bits than VT.
853 bool bitsLT(MVT VT) const {
854 return getSizeInBits() < VT.getSizeInBits();
857 /// Return true if this has no more bits than VT.
858 bool bitsLE(MVT VT) const {
859 return getSizeInBits() <= VT.getSizeInBits();
862 static MVT getFloatingPointVT(unsigned BitWidth) {
863 switch (BitWidth) {
864 default:
865 llvm_unreachable("Bad bit width!");
866 case 16:
867 return MVT::f16;
868 case 32:
869 return MVT::f32;
870 case 64:
871 return MVT::f64;
872 case 80:
873 return MVT::f80;
874 case 128:
875 return MVT::f128;
879 static MVT getIntegerVT(unsigned BitWidth) {
880 switch (BitWidth) {
881 default:
882 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
883 case 1:
884 return MVT::i1;
885 case 8:
886 return MVT::i8;
887 case 16:
888 return MVT::i16;
889 case 32:
890 return MVT::i32;
891 case 64:
892 return MVT::i64;
893 case 128:
894 return MVT::i128;
898 static MVT getVectorVT(MVT VT, unsigned NumElements) {
899 switch (VT.SimpleTy) {
900 default:
901 break;
902 case MVT::i1:
903 if (NumElements == 1) return MVT::v1i1;
904 if (NumElements == 2) return MVT::v2i1;
905 if (NumElements == 4) return MVT::v4i1;
906 if (NumElements == 8) return MVT::v8i1;
907 if (NumElements == 16) return MVT::v16i1;
908 if (NumElements == 32) return MVT::v32i1;
909 if (NumElements == 64) return MVT::v64i1;
910 if (NumElements == 128) return MVT::v128i1;
911 if (NumElements == 256) return MVT::v256i1;
912 if (NumElements == 512) return MVT::v512i1;
913 if (NumElements == 1024) return MVT::v1024i1;
914 break;
915 case MVT::i8:
916 if (NumElements == 1) return MVT::v1i8;
917 if (NumElements == 2) return MVT::v2i8;
918 if (NumElements == 4) return MVT::v4i8;
919 if (NumElements == 8) return MVT::v8i8;
920 if (NumElements == 16) return MVT::v16i8;
921 if (NumElements == 32) return MVT::v32i8;
922 if (NumElements == 64) return MVT::v64i8;
923 if (NumElements == 128) return MVT::v128i8;
924 if (NumElements == 256) return MVT::v256i8;
925 break;
926 case MVT::i16:
927 if (NumElements == 1) return MVT::v1i16;
928 if (NumElements == 2) return MVT::v2i16;
929 if (NumElements == 3) return MVT::v3i16;
930 if (NumElements == 4) return MVT::v4i16;
931 if (NumElements == 8) return MVT::v8i16;
932 if (NumElements == 16) return MVT::v16i16;
933 if (NumElements == 32) return MVT::v32i16;
934 if (NumElements == 64) return MVT::v64i16;
935 if (NumElements == 128) return MVT::v128i16;
936 break;
937 case MVT::i32:
938 if (NumElements == 1) return MVT::v1i32;
939 if (NumElements == 2) return MVT::v2i32;
940 if (NumElements == 3) return MVT::v3i32;
941 if (NumElements == 4) return MVT::v4i32;
942 if (NumElements == 5) return MVT::v5i32;
943 if (NumElements == 8) return MVT::v8i32;
944 if (NumElements == 16) return MVT::v16i32;
945 if (NumElements == 32) return MVT::v32i32;
946 if (NumElements == 64) return MVT::v64i32;
947 if (NumElements == 128) return MVT::v128i32;
948 if (NumElements == 256) return MVT::v256i32;
949 if (NumElements == 512) return MVT::v512i32;
950 if (NumElements == 1024) return MVT::v1024i32;
951 if (NumElements == 2048) return MVT::v2048i32;
952 break;
953 case MVT::i64:
954 if (NumElements == 1) return MVT::v1i64;
955 if (NumElements == 2) return MVT::v2i64;
956 if (NumElements == 4) return MVT::v4i64;
957 if (NumElements == 8) return MVT::v8i64;
958 if (NumElements == 16) return MVT::v16i64;
959 if (NumElements == 32) return MVT::v32i64;
960 break;
961 case MVT::i128:
962 if (NumElements == 1) return MVT::v1i128;
963 break;
964 case MVT::f16:
965 if (NumElements == 2) return MVT::v2f16;
966 if (NumElements == 3) return MVT::v3f16;
967 if (NumElements == 4) return MVT::v4f16;
968 if (NumElements == 8) return MVT::v8f16;
969 if (NumElements == 16) return MVT::v16f16;
970 if (NumElements == 32) return MVT::v32f16;
971 break;
972 case MVT::f32:
973 if (NumElements == 1) return MVT::v1f32;
974 if (NumElements == 2) return MVT::v2f32;
975 if (NumElements == 3) return MVT::v3f32;
976 if (NumElements == 4) return MVT::v4f32;
977 if (NumElements == 5) return MVT::v5f32;
978 if (NumElements == 8) return MVT::v8f32;
979 if (NumElements == 16) return MVT::v16f32;
980 if (NumElements == 32) return MVT::v32f32;
981 if (NumElements == 64) return MVT::v64f32;
982 if (NumElements == 128) return MVT::v128f32;
983 if (NumElements == 256) return MVT::v256f32;
984 if (NumElements == 512) return MVT::v512f32;
985 if (NumElements == 1024) return MVT::v1024f32;
986 if (NumElements == 2048) return MVT::v2048f32;
987 break;
988 case MVT::f64:
989 if (NumElements == 1) return MVT::v1f64;
990 if (NumElements == 2) return MVT::v2f64;
991 if (NumElements == 4) return MVT::v4f64;
992 if (NumElements == 8) return MVT::v8f64;
993 break;
995 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
998 static MVT getScalableVectorVT(MVT VT, unsigned NumElements) {
999 switch(VT.SimpleTy) {
1000 default:
1001 break;
1002 case MVT::i1:
1003 if (NumElements == 1) return MVT::nxv1i1;
1004 if (NumElements == 2) return MVT::nxv2i1;
1005 if (NumElements == 4) return MVT::nxv4i1;
1006 if (NumElements == 8) return MVT::nxv8i1;
1007 if (NumElements == 16) return MVT::nxv16i1;
1008 if (NumElements == 32) return MVT::nxv32i1;
1009 break;
1010 case MVT::i8:
1011 if (NumElements == 1) return MVT::nxv1i8;
1012 if (NumElements == 2) return MVT::nxv2i8;
1013 if (NumElements == 4) return MVT::nxv4i8;
1014 if (NumElements == 8) return MVT::nxv8i8;
1015 if (NumElements == 16) return MVT::nxv16i8;
1016 if (NumElements == 32) return MVT::nxv32i8;
1017 break;
1018 case MVT::i16:
1019 if (NumElements == 1) return MVT::nxv1i16;
1020 if (NumElements == 2) return MVT::nxv2i16;
1021 if (NumElements == 4) return MVT::nxv4i16;
1022 if (NumElements == 8) return MVT::nxv8i16;
1023 if (NumElements == 16) return MVT::nxv16i16;
1024 if (NumElements == 32) return MVT::nxv32i16;
1025 break;
1026 case MVT::i32:
1027 if (NumElements == 1) return MVT::nxv1i32;
1028 if (NumElements == 2) return MVT::nxv2i32;
1029 if (NumElements == 4) return MVT::nxv4i32;
1030 if (NumElements == 8) return MVT::nxv8i32;
1031 if (NumElements == 16) return MVT::nxv16i32;
1032 if (NumElements == 32) return MVT::nxv32i32;
1033 break;
1034 case MVT::i64:
1035 if (NumElements == 1) return MVT::nxv1i64;
1036 if (NumElements == 2) return MVT::nxv2i64;
1037 if (NumElements == 4) return MVT::nxv4i64;
1038 if (NumElements == 8) return MVT::nxv8i64;
1039 if (NumElements == 16) return MVT::nxv16i64;
1040 if (NumElements == 32) return MVT::nxv32i64;
1041 break;
1042 case MVT::f16:
1043 if (NumElements == 2) return MVT::nxv2f16;
1044 if (NumElements == 4) return MVT::nxv4f16;
1045 if (NumElements == 8) return MVT::nxv8f16;
1046 break;
1047 case MVT::f32:
1048 if (NumElements == 1) return MVT::nxv1f32;
1049 if (NumElements == 2) return MVT::nxv2f32;
1050 if (NumElements == 4) return MVT::nxv4f32;
1051 if (NumElements == 8) return MVT::nxv8f32;
1052 if (NumElements == 16) return MVT::nxv16f32;
1053 break;
1054 case MVT::f64:
1055 if (NumElements == 1) return MVT::nxv1f64;
1056 if (NumElements == 2) return MVT::nxv2f64;
1057 if (NumElements == 4) return MVT::nxv4f64;
1058 if (NumElements == 8) return MVT::nxv8f64;
1059 break;
1061 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
1064 static MVT getVectorVT(MVT VT, unsigned NumElements, bool IsScalable) {
1065 if (IsScalable)
1066 return getScalableVectorVT(VT, NumElements);
1067 return getVectorVT(VT, NumElements);
1070 static MVT getVectorVT(MVT VT, ElementCount EC) {
1071 if (EC.Scalable)
1072 return getScalableVectorVT(VT, EC.Min);
1073 return getVectorVT(VT, EC.Min);
1076 /// Return the value type corresponding to the specified type. This returns
1077 /// all pointers as iPTR. If HandleUnknown is true, unknown types are
1078 /// returned as Other, otherwise they are invalid.
1079 static MVT getVT(Type *Ty, bool HandleUnknown = false);
1081 private:
1082 /// A simple iterator over the MVT::SimpleValueType enum.
1083 struct mvt_iterator {
1084 SimpleValueType VT;
1086 mvt_iterator(SimpleValueType VT) : VT(VT) {}
1088 MVT operator*() const { return VT; }
1089 bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
1091 mvt_iterator& operator++() {
1092 VT = (MVT::SimpleValueType)((int)VT + 1);
1093 assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
1094 "MVT iterator overflowed.");
1095 return *this;
1099 /// A range of the MVT::SimpleValueType enum.
1100 using mvt_range = iterator_range<mvt_iterator>;
1102 public:
1103 /// SimpleValueType Iteration
1104 /// @{
1105 static mvt_range all_valuetypes() {
1106 return mvt_range(MVT::FIRST_VALUETYPE, MVT::LAST_VALUETYPE);
1109 static mvt_range integer_valuetypes() {
1110 return mvt_range(MVT::FIRST_INTEGER_VALUETYPE,
1111 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VALUETYPE + 1));
1114 static mvt_range fp_valuetypes() {
1115 return mvt_range(MVT::FIRST_FP_VALUETYPE,
1116 (MVT::SimpleValueType)(MVT::LAST_FP_VALUETYPE + 1));
1119 static mvt_range vector_valuetypes() {
1120 return mvt_range(MVT::FIRST_VECTOR_VALUETYPE,
1121 (MVT::SimpleValueType)(MVT::LAST_VECTOR_VALUETYPE + 1));
1124 static mvt_range fixedlen_vector_valuetypes() {
1125 return mvt_range(
1126 MVT::FIRST_FIXEDLEN_VECTOR_VALUETYPE,
1127 (MVT::SimpleValueType)(MVT::LAST_FIXEDLEN_VECTOR_VALUETYPE + 1));
1130 static mvt_range scalable_vector_valuetypes() {
1131 return mvt_range(
1132 MVT::FIRST_SCALABLE_VECTOR_VALUETYPE,
1133 (MVT::SimpleValueType)(MVT::LAST_SCALABLE_VECTOR_VALUETYPE + 1));
1136 static mvt_range integer_fixedlen_vector_valuetypes() {
1137 return mvt_range(
1138 MVT::FIRST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE,
1139 (MVT::SimpleValueType)(MVT::LAST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE + 1));
1142 static mvt_range fp_fixedlen_vector_valuetypes() {
1143 return mvt_range(
1144 MVT::FIRST_FP_FIXEDLEN_VECTOR_VALUETYPE,
1145 (MVT::SimpleValueType)(MVT::LAST_FP_FIXEDLEN_VECTOR_VALUETYPE + 1));
1148 static mvt_range integer_scalable_vector_valuetypes() {
1149 return mvt_range(
1150 MVT::FIRST_INTEGER_SCALABLE_VECTOR_VALUETYPE,
1151 (MVT::SimpleValueType)(MVT::LAST_INTEGER_SCALABLE_VECTOR_VALUETYPE + 1));
1154 static mvt_range fp_scalable_vector_valuetypes() {
1155 return mvt_range(
1156 MVT::FIRST_FP_SCALABLE_VECTOR_VALUETYPE,
1157 (MVT::SimpleValueType)(MVT::LAST_FP_SCALABLE_VECTOR_VALUETYPE + 1));
1159 /// @}
1162 } // end namespace llvm
1164 #endif // LLVM_CODEGEN_MACHINEVALUETYPE_H