• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- Support/MachineValueType.h - Machine-Level types ---------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the set of machine-level target independent types which
10 // legal values in the code generator use.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_SUPPORT_MACHINEVALUETYPE_H
15 #define LLVM_SUPPORT_MACHINEVALUETYPE_H
16 
17 #include "llvm/ADT/iterator_range.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/MathExtras.h"
20 #include "llvm/Support/TypeSize.h"
21 #include <cassert>
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       bf16           =   8,   // This is a 16 bit brain floating point value
51       f16            =   9,   // This is a 16 bit floating point value
52       f32            =  10,   // This is a 32 bit floating point value
53       f64            =  11,   // This is a 64 bit floating point value
54       f80            =  12,   // This is a 80 bit floating point value
55       f128           =  13,   // This is a 128 bit floating point value
56       ppcf128        =  14,   // This is a PPC 128-bit floating point value
57 
58       FIRST_FP_VALUETYPE = bf16,
59       LAST_FP_VALUETYPE  = ppcf128,
60 
61       v1i1           =  15,   //    1 x i1
62       v2i1           =  16,   //    2 x i1
63       v4i1           =  17,   //    4 x i1
64       v8i1           =  18,   //    8 x i1
65       v16i1          =  19,   //   16 x i1
66       v32i1          =  20,   //   32 x i1
67       v64i1          =  21,   //   64 x i1
68       v128i1         =  22,   //  128 x i1
69       v256i1         =  23,   //  256 x i1
70       v512i1         =  24,   //  512 x i1
71       v1024i1        =  25,   // 1024 x i1
72 
73       v1i8           =  26,   //  1 x i8
74       v2i8           =  27,   //  2 x i8
75       v4i8           =  28,   //  4 x i8
76       v8i8           =  29,   //  8 x i8
77       v16i8          =  30,   // 16 x i8
78       v32i8          =  31,   // 32 x i8
79       v64i8          =  32,   // 64 x i8
80       v128i8         =  33,   //128 x i8
81       v256i8         =  34,   //256 x i8
82 
83       v1i16          =  35,   //  1 x i16
84       v2i16          =  36,   //  2 x i16
85       v3i16          =  37,   //  3 x i16
86       v4i16          =  38,   //  4 x i16
87       v8i16          =  39,   //  8 x i16
88       v16i16         =  40,   // 16 x i16
89       v32i16         =  41,   // 32 x i16
90       v64i16         =  42,   // 64 x i16
91       v128i16        =  43,   //128 x i16
92 
93       v1i32          =  44,   //    1 x i32
94       v2i32          =  45,   //    2 x i32
95       v3i32          =  46,   //    3 x i32
96       v4i32          =  47,   //    4 x i32
97       v5i32          =  48,   //    5 x i32
98       v8i32          =  49,   //    8 x i32
99       v16i32         =  50,   //   16 x i32
100       v32i32         =  51,   //   32 x i32
101       v64i32         =  52,   //   64 x i32
102       v128i32        =  53,   //  128 x i32
103       v256i32        =  54,   //  256 x i32
104       v512i32        =  55,   //  512 x i32
105       v1024i32       =  56,   // 1024 x i32
106       v2048i32       =  57,   // 2048 x i32
107 
108       v1i64          =  58,   //  1 x i64
109       v2i64          =  59,   //  2 x i64
110       v4i64          =  60,   //  4 x i64
111       v8i64          =  61,   //  8 x i64
112       v16i64         =  62,   // 16 x i64
113       v32i64         =  63,   // 32 x i64
114       v64i64         =  64,   // 64 x i64
115       v128i64        =  65,   // 128 x i64
116       v256i64        =  66,   // 256 x i64
117 
118       v1i128         =  67,   //  1 x i128
119 
120       FIRST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE = v1i1,
121       LAST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE = v1i128,
122 
123       v2f16          =  68,   //    2 x f16
124       v3f16          =  69,   //    3 x f16
125       v4f16          =  70,   //    4 x f16
126       v8f16          =  71,   //    8 x f16
127       v16f16         =  72,   //   16 x f16
128       v32f16         =  73,   //   32 x f16
129       v64f16         =  74,   //   64 x f16
130       v128f16        =  75,   //  128 x f16
131       v2bf16         =  76,   //    2 x bf16
132       v3bf16         =  77,   //    3 x bf16
133       v4bf16         =  78,   //    4 x bf16
134       v8bf16         =  79,   //    8 x bf16
135       v16bf16        =  80,   //   16 x bf16
136       v32bf16        =  81,   //   32 x bf16
137       v64bf16        =  82,   //   64 x bf16
138       v128bf16       =  83,   //  128 x bf16
139       v1f32          =  84,   //    1 x f32
140       v2f32          =  85,   //    2 x f32
141       v3f32          =  86,   //    3 x f32
142       v4f32          =  87,   //    4 x f32
143       v5f32          =  88,   //    5 x f32
144       v8f32          =  89,   //    8 x f32
145       v16f32         =  90,   //   16 x f32
146       v32f32         =  91,   //   32 x f32
147       v64f32         =  92,   //   64 x f32
148       v128f32        =  93,   //  128 x f32
149       v256f32        =  94,   //  256 x f32
150       v512f32        =  95,   //  512 x f32
151       v1024f32       =  96,   // 1024 x f32
152       v2048f32       =  97,   // 2048 x f32
153       v1f64          =  98,   //    1 x f64
154       v2f64          =  99,   //    2 x f64
155       v4f64          = 100,   //    4 x f64
156       v8f64          = 101,   //    8 x f64
157       v16f64         = 102,   //   16 x f64
158       v32f64         = 103,   //   32 x f64
159       v64f64         = 104,   //   64 x f64
160       v128f64        = 105,   //  128 x f64
161       v256f64        = 106,   //  256 x f64
162 
163       FIRST_FP_FIXEDLEN_VECTOR_VALUETYPE = v2f16,
164       LAST_FP_FIXEDLEN_VECTOR_VALUETYPE = v256f64,
165 
166       FIRST_FIXEDLEN_VECTOR_VALUETYPE = v1i1,
167       LAST_FIXEDLEN_VECTOR_VALUETYPE = v256f64,
168 
169       nxv1i1         = 107,   // n x  1 x i1
170       nxv2i1         = 108,   // n x  2 x i1
171       nxv4i1         = 109,   // n x  4 x i1
172       nxv8i1         = 110,   // n x  8 x i1
173       nxv16i1        = 111,   // n x 16 x i1
174       nxv32i1        = 112,   // n x 32 x i1
175       nxv64i1        = 113,   // n x  64 x i1
176 
177       nxv1i8         = 114,   // n x  1 x i8
178       nxv2i8         = 115,   // n x  2 x i8
179       nxv4i8         = 116,   // n x  4 x i8
180       nxv8i8         = 117,   // n x  8 x i8
181       nxv16i8        = 118,   // n x 16 x i8
182       nxv32i8        = 119,   // n x 32 x i8
183       nxv64i8        = 120,   // n x  64 x i8
184 
185       nxv1i16        = 121,  // n x  1 x i16
186       nxv2i16        = 122,  // n x  2 x i16
187       nxv4i16        = 123,  // n x  4 x i16
188       nxv8i16        = 124,  // n x  8 x i16
189       nxv16i16       = 125,  // n x 16 x i16
190       nxv32i16       = 126,  // n x 32 x i16
191 
192       nxv1i32        = 127,  // n x  1 x i32
193       nxv2i32        = 128,  // n x  2 x i32
194       nxv4i32        = 129,  // n x  4 x i32
195       nxv8i32        = 130,  // n x  8 x i32
196       nxv16i32       = 131,  // n x 16 x i32
197       nxv32i32       = 132,  // n x 32 x i32
198 
199       nxv1i64        = 133,  // n x  1 x i64
200       nxv2i64        = 134,  // n x  2 x i64
201       nxv4i64        = 135,  // n x  4 x i64
202       nxv8i64        = 136,  // n x  8 x i64
203       nxv16i64       = 137,  // n x 16 x i64
204       nxv32i64       = 138,  // n x 32 x i64
205 
206       FIRST_INTEGER_SCALABLE_VECTOR_VALUETYPE = nxv1i1,
207       LAST_INTEGER_SCALABLE_VECTOR_VALUETYPE = nxv32i64,
208 
209       nxv1f16        = 139,   // n x   1 x f16
210       nxv2f16        = 140,  // n x  2 x f16
211       nxv4f16        = 141,  // n x  4 x f16
212       nxv8f16        = 142,  // n x  8 x f16
213       nxv16f16       = 143,   // n x  16 x f16
214       nxv32f16       = 144,   // n x  32 x f16
215       nxv2bf16       = 145,  // n x  2 x bf16
216       nxv4bf16       = 146,  // n x  4 x bf16
217       nxv8bf16       = 147,  // n x  8 x bf16
218       nxv1f32        = 148,  // n x  1 x f32
219       nxv2f32        = 149,  // n x  2 x f32
220       nxv4f32        = 150,  // n x  4 x f32
221       nxv8f32        = 151,  // n x  8 x f32
222       nxv16f32       = 152,  // n x 16 x f32
223       nxv1f64        = 153,  // n x  1 x f64
224       nxv2f64        = 154,  // n x  2 x f64
225       nxv4f64        = 155,  // n x  4 x f64
226       nxv8f64        = 156,  // n x  8 x f64
227 
228       FIRST_FP_SCALABLE_VECTOR_VALUETYPE = nxv1f16,
229       LAST_FP_SCALABLE_VECTOR_VALUETYPE = nxv8f64,
230 
231       FIRST_SCALABLE_VECTOR_VALUETYPE = nxv1i1,
232       LAST_SCALABLE_VECTOR_VALUETYPE = nxv8f64,
233 
234       FIRST_VECTOR_VALUETYPE = v1i1,
235       LAST_VECTOR_VALUETYPE  = nxv8f64,
236 
237       x86mmx         = 157,   // This is an X86 MMX value
238 
239       Glue           = 158,   // This glues nodes together during pre-RA sched
240 
241       isVoid         = 159,   // This has no value
242 
243       Untyped        = 160,   // This value takes a register, but has
244                               // unspecified type.  The register class
245                               // will be determined by the opcode.
246 
247       exnref         = 161,   // WebAssembly's exnref type
248       funcref        = 162,   // WebAssembly's funcref type
249       externref      = 163,   // WebAssembly's externref type
250 
251       FIRST_VALUETYPE =  1,   // This is always the beginning of the list.
252       LAST_VALUETYPE = 164,   // This always remains at the end of the list.
253 
254       // This is the current maximum for LAST_VALUETYPE.
255       // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
256       // This value must be a multiple of 32.
257       MAX_ALLOWED_VALUETYPE = 192,
258 
259       // A value of type llvm::TokenTy
260       token          = 248,
261 
262       // This is MDNode or MDString.
263       Metadata       = 249,
264 
265       // An int value the size of the pointer of the current
266       // target to any address space. This must only be used internal to
267       // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
268       iPTRAny        = 250,
269 
270       // A vector with any length and element size. This is used
271       // for intrinsics that have overloadings based on vector types.
272       // This is only for tblgen's consumption!
273       vAny           = 251,
274 
275       // Any floating-point or vector floating-point value. This is used
276       // for intrinsics that have overloadings based on floating-point types.
277       // This is only for tblgen's consumption!
278       fAny           = 252,
279 
280       // An integer or vector integer value of any bit width. This is
281       // used for intrinsics that have overloadings based on integer bit widths.
282       // This is only for tblgen's consumption!
283       iAny           = 253,
284 
285       // An int value the size of the pointer of the current
286       // target.  This should only be used internal to tblgen!
287       iPTR           = 254,
288 
289       // Any type. This is used for intrinsics that have overloadings.
290       // This is only for tblgen's consumption!
291       Any            = 255
292     };
293 
294     SimpleValueType SimpleTy = INVALID_SIMPLE_VALUE_TYPE;
295 
296     constexpr MVT() = default;
MVT(SimpleValueType SVT)297     constexpr MVT(SimpleValueType SVT) : SimpleTy(SVT) {}
298 
299     bool operator>(const MVT& S)  const { return SimpleTy >  S.SimpleTy; }
300     bool operator<(const MVT& S)  const { return SimpleTy <  S.SimpleTy; }
301     bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
302     bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
303     bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
304     bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
305 
306     /// Return true if this is a valid simple valuetype.
isValid()307     bool isValid() const {
308       return (SimpleTy >= MVT::FIRST_VALUETYPE &&
309               SimpleTy < MVT::LAST_VALUETYPE);
310     }
311 
312     /// Return true if this is a FP or a vector FP type.
isFloatingPoint()313     bool isFloatingPoint() const {
314       return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
315                SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
316               (SimpleTy >= MVT::FIRST_FP_FIXEDLEN_VECTOR_VALUETYPE &&
317                SimpleTy <= MVT::LAST_FP_FIXEDLEN_VECTOR_VALUETYPE) ||
318               (SimpleTy >= MVT::FIRST_FP_SCALABLE_VECTOR_VALUETYPE &&
319                SimpleTy <= MVT::LAST_FP_SCALABLE_VECTOR_VALUETYPE));
320     }
321 
322     /// Return true if this is an integer or a vector integer type.
isInteger()323     bool isInteger() const {
324       return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
325                SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
326               (SimpleTy >= MVT::FIRST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE &&
327                SimpleTy <= MVT::LAST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE) ||
328               (SimpleTy >= MVT::FIRST_INTEGER_SCALABLE_VECTOR_VALUETYPE &&
329                SimpleTy <= MVT::LAST_INTEGER_SCALABLE_VECTOR_VALUETYPE));
330     }
331 
332     /// Return true if this is an integer, not including vectors.
isScalarInteger()333     bool isScalarInteger() const {
334       return (SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
335               SimpleTy <= MVT::LAST_INTEGER_VALUETYPE);
336     }
337 
338     /// Return true if this is a vector value type.
isVector()339     bool isVector() const {
340       return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
341               SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
342     }
343 
344     /// Return true if this is a vector value type where the
345     /// runtime length is machine dependent
isScalableVector()346     bool isScalableVector() const {
347       return (SimpleTy >= MVT::FIRST_SCALABLE_VECTOR_VALUETYPE &&
348               SimpleTy <= MVT::LAST_SCALABLE_VECTOR_VALUETYPE);
349     }
350 
isFixedLengthVector()351     bool isFixedLengthVector() const {
352       return (SimpleTy >= MVT::FIRST_FIXEDLEN_VECTOR_VALUETYPE &&
353               SimpleTy <= MVT::LAST_FIXEDLEN_VECTOR_VALUETYPE);
354     }
355 
356     /// Return true if this is a 16-bit vector type.
is16BitVector()357     bool is16BitVector() const {
358       return (SimpleTy == MVT::v2i8  || SimpleTy == MVT::v1i16 ||
359               SimpleTy == MVT::v16i1);
360     }
361 
362     /// Return true if this is a 32-bit vector type.
is32BitVector()363     bool is32BitVector() const {
364       return (SimpleTy == MVT::v32i1 || SimpleTy == MVT::v4i8   ||
365               SimpleTy == MVT::v2i16 || SimpleTy == MVT::v1i32  ||
366               SimpleTy == MVT::v2f16 || SimpleTy == MVT::v2bf16 ||
367               SimpleTy == MVT::v1f32);
368     }
369 
370     /// Return true if this is a 64-bit vector type.
is64BitVector()371     bool is64BitVector() const {
372       return (SimpleTy == MVT::v64i1  || SimpleTy == MVT::v8i8  ||
373               SimpleTy == MVT::v4i16  || SimpleTy == MVT::v2i32 ||
374               SimpleTy == MVT::v1i64  || SimpleTy == MVT::v4f16 ||
375               SimpleTy == MVT::v4bf16 ||SimpleTy == MVT::v2f32  ||
376               SimpleTy == MVT::v1f64);
377     }
378 
379     /// Return true if this is a 128-bit vector type.
is128BitVector()380     bool is128BitVector() const {
381       return (SimpleTy == MVT::v128i1 || SimpleTy == MVT::v16i8  ||
382               SimpleTy == MVT::v8i16  || SimpleTy == MVT::v4i32  ||
383               SimpleTy == MVT::v2i64  || SimpleTy == MVT::v1i128 ||
384               SimpleTy == MVT::v8f16  || SimpleTy == MVT::v8bf16 ||
385               SimpleTy == MVT::v4f32  || SimpleTy == MVT::v2f64);
386     }
387 
388     /// Return true if this is a 256-bit vector type.
is256BitVector()389     bool is256BitVector() const {
390       return (SimpleTy == MVT::v16f16 || SimpleTy == MVT::v16bf16 ||
391               SimpleTy == MVT::v8f32  || SimpleTy == MVT::v4f64   ||
392               SimpleTy == MVT::v32i8  || SimpleTy == MVT::v16i16  ||
393               SimpleTy == MVT::v8i32  || SimpleTy == MVT::v4i64   ||
394               SimpleTy == MVT::v256i1);
395     }
396 
397     /// Return true if this is a 512-bit vector type.
is512BitVector()398     bool is512BitVector() const {
399       return (SimpleTy == MVT::v32f16 || SimpleTy == MVT::v32bf16 ||
400               SimpleTy == MVT::v16f32 || SimpleTy == MVT::v8f64   ||
401               SimpleTy == MVT::v512i1 || SimpleTy == MVT::v64i8   ||
402               SimpleTy == MVT::v32i16 || SimpleTy == MVT::v16i32  ||
403               SimpleTy == MVT::v8i64);
404     }
405 
406     /// Return true if this is a 1024-bit vector type.
is1024BitVector()407     bool is1024BitVector() const {
408       return (SimpleTy == MVT::v1024i1 || SimpleTy == MVT::v128i8 ||
409               SimpleTy == MVT::v64i16  || SimpleTy == MVT::v32i32 ||
410               SimpleTy == MVT::v16i64  || SimpleTy == MVT::v64f16 ||
411               SimpleTy == MVT::v32f32  || SimpleTy == MVT::v16f64 ||
412               SimpleTy == MVT::v64bf16);
413     }
414 
415     /// Return true if this is a 2048-bit vector type.
is2048BitVector()416     bool is2048BitVector() const {
417       return (SimpleTy == MVT::v256i8  || SimpleTy == MVT::v128i16 ||
418               SimpleTy == MVT::v64i32  || SimpleTy == MVT::v32i64  ||
419               SimpleTy == MVT::v128f16 || SimpleTy == MVT::v64f32  ||
420               SimpleTy == MVT::v32f64  || SimpleTy == MVT::v128bf16);
421     }
422 
423     /// Return true if this is an overloaded type for TableGen.
isOverloaded()424     bool isOverloaded() const {
425       return (SimpleTy == MVT::Any || SimpleTy == MVT::iAny ||
426               SimpleTy == MVT::fAny || SimpleTy == MVT::vAny ||
427               SimpleTy == MVT::iPTRAny);
428     }
429 
430     /// Return a vector with the same number of elements as this vector, but
431     /// with the element type converted to an integer type with the same
432     /// bitwidth.
changeVectorElementTypeToInteger()433     MVT changeVectorElementTypeToInteger() const {
434       MVT EltTy = getVectorElementType();
435       MVT IntTy = MVT::getIntegerVT(EltTy.getSizeInBits());
436       MVT VecTy = MVT::getVectorVT(IntTy, getVectorElementCount());
437       assert(VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
438              "Simple vector VT not representable by simple integer vector VT!");
439       return VecTy;
440     }
441 
442     /// Return a VT for a vector type whose attributes match ourselves
443     /// with the exception of the element type that is chosen by the caller.
changeVectorElementType(MVT EltVT)444     MVT changeVectorElementType(MVT EltVT) const {
445       MVT VecTy = MVT::getVectorVT(EltVT, getVectorElementCount());
446       assert(VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
447              "Simple vector VT not representable by simple integer vector VT!");
448       return VecTy;
449     }
450 
451     /// Return the type converted to an equivalently sized integer or vector
452     /// with integer element type. Similar to changeVectorElementTypeToInteger,
453     /// but also handles scalars.
changeTypeToInteger()454     MVT changeTypeToInteger() {
455       if (isVector())
456         return changeVectorElementTypeToInteger();
457       return MVT::getIntegerVT(getSizeInBits());
458     }
459 
460     /// Return a VT for a vector type with the same element type but
461     /// half the number of elements.
getHalfNumVectorElementsVT()462     MVT getHalfNumVectorElementsVT() const {
463       MVT EltVT = getVectorElementType();
464       auto EltCnt = getVectorElementCount();
465       assert(EltCnt.isKnownEven() && "Splitting vector, but not in half!");
466       return getVectorVT(EltVT, EltCnt.divideCoefficientBy(2));
467     }
468 
469     /// Returns true if the given vector is a power of 2.
isPow2VectorType()470     bool isPow2VectorType() const {
471       unsigned NElts = getVectorNumElements();
472       return !(NElts & (NElts - 1));
473     }
474 
475     /// Widens the length of the given vector MVT up to the nearest power of 2
476     /// and returns that type.
getPow2VectorType()477     MVT getPow2VectorType() const {
478       if (isPow2VectorType())
479         return *this;
480 
481       unsigned NElts = getVectorNumElements();
482       unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
483       return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
484     }
485 
486     /// If this is a vector, return the element type, otherwise return this.
getScalarType()487     MVT getScalarType() const {
488       return isVector() ? getVectorElementType() : *this;
489     }
490 
getVectorElementType()491     MVT getVectorElementType() const {
492       switch (SimpleTy) {
493       default:
494         llvm_unreachable("Not a vector MVT!");
495       case v1i1:
496       case v2i1:
497       case v4i1:
498       case v8i1:
499       case v16i1:
500       case v32i1:
501       case v64i1:
502       case v128i1:
503       case v256i1:
504       case v512i1:
505       case v1024i1:
506       case nxv1i1:
507       case nxv2i1:
508       case nxv4i1:
509       case nxv8i1:
510       case nxv16i1:
511       case nxv32i1:
512       case nxv64i1: return i1;
513       case v1i8:
514       case v2i8:
515       case v4i8:
516       case v8i8:
517       case v16i8:
518       case v32i8:
519       case v64i8:
520       case v128i8:
521       case v256i8:
522       case nxv1i8:
523       case nxv2i8:
524       case nxv4i8:
525       case nxv8i8:
526       case nxv16i8:
527       case nxv32i8:
528       case nxv64i8: return i8;
529       case v1i16:
530       case v2i16:
531       case v3i16:
532       case v4i16:
533       case v8i16:
534       case v16i16:
535       case v32i16:
536       case v64i16:
537       case v128i16:
538       case nxv1i16:
539       case nxv2i16:
540       case nxv4i16:
541       case nxv8i16:
542       case nxv16i16:
543       case nxv32i16: return i16;
544       case v1i32:
545       case v2i32:
546       case v3i32:
547       case v4i32:
548       case v5i32:
549       case v8i32:
550       case v16i32:
551       case v32i32:
552       case v64i32:
553       case v128i32:
554       case v256i32:
555       case v512i32:
556       case v1024i32:
557       case v2048i32:
558       case nxv1i32:
559       case nxv2i32:
560       case nxv4i32:
561       case nxv8i32:
562       case nxv16i32:
563       case nxv32i32: return i32;
564       case v1i64:
565       case v2i64:
566       case v4i64:
567       case v8i64:
568       case v16i64:
569       case v32i64:
570       case v64i64:
571       case v128i64:
572       case v256i64:
573       case nxv1i64:
574       case nxv2i64:
575       case nxv4i64:
576       case nxv8i64:
577       case nxv16i64:
578       case nxv32i64: return i64;
579       case v1i128: return i128;
580       case v2f16:
581       case v3f16:
582       case v4f16:
583       case v8f16:
584       case v16f16:
585       case v32f16:
586       case v64f16:
587       case v128f16:
588       case nxv1f16:
589       case nxv2f16:
590       case nxv4f16:
591       case nxv8f16:
592       case nxv16f16:
593       case nxv32f16: return f16;
594       case v2bf16:
595       case v3bf16:
596       case v4bf16:
597       case v8bf16:
598       case v16bf16:
599       case v32bf16:
600       case v64bf16:
601       case v128bf16:
602       case nxv2bf16:
603       case nxv4bf16:
604       case nxv8bf16: return bf16;
605       case v1f32:
606       case v2f32:
607       case v3f32:
608       case v4f32:
609       case v5f32:
610       case v8f32:
611       case v16f32:
612       case v32f32:
613       case v64f32:
614       case v128f32:
615       case v256f32:
616       case v512f32:
617       case v1024f32:
618       case v2048f32:
619       case nxv1f32:
620       case nxv2f32:
621       case nxv4f32:
622       case nxv8f32:
623       case nxv16f32: return f32;
624       case v1f64:
625       case v2f64:
626       case v4f64:
627       case v8f64:
628       case v16f64:
629       case v32f64:
630       case v64f64:
631       case v128f64:
632       case v256f64:
633       case nxv1f64:
634       case nxv2f64:
635       case nxv4f64:
636       case nxv8f64: return f64;
637       }
638     }
639 
getVectorNumElements()640     unsigned getVectorNumElements() const {
641       switch (SimpleTy) {
642       default:
643         llvm_unreachable("Not a vector MVT!");
644       case v2048i32:
645       case v2048f32: return 2048;
646       case v1024i1:
647       case v1024i32:
648       case v1024f32: return 1024;
649       case v512i1:
650       case v512i32:
651       case v512f32: return 512;
652       case v256i1:
653       case v256i8:
654       case v256i32:
655       case v256i64:
656       case v256f32:
657       case v256f64: return 256;
658       case v128i1:
659       case v128i8:
660       case v128i16:
661       case v128i32:
662       case v128i64:
663       case v128f16:
664       case v128bf16:
665       case v128f32:
666       case v128f64: return 128;
667       case v64i1:
668       case v64i8:
669       case v64i16:
670       case v64i32:
671       case v64i64:
672       case v64f16:
673       case v64bf16:
674       case v64f32:
675       case v64f64:
676       case nxv64i1:
677       case nxv64i8: return 64;
678       case v32i1:
679       case v32i8:
680       case v32i16:
681       case v32i32:
682       case v32i64:
683       case v32f16:
684       case v32bf16:
685       case v32f32:
686       case v32f64:
687       case nxv32i1:
688       case nxv32i8:
689       case nxv32i16:
690       case nxv32i32:
691       case nxv32i64:
692       case nxv32f16: return 32;
693       case v16i1:
694       case v16i8:
695       case v16i16:
696       case v16i32:
697       case v16i64:
698       case v16f16:
699       case v16bf16:
700       case v16f32:
701       case v16f64:
702       case nxv16i1:
703       case nxv16i8:
704       case nxv16i16:
705       case nxv16i32:
706       case nxv16i64:
707       case nxv16f16:
708       case nxv16f32: return 16;
709       case v8i1:
710       case v8i8:
711       case v8i16:
712       case v8i32:
713       case v8i64:
714       case v8f16:
715       case v8bf16:
716       case v8f32:
717       case v8f64:
718       case nxv8i1:
719       case nxv8i8:
720       case nxv8i16:
721       case nxv8i32:
722       case nxv8i64:
723       case nxv8f16:
724       case nxv8bf16:
725       case nxv8f32:
726       case nxv8f64: return 8;
727       case v5i32:
728       case v5f32: return 5;
729       case v4i1:
730       case v4i8:
731       case v4i16:
732       case v4i32:
733       case v4i64:
734       case v4f16:
735       case v4bf16:
736       case v4f32:
737       case v4f64:
738       case nxv4i1:
739       case nxv4i8:
740       case nxv4i16:
741       case nxv4i32:
742       case nxv4i64:
743       case nxv4f16:
744       case nxv4bf16:
745       case nxv4f32:
746       case nxv4f64: return 4;
747       case v3i16:
748       case v3i32:
749       case v3f16:
750       case v3bf16:
751       case v3f32: return 3;
752       case v2i1:
753       case v2i8:
754       case v2i16:
755       case v2i32:
756       case v2i64:
757       case v2f16:
758       case v2bf16:
759       case v2f32:
760       case v2f64:
761       case nxv2i1:
762       case nxv2i8:
763       case nxv2i16:
764       case nxv2i32:
765       case nxv2i64:
766       case nxv2f16:
767       case nxv2bf16:
768       case nxv2f32:
769       case nxv2f64: return 2;
770       case v1i1:
771       case v1i8:
772       case v1i16:
773       case v1i32:
774       case v1i64:
775       case v1i128:
776       case v1f32:
777       case v1f64:
778       case nxv1i1:
779       case nxv1i8:
780       case nxv1i16:
781       case nxv1i32:
782       case nxv1i64:
783       case nxv1f16:
784       case nxv1f32:
785       case nxv1f64: return 1;
786       }
787     }
788 
getVectorElementCount()789     ElementCount getVectorElementCount() const {
790       return ElementCount::get(getVectorNumElements(), isScalableVector());
791     }
792 
793     /// Given a vector type, return the minimum number of elements it contains.
getVectorMinNumElements()794     unsigned getVectorMinNumElements() const {
795       return getVectorElementCount().getKnownMinValue();
796     }
797 
798     /// Returns the size of the specified MVT in bits.
799     ///
800     /// If the value type is a scalable vector type, the scalable property will
801     /// be set and the runtime size will be a positive integer multiple of the
802     /// base size.
getSizeInBits()803     TypeSize getSizeInBits() const {
804       switch (SimpleTy) {
805       default:
806         llvm_unreachable("getSizeInBits called on extended MVT.");
807       case Other:
808         llvm_unreachable("Value type is non-standard value, Other.");
809       case iPTR:
810         llvm_unreachable("Value type size is target-dependent. Ask TLI.");
811       case iPTRAny:
812       case iAny:
813       case fAny:
814       case vAny:
815       case Any:
816         llvm_unreachable("Value type is overloaded.");
817       case token:
818         llvm_unreachable("Token type is a sentinel that cannot be used "
819                          "in codegen and has no size");
820       case Metadata:
821         llvm_unreachable("Value type is metadata.");
822       case i1:
823       case v1i1: return TypeSize::Fixed(1);
824       case nxv1i1: return TypeSize::Scalable(1);
825       case v2i1: return TypeSize::Fixed(2);
826       case nxv2i1: return TypeSize::Scalable(2);
827       case v4i1: return TypeSize::Fixed(4);
828       case nxv4i1: return TypeSize::Scalable(4);
829       case i8  :
830       case v1i8:
831       case v8i1: return TypeSize::Fixed(8);
832       case nxv1i8:
833       case nxv8i1: return TypeSize::Scalable(8);
834       case i16 :
835       case f16:
836       case bf16:
837       case v16i1:
838       case v2i8:
839       case v1i16: return TypeSize::Fixed(16);
840       case nxv16i1:
841       case nxv2i8:
842       case nxv1i16:
843       case nxv1f16: return TypeSize::Scalable(16);
844       case f32 :
845       case i32 :
846       case v32i1:
847       case v4i8:
848       case v2i16:
849       case v2f16:
850       case v2bf16:
851       case v1f32:
852       case v1i32: return TypeSize::Fixed(32);
853       case nxv32i1:
854       case nxv4i8:
855       case nxv2i16:
856       case nxv1i32:
857       case nxv2f16:
858       case nxv2bf16:
859       case nxv1f32: return TypeSize::Scalable(32);
860       case v3i16:
861       case v3f16:
862       case v3bf16: return TypeSize::Fixed(48);
863       case x86mmx:
864       case f64 :
865       case i64 :
866       case v64i1:
867       case v8i8:
868       case v4i16:
869       case v2i32:
870       case v1i64:
871       case v4f16:
872       case v4bf16:
873       case v2f32:
874       case v1f64: return TypeSize::Fixed(64);
875       case nxv64i1:
876       case nxv8i8:
877       case nxv4i16:
878       case nxv2i32:
879       case nxv1i64:
880       case nxv4f16:
881       case nxv4bf16:
882       case nxv2f32:
883       case nxv1f64: return TypeSize::Scalable(64);
884       case f80 :  return TypeSize::Fixed(80);
885       case v3i32:
886       case v3f32: return TypeSize::Fixed(96);
887       case f128:
888       case ppcf128:
889       case i128:
890       case v128i1:
891       case v16i8:
892       case v8i16:
893       case v4i32:
894       case v2i64:
895       case v1i128:
896       case v8f16:
897       case v8bf16:
898       case v4f32:
899       case v2f64: return TypeSize::Fixed(128);
900       case nxv16i8:
901       case nxv8i16:
902       case nxv4i32:
903       case nxv2i64:
904       case nxv8f16:
905       case nxv8bf16:
906       case nxv4f32:
907       case nxv2f64: return TypeSize::Scalable(128);
908       case v5i32:
909       case v5f32: return TypeSize::Fixed(160);
910       case v256i1:
911       case v32i8:
912       case v16i16:
913       case v8i32:
914       case v4i64:
915       case v16f16:
916       case v16bf16:
917       case v8f32:
918       case v4f64: return TypeSize::Fixed(256);
919       case nxv32i8:
920       case nxv16i16:
921       case nxv8i32:
922       case nxv4i64:
923       case nxv16f16:
924       case nxv8f32:
925       case nxv4f64: return TypeSize::Scalable(256);
926       case v512i1:
927       case v64i8:
928       case v32i16:
929       case v16i32:
930       case v8i64:
931       case v32f16:
932       case v32bf16:
933       case v16f32:
934       case v8f64: return TypeSize::Fixed(512);
935       case nxv64i8:
936       case nxv32i16:
937       case nxv16i32:
938       case nxv8i64:
939       case nxv32f16:
940       case nxv16f32:
941       case nxv8f64: return TypeSize::Scalable(512);
942       case v1024i1:
943       case v128i8:
944       case v64i16:
945       case v32i32:
946       case v16i64:
947       case v64f16:
948       case v64bf16:
949       case v32f32:
950       case v16f64: return TypeSize::Fixed(1024);
951       case nxv32i32:
952       case nxv16i64: return TypeSize::Scalable(1024);
953       case v256i8:
954       case v128i16:
955       case v64i32:
956       case v32i64:
957       case v128f16:
958       case v128bf16:
959       case v64f32:
960       case v32f64: return TypeSize::Fixed(2048);
961       case nxv32i64: return TypeSize::Scalable(2048);
962       case v128i32:
963       case v64i64:
964       case v128f32:
965       case v64f64:  return TypeSize::Fixed(4096);
966       case v256i32:
967       case v128i64:
968       case v256f32:
969       case v128f64:  return TypeSize::Fixed(8192);
970       case v512i32:
971       case v256i64:
972       case v512f32:
973       case v256f64:  return TypeSize::Fixed(16384);
974       case v1024i32:
975       case v1024f32:  return TypeSize::Fixed(32768);
976       case v2048i32:
977       case v2048f32:  return TypeSize::Fixed(65536);
978       case exnref:
979       case funcref:
980       case externref: return TypeSize::Fixed(0); // opaque type
981       }
982     }
983 
984     /// Return the size of the specified fixed width value type in bits. The
985     /// function will assert if the type is scalable.
getFixedSizeInBits()986     uint64_t getFixedSizeInBits() const {
987       return getSizeInBits().getFixedSize();
988     }
989 
getScalarSizeInBits()990     uint64_t getScalarSizeInBits() const {
991       return getScalarType().getSizeInBits().getFixedSize();
992     }
993 
994     /// Return the number of bytes overwritten by a store of the specified value
995     /// type.
996     ///
997     /// If the value type is a scalable vector type, the scalable property will
998     /// be set and the runtime size will be a positive integer multiple of the
999     /// base size.
getStoreSize()1000     TypeSize getStoreSize() const {
1001       TypeSize BaseSize = getSizeInBits();
1002       return {(BaseSize.getKnownMinSize() + 7) / 8, BaseSize.isScalable()};
1003     }
1004 
1005     /// Return the number of bits overwritten by a store of the specified value
1006     /// type.
1007     ///
1008     /// If the value type is a scalable vector type, the scalable property will
1009     /// be set and the runtime size will be a positive integer multiple of the
1010     /// base size.
getStoreSizeInBits()1011     TypeSize getStoreSizeInBits() const {
1012       return getStoreSize() * 8;
1013     }
1014 
1015     /// Returns true if the number of bits for the type is a multiple of an
1016     /// 8-bit byte.
isByteSized()1017     bool isByteSized() const { return getSizeInBits().isKnownMultipleOf(8); }
1018 
1019     /// Return true if we know at compile time this has more bits than VT.
knownBitsGT(MVT VT)1020     bool knownBitsGT(MVT VT) const {
1021       return TypeSize::isKnownGT(getSizeInBits(), VT.getSizeInBits());
1022     }
1023 
1024     /// Return true if we know at compile time this has more than or the same
1025     /// bits as VT.
knownBitsGE(MVT VT)1026     bool knownBitsGE(MVT VT) const {
1027       return TypeSize::isKnownGE(getSizeInBits(), VT.getSizeInBits());
1028     }
1029 
1030     /// Return true if we know at compile time this has fewer bits than VT.
knownBitsLT(MVT VT)1031     bool knownBitsLT(MVT VT) const {
1032       return TypeSize::isKnownLT(getSizeInBits(), VT.getSizeInBits());
1033     }
1034 
1035     /// Return true if we know at compile time this has fewer than or the same
1036     /// bits as VT.
knownBitsLE(MVT VT)1037     bool knownBitsLE(MVT VT) const {
1038       return TypeSize::isKnownLE(getSizeInBits(), VT.getSizeInBits());
1039     }
1040 
1041     /// Return true if this has more bits than VT.
bitsGT(MVT VT)1042     bool bitsGT(MVT VT) const {
1043       assert(isScalableVector() == VT.isScalableVector() &&
1044              "Comparison between scalable and fixed types");
1045       return knownBitsGT(VT);
1046     }
1047 
1048     /// Return true if this has no less bits than VT.
bitsGE(MVT VT)1049     bool bitsGE(MVT VT) const {
1050       assert(isScalableVector() == VT.isScalableVector() &&
1051              "Comparison between scalable and fixed types");
1052       return knownBitsGE(VT);
1053     }
1054 
1055     /// Return true if this has less bits than VT.
bitsLT(MVT VT)1056     bool bitsLT(MVT VT) const {
1057       assert(isScalableVector() == VT.isScalableVector() &&
1058              "Comparison between scalable and fixed types");
1059       return knownBitsLT(VT);
1060     }
1061 
1062     /// Return true if this has no more bits than VT.
bitsLE(MVT VT)1063     bool bitsLE(MVT VT) const {
1064       assert(isScalableVector() == VT.isScalableVector() &&
1065              "Comparison between scalable and fixed types");
1066       return knownBitsLE(VT);
1067     }
1068 
getFloatingPointVT(unsigned BitWidth)1069     static MVT getFloatingPointVT(unsigned BitWidth) {
1070       switch (BitWidth) {
1071       default:
1072         llvm_unreachable("Bad bit width!");
1073       case 16:
1074         return MVT::f16;
1075       case 32:
1076         return MVT::f32;
1077       case 64:
1078         return MVT::f64;
1079       case 80:
1080         return MVT::f80;
1081       case 128:
1082         return MVT::f128;
1083       }
1084     }
1085 
getIntegerVT(unsigned BitWidth)1086     static MVT getIntegerVT(unsigned BitWidth) {
1087       switch (BitWidth) {
1088       default:
1089         return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
1090       case 1:
1091         return MVT::i1;
1092       case 8:
1093         return MVT::i8;
1094       case 16:
1095         return MVT::i16;
1096       case 32:
1097         return MVT::i32;
1098       case 64:
1099         return MVT::i64;
1100       case 128:
1101         return MVT::i128;
1102       }
1103     }
1104 
getVectorVT(MVT VT,unsigned NumElements)1105     static MVT getVectorVT(MVT VT, unsigned NumElements) {
1106       switch (VT.SimpleTy) {
1107       default:
1108         break;
1109       case MVT::i1:
1110         if (NumElements == 1)    return MVT::v1i1;
1111         if (NumElements == 2)    return MVT::v2i1;
1112         if (NumElements == 4)    return MVT::v4i1;
1113         if (NumElements == 8)    return MVT::v8i1;
1114         if (NumElements == 16)   return MVT::v16i1;
1115         if (NumElements == 32)   return MVT::v32i1;
1116         if (NumElements == 64)   return MVT::v64i1;
1117         if (NumElements == 128)  return MVT::v128i1;
1118         if (NumElements == 256)  return MVT::v256i1;
1119         if (NumElements == 512)  return MVT::v512i1;
1120         if (NumElements == 1024) return MVT::v1024i1;
1121         break;
1122       case MVT::i8:
1123         if (NumElements == 1)   return MVT::v1i8;
1124         if (NumElements == 2)   return MVT::v2i8;
1125         if (NumElements == 4)   return MVT::v4i8;
1126         if (NumElements == 8)   return MVT::v8i8;
1127         if (NumElements == 16)  return MVT::v16i8;
1128         if (NumElements == 32)  return MVT::v32i8;
1129         if (NumElements == 64)  return MVT::v64i8;
1130         if (NumElements == 128) return MVT::v128i8;
1131         if (NumElements == 256) return MVT::v256i8;
1132         break;
1133       case MVT::i16:
1134         if (NumElements == 1)   return MVT::v1i16;
1135         if (NumElements == 2)   return MVT::v2i16;
1136         if (NumElements == 3)   return MVT::v3i16;
1137         if (NumElements == 4)   return MVT::v4i16;
1138         if (NumElements == 8)   return MVT::v8i16;
1139         if (NumElements == 16)  return MVT::v16i16;
1140         if (NumElements == 32)  return MVT::v32i16;
1141         if (NumElements == 64)  return MVT::v64i16;
1142         if (NumElements == 128) return MVT::v128i16;
1143         break;
1144       case MVT::i32:
1145         if (NumElements == 1)    return MVT::v1i32;
1146         if (NumElements == 2)    return MVT::v2i32;
1147         if (NumElements == 3)    return MVT::v3i32;
1148         if (NumElements == 4)    return MVT::v4i32;
1149         if (NumElements == 5)    return MVT::v5i32;
1150         if (NumElements == 8)    return MVT::v8i32;
1151         if (NumElements == 16)   return MVT::v16i32;
1152         if (NumElements == 32)   return MVT::v32i32;
1153         if (NumElements == 64)   return MVT::v64i32;
1154         if (NumElements == 128)  return MVT::v128i32;
1155         if (NumElements == 256)  return MVT::v256i32;
1156         if (NumElements == 512)  return MVT::v512i32;
1157         if (NumElements == 1024) return MVT::v1024i32;
1158         if (NumElements == 2048) return MVT::v2048i32;
1159         break;
1160       case MVT::i64:
1161         if (NumElements == 1)  return MVT::v1i64;
1162         if (NumElements == 2)  return MVT::v2i64;
1163         if (NumElements == 4)  return MVT::v4i64;
1164         if (NumElements == 8)  return MVT::v8i64;
1165         if (NumElements == 16) return MVT::v16i64;
1166         if (NumElements == 32) return MVT::v32i64;
1167         if (NumElements == 64) return MVT::v64i64;
1168         if (NumElements == 128) return MVT::v128i64;
1169         if (NumElements == 256) return MVT::v256i64;
1170         break;
1171       case MVT::i128:
1172         if (NumElements == 1)  return MVT::v1i128;
1173         break;
1174       case MVT::f16:
1175         if (NumElements == 2)   return MVT::v2f16;
1176         if (NumElements == 3)   return MVT::v3f16;
1177         if (NumElements == 4)   return MVT::v4f16;
1178         if (NumElements == 8)   return MVT::v8f16;
1179         if (NumElements == 16)  return MVT::v16f16;
1180         if (NumElements == 32)  return MVT::v32f16;
1181         if (NumElements == 64)  return MVT::v64f16;
1182         if (NumElements == 128) return MVT::v128f16;
1183         break;
1184       case MVT::bf16:
1185         if (NumElements == 2)   return MVT::v2bf16;
1186         if (NumElements == 3)   return MVT::v3bf16;
1187         if (NumElements == 4)   return MVT::v4bf16;
1188         if (NumElements == 8)   return MVT::v8bf16;
1189         if (NumElements == 16)  return MVT::v16bf16;
1190         if (NumElements == 32)  return MVT::v32bf16;
1191         if (NumElements == 64)  return MVT::v64bf16;
1192         if (NumElements == 128) return MVT::v128bf16;
1193         break;
1194       case MVT::f32:
1195         if (NumElements == 1)    return MVT::v1f32;
1196         if (NumElements == 2)    return MVT::v2f32;
1197         if (NumElements == 3)    return MVT::v3f32;
1198         if (NumElements == 4)    return MVT::v4f32;
1199         if (NumElements == 5)    return MVT::v5f32;
1200         if (NumElements == 8)    return MVT::v8f32;
1201         if (NumElements == 16)   return MVT::v16f32;
1202         if (NumElements == 32)   return MVT::v32f32;
1203         if (NumElements == 64)   return MVT::v64f32;
1204         if (NumElements == 128)  return MVT::v128f32;
1205         if (NumElements == 256)  return MVT::v256f32;
1206         if (NumElements == 512)  return MVT::v512f32;
1207         if (NumElements == 1024) return MVT::v1024f32;
1208         if (NumElements == 2048) return MVT::v2048f32;
1209         break;
1210       case MVT::f64:
1211         if (NumElements == 1)  return MVT::v1f64;
1212         if (NumElements == 2)  return MVT::v2f64;
1213         if (NumElements == 4)  return MVT::v4f64;
1214         if (NumElements == 8)  return MVT::v8f64;
1215         if (NumElements == 16) return MVT::v16f64;
1216         if (NumElements == 32) return MVT::v32f64;
1217         if (NumElements == 64) return MVT::v64f64;
1218         if (NumElements == 128) return MVT::v128f64;
1219         if (NumElements == 256) return MVT::v256f64;
1220         break;
1221       }
1222       return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
1223     }
1224 
getScalableVectorVT(MVT VT,unsigned NumElements)1225     static MVT getScalableVectorVT(MVT VT, unsigned NumElements) {
1226       switch(VT.SimpleTy) {
1227         default:
1228           break;
1229         case MVT::i1:
1230           if (NumElements == 1)  return MVT::nxv1i1;
1231           if (NumElements == 2)  return MVT::nxv2i1;
1232           if (NumElements == 4)  return MVT::nxv4i1;
1233           if (NumElements == 8)  return MVT::nxv8i1;
1234           if (NumElements == 16) return MVT::nxv16i1;
1235           if (NumElements == 32) return MVT::nxv32i1;
1236           if (NumElements == 64) return MVT::nxv64i1;
1237           break;
1238         case MVT::i8:
1239           if (NumElements == 1)  return MVT::nxv1i8;
1240           if (NumElements == 2)  return MVT::nxv2i8;
1241           if (NumElements == 4)  return MVT::nxv4i8;
1242           if (NumElements == 8)  return MVT::nxv8i8;
1243           if (NumElements == 16) return MVT::nxv16i8;
1244           if (NumElements == 32) return MVT::nxv32i8;
1245           if (NumElements == 64) return MVT::nxv64i8;
1246           break;
1247         case MVT::i16:
1248           if (NumElements == 1)  return MVT::nxv1i16;
1249           if (NumElements == 2)  return MVT::nxv2i16;
1250           if (NumElements == 4)  return MVT::nxv4i16;
1251           if (NumElements == 8)  return MVT::nxv8i16;
1252           if (NumElements == 16) return MVT::nxv16i16;
1253           if (NumElements == 32) return MVT::nxv32i16;
1254           break;
1255         case MVT::i32:
1256           if (NumElements == 1)  return MVT::nxv1i32;
1257           if (NumElements == 2)  return MVT::nxv2i32;
1258           if (NumElements == 4)  return MVT::nxv4i32;
1259           if (NumElements == 8)  return MVT::nxv8i32;
1260           if (NumElements == 16) return MVT::nxv16i32;
1261           if (NumElements == 32) return MVT::nxv32i32;
1262           break;
1263         case MVT::i64:
1264           if (NumElements == 1)  return MVT::nxv1i64;
1265           if (NumElements == 2)  return MVT::nxv2i64;
1266           if (NumElements == 4)  return MVT::nxv4i64;
1267           if (NumElements == 8)  return MVT::nxv8i64;
1268           if (NumElements == 16) return MVT::nxv16i64;
1269           if (NumElements == 32) return MVT::nxv32i64;
1270           break;
1271         case MVT::f16:
1272           if (NumElements == 1)  return MVT::nxv1f16;
1273           if (NumElements == 2)  return MVT::nxv2f16;
1274           if (NumElements == 4)  return MVT::nxv4f16;
1275           if (NumElements == 8)  return MVT::nxv8f16;
1276           if (NumElements == 16)  return MVT::nxv16f16;
1277           if (NumElements == 32)  return MVT::nxv32f16;
1278           break;
1279         case MVT::bf16:
1280           if (NumElements == 2)  return MVT::nxv2bf16;
1281           if (NumElements == 4)  return MVT::nxv4bf16;
1282           if (NumElements == 8)  return MVT::nxv8bf16;
1283           break;
1284         case MVT::f32:
1285           if (NumElements == 1)  return MVT::nxv1f32;
1286           if (NumElements == 2)  return MVT::nxv2f32;
1287           if (NumElements == 4)  return MVT::nxv4f32;
1288           if (NumElements == 8)  return MVT::nxv8f32;
1289           if (NumElements == 16) return MVT::nxv16f32;
1290           break;
1291         case MVT::f64:
1292           if (NumElements == 1)  return MVT::nxv1f64;
1293           if (NumElements == 2)  return MVT::nxv2f64;
1294           if (NumElements == 4)  return MVT::nxv4f64;
1295           if (NumElements == 8)  return MVT::nxv8f64;
1296           break;
1297       }
1298       return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
1299     }
1300 
getVectorVT(MVT VT,unsigned NumElements,bool IsScalable)1301     static MVT getVectorVT(MVT VT, unsigned NumElements, bool IsScalable) {
1302       if (IsScalable)
1303         return getScalableVectorVT(VT, NumElements);
1304       return getVectorVT(VT, NumElements);
1305     }
1306 
getVectorVT(MVT VT,ElementCount EC)1307     static MVT getVectorVT(MVT VT, ElementCount EC) {
1308       if (EC.isScalable())
1309         return getScalableVectorVT(VT, EC.getKnownMinValue());
1310       return getVectorVT(VT, EC.getKnownMinValue());
1311     }
1312 
1313     /// Return the value type corresponding to the specified type.  This returns
1314     /// all pointers as iPTR.  If HandleUnknown is true, unknown types are
1315     /// returned as Other, otherwise they are invalid.
1316     static MVT getVT(Type *Ty, bool HandleUnknown = false);
1317 
1318   private:
1319     /// A simple iterator over the MVT::SimpleValueType enum.
1320     struct mvt_iterator {
1321       SimpleValueType VT;
1322 
mvt_iteratormvt_iterator1323       mvt_iterator(SimpleValueType VT) : VT(VT) {}
1324 
1325       MVT operator*() const { return VT; }
1326       bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
1327 
1328       mvt_iterator& operator++() {
1329         VT = (MVT::SimpleValueType)((int)VT + 1);
1330         assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
1331                "MVT iterator overflowed.");
1332         return *this;
1333       }
1334     };
1335 
1336     /// A range of the MVT::SimpleValueType enum.
1337     using mvt_range = iterator_range<mvt_iterator>;
1338 
1339   public:
1340     /// SimpleValueType Iteration
1341     /// @{
all_valuetypes()1342     static mvt_range all_valuetypes() {
1343       return mvt_range(MVT::FIRST_VALUETYPE, MVT::LAST_VALUETYPE);
1344     }
1345 
integer_valuetypes()1346     static mvt_range integer_valuetypes() {
1347       return mvt_range(MVT::FIRST_INTEGER_VALUETYPE,
1348                        (MVT::SimpleValueType)(MVT::LAST_INTEGER_VALUETYPE + 1));
1349     }
1350 
fp_valuetypes()1351     static mvt_range fp_valuetypes() {
1352       return mvt_range(MVT::FIRST_FP_VALUETYPE,
1353                        (MVT::SimpleValueType)(MVT::LAST_FP_VALUETYPE + 1));
1354     }
1355 
vector_valuetypes()1356     static mvt_range vector_valuetypes() {
1357       return mvt_range(MVT::FIRST_VECTOR_VALUETYPE,
1358                        (MVT::SimpleValueType)(MVT::LAST_VECTOR_VALUETYPE + 1));
1359     }
1360 
fixedlen_vector_valuetypes()1361     static mvt_range fixedlen_vector_valuetypes() {
1362       return mvt_range(
1363                MVT::FIRST_FIXEDLEN_VECTOR_VALUETYPE,
1364                (MVT::SimpleValueType)(MVT::LAST_FIXEDLEN_VECTOR_VALUETYPE + 1));
1365     }
1366 
scalable_vector_valuetypes()1367     static mvt_range scalable_vector_valuetypes() {
1368       return mvt_range(
1369                MVT::FIRST_SCALABLE_VECTOR_VALUETYPE,
1370                (MVT::SimpleValueType)(MVT::LAST_SCALABLE_VECTOR_VALUETYPE + 1));
1371     }
1372 
integer_fixedlen_vector_valuetypes()1373     static mvt_range integer_fixedlen_vector_valuetypes() {
1374       return mvt_range(
1375        MVT::FIRST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE,
1376        (MVT::SimpleValueType)(MVT::LAST_INTEGER_FIXEDLEN_VECTOR_VALUETYPE + 1));
1377     }
1378 
fp_fixedlen_vector_valuetypes()1379     static mvt_range fp_fixedlen_vector_valuetypes() {
1380       return mvt_range(
1381           MVT::FIRST_FP_FIXEDLEN_VECTOR_VALUETYPE,
1382           (MVT::SimpleValueType)(MVT::LAST_FP_FIXEDLEN_VECTOR_VALUETYPE + 1));
1383     }
1384 
integer_scalable_vector_valuetypes()1385     static mvt_range integer_scalable_vector_valuetypes() {
1386       return mvt_range(
1387        MVT::FIRST_INTEGER_SCALABLE_VECTOR_VALUETYPE,
1388        (MVT::SimpleValueType)(MVT::LAST_INTEGER_SCALABLE_VECTOR_VALUETYPE + 1));
1389     }
1390 
fp_scalable_vector_valuetypes()1391     static mvt_range fp_scalable_vector_valuetypes() {
1392       return mvt_range(
1393             MVT::FIRST_FP_SCALABLE_VECTOR_VALUETYPE,
1394             (MVT::SimpleValueType)(MVT::LAST_FP_SCALABLE_VECTOR_VALUETYPE + 1));
1395     }
1396     /// @}
1397   };
1398 
1399 } // end namespace llvm
1400 
1401 #endif // LLVM_CODEGEN_MACHINEVALUETYPE_H
1402