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