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