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