LLVM  3.7.0
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 
22 namespace llvm {
23 
24  class Type;
25 
26  /// MVT - 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:
32  // INVALID_SIMPLE_VALUE_TYPE - Simple value types less than zero are
33  // considered extended value types.
35 
36  // If you change this numbering, you must change the values in
37  // ValueTypes.td as well!
38  Other = 0, // This is a non-standard value
39  i1 = 1, // This is a 1 bit integer value
40  i8 = 2, // This is an 8 bit integer value
41  i16 = 3, // This is a 16 bit integer value
42  i32 = 4, // This is a 32 bit integer value
43  i64 = 5, // This is a 64 bit integer value
44  i128 = 6, // This is a 128 bit integer value
45 
48 
49  f16 = 7, // This is a 16 bit floating point value
50  f32 = 8, // This is a 32 bit floating point value
51  f64 = 9, // This is a 64 bit floating point value
52  f80 = 10, // This is a 80 bit floating point value
53  f128 = 11, // This is a 128 bit floating point value
54  ppcf128 = 12, // This is a PPC 128-bit floating point value
55 
58 
59  v2i1 = 13, // 2 x i1
60  v4i1 = 14, // 4 x i1
61  v8i1 = 15, // 8 x i1
62  v16i1 = 16, // 16 x i1
63  v32i1 = 17, // 32 x i1
64  v64i1 = 18, // 64 x i1
65 
66  v1i8 = 19, // 1 x i8
67  v2i8 = 20, // 2 x i8
68  v4i8 = 21, // 4 x i8
69  v8i8 = 22, // 8 x i8
70  v16i8 = 23, // 16 x i8
71  v32i8 = 24, // 32 x i8
72  v64i8 = 25, // 64 x i8
73  v1i16 = 26, // 1 x i16
74  v2i16 = 27, // 2 x i16
75  v4i16 = 28, // 4 x i16
76  v8i16 = 29, // 8 x i16
77  v16i16 = 30, // 16 x i16
78  v32i16 = 31, // 32 x i16
79  v1i32 = 32, // 1 x i32
80  v2i32 = 33, // 2 x i32
81  v4i32 = 34, // 4 x i32
82  v8i32 = 35, // 8 x i32
83  v16i32 = 36, // 16 x i32
84  v1i64 = 37, // 1 x i64
85  v2i64 = 38, // 2 x i64
86  v4i64 = 39, // 4 x i64
87  v8i64 = 40, // 8 x i64
88  v16i64 = 41, // 16 x i64
89  v1i128 = 42, // 1 x i128
90 
93 
94  v2f16 = 43, // 2 x f16
95  v4f16 = 44, // 4 x f16
96  v8f16 = 45, // 8 x f16
97  v1f32 = 46, // 1 x f32
98  v2f32 = 47, // 2 x f32
99  v4f32 = 48, // 4 x f32
100  v8f32 = 49, // 8 x f32
101  v16f32 = 50, // 16 x f32
102  v1f64 = 51, // 1 x f64
103  v2f64 = 52, // 2 x f64
104  v4f64 = 53, // 4 x f64
105  v8f64 = 54, // 8 x f64
106 
109 
112 
113  x86mmx = 55, // This is an X86 MMX value
114 
115  Glue = 56, // This glues nodes together during pre-RA sched
116 
117  isVoid = 57, // This has no value
118 
119  Untyped = 58, // This value takes a register, but has
120  // unspecified type. The register class
121  // will be determined by the opcode.
122 
123  FIRST_VALUETYPE = 0, // This is always the beginning of the list.
124  LAST_VALUETYPE = 59, // This always remains at the end of the list.
125 
126  // This is the current maximum for LAST_VALUETYPE.
127  // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
128  // This value must be a multiple of 32.
130 
131  // Metadata - This is MDNode or MDString.
132  Metadata = 250,
133 
134  // iPTRAny - An int value the size of the pointer of the current
135  // target to any address space. This must only be used internal to
136  // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
137  iPTRAny = 251,
138 
139  // vAny - A vector with any length and element size. This is used
140  // for intrinsics that have overloadings based on vector types.
141  // This is only for tblgen's consumption!
142  vAny = 252,
143 
144  // fAny - Any floating-point or vector floating-point value. This is used
145  // for intrinsics that have overloadings based on floating-point types.
146  // This is only for tblgen's consumption!
147  fAny = 253,
148 
149  // iAny - An integer or vector integer value of any bit width. This is
150  // used for intrinsics that have overloadings based on integer bit widths.
151  // This is only for tblgen's consumption!
152  iAny = 254,
153 
154  // iPTR - An int value the size of the pointer of the current
155  // target. This should only be used internal to tblgen!
156  iPTR = 255,
157 
158  // Any - Any type. This is used for intrinsics that have overloadings.
159  // This is only for tblgen's consumption!
160  Any = 256
161  };
162 
164 
167 
168  bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; }
169  bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; }
170  bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
171  bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
172  bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
173  bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
174 
175  /// isValid - Return true if this is a valid simple valuetype.
176  bool isValid() const {
177  return (SimpleTy >= MVT::FIRST_VALUETYPE &&
179  }
180 
181  /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
182  bool isFloatingPoint() const {
183  return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
187  }
188 
189  /// isInteger - Return true if this is an integer, or a vector integer type.
190  bool isInteger() const {
195  }
196 
197  /// isVector - Return true if this is a vector value type.
198  bool isVector() const {
201  }
202 
203  /// is16BitVector - Return true if this is a 16-bit vector type.
204  bool is16BitVector() const {
205  return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 ||
206  SimpleTy == MVT::v16i1);
207  }
208 
209  /// is32BitVector - Return true if this is a 32-bit vector type.
210  bool is32BitVector() const {
211  return (SimpleTy == MVT::v4i8 || SimpleTy == MVT::v2i16 ||
213  SimpleTy == MVT::v1f32);
214  }
215 
216  /// is64BitVector - Return true if this is a 64-bit vector type.
217  bool is64BitVector() const {
218  return (SimpleTy == MVT::v8i8 || SimpleTy == MVT::v4i16 ||
221  SimpleTy == MVT::v1f64);
222  }
223 
224  /// is128BitVector - Return true if this is a 128-bit vector type.
225  bool is128BitVector() const {
226  return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
230  }
231 
232  /// is256BitVector - Return true if this is a 256-bit vector type.
233  bool is256BitVector() const {
234  return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64 ||
237  }
238 
239  /// is512BitVector - Return true if this is a 512-bit vector type.
240  bool is512BitVector() const {
241  return (SimpleTy == MVT::v8f64 || SimpleTy == MVT::v16f32 ||
244  }
245 
246  /// is1024BitVector - Return true if this is a 1024-bit vector type.
247  bool is1024BitVector() const {
248  return (SimpleTy == MVT::v16i64);
249  }
250 
251  /// isOverloaded - Return true if this is an overloaded type for TableGen.
252  bool isOverloaded() const {
253  return (SimpleTy==MVT::Any ||
256  }
257 
258  /// isPow2VectorType - Returns true if the given vector is a power of 2.
259  bool isPow2VectorType() const {
260  unsigned NElts = getVectorNumElements();
261  return !(NElts & (NElts - 1));
262  }
263 
264  /// getPow2VectorType - Widens the length of the given vector MVT up to
265  /// the nearest power of 2 and returns that type.
267  if (isPow2VectorType())
268  return *this;
269 
270  unsigned NElts = getVectorNumElements();
271  unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
272  return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
273  }
274 
275  /// getScalarType - If this is a vector type, return the element type,
276  /// otherwise return this.
277  MVT getScalarType() const {
278  return isVector() ? getVectorElementType() : *this;
279  }
280 
282  switch (SimpleTy) {
283  default:
284  llvm_unreachable("Not a vector MVT!");
285  case v2i1 :
286  case v4i1 :
287  case v8i1 :
288  case v16i1 :
289  case v32i1 :
290  case v64i1: return i1;
291  case v1i8 :
292  case v2i8 :
293  case v4i8 :
294  case v8i8 :
295  case v16i8:
296  case v32i8:
297  case v64i8: return i8;
298  case v1i16:
299  case v2i16:
300  case v4i16:
301  case v8i16:
302  case v16i16:
303  case v32i16: return i16;
304  case v1i32:
305  case v2i32:
306  case v4i32:
307  case v8i32:
308  case v16i32: return i32;
309  case v1i64:
310  case v2i64:
311  case v4i64:
312  case v8i64:
313  case v16i64: return i64;
314  case v1i128: return i128;
315  case v2f16:
316  case v4f16:
317  case v8f16: return f16;
318  case v1f32:
319  case v2f32:
320  case v4f32:
321  case v8f32:
322  case v16f32: return f32;
323  case v1f64:
324  case v2f64:
325  case v4f64:
326  case v8f64: return f64;
327  }
328  }
329 
330  unsigned getVectorNumElements() const {
331  switch (SimpleTy) {
332  default:
333  llvm_unreachable("Not a vector MVT!");
334  case v32i1:
335  case v32i8:
336  case v32i16: return 32;
337  case v64i1:
338  case v64i8: return 64;
339  case v16i1:
340  case v16i8:
341  case v16i16:
342  case v16i32:
343  case v16i64:
344  case v16f32: return 16;
345  case v8i1 :
346  case v8i8 :
347  case v8i16:
348  case v8i32:
349  case v8i64:
350  case v8f16:
351  case v8f32:
352  case v8f64: return 8;
353  case v4i1:
354  case v4i8:
355  case v4i16:
356  case v4i32:
357  case v4i64:
358  case v4f16:
359  case v4f32:
360  case v4f64: return 4;
361  case v2i1:
362  case v2i8:
363  case v2i16:
364  case v2i32:
365  case v2i64:
366  case v2f16:
367  case v2f32:
368  case v2f64: return 2;
369  case v1i8:
370  case v1i16:
371  case v1i32:
372  case v1i64:
373  case v1i128:
374  case v1f32:
375  case v1f64: return 1;
376  }
377  }
378 
379  unsigned getSizeInBits() const {
380  switch (SimpleTy) {
381  default:
382  llvm_unreachable("getSizeInBits called on extended MVT.");
383  case Other:
384  llvm_unreachable("Value type is non-standard value, Other.");
385  case iPTR:
386  llvm_unreachable("Value type size is target-dependent. Ask TLI.");
387  case iPTRAny:
388  case iAny:
389  case fAny:
390  case vAny:
391  case Any:
392  llvm_unreachable("Value type is overloaded.");
393  case Metadata:
394  llvm_unreachable("Value type is metadata.");
395  case i1 : return 1;
396  case v2i1: return 2;
397  case v4i1: return 4;
398  case i8 :
399  case v1i8:
400  case v8i1: return 8;
401  case i16 :
402  case f16:
403  case v16i1:
404  case v2i8:
405  case v1i16: return 16;
406  case f32 :
407  case i32 :
408  case v32i1:
409  case v4i8:
410  case v2i16:
411  case v2f16:
412  case v1f32:
413  case v1i32: return 32;
414  case x86mmx:
415  case f64 :
416  case i64 :
417  case v64i1:
418  case v8i8:
419  case v4i16:
420  case v2i32:
421  case v1i64:
422  case v4f16:
423  case v2f32:
424  case v1f64: return 64;
425  case f80 : return 80;
426  case f128:
427  case ppcf128:
428  case i128:
429  case v16i8:
430  case v8i16:
431  case v4i32:
432  case v2i64:
433  case v1i128:
434  case v8f16:
435  case v4f32:
436  case v2f64: return 128;
437  case v32i8:
438  case v16i16:
439  case v8i32:
440  case v4i64:
441  case v8f32:
442  case v4f64: return 256;
443  case v64i8:
444  case v32i16:
445  case v16i32:
446  case v8i64:
447  case v16f32:
448  case v8f64: return 512;
449  case v16i64:return 1024;
450  }
451  }
452 
453  unsigned getScalarSizeInBits() const {
454  return getScalarType().getSizeInBits();
455  }
456 
457  /// getStoreSize - Return the number of bytes overwritten by a store
458  /// of the specified value type.
459  unsigned getStoreSize() const {
460  return (getSizeInBits() + 7) / 8;
461  }
462 
463  /// getStoreSizeInBits - Return the number of bits overwritten by a store
464  /// of the specified value type.
465  unsigned getStoreSizeInBits() const {
466  return getStoreSize() * 8;
467  }
468 
469  /// Return true if this has more bits than VT.
470  bool bitsGT(MVT VT) const {
471  return getSizeInBits() > VT.getSizeInBits();
472  }
473 
474  /// Return true if this has no less bits than VT.
475  bool bitsGE(MVT VT) const {
476  return getSizeInBits() >= VT.getSizeInBits();
477  }
478 
479  /// Return true if this has less bits than VT.
480  bool bitsLT(MVT VT) const {
481  return getSizeInBits() < VT.getSizeInBits();
482  }
483 
484  /// Return true if this has no more bits than VT.
485  bool bitsLE(MVT VT) const {
486  return getSizeInBits() <= VT.getSizeInBits();
487  }
488 
489 
490  static MVT getFloatingPointVT(unsigned BitWidth) {
491  switch (BitWidth) {
492  default:
493  llvm_unreachable("Bad bit width!");
494  case 16:
495  return MVT::f16;
496  case 32:
497  return MVT::f32;
498  case 64:
499  return MVT::f64;
500  case 80:
501  return MVT::f80;
502  case 128:
503  return MVT::f128;
504  }
505  }
506 
507  static MVT getIntegerVT(unsigned BitWidth) {
508  switch (BitWidth) {
509  default:
511  case 1:
512  return MVT::i1;
513  case 8:
514  return MVT::i8;
515  case 16:
516  return MVT::i16;
517  case 32:
518  return MVT::i32;
519  case 64:
520  return MVT::i64;
521  case 128:
522  return MVT::i128;
523  }
524  }
525 
526  static MVT getVectorVT(MVT VT, unsigned NumElements) {
527  switch (VT.SimpleTy) {
528  default:
529  break;
530  case MVT::i1:
531  if (NumElements == 2) return MVT::v2i1;
532  if (NumElements == 4) return MVT::v4i1;
533  if (NumElements == 8) return MVT::v8i1;
534  if (NumElements == 16) return MVT::v16i1;
535  if (NumElements == 32) return MVT::v32i1;
536  if (NumElements == 64) return MVT::v64i1;
537  break;
538  case MVT::i8:
539  if (NumElements == 1) return MVT::v1i8;
540  if (NumElements == 2) return MVT::v2i8;
541  if (NumElements == 4) return MVT::v4i8;
542  if (NumElements == 8) return MVT::v8i8;
543  if (NumElements == 16) return MVT::v16i8;
544  if (NumElements == 32) return MVT::v32i8;
545  if (NumElements == 64) return MVT::v64i8;
546  break;
547  case MVT::i16:
548  if (NumElements == 1) return MVT::v1i16;
549  if (NumElements == 2) return MVT::v2i16;
550  if (NumElements == 4) return MVT::v4i16;
551  if (NumElements == 8) return MVT::v8i16;
552  if (NumElements == 16) return MVT::v16i16;
553  if (NumElements == 32) return MVT::v32i16;
554  break;
555  case MVT::i32:
556  if (NumElements == 1) return MVT::v1i32;
557  if (NumElements == 2) return MVT::v2i32;
558  if (NumElements == 4) return MVT::v4i32;
559  if (NumElements == 8) return MVT::v8i32;
560  if (NumElements == 16) return MVT::v16i32;
561  break;
562  case MVT::i64:
563  if (NumElements == 1) return MVT::v1i64;
564  if (NumElements == 2) return MVT::v2i64;
565  if (NumElements == 4) return MVT::v4i64;
566  if (NumElements == 8) return MVT::v8i64;
567  if (NumElements == 16) return MVT::v16i64;
568  break;
569  case MVT::i128:
570  if (NumElements == 1) return MVT::v1i128;
571  break;
572  case MVT::f16:
573  if (NumElements == 2) return MVT::v2f16;
574  if (NumElements == 4) return MVT::v4f16;
575  if (NumElements == 8) return MVT::v8f16;
576  break;
577  case MVT::f32:
578  if (NumElements == 1) return MVT::v1f32;
579  if (NumElements == 2) return MVT::v2f32;
580  if (NumElements == 4) return MVT::v4f32;
581  if (NumElements == 8) return MVT::v8f32;
582  if (NumElements == 16) return MVT::v16f32;
583  break;
584  case MVT::f64:
585  if (NumElements == 1) return MVT::v1f64;
586  if (NumElements == 2) return MVT::v2f64;
587  if (NumElements == 4) return MVT::v4f64;
588  if (NumElements == 8) return MVT::v8f64;
589  break;
590  }
592  }
593 
594  /// Return the value type corresponding to the specified type. This returns
595  /// all pointers as iPTR. If HandleUnknown is true, unknown types are
596  /// returned as Other, otherwise they are invalid.
597  static MVT getVT(Type *Ty, bool HandleUnknown = false);
598 
599  private:
600  /// A simple iterator over the MVT::SimpleValueType enum.
601  struct mvt_iterator {
602  SimpleValueType VT;
603  mvt_iterator(SimpleValueType VT) : VT(VT) {}
604  MVT operator*() const { return VT; }
605  bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
606  mvt_iterator& operator++() {
607  VT = (MVT::SimpleValueType)((int)VT + 1);
608  assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
609  "MVT iterator overflowed.");
610  return *this;
611  }
612  };
613  /// A range of the MVT::SimpleValueType enum.
614  typedef iterator_range<mvt_iterator> mvt_range;
615 
616  public:
617  /// SimpleValueType Iteration
618  /// @{
621  }
625  }
629  }
633  }
635  return mvt_range(
638  }
640  return mvt_range(
643  }
644  /// @}
645  };
646 
647 } // End llvm namespace
648 
649 #endif
bool is16BitVector() const
is16BitVector - Return true if this is a 16-bit vector type.
static MVT getIntegerVT(unsigned BitWidth)
unsigned Log2_32_Ceil(uint32_t Value)
Log2_32_Ceil - This function returns the ceil log base 2 of the specified value, 32 if the value is z...
Definition: MathExtras.h:481
bool is1024BitVector() const
is1024BitVector - Return true if this is a 1024-bit vector type.
static MVT getVectorVT(MVT VT, unsigned NumElements)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
unsigned getScalarSizeInBits() const
bool is512BitVector() const
is512BitVector - Return true if this is a 512-bit vector type.
bool operator>=(const MVT &S) const
static MVT getFloatingPointVT(unsigned BitWidth)
unsigned getSizeInBits() const
LLVM_CONSTEXPR MVT(SimpleValueType SVT)
bool is32BitVector() const
is32BitVector - Return true if this is a 32-bit vector type.
bool bitsLT(MVT VT) const
Return true if this has less bits than VT.
#define LLVM_CONSTEXPR
Definition: Compiler.h:98
bool bitsLE(MVT VT) const
Return true if this has no more bits than VT.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
bool operator!=(const MVT &S) const
SimpleValueType SimpleTy
MVT getScalarType() const
getScalarType - If this is a vector type, return the element type, otherwise return this...
unsigned getStoreSize() const
getStoreSize - Return the number of bytes overwritten by a store of the specified value type...
bool bitsGE(MVT VT) const
Return true if this has no less bits than VT.
bool operator==(const MVT &S) const
static mvt_range integer_vector_valuetypes()
bool operator<(const MVT &S) const
static mvt_range fp_vector_valuetypes()
bool isInteger() const
isInteger - Return true if this is an integer, or a vector integer type.
unsigned getVectorNumElements() const
MVT - Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
bool isVector() const
isVector - Return true if this is a vector value type.
bool operator<=(const MVT &S) const
bool isFloatingPoint() const
isFloatingPoint - Return true if this is a FP, or a vector FP type.
bool isPow2VectorType() const
isPow2VectorType - Returns true if the given vector is a power of 2.
static mvt_range fp_valuetypes()
LLVM_CONSTEXPR MVT()
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:249
bool isOverloaded() const
isOverloaded - Return true if this is an overloaded type for TableGen.
BlockMass operator*(const BlockMass &L, const BranchProbability &R)
bool is64BitVector() const
is64BitVector - Return true if this is a 64-bit vector type.
static mvt_range integer_valuetypes()
bool is128BitVector() const
is128BitVector - Return true if this is a 128-bit vector type.
A range adaptor for a pair of iterators.
static mvt_range all_valuetypes()
SimpleValueType Iteration.
bool isValid() const
isValid - Return true if this is a valid simple valuetype.
bool is256BitVector() const
is256BitVector - Return true if this is a 256-bit vector type.
unsigned getStoreSizeInBits() const
getStoreSizeInBits - Return the number of bits overwritten by a store of the specified value type...
bool operator>(const MVT &S) const
bool bitsGT(MVT VT) const
Return true if this has more bits than VT.
MVT getPow2VectorType() const
getPow2VectorType - Widens the length of the given vector MVT up to the nearest power of 2 and return...
MVT getVectorElementType() const
Root of the metadata hierarchy.
Definition: Metadata.h:45