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