LLVM  10.0.0
MachineValueType.h
Go to the documentation of this file.
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 
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.
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 
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 
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  v256i1 = 22, // 256 x i1
69  v512i1 = 23, // 512 x i1
70  v1024i1 = 24, // 1024 x i1
71 
72  v1i8 = 25, // 1 x i8
73  v2i8 = 26, // 2 x i8
74  v4i8 = 27, // 4 x i8
75  v8i8 = 28, // 8 x i8
76  v16i8 = 29, // 16 x i8
77  v32i8 = 30, // 32 x i8
78  v64i8 = 31, // 64 x i8
79  v128i8 = 32, //128 x i8
80  v256i8 = 33, //256 x i8
81 
82  v1i16 = 34, // 1 x i16
83  v2i16 = 35, // 2 x i16
84  v3i16 = 36, // 3 x i16
85  v4i16 = 37, // 4 x i16
86  v8i16 = 38, // 8 x i16
87  v16i16 = 39, // 16 x i16
88  v32i16 = 40, // 32 x i16
89  v64i16 = 41, // 64 x i16
90  v128i16 = 42, //128 x i16
91 
92  v1i32 = 43, // 1 x i32
93  v2i32 = 44, // 2 x i32
94  v3i32 = 45, // 3 x i32
95  v4i32 = 46, // 4 x i32
96  v5i32 = 47, // 5 x i32
97  v8i32 = 48, // 8 x i32
98  v16i32 = 49, // 16 x i32
99  v32i32 = 50, // 32 x i32
100  v64i32 = 51, // 64 x i32
101  v128i32 = 52, // 128 x i32
102  v256i32 = 53, // 256 x i32
103  v512i32 = 54, // 512 x i32
104  v1024i32 = 55, // 1024 x i32
105  v2048i32 = 56, // 2048 x i32
106 
107  v1i64 = 57, // 1 x i64
108  v2i64 = 58, // 2 x i64
109  v4i64 = 59, // 4 x i64
110  v8i64 = 60, // 8 x i64
111  v16i64 = 61, // 16 x i64
112  v32i64 = 62, // 32 x i64
113 
114  v1i128 = 63, // 1 x i128
115 
118 
119  v2f16 = 64, // 2 x f16
120  v3f16 = 65, // 3 x f16
121  v4f16 = 66, // 4 x f16
122  v8f16 = 67, // 8 x f16
123  v16f16 = 68, // 16 x f16
124  v32f16 = 69, // 32 x f16
125  v1f32 = 70, // 1 x f32
126  v2f32 = 71, // 2 x f32
127  v3f32 = 72, // 3 x f32
128  v4f32 = 73, // 4 x f32
129  v5f32 = 74, // 5 x f32
130  v8f32 = 75, // 8 x f32
131  v16f32 = 76, // 16 x f32
132  v32f32 = 77, // 32 x f32
133  v64f32 = 78, // 64 x f32
134  v128f32 = 79, // 128 x f32
135  v256f32 = 80, // 256 x f32
136  v512f32 = 81, // 512 x f32
137  v1024f32 = 82, // 1024 x f32
138  v2048f32 = 83, // 2048 x f32
139  v1f64 = 84, // 1 x f64
140  v2f64 = 85, // 2 x f64
141  v4f64 = 86, // 4 x f64
142  v8f64 = 87, // 8 x f64
143 
146 
149 
150  nxv1i1 = 88, // n x 1 x i1
151  nxv2i1 = 89, // n x 2 x i1
152  nxv4i1 = 90, // n x 4 x i1
153  nxv8i1 = 91, // n x 8 x i1
154  nxv16i1 = 92, // n x 16 x i1
155  nxv32i1 = 93, // n x 32 x i1
156 
157  nxv1i8 = 94, // n x 1 x i8
158  nxv2i8 = 95, // n x 2 x i8
159  nxv4i8 = 96, // n x 4 x i8
160  nxv8i8 = 97, // n x 8 x i8
161  nxv16i8 = 98, // n x 16 x i8
162  nxv32i8 = 99, // n x 32 x i8
163 
164  nxv1i16 = 100, // n x 1 x i16
165  nxv2i16 = 101, // n x 2 x i16
166  nxv4i16 = 102, // n x 4 x i16
167  nxv8i16 = 103, // n x 8 x i16
168  nxv16i16 = 104, // n x 16 x i16
169  nxv32i16 = 105, // n x 32 x i16
170 
171  nxv1i32 = 106, // n x 1 x i32
172  nxv2i32 = 107, // n x 2 x i32
173  nxv4i32 = 108, // n x 4 x i32
174  nxv8i32 = 109, // n x 8 x i32
175  nxv16i32 = 110, // n x 16 x i32
176  nxv32i32 = 111, // n x 32 x i32
177 
178  nxv1i64 = 112, // n x 1 x i64
179  nxv2i64 = 113, // n x 2 x i64
180  nxv4i64 = 114, // n x 4 x i64
181  nxv8i64 = 115, // n x 8 x i64
182  nxv16i64 = 116, // n x 16 x i64
183  nxv32i64 = 117, // n x 32 x i64
184 
187 
188  nxv2f16 = 118, // n x 2 x f16
189  nxv4f16 = 119, // n x 4 x f16
190  nxv8f16 = 120, // n x 8 x f16
191  nxv1f32 = 121, // n x 1 x f32
192  nxv2f32 = 122, // n x 2 x f32
193  nxv4f32 = 123, // n x 4 x f32
194  nxv8f32 = 124, // n x 8 x f32
195  nxv16f32 = 125, // n x 16 x f32
196  nxv1f64 = 126, // n x 1 x f64
197  nxv2f64 = 127, // n x 2 x f64
198  nxv4f64 = 128, // n x 4 x f64
199  nxv8f64 = 129, // n x 8 x f64
200 
203 
206 
209 
210  x86mmx = 130, // This is an X86 MMX value
211 
212  Glue = 131, // This glues nodes together during pre-RA sched
213 
214  isVoid = 132, // This has no value
215 
216  Untyped = 133, // This value takes a register, but has
217  // unspecified type. The register class
218  // will be determined by the opcode.
219 
220  exnref = 134, // WebAssembly's exnref type
221 
222  FIRST_VALUETYPE = 1, // This is always the beginning of the list.
223  LAST_VALUETYPE = 135, // This always remains at the end of the list.
224 
225  // This is the current maximum for LAST_VALUETYPE.
226  // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
227  // This value must be a multiple of 32.
229 
230  // A value of type llvm::TokenTy
231  token = 248,
232 
233  // This is MDNode or MDString.
234  Metadata = 249,
235 
236  // An int value the size of the pointer of the current
237  // target to any address space. This must only be used internal to
238  // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
239  iPTRAny = 250,
240 
241  // A vector with any length and element size. This is used
242  // for intrinsics that have overloadings based on vector types.
243  // This is only for tblgen's consumption!
244  vAny = 251,
245 
246  // Any floating-point or vector floating-point value. This is used
247  // for intrinsics that have overloadings based on floating-point types.
248  // This is only for tblgen's consumption!
249  fAny = 252,
250 
251  // An integer or vector integer value of any bit width. This is
252  // used for intrinsics that have overloadings based on integer bit widths.
253  // This is only for tblgen's consumption!
254  iAny = 253,
255 
256  // An int value the size of the pointer of the current
257  // target. This should only be used internal to tblgen!
258  iPTR = 254,
259 
260  // Any type. This is used for intrinsics that have overloadings.
261  // This is only for tblgen's consumption!
262  Any = 255
263  };
264 
266 
267  constexpr MVT() = default;
268  constexpr MVT(SimpleValueType SVT) : SimpleTy(SVT) {}
269 
270  bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; }
271  bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; }
272  bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
273  bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
274  bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
275  bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
276 
277  /// Return true if this is a valid simple valuetype.
278  bool isValid() const {
279  return (SimpleTy >= MVT::FIRST_VALUETYPE &&
280  SimpleTy < MVT::LAST_VALUETYPE);
281  }
282 
283  /// Return true if this is a FP or a vector FP type.
284  bool isFloatingPoint() const {
285  return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
286  SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
291  }
292 
293  /// Return true if this is an integer or a vector integer type.
294  bool isInteger() const {
295  return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
296  SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
301  }
302 
303  /// Return true if this is an integer, not including vectors.
304  bool isScalarInteger() const {
305  return (SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
306  SimpleTy <= MVT::LAST_INTEGER_VALUETYPE);
307  }
308 
309  /// Return true if this is a vector value type.
310  bool isVector() const {
311  return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
312  SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
313  }
314 
315  /// Return true if this is a vector value type where the
316  /// runtime length is machine dependent
317  bool isScalableVector() const {
318  return (SimpleTy >= MVT::FIRST_SCALABLE_VECTOR_VALUETYPE &&
320  }
321 
322  bool isFixedLengthVector() const {
323  return (SimpleTy >= MVT::FIRST_FIXEDLEN_VECTOR_VALUETYPE &&
325  }
326 
327  /// Return true if this is a 16-bit vector type.
328  bool is16BitVector() const {
329  return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 ||
330  SimpleTy == MVT::v16i1);
331  }
332 
333  /// Return true if this is a 32-bit vector type.
334  bool is32BitVector() const {
335  return (SimpleTy == MVT::v32i1 || SimpleTy == MVT::v4i8 ||
336  SimpleTy == MVT::v2i16 || SimpleTy == MVT::v1i32 ||
337  SimpleTy == MVT::v2f16 || SimpleTy == MVT::v1f32);
338  }
339 
340  /// Return true if this is a 64-bit vector type.
341  bool is64BitVector() const {
342  return (SimpleTy == MVT::v64i1 || SimpleTy == MVT::v8i8 ||
343  SimpleTy == MVT::v4i16 || SimpleTy == MVT::v2i32 ||
344  SimpleTy == MVT::v1i64 || SimpleTy == MVT::v4f16 ||
345  SimpleTy == MVT::v2f32 || SimpleTy == MVT::v1f64);
346  }
347 
348  /// Return true if this is a 128-bit vector type.
349  bool is128BitVector() const {
350  return (SimpleTy == MVT::v128i1 || SimpleTy == MVT::v16i8 ||
351  SimpleTy == MVT::v8i16 || SimpleTy == MVT::v4i32 ||
352  SimpleTy == MVT::v2i64 || SimpleTy == MVT::v1i128 ||
353  SimpleTy == MVT::v8f16 || SimpleTy == MVT::v4f32 ||
354  SimpleTy == MVT::v2f64);
355  }
356 
357  /// Return true if this is a 256-bit vector type.
358  bool is256BitVector() const {
359  return (SimpleTy == MVT::v16f16 || SimpleTy == MVT::v8f32 ||
360  SimpleTy == MVT::v4f64 || SimpleTy == MVT::v32i8 ||
361  SimpleTy == MVT::v16i16 || SimpleTy == MVT::v8i32 ||
362  SimpleTy == MVT::v4i64 || SimpleTy == MVT::v256i1);
363  }
364 
365  /// Return true if this is a 512-bit vector type.
366  bool is512BitVector() const {
367  return (SimpleTy == MVT::v32f16 || SimpleTy == MVT::v16f32 ||
368  SimpleTy == MVT::v8f64 || SimpleTy == MVT::v512i1 ||
369  SimpleTy == MVT::v64i8 || SimpleTy == MVT::v32i16 ||
370  SimpleTy == MVT::v16i32 || SimpleTy == MVT::v8i64);
371  }
372 
373  /// Return true if this is a 1024-bit vector type.
374  bool is1024BitVector() const {
375  return (SimpleTy == MVT::v1024i1 || SimpleTy == MVT::v128i8 ||
376  SimpleTy == MVT::v64i16 || SimpleTy == MVT::v32i32 ||
377  SimpleTy == MVT::v16i64);
378  }
379 
380  /// Return true if this is a 2048-bit vector type.
381  bool is2048BitVector() const {
382  return (SimpleTy == MVT::v256i8 || SimpleTy == MVT::v128i16 ||
383  SimpleTy == MVT::v64i32 || SimpleTy == MVT::v32i64);
384  }
385 
386  /// Return true if this is an overloaded type for TableGen.
387  bool isOverloaded() const {
388  return (SimpleTy==MVT::Any ||
389  SimpleTy==MVT::iAny || SimpleTy==MVT::fAny ||
390  SimpleTy==MVT::vAny || SimpleTy==MVT::iPTRAny);
391  }
392 
393  /// Return a VT for a vector type with the same element type but
394  /// half the number of elements.
396  MVT EltVT = getVectorElementType();
397  auto EltCnt = getVectorElementCount();
398  assert(!(EltCnt.Min & 1) && "Splitting vector, but not in half!");
399  return getVectorVT(EltVT, EltCnt / 2);
400  }
401 
402  /// Returns true if the given vector is a power of 2.
403  bool isPow2VectorType() const {
404  unsigned NElts = getVectorNumElements();
405  return !(NElts & (NElts - 1));
406  }
407 
408  /// Widens the length of the given vector MVT up to the nearest power of 2
409  /// and returns that type.
411  if (isPow2VectorType())
412  return *this;
413 
414  unsigned NElts = getVectorNumElements();
415  unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
416  return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
417  }
418 
419  /// If this is a vector, return the element type, otherwise return this.
420  MVT getScalarType() const {
421  return isVector() ? getVectorElementType() : *this;
422  }
423 
425  switch (SimpleTy) {
426  default:
427  llvm_unreachable("Not a vector MVT!");
428  case v1i1:
429  case v2i1:
430  case v4i1:
431  case v8i1:
432  case v16i1:
433  case v32i1:
434  case v64i1:
435  case v128i1:
436  case v256i1:
437  case v512i1:
438  case v1024i1:
439  case nxv1i1:
440  case nxv2i1:
441  case nxv4i1:
442  case nxv8i1:
443  case nxv16i1:
444  case nxv32i1: return i1;
445  case v1i8:
446  case v2i8:
447  case v4i8:
448  case v8i8:
449  case v16i8:
450  case v32i8:
451  case v64i8:
452  case v128i8:
453  case v256i8:
454  case nxv1i8:
455  case nxv2i8:
456  case nxv4i8:
457  case nxv8i8:
458  case nxv16i8:
459  case nxv32i8: return i8;
460  case v1i16:
461  case v2i16:
462  case v3i16:
463  case v4i16:
464  case v8i16:
465  case v16i16:
466  case v32i16:
467  case v64i16:
468  case v128i16:
469  case nxv1i16:
470  case nxv2i16:
471  case nxv4i16:
472  case nxv8i16:
473  case nxv16i16:
474  case nxv32i16: return i16;
475  case v1i32:
476  case v2i32:
477  case v3i32:
478  case v4i32:
479  case v5i32:
480  case v8i32:
481  case v16i32:
482  case v32i32:
483  case v64i32:
484  case v128i32:
485  case v256i32:
486  case v512i32:
487  case v1024i32:
488  case v2048i32:
489  case nxv1i32:
490  case nxv2i32:
491  case nxv4i32:
492  case nxv8i32:
493  case nxv16i32:
494  case nxv32i32: return i32;
495  case v1i64:
496  case v2i64:
497  case v4i64:
498  case v8i64:
499  case v16i64:
500  case v32i64:
501  case nxv1i64:
502  case nxv2i64:
503  case nxv4i64:
504  case nxv8i64:
505  case nxv16i64:
506  case nxv32i64: return i64;
507  case v1i128: return i128;
508  case v2f16:
509  case v3f16:
510  case v4f16:
511  case v8f16:
512  case v16f16:
513  case v32f16:
514  case nxv2f16:
515  case nxv4f16:
516  case nxv8f16: return f16;
517  case v1f32:
518  case v2f32:
519  case v3f32:
520  case v4f32:
521  case v5f32:
522  case v8f32:
523  case v16f32:
524  case v32f32:
525  case v64f32:
526  case v128f32:
527  case v256f32:
528  case v512f32:
529  case v1024f32:
530  case v2048f32:
531  case nxv1f32:
532  case nxv2f32:
533  case nxv4f32:
534  case nxv8f32:
535  case nxv16f32: return f32;
536  case v1f64:
537  case v2f64:
538  case v4f64:
539  case v8f64:
540  case nxv1f64:
541  case nxv2f64:
542  case nxv4f64:
543  case nxv8f64: return f64;
544  }
545  }
546 
547  unsigned getVectorNumElements() const {
548  switch (SimpleTy) {
549  default:
550  llvm_unreachable("Not a vector MVT!");
551  case v2048i32:
552  case v2048f32: return 2048;
553  case v1024i1:
554  case v1024i32:
555  case v1024f32: return 1024;
556  case v512i1:
557  case v512i32:
558  case v512f32: return 512;
559  case v256i1:
560  case v256i8:
561  case v256i32:
562  case v256f32: return 256;
563  case v128i1:
564  case v128i8:
565  case v128i16:
566  case v128i32:
567  case v128f32: return 128;
568  case v64i1:
569  case v64i8:
570  case v64i16:
571  case v64i32:
572  case v64f32: return 64;
573  case v32i1:
574  case v32i8:
575  case v32i16:
576  case v32i32:
577  case v32i64:
578  case v32f16:
579  case v32f32:
580  case nxv32i1:
581  case nxv32i8:
582  case nxv32i16:
583  case nxv32i32:
584  case nxv32i64: return 32;
585  case v16i1:
586  case v16i8:
587  case v16i16:
588  case v16i32:
589  case v16i64:
590  case v16f16:
591  case v16f32:
592  case nxv16i1:
593  case nxv16i8:
594  case nxv16i16:
595  case nxv16i32:
596  case nxv16i64:
597  case nxv16f32: return 16;
598  case v8i1:
599  case v8i8:
600  case v8i16:
601  case v8i32:
602  case v8i64:
603  case v8f16:
604  case v8f32:
605  case v8f64:
606  case nxv8i1:
607  case nxv8i8:
608  case nxv8i16:
609  case nxv8i32:
610  case nxv8i64:
611  case nxv8f16:
612  case nxv8f32:
613  case nxv8f64: return 8;
614  case v5i32:
615  case v5f32: return 5;
616  case v4i1:
617  case v4i8:
618  case v4i16:
619  case v4i32:
620  case v4i64:
621  case v4f16:
622  case v4f32:
623  case v4f64:
624  case nxv4i1:
625  case nxv4i8:
626  case nxv4i16:
627  case nxv4i32:
628  case nxv4i64:
629  case nxv4f16:
630  case nxv4f32:
631  case nxv4f64: return 4;
632  case v3i16:
633  case v3i32:
634  case v3f16:
635  case v3f32: return 3;
636  case v2i1:
637  case v2i8:
638  case v2i16:
639  case v2i32:
640  case v2i64:
641  case v2f16:
642  case v2f32:
643  case v2f64:
644  case nxv2i1:
645  case nxv2i8:
646  case nxv2i16:
647  case nxv2i32:
648  case nxv2i64:
649  case nxv2f16:
650  case nxv2f32:
651  case nxv2f64: return 2;
652  case v1i1:
653  case v1i8:
654  case v1i16:
655  case v1i32:
656  case v1i64:
657  case v1i128:
658  case v1f32:
659  case v1f64:
660  case nxv1i1:
661  case nxv1i8:
662  case nxv1i16:
663  case nxv1i32:
664  case nxv1i64:
665  case nxv1f32:
666  case nxv1f64: return 1;
667  }
668  }
669 
671  return { getVectorNumElements(), isScalableVector() };
672  }
673 
674  /// Returns the size of the specified MVT in bits.
675  ///
676  /// If the value type is a scalable vector type, the scalable property will
677  /// be set and the runtime size will be a positive integer multiple of the
678  /// base size.
680  switch (SimpleTy) {
681  default:
682  llvm_unreachable("getSizeInBits called on extended MVT.");
683  case Other:
684  llvm_unreachable("Value type is non-standard value, Other.");
685  case iPTR:
686  llvm_unreachable("Value type size is target-dependent. Ask TLI.");
687  case iPTRAny:
688  case iAny:
689  case fAny:
690  case vAny:
691  case Any:
692  llvm_unreachable("Value type is overloaded.");
693  case token:
694  llvm_unreachable("Token type is a sentinel that cannot be used "
695  "in codegen and has no size");
696  case Metadata:
697  llvm_unreachable("Value type is metadata.");
698  case i1:
699  case v1i1: return TypeSize::Fixed(1);
700  case nxv1i1: return TypeSize::Scalable(1);
701  case v2i1: return TypeSize::Fixed(2);
702  case nxv2i1: return TypeSize::Scalable(2);
703  case v4i1: return TypeSize::Fixed(4);
704  case nxv4i1: return TypeSize::Scalable(4);
705  case i8 :
706  case v1i8:
707  case v8i1: return TypeSize::Fixed(8);
708  case nxv1i8:
709  case nxv8i1: return TypeSize::Scalable(8);
710  case i16 :
711  case f16:
712  case v16i1:
713  case v2i8:
714  case v1i16: return TypeSize::Fixed(16);
715  case nxv16i1:
716  case nxv2i8:
717  case nxv1i16: return TypeSize::Scalable(16);
718  case f32 :
719  case i32 :
720  case v32i1:
721  case v4i8:
722  case v2i16:
723  case v2f16:
724  case v1f32:
725  case v1i32: return TypeSize::Fixed(32);
726  case nxv32i1:
727  case nxv4i8:
728  case nxv2i16:
729  case nxv1i32:
730  case nxv2f16:
731  case nxv1f32: return TypeSize::Scalable(32);
732  case v3i16:
733  case v3f16: return TypeSize::Fixed(48);
734  case x86mmx:
735  case f64 :
736  case i64 :
737  case v64i1:
738  case v8i8:
739  case v4i16:
740  case v2i32:
741  case v1i64:
742  case v4f16:
743  case v2f32:
744  case v1f64: return TypeSize::Fixed(64);
745  case nxv8i8:
746  case nxv4i16:
747  case nxv2i32:
748  case nxv1i64:
749  case nxv4f16:
750  case nxv2f32:
751  case nxv1f64: return TypeSize::Scalable(64);
752  case f80 : return TypeSize::Fixed(80);
753  case v3i32:
754  case v3f32: return TypeSize::Fixed(96);
755  case f128:
756  case ppcf128:
757  case i128:
758  case v128i1:
759  case v16i8:
760  case v8i16:
761  case v4i32:
762  case v2i64:
763  case v1i128:
764  case v8f16:
765  case v4f32:
766  case v2f64: return TypeSize::Fixed(128);
767  case nxv16i8:
768  case nxv8i16:
769  case nxv4i32:
770  case nxv2i64:
771  case nxv8f16:
772  case nxv4f32:
773  case nxv2f64: return TypeSize::Scalable(128);
774  case v5i32:
775  case v5f32: return TypeSize::Fixed(160);
776  case v256i1:
777  case v32i8:
778  case v16i16:
779  case v8i32:
780  case v4i64:
781  case v16f16:
782  case v8f32:
783  case v4f64: return TypeSize::Fixed(256);
784  case nxv32i8:
785  case nxv16i16:
786  case nxv8i32:
787  case nxv4i64:
788  case nxv8f32:
789  case nxv4f64: return TypeSize::Scalable(256);
790  case v512i1:
791  case v64i8:
792  case v32i16:
793  case v16i32:
794  case v8i64:
795  case v32f16:
796  case v16f32:
797  case v8f64: return TypeSize::Fixed(512);
798  case nxv32i16:
799  case nxv16i32:
800  case nxv8i64:
801  case nxv16f32:
802  case nxv8f64: return TypeSize::Scalable(512);
803  case v1024i1:
804  case v128i8:
805  case v64i16:
806  case v32i32:
807  case v16i64:
808  case v32f32: return TypeSize::Fixed(1024);
809  case nxv32i32:
810  case nxv16i64: return TypeSize::Scalable(1024);
811  case v256i8:
812  case v128i16:
813  case v64i32:
814  case v32i64:
815  case v64f32: return TypeSize::Fixed(2048);
816  case nxv32i64: return TypeSize::Scalable(2048);
817  case v128i32:
818  case v128f32: return TypeSize::Fixed(4096);
819  case v256i32:
820  case v256f32: return TypeSize::Fixed(8192);
821  case v512i32:
822  case v512f32: return TypeSize::Fixed(16384);
823  case v1024i32:
824  case v1024f32: return TypeSize::Fixed(32768);
825  case v2048i32:
826  case v2048f32: return TypeSize::Fixed(65536);
827  case exnref: return TypeSize::Fixed(0); // opaque type
828  }
829  }
830 
832  return getScalarType().getSizeInBits();
833  }
834 
835  /// Return the number of bytes overwritten by a store of the specified value
836  /// type.
837  ///
838  /// If the value type is a scalable vector type, the scalable property will
839  /// be set and the runtime size will be a positive integer multiple of the
840  /// base size.
842  TypeSize BaseSize = getSizeInBits();
843  return {(BaseSize.getKnownMinSize() + 7) / 8, BaseSize.isScalable()};
844  }
845 
846  /// Return the number of bits overwritten by a store of the specified value
847  /// type.
848  ///
849  /// If the value type is a scalable vector type, the scalable property will
850  /// be set and the runtime size will be a positive integer multiple of the
851  /// base size.
853  return getStoreSize() * 8;
854  }
855 
856  /// Returns true if the number of bits for the type is a multiple of an
857  /// 8-bit byte.
858  bool isByteSized() const {
859  return getSizeInBits().isByteSized();
860  }
861 
862  /// Return true if this has more bits than VT.
863  bool bitsGT(MVT VT) const {
864  return getSizeInBits() > VT.getSizeInBits();
865  }
866 
867  /// Return true if this has no less bits than VT.
868  bool bitsGE(MVT VT) const {
869  return getSizeInBits() >= VT.getSizeInBits();
870  }
871 
872  /// Return true if this has less bits than VT.
873  bool bitsLT(MVT VT) const {
874  return getSizeInBits() < VT.getSizeInBits();
875  }
876 
877  /// Return true if this has no more bits than VT.
878  bool bitsLE(MVT VT) const {
879  return getSizeInBits() <= VT.getSizeInBits();
880  }
881 
882  static MVT getFloatingPointVT(unsigned BitWidth) {
883  switch (BitWidth) {
884  default:
885  llvm_unreachable("Bad bit width!");
886  case 16:
887  return MVT::f16;
888  case 32:
889  return MVT::f32;
890  case 64:
891  return MVT::f64;
892  case 80:
893  return MVT::f80;
894  case 128:
895  return MVT::f128;
896  }
897  }
898 
899  static MVT getIntegerVT(unsigned BitWidth) {
900  switch (BitWidth) {
901  default:
903  case 1:
904  return MVT::i1;
905  case 8:
906  return MVT::i8;
907  case 16:
908  return MVT::i16;
909  case 32:
910  return MVT::i32;
911  case 64:
912  return MVT::i64;
913  case 128:
914  return MVT::i128;
915  }
916  }
917 
918  static MVT getVectorVT(MVT VT, unsigned NumElements) {
919  switch (VT.SimpleTy) {
920  default:
921  break;
922  case MVT::i1:
923  if (NumElements == 1) return MVT::v1i1;
924  if (NumElements == 2) return MVT::v2i1;
925  if (NumElements == 4) return MVT::v4i1;
926  if (NumElements == 8) return MVT::v8i1;
927  if (NumElements == 16) return MVT::v16i1;
928  if (NumElements == 32) return MVT::v32i1;
929  if (NumElements == 64) return MVT::v64i1;
930  if (NumElements == 128) return MVT::v128i1;
931  if (NumElements == 256) return MVT::v256i1;
932  if (NumElements == 512) return MVT::v512i1;
933  if (NumElements == 1024) return MVT::v1024i1;
934  break;
935  case MVT::i8:
936  if (NumElements == 1) return MVT::v1i8;
937  if (NumElements == 2) return MVT::v2i8;
938  if (NumElements == 4) return MVT::v4i8;
939  if (NumElements == 8) return MVT::v8i8;
940  if (NumElements == 16) return MVT::v16i8;
941  if (NumElements == 32) return MVT::v32i8;
942  if (NumElements == 64) return MVT::v64i8;
943  if (NumElements == 128) return MVT::v128i8;
944  if (NumElements == 256) return MVT::v256i8;
945  break;
946  case MVT::i16:
947  if (NumElements == 1) return MVT::v1i16;
948  if (NumElements == 2) return MVT::v2i16;
949  if (NumElements == 3) return MVT::v3i16;
950  if (NumElements == 4) return MVT::v4i16;
951  if (NumElements == 8) return MVT::v8i16;
952  if (NumElements == 16) return MVT::v16i16;
953  if (NumElements == 32) return MVT::v32i16;
954  if (NumElements == 64) return MVT::v64i16;
955  if (NumElements == 128) return MVT::v128i16;
956  break;
957  case MVT::i32:
958  if (NumElements == 1) return MVT::v1i32;
959  if (NumElements == 2) return MVT::v2i32;
960  if (NumElements == 3) return MVT::v3i32;
961  if (NumElements == 4) return MVT::v4i32;
962  if (NumElements == 5) return MVT::v5i32;
963  if (NumElements == 8) return MVT::v8i32;
964  if (NumElements == 16) return MVT::v16i32;
965  if (NumElements == 32) return MVT::v32i32;
966  if (NumElements == 64) return MVT::v64i32;
967  if (NumElements == 128) return MVT::v128i32;
968  if (NumElements == 256) return MVT::v256i32;
969  if (NumElements == 512) return MVT::v512i32;
970  if (NumElements == 1024) return MVT::v1024i32;
971  if (NumElements == 2048) return MVT::v2048i32;
972  break;
973  case MVT::i64:
974  if (NumElements == 1) return MVT::v1i64;
975  if (NumElements == 2) return MVT::v2i64;
976  if (NumElements == 4) return MVT::v4i64;
977  if (NumElements == 8) return MVT::v8i64;
978  if (NumElements == 16) return MVT::v16i64;
979  if (NumElements == 32) return MVT::v32i64;
980  break;
981  case MVT::i128:
982  if (NumElements == 1) return MVT::v1i128;
983  break;
984  case MVT::f16:
985  if (NumElements == 2) return MVT::v2f16;
986  if (NumElements == 3) return MVT::v3f16;
987  if (NumElements == 4) return MVT::v4f16;
988  if (NumElements == 8) return MVT::v8f16;
989  if (NumElements == 16) return MVT::v16f16;
990  if (NumElements == 32) return MVT::v32f16;
991  break;
992  case MVT::f32:
993  if (NumElements == 1) return MVT::v1f32;
994  if (NumElements == 2) return MVT::v2f32;
995  if (NumElements == 3) return MVT::v3f32;
996  if (NumElements == 4) return MVT::v4f32;
997  if (NumElements == 5) return MVT::v5f32;
998  if (NumElements == 8) return MVT::v8f32;
999  if (NumElements == 16) return MVT::v16f32;
1000  if (NumElements == 32) return MVT::v32f32;
1001  if (NumElements == 64) return MVT::v64f32;
1002  if (NumElements == 128) return MVT::v128f32;
1003  if (NumElements == 256) return MVT::v256f32;
1004  if (NumElements == 512) return MVT::v512f32;
1005  if (NumElements == 1024) return MVT::v1024f32;
1006  if (NumElements == 2048) return MVT::v2048f32;
1007  break;
1008  case MVT::f64:
1009  if (NumElements == 1) return MVT::v1f64;
1010  if (NumElements == 2) return MVT::v2f64;
1011  if (NumElements == 4) return MVT::v4f64;
1012  if (NumElements == 8) return MVT::v8f64;
1013  break;
1014  }
1016  }
1017 
1018  static MVT getScalableVectorVT(MVT VT, unsigned NumElements) {
1019  switch(VT.SimpleTy) {
1020  default:
1021  break;
1022  case MVT::i1:
1023  if (NumElements == 1) return MVT::nxv1i1;
1024  if (NumElements == 2) return MVT::nxv2i1;
1025  if (NumElements == 4) return MVT::nxv4i1;
1026  if (NumElements == 8) return MVT::nxv8i1;
1027  if (NumElements == 16) return MVT::nxv16i1;
1028  if (NumElements == 32) return MVT::nxv32i1;
1029  break;
1030  case MVT::i8:
1031  if (NumElements == 1) return MVT::nxv1i8;
1032  if (NumElements == 2) return MVT::nxv2i8;
1033  if (NumElements == 4) return MVT::nxv4i8;
1034  if (NumElements == 8) return MVT::nxv8i8;
1035  if (NumElements == 16) return MVT::nxv16i8;
1036  if (NumElements == 32) return MVT::nxv32i8;
1037  break;
1038  case MVT::i16:
1039  if (NumElements == 1) return MVT::nxv1i16;
1040  if (NumElements == 2) return MVT::nxv2i16;
1041  if (NumElements == 4) return MVT::nxv4i16;
1042  if (NumElements == 8) return MVT::nxv8i16;
1043  if (NumElements == 16) return MVT::nxv16i16;
1044  if (NumElements == 32) return MVT::nxv32i16;
1045  break;
1046  case MVT::i32:
1047  if (NumElements == 1) return MVT::nxv1i32;
1048  if (NumElements == 2) return MVT::nxv2i32;
1049  if (NumElements == 4) return MVT::nxv4i32;
1050  if (NumElements == 8) return MVT::nxv8i32;
1051  if (NumElements == 16) return MVT::nxv16i32;
1052  if (NumElements == 32) return MVT::nxv32i32;
1053  break;
1054  case MVT::i64:
1055  if (NumElements == 1) return MVT::nxv1i64;
1056  if (NumElements == 2) return MVT::nxv2i64;
1057  if (NumElements == 4) return MVT::nxv4i64;
1058  if (NumElements == 8) return MVT::nxv8i64;
1059  if (NumElements == 16) return MVT::nxv16i64;
1060  if (NumElements == 32) return MVT::nxv32i64;
1061  break;
1062  case MVT::f16:
1063  if (NumElements == 2) return MVT::nxv2f16;
1064  if (NumElements == 4) return MVT::nxv4f16;
1065  if (NumElements == 8) return MVT::nxv8f16;
1066  break;
1067  case MVT::f32:
1068  if (NumElements == 1) return MVT::nxv1f32;
1069  if (NumElements == 2) return MVT::nxv2f32;
1070  if (NumElements == 4) return MVT::nxv4f32;
1071  if (NumElements == 8) return MVT::nxv8f32;
1072  if (NumElements == 16) return MVT::nxv16f32;
1073  break;
1074  case MVT::f64:
1075  if (NumElements == 1) return MVT::nxv1f64;
1076  if (NumElements == 2) return MVT::nxv2f64;
1077  if (NumElements == 4) return MVT::nxv4f64;
1078  if (NumElements == 8) return MVT::nxv8f64;
1079  break;
1080  }
1082  }
1083 
1084  static MVT getVectorVT(MVT VT, unsigned NumElements, bool IsScalable) {
1085  if (IsScalable)
1086  return getScalableVectorVT(VT, NumElements);
1087  return getVectorVT(VT, NumElements);
1088  }
1089 
1090  static MVT getVectorVT(MVT VT, ElementCount EC) {
1091  if (EC.Scalable)
1092  return getScalableVectorVT(VT, EC.Min);
1093  return getVectorVT(VT, EC.Min);
1094  }
1095 
1096  /// Return the value type corresponding to the specified type. This returns
1097  /// all pointers as iPTR. If HandleUnknown is true, unknown types are
1098  /// returned as Other, otherwise they are invalid.
1099  static MVT getVT(Type *Ty, bool HandleUnknown = false);
1100 
1101  private:
1102  /// A simple iterator over the MVT::SimpleValueType enum.
1103  struct mvt_iterator {
1104  SimpleValueType VT;
1105 
1106  mvt_iterator(SimpleValueType VT) : VT(VT) {}
1107 
1108  MVT operator*() const { return VT; }
1109  bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
1110 
1111  mvt_iterator& operator++() {
1112  VT = (MVT::SimpleValueType)((int)VT + 1);
1113  assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
1114  "MVT iterator overflowed.");
1115  return *this;
1116  }
1117  };
1118 
1119  /// A range of the MVT::SimpleValueType enum.
1121 
1122  public:
1123  /// SimpleValueType Iteration
1124  /// @{
1127  }
1128 
1132  }
1133 
1137  }
1138 
1142  }
1143 
1145  return mvt_range(
1148  }
1149 
1151  return mvt_range(
1154  }
1155 
1157  return mvt_range(
1160  }
1161 
1163  return mvt_range(
1166  }
1167 
1169  return mvt_range(
1172  }
1173 
1175  return mvt_range(
1178  }
1179  /// @}
1180  };
1181 
1182 } // end namespace llvm
1183 
1184 #endif // LLVM_CODEGEN_MACHINEVALUETYPE_H
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
static MVT getIntegerVT(unsigned BitWidth)
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
Definition: MathExtras.h:598
bool operator>=(const MVT &S) const
bool isScalable() const
Definition: TypeSize.h:137
Definition: Any.h:26
bool isInteger() const
Return true if this is an integer or a vector integer type.
ElementCount getVectorElementCount() const
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static MVT getVectorVT(MVT VT, unsigned NumElements)
bool isVector() const
Return true if this is a vector value type.
bool isPow2VectorType() const
Returns true if the given vector is a power of 2.
static mvt_range fp_fixedlen_vector_valuetypes()
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
bool is256BitVector() const
Return true if this is a 256-bit vector type.
bool isFixedLengthVector() const
MVT getPow2VectorType() const
Widens the length of the given vector MVT up to the nearest power of 2 and returns that type...
static MVT getFloatingPointVT(unsigned BitWidth)
unsigned getVectorNumElements() const
bool operator>(const MVT &S) const
static constexpr TypeSize Scalable(uint64_t MinSize)
Definition: TypeSize.h:63
unsigned Min
Definition: TypeSize.h:25
bool isValid() const
Return true if this is a valid simple valuetype.
static MVT getScalableVectorVT(MVT VT, unsigned NumElements)
constexpr MVT(SimpleValueType SVT)
MVT getHalfNumVectorElementsVT() const
Return a VT for a vector type with the same element type but half the number of elements.
SimpleValueType SimpleTy
APInt operator*(APInt a, uint64_t RHS)
Definition: APInt.h:2148
bool is64BitVector() const
Return true if this is a 64-bit vector type.
static mvt_range integer_fixedlen_vector_valuetypes()
bool is1024BitVector() const
Return true if this is a 1024-bit vector type.
bool operator<=(const MVT &S) const
bool is2048BitVector() const
Return true if this is a 2048-bit vector type.
bool is16BitVector() const
Return true if this is a 16-bit vector type.
bool bitsLT(MVT VT) const
Return true if this has less bits than VT.
bool bitsGT(MVT VT) const
Return true if this has more bits than VT.
MVT getVectorElementType() const
bool isScalableVector() const
Return true if this is a vector value type where the runtime length is machine dependent.
bool is128BitVector() const
Return true if this is a 128-bit vector type.
bool bitsGE(MVT VT) const
Return true if this has no less bits than VT.
bool operator<(const MVT &S) const
Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
bool isScalarInteger() const
Return true if this is an integer, not including vectors.
static mvt_range fp_valuetypes()
bool isByteSized() const
Definition: TypeSize.h:142
bool bitsLE(MVT VT) const
Return true if this has no more bits than VT.
static mvt_range vector_valuetypes()
static MVT getVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
Definition: ValueTypes.cpp:324
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool operator==(const MVT &S) const
bool isByteSized() const
Returns true if the number of bits for the type is a multiple of an 8-bit byte.
static MVT getVectorVT(MVT VT, ElementCount EC)
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
static mvt_range integer_scalable_vector_valuetypes()
static mvt_range fp_scalable_vector_valuetypes()
TypeSize getScalarSizeInBits() const
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
static mvt_range integer_valuetypes()
A range adaptor for a pair of iterators.
bool operator!=(const MVT &S) const
bool isOverloaded() const
Return true if this is an overloaded type for TableGen.
constexpr MVT()=default
bool is32BitVector() const
Return true if this is a 32-bit vector type.
static mvt_range all_valuetypes()
SimpleValueType Iteration.
static MVT getVectorVT(MVT VT, unsigned NumElements, bool IsScalable)
TypeSize getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
static constexpr TypeSize Fixed(uint64_t Size)
Definition: TypeSize.h:59
uint64_t getKnownMinSize() const
Definition: TypeSize.h:132
bool is512BitVector() const
Return true if this is a 512-bit vector type.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static mvt_range fixedlen_vector_valuetypes()
Root of the metadata hierarchy.
Definition: Metadata.h:58
static mvt_range scalable_vector_valuetypes()