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