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