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