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