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