Add in new data types that are used by AMDIL/ANL among others.
[oota-llvm.git] / include / llvm / CodeGen / ValueTypes.h
1 //===- CodeGen/ValueTypes.h - Low-Level Target independ. 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 low-level target independent types which various
11 // values in the code generator are.  This allows the target specific behavior
12 // of instructions to be described to target independent passes.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CODEGEN_VALUETYPES_H
17 #define LLVM_CODEGEN_VALUETYPES_H
18
19 #include "llvm/Support/DataTypes.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/MathExtras.h"
22 #include <cassert>
23 #include <string>
24
25 namespace llvm {
26   class Type;
27   class LLVMContext;
28   struct EVT;
29
30   /// MVT - Machine Value Type.  Every type that is supported natively by some
31   /// processor targeted by LLVM occurs here.  This means that any legal value
32   /// type can be represented by a MVT.
33   class MVT {
34   public:
35     enum SimpleValueType {
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
46       FIRST_INTEGER_VALUETYPE = i1,
47       LAST_INTEGER_VALUETYPE  = i128,
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
56       FIRST_FP_VALUETYPE = f16,
57       LAST_FP_VALUETYPE  = ppcf128,
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       v2i8           =  17,   //  2 x i8
64       v4i8           =  18,   //  4 x i8
65       v8i8           =  19,   //  8 x i8
66       v16i8          =  20,   // 16 x i8
67       v32i8          =  21,   // 32 x i8
68       v1i16          =  22,   //  1 x i16
69       v2i16          =  23,   //  2 x i16
70       v4i16          =  24,   //  4 x i16
71       v8i16          =  25,   //  8 x i16
72       v16i16         =  26,   // 16 x i16
73       v1i32          =  27,   //  1 x i32
74       v2i32          =  28,   //  2 x i32
75       v4i32          =  29,   //  4 x i32
76       v8i32          =  30,   //  8 x i32
77       v16i32         =  31,   // 16 x i32
78       v1i64          =  32,   //  1 x i64
79       v2i64          =  33,   //  2 x i64
80       v4i64          =  34,   //  4 x i64
81       v8i64          =  35,   //  8 x i64
82       v16i64         =  36,   // 16 x i64
83
84       v2f16          =  37,   //  2 x f16
85       v2f32          =  38,   //  2 x f32
86       v4f32          =  39,   //  4 x f32
87       v8f32          =  40,   //  8 x f32
88       v2f64          =  41,   //  2 x f64
89       v4f64          =  42,   //  4 x f64
90
91       FIRST_VECTOR_VALUETYPE = v2i1,
92       LAST_VECTOR_VALUETYPE  = v4f64,
93       FIRST_INTEGER_VECTOR_VALUETYPE = v2i1,
94       LAST_INTEGER_VECTOR_VALUETYPE = v16i64,
95       FIRST_FP_VECTOR_VALUETYPE = v2f16,
96       LAST_FP_VECTOR_VALUETYPE = v4f64,
97
98       x86mmx         =  43,   // This is an X86 MMX value
99
100       Glue           =  44,   // This glues nodes together during pre-RA sched
101
102       isVoid         =  45,   // This has no value
103
104       Untyped        =  46,   // This value takes a register, but has
105                               // unspecified type.  The register class
106                               // will be determined by the opcode.
107
108       LAST_VALUETYPE =  47,   // This always remains at the end of the list.
109
110       // This is the current maximum for LAST_VALUETYPE.
111       // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
112       // This value must be a multiple of 32.
113       MAX_ALLOWED_VALUETYPE = 64,
114
115       // Metadata - This is MDNode or MDString.
116       Metadata       = 250,
117
118       // iPTRAny - An int value the size of the pointer of the current
119       // target to any address space. This must only be used internal to
120       // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
121       iPTRAny        = 251,
122
123       // vAny - A vector with any length and element size. This is used
124       // for intrinsics that have overloadings based on vector types.
125       // This is only for tblgen's consumption!
126       vAny           = 252,
127
128       // fAny - Any floating-point or vector floating-point value. This is used
129       // for intrinsics that have overloadings based on floating-point types.
130       // This is only for tblgen's consumption!
131       fAny           = 253,
132
133       // iAny - An integer or vector integer value of any bit width. This is
134       // used for intrinsics that have overloadings based on integer bit widths.
135       // This is only for tblgen's consumption!
136       iAny           = 254,
137
138       // iPTR - An int value the size of the pointer of the current
139       // target.  This should only be used internal to tblgen!
140       iPTR           = 255,
141
142       // LastSimpleValueType - The greatest valid SimpleValueType value.
143       LastSimpleValueType = 255,
144
145       // INVALID_SIMPLE_VALUE_TYPE - Simple value types greater than or equal
146       // to this are considered extended value types.
147       INVALID_SIMPLE_VALUE_TYPE = LastSimpleValueType + 1
148     };
149
150     SimpleValueType SimpleTy;
151
152     MVT() : SimpleTy((SimpleValueType)(INVALID_SIMPLE_VALUE_TYPE)) {}
153     MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
154
155     bool operator>(const MVT& S)  const { return SimpleTy >  S.SimpleTy; }
156     bool operator<(const MVT& S)  const { return SimpleTy <  S.SimpleTy; }
157     bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
158     bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
159     bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
160     bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
161
162     /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
163     bool isFloatingPoint() const {
164       return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
165                SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
166               (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE &&
167                SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE));
168     }
169
170     /// isInteger - Return true if this is an integer, or a vector integer type.
171     bool isInteger() const {
172       return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
173                SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
174               (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE &&
175                SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE));
176     }
177
178     /// isVector - Return true if this is a vector value type.
179     bool isVector() const {
180       return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
181               SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
182     }
183
184     /// is64BitVector - Return true if this is a 64-bit vector type.
185     bool is64BitVector() const {
186       return (SimpleTy == MVT::v8i8  || SimpleTy == MVT::v4i16 ||
187               SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
188               SimpleTy == MVT::v2f32);
189     }
190
191     /// is128BitVector - Return true if this is a 128-bit vector type.
192     bool is128BitVector() const {
193       return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
194               SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 ||
195               SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64);
196     }
197
198     /// is256BitVector - Return true if this is a 256-bit vector type.
199     bool is256BitVector() const {
200       return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64  ||
201               SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
202               SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
203     }
204
205     /// is512BitVector - Return true if this is a 512-bit vector type.
206     bool is512BitVector() const {
207       return (SimpleTy == MVT::v8i64 || SimpleTy == MVT::v16i32);
208     }
209
210     /// is1024BitVector - Return true if this is a 1024-bit vector type.
211     bool is1024BitVector() const {
212       return (SimpleTy == MVT::v16i64);
213     }
214
215     /// isPow2VectorType - Returns true if the given vector is a power of 2.
216     bool isPow2VectorType() const {
217       unsigned NElts = getVectorNumElements();
218       return !(NElts & (NElts - 1));
219     }
220
221     /// getPow2VectorType - Widens the length of the given vector MVT up to
222     /// the nearest power of 2 and returns that type.
223     MVT getPow2VectorType() const {
224       if (isPow2VectorType())
225         return *this;
226
227       unsigned NElts = getVectorNumElements();
228       unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
229       return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
230     }
231
232     /// getScalarType - If this is a vector type, return the element type,
233     /// otherwise return this.
234     MVT getScalarType() const {
235       return isVector() ? getVectorElementType() : *this;
236     }
237
238     MVT getVectorElementType() const {
239       switch (SimpleTy) {
240       default:
241         llvm_unreachable("Not a vector MVT!");
242       case v2i1 :
243       case v4i1 :
244       case v8i1 :
245       case v16i1: return i1;
246       case v2i8 :
247       case v4i8 :
248       case v8i8 :
249       case v16i8:
250       case v32i8: return i8;
251       case v1i16:
252       case v2i16:
253       case v4i16:
254       case v8i16:
255       case v16i16: return i16;
256       case v1i32:
257       case v2i32:
258       case v4i32:
259       case v8i32:
260       case v16i32: return i32;
261       case v1i64:
262       case v2i64:
263       case v4i64:
264       case v8i64:
265       case v16i64: return i64;
266       case v2f16: return f16;
267       case v2f32:
268       case v4f32:
269       case v8f32: return f32;
270       case v2f64:
271       case v4f64: return f64;
272       }
273     }
274
275     unsigned getVectorNumElements() const {
276       switch (SimpleTy) {
277       default:
278         llvm_unreachable("Not a vector MVT!");
279       case v32i8: return 32;
280       case v16i1:
281       case v16i8:
282       case v16i16:
283       case v16i32:
284       case v16i64:return 16;
285       case v8i1:
286       case v8i8 :
287       case v8i16:
288       case v8i32:
289       case v8i64:
290       case v8f32: return 8;
291       case v4i1:
292       case v4i8:
293       case v4i16:
294       case v4i32:
295       case v4i64:
296       case v4f32:
297       case v4f64: return 4;
298       case v2i1:
299       case v2i8:
300       case v2i16:
301       case v2i32:
302       case v2i64:
303       case v2f16:
304       case v2f32:
305       case v2f64: return 2;
306       case v1i16:
307       case v1i32:
308       case v1i64: return 1;
309       }
310     }
311
312     unsigned getSizeInBits() const {
313       switch (SimpleTy) {
314       case iPTR:
315         llvm_unreachable("Value type size is target-dependent. Ask TLI.");
316       case iPTRAny:
317       case iAny:
318       case fAny:
319         llvm_unreachable("Value type is overloaded.");
320       default:
321         llvm_unreachable("getSizeInBits called on extended MVT.");
322       case i1  :  return 1;
323       case v2i1:  return 2;
324       case v4i1:  return 4;
325       case i8  :
326       case v8i1: return 8;
327       case i16 :
328       case f16:
329       case v16i1:
330       case v2i8:
331       case v1i16: return 16;
332       case f32 :
333       case i32 :
334       case v4i8:
335       case v2i16:
336       case v2f16: 
337       case v1i32: return 32;
338       case x86mmx:
339       case f64 :
340       case i64 :
341       case v8i8:
342       case v4i16:
343       case v2i32:
344       case v1i64:
345       case v2f32: return 64;
346       case f80 :  return 80;
347       case f128:
348       case ppcf128:
349       case i128:
350       case v16i8:
351       case v8i16:
352       case v4i32:
353       case v2i64:
354       case v4f32:
355       case v2f64: return 128;
356       case v32i8:
357       case v16i16:
358       case v8i32:
359       case v4i64:
360       case v8f32:
361       case v4f64: return 256;
362       case v16i32:
363       case v8i64: return 512;
364       case v16i64:return 1024;
365       }
366     }
367
368     /// getStoreSize - Return the number of bytes overwritten by a store
369     /// of the specified value type.
370     unsigned getStoreSize() const {
371       return (getSizeInBits() + 7) / 8;
372     }
373
374     /// getStoreSizeInBits - Return the number of bits overwritten by a store
375     /// of the specified value type.
376     unsigned getStoreSizeInBits() const {
377       return getStoreSize() * 8;
378     }
379
380     static MVT getFloatingPointVT(unsigned BitWidth) {
381       switch (BitWidth) {
382       default:
383         llvm_unreachable("Bad bit width!");
384       case 16:
385         return MVT::f16;
386       case 32:
387         return MVT::f32;
388       case 64:
389         return MVT::f64;
390       case 80:
391         return MVT::f80;
392       case 128:
393         return MVT::f128;
394       }
395     }
396
397     static MVT getIntegerVT(unsigned BitWidth) {
398       switch (BitWidth) {
399       default:
400         return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
401       case 1:
402         return MVT::i1;
403       case 8:
404         return MVT::i8;
405       case 16:
406         return MVT::i16;
407       case 32:
408         return MVT::i32;
409       case 64:
410         return MVT::i64;
411       case 128:
412         return MVT::i128;
413       }
414     }
415
416     static MVT getVectorVT(MVT VT, unsigned NumElements) {
417       switch (VT.SimpleTy) {
418       default:
419         break;
420       case MVT::i1:
421         if (NumElements == 2)  return MVT::v2i1;
422         if (NumElements == 4)  return MVT::v4i1;
423         if (NumElements == 8)  return MVT::v8i1;
424         if (NumElements == 16) return MVT::v16i1;
425         break;
426       case MVT::i8:
427         if (NumElements == 2)  return MVT::v2i8;
428         if (NumElements == 4)  return MVT::v4i8;
429         if (NumElements == 8)  return MVT::v8i8;
430         if (NumElements == 16) return MVT::v16i8;
431         if (NumElements == 32) return MVT::v32i8;
432         break;
433       case MVT::i16:
434         if (NumElements == 1)  return MVT::v1i16;
435         if (NumElements == 2)  return MVT::v2i16;
436         if (NumElements == 4)  return MVT::v4i16;
437         if (NumElements == 8)  return MVT::v8i16;
438         if (NumElements == 16) return MVT::v16i16;
439         break;
440       case MVT::i32:
441         if (NumElements == 1)  return MVT::v1i32;
442         if (NumElements == 2)  return MVT::v2i32;
443         if (NumElements == 4)  return MVT::v4i32;
444         if (NumElements == 8)  return MVT::v8i32;
445         if (NumElements == 16) return MVT::v16i32;
446         break;
447       case MVT::i64:
448         if (NumElements == 1)  return MVT::v1i64;
449         if (NumElements == 2)  return MVT::v2i64;
450         if (NumElements == 4)  return MVT::v4i64;
451         if (NumElements == 8)  return MVT::v8i64;
452         if (NumElements == 16) return MVT::v16i64;
453         break;
454       case MVT::f16:
455         if (NumElements == 2)  return MVT::v2f16;
456         break;
457       case MVT::f32:
458         if (NumElements == 2)  return MVT::v2f32;
459         if (NumElements == 4)  return MVT::v4f32;
460         if (NumElements == 8)  return MVT::v8f32;
461         break;
462       case MVT::f64:
463         if (NumElements == 2)  return MVT::v2f64;
464         if (NumElements == 4)  return MVT::v4f64;
465         break;
466       }
467       return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
468     }
469   };
470
471
472   /// EVT - Extended Value Type.  Capable of holding value types which are not
473   /// native for any processor (such as the i12345 type), as well as the types
474   /// a MVT can represent.
475   struct EVT {
476   private:
477     MVT V;
478     Type *LLVMTy;
479
480   public:
481     EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)),
482             LLVMTy(0) {}
483     EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(0) { }
484     EVT(MVT S) : V(S), LLVMTy(0) {}
485
486     bool operator==(EVT VT) const {
487       return !(*this != VT);
488     }
489     bool operator!=(EVT VT) const {
490       if (V.SimpleTy != VT.V.SimpleTy)
491         return true;
492       if (V.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
493         return LLVMTy != VT.LLVMTy;
494       return false;
495     }
496
497     /// getFloatingPointVT - Returns the EVT that represents a floating point
498     /// type with the given number of bits.  There are two floating point types
499     /// with 128 bits - this returns f128 rather than ppcf128.
500     static EVT getFloatingPointVT(unsigned BitWidth) {
501       return MVT::getFloatingPointVT(BitWidth);
502     }
503
504     /// getIntegerVT - Returns the EVT that represents an integer with the given
505     /// number of bits.
506     static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) {
507       MVT M = MVT::getIntegerVT(BitWidth);
508       if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
509         return M;
510       return getExtendedIntegerVT(Context, BitWidth);
511     }
512
513     /// getVectorVT - Returns the EVT that represents a vector NumElements in
514     /// length, where each element is of type VT.
515     static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements) {
516       MVT M = MVT::getVectorVT(VT.V, NumElements);
517       if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
518         return M;
519       return getExtendedVectorVT(Context, VT, NumElements);
520     }
521
522     /// changeVectorElementTypeToInteger - Return a vector with the same number
523     /// of elements as this vector, but with the element type converted to an
524     /// integer type with the same bitwidth.
525     EVT changeVectorElementTypeToInteger() const {
526       if (!isSimple())
527         return changeExtendedVectorElementTypeToInteger();
528       MVT EltTy = getSimpleVT().getVectorElementType();
529       unsigned BitWidth = EltTy.getSizeInBits();
530       MVT IntTy = MVT::getIntegerVT(BitWidth);
531       MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements());
532       assert(VecTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
533              "Simple vector VT not representable by simple integer vector VT!");
534       return VecTy;
535     }
536
537     /// isSimple - Test if the given EVT is simple (as opposed to being
538     /// extended).
539     bool isSimple() const {
540       return V.SimpleTy <= MVT::LastSimpleValueType;
541     }
542
543     /// isExtended - Test if the given EVT is extended (as opposed to
544     /// being simple).
545     bool isExtended() const {
546       return !isSimple();
547     }
548
549     /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
550     bool isFloatingPoint() const {
551       return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
552     }
553
554     /// isInteger - Return true if this is an integer, or a vector integer type.
555     bool isInteger() const {
556       return isSimple() ? V.isInteger() : isExtendedInteger();
557     }
558
559     /// isVector - Return true if this is a vector value type.
560     bool isVector() const {
561       return isSimple() ? V.isVector() : isExtendedVector();
562     }
563
564     /// is16BitVector - Return true if this is a 16-bit vector type.
565     bool is16BitVector() const {
566       if (!isSimple())
567         return isExtended16BitVector();
568
569       return (V == MVT::v2i8  || V==MVT::v1i16 || V == MVT::v16i1);
570     }
571
572     /// is32BitVector - Return true if this is a 32-bit vector type.
573     bool is32BitVector() const {
574       if (!isSimple())
575         return isExtended32BitVector();
576
577       return (V == MVT::v4i8  || V==MVT::v2i16
578           || V==MVT::v1i32);
579     }
580
581     /// is64BitVector - Return true if this is a 64-bit vector type.
582     bool is64BitVector() const {
583       return isSimple() ? V.is64BitVector() : isExtended64BitVector();
584     }
585
586     /// is128BitVector - Return true if this is a 128-bit vector type.
587     bool is128BitVector() const {
588       return isSimple() ? V.is128BitVector() : isExtended128BitVector();
589     }
590
591     /// is256BitVector - Return true if this is a 256-bit vector type.
592     bool is256BitVector() const {
593       return isSimple() ? V.is256BitVector() : isExtended256BitVector();
594     }
595
596     /// is512BitVector - Return true if this is a 512-bit vector type.
597     bool is512BitVector() const {
598       return isSimple() ? V.is512BitVector() : isExtended512BitVector();
599     }
600
601     /// is1024BitVector - Return true if this is a 1024-bit vector type.
602     bool is1024BitVector() const {
603       return isSimple() ? V.is1024BitVector() : isExtended1024BitVector();
604     }
605
606     /// isOverloaded - Return true if this is an overloaded type for TableGen.
607     bool isOverloaded() const {
608       return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
609     }
610
611     /// isByteSized - Return true if the bit size is a multiple of 8.
612     bool isByteSized() const {
613       return (getSizeInBits() & 7) == 0;
614     }
615
616     /// isRound - Return true if the size is a power-of-two number of bytes.
617     bool isRound() const {
618       unsigned BitSize = getSizeInBits();
619       return BitSize >= 8 && !(BitSize & (BitSize - 1));
620     }
621
622     /// bitsEq - Return true if this has the same number of bits as VT.
623     bool bitsEq(EVT VT) const {
624       if (EVT::operator==(VT)) return true;
625       return getSizeInBits() == VT.getSizeInBits();
626     }
627
628     /// bitsGT - Return true if this has more bits than VT.
629     bool bitsGT(EVT VT) const {
630       if (EVT::operator==(VT)) return false;
631       return getSizeInBits() > VT.getSizeInBits();
632     }
633
634     /// bitsGE - Return true if this has no less bits than VT.
635     bool bitsGE(EVT VT) const {
636       if (EVT::operator==(VT)) return true;
637       return getSizeInBits() >= VT.getSizeInBits();
638     }
639
640     /// bitsLT - Return true if this has less bits than VT.
641     bool bitsLT(EVT VT) const {
642       if (EVT::operator==(VT)) return false;
643       return getSizeInBits() < VT.getSizeInBits();
644     }
645
646     /// bitsLE - Return true if this has no more bits than VT.
647     bool bitsLE(EVT VT) const {
648       if (EVT::operator==(VT)) return true;
649       return getSizeInBits() <= VT.getSizeInBits();
650     }
651
652
653     /// getSimpleVT - Return the SimpleValueType held in the specified
654     /// simple EVT.
655     MVT getSimpleVT() const {
656       assert(isSimple() && "Expected a SimpleValueType!");
657       return V;
658     }
659
660     /// getScalarType - If this is a vector type, return the element type,
661     /// otherwise return this.
662     EVT getScalarType() const {
663       return isVector() ? getVectorElementType() : *this;
664     }
665
666     /// getVectorElementType - Given a vector type, return the type of
667     /// each element.
668     EVT getVectorElementType() const {
669       assert(isVector() && "Invalid vector type!");
670       if (isSimple())
671         return V.getVectorElementType();
672       return getExtendedVectorElementType();
673     }
674
675     /// getVectorNumElements - Given a vector type, return the number of
676     /// elements it contains.
677     unsigned getVectorNumElements() const {
678       assert(isVector() && "Invalid vector type!");
679       if (isSimple())
680         return V.getVectorNumElements();
681       return getExtendedVectorNumElements();
682     }
683
684     /// getSizeInBits - Return the size of the specified value type in bits.
685     unsigned getSizeInBits() const {
686       if (isSimple())
687         return V.getSizeInBits();
688       return getExtendedSizeInBits();
689     }
690
691     /// getStoreSize - Return the number of bytes overwritten by a store
692     /// of the specified value type.
693     unsigned getStoreSize() const {
694       return (getSizeInBits() + 7) / 8;
695     }
696
697     /// getStoreSizeInBits - Return the number of bits overwritten by a store
698     /// of the specified value type.
699     unsigned getStoreSizeInBits() const {
700       return getStoreSize() * 8;
701     }
702
703     /// getRoundIntegerType - Rounds the bit-width of the given integer EVT up
704     /// to the nearest power of two (and at least to eight), and returns the
705     /// integer EVT with that number of bits.
706     EVT getRoundIntegerType(LLVMContext &Context) const {
707       assert(isInteger() && !isVector() && "Invalid integer type!");
708       unsigned BitWidth = getSizeInBits();
709       if (BitWidth <= 8)
710         return EVT(MVT::i8);
711       return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
712     }
713
714     /// getHalfSizedIntegerVT - Finds the smallest simple value type that is
715     /// greater than or equal to half the width of this EVT. If no simple
716     /// value type can be found, an extended integer value type of half the
717     /// size (rounded up) is returned.
718     EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
719       assert(isInteger() && !isVector() && "Invalid integer type!");
720       unsigned EVTSize = getSizeInBits();
721       for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
722           IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) {
723         EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
724         if (HalfVT.getSizeInBits() * 2 >= EVTSize)
725           return HalfVT;
726       }
727       return getIntegerVT(Context, (EVTSize + 1) / 2);
728     }
729
730     /// isPow2VectorType - Returns true if the given vector is a power of 2.
731     bool isPow2VectorType() const {
732       unsigned NElts = getVectorNumElements();
733       return !(NElts & (NElts - 1));
734     }
735
736     /// getPow2VectorType - Widens the length of the given vector EVT up to
737     /// the nearest power of 2 and returns that type.
738     EVT getPow2VectorType(LLVMContext &Context) const {
739       if (!isPow2VectorType()) {
740         unsigned NElts = getVectorNumElements();
741         unsigned Pow2NElts = 1 <<  Log2_32_Ceil(NElts);
742         return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts);
743       }
744       else {
745         return *this;
746       }
747     }
748
749     /// getEVTString - This function returns value type as a string,
750     /// e.g. "i32".
751     std::string getEVTString() const;
752
753     /// getTypeForEVT - This method returns an LLVM type corresponding to the
754     /// specified EVT.  For integer types, this returns an unsigned type.  Note
755     /// that this will abort for types that cannot be represented.
756     Type *getTypeForEVT(LLVMContext &Context) const;
757
758     /// getEVT - Return the value type corresponding to the specified type.
759     /// This returns all pointers as iPTR.  If HandleUnknown is true, unknown
760     /// types are returned as Other, otherwise they are invalid.
761     static EVT getEVT(Type *Ty, bool HandleUnknown = false);
762
763     intptr_t getRawBits() {
764       if (isSimple())
765         return V.SimpleTy;
766       else
767         return (intptr_t)(LLVMTy);
768     }
769
770     /// compareRawBits - A meaningless but well-behaved order, useful for
771     /// constructing containers.
772     struct compareRawBits {
773       bool operator()(EVT L, EVT R) const {
774         if (L.V.SimpleTy == R.V.SimpleTy)
775           return L.LLVMTy < R.LLVMTy;
776         else
777           return L.V.SimpleTy < R.V.SimpleTy;
778       }
779     };
780
781   private:
782     // Methods for handling the Extended-type case in functions above.
783     // These are all out-of-line to prevent users of this header file
784     // from having a dependency on Type.h.
785     EVT changeExtendedVectorElementTypeToInteger() const;
786     static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
787     static EVT getExtendedVectorVT(LLVMContext &C, EVT VT,
788                                    unsigned NumElements);
789     bool isExtendedFloatingPoint() const;
790     bool isExtendedInteger() const;
791     bool isExtendedVector() const;
792     bool isExtended16BitVector() const;
793     bool isExtended32BitVector() const;
794     bool isExtended64BitVector() const;
795     bool isExtended128BitVector() const;
796     bool isExtended256BitVector() const;
797     bool isExtended512BitVector() const;
798     bool isExtended1024BitVector() const;
799     EVT getExtendedVectorElementType() const;
800     unsigned getExtendedVectorNumElements() const;
801     unsigned getExtendedSizeInBits() const;
802   };
803
804 } // End llvm namespace
805
806 #endif