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