Change AsmOperandInfo::ConstraintVT to MVT, instead of EVT.
[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     /// is16BitVector - Return true if this is a 16-bit vector type.
185     bool is16BitVector() const {
186       return (SimpleTy == MVT::v2i8  || SimpleTy == MVT::v1i16 ||
187               SimpleTy == MVT::v16i1);
188     }
189
190     /// is32BitVector - Return true if this is a 32-bit vector type.
191     bool is32BitVector() const {
192       return (SimpleTy == MVT::v4i8  || SimpleTy == MVT::v2i16 ||
193               SimpleTy == MVT::v1i32);
194     }
195
196     /// is64BitVector - Return true if this is a 64-bit vector type.
197     bool is64BitVector() const {
198       return (SimpleTy == MVT::v8i8  || SimpleTy == MVT::v4i16 ||
199               SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
200               SimpleTy == MVT::v2f32);
201     }
202
203     /// is128BitVector - Return true if this is a 128-bit vector type.
204     bool is128BitVector() const {
205       return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
206               SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 ||
207               SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64);
208     }
209
210     /// is256BitVector - Return true if this is a 256-bit vector type.
211     bool is256BitVector() const {
212       return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64  ||
213               SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
214               SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
215     }
216
217     /// is512BitVector - Return true if this is a 512-bit vector type.
218     bool is512BitVector() const {
219       return (SimpleTy == MVT::v8i64 || SimpleTy == MVT::v16i32);
220     }
221
222     /// is1024BitVector - Return true if this is a 1024-bit vector type.
223     bool is1024BitVector() const {
224       return (SimpleTy == MVT::v16i64);
225     }
226
227     /// isPow2VectorType - Returns true if the given vector is a power of 2.
228     bool isPow2VectorType() const {
229       unsigned NElts = getVectorNumElements();
230       return !(NElts & (NElts - 1));
231     }
232
233     /// getPow2VectorType - Widens the length of the given vector MVT up to
234     /// the nearest power of 2 and returns that type.
235     MVT getPow2VectorType() const {
236       if (isPow2VectorType())
237         return *this;
238
239       unsigned NElts = getVectorNumElements();
240       unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
241       return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
242     }
243
244     /// getScalarType - If this is a vector type, return the element type,
245     /// otherwise return this.
246     MVT getScalarType() const {
247       return isVector() ? getVectorElementType() : *this;
248     }
249
250     MVT getVectorElementType() const {
251       switch (SimpleTy) {
252       default:
253         llvm_unreachable("Not a vector MVT!");
254       case v2i1 :
255       case v4i1 :
256       case v8i1 :
257       case v16i1: return i1;
258       case v2i8 :
259       case v4i8 :
260       case v8i8 :
261       case v16i8:
262       case v32i8: return i8;
263       case v1i16:
264       case v2i16:
265       case v4i16:
266       case v8i16:
267       case v16i16: return i16;
268       case v1i32:
269       case v2i32:
270       case v4i32:
271       case v8i32:
272       case v16i32: return i32;
273       case v1i64:
274       case v2i64:
275       case v4i64:
276       case v8i64:
277       case v16i64: return i64;
278       case v2f16: return f16;
279       case v2f32:
280       case v4f32:
281       case v8f32: return f32;
282       case v2f64:
283       case v4f64: return f64;
284       }
285     }
286
287     unsigned getVectorNumElements() const {
288       switch (SimpleTy) {
289       default:
290         llvm_unreachable("Not a vector MVT!");
291       case v32i8: return 32;
292       case v16i1:
293       case v16i8:
294       case v16i16:
295       case v16i32:
296       case v16i64:return 16;
297       case v8i1:
298       case v8i8 :
299       case v8i16:
300       case v8i32:
301       case v8i64:
302       case v8f32: return 8;
303       case v4i1:
304       case v4i8:
305       case v4i16:
306       case v4i32:
307       case v4i64:
308       case v4f32:
309       case v4f64: return 4;
310       case v2i1:
311       case v2i8:
312       case v2i16:
313       case v2i32:
314       case v2i64:
315       case v2f16:
316       case v2f32:
317       case v2f64: return 2;
318       case v1i16:
319       case v1i32:
320       case v1i64: return 1;
321       }
322     }
323
324     unsigned getSizeInBits() const {
325       switch (SimpleTy) {
326       case iPTR:
327         llvm_unreachable("Value type size is target-dependent. Ask TLI.");
328       case iPTRAny:
329       case iAny:
330       case fAny:
331         llvm_unreachable("Value type is overloaded.");
332       default:
333         llvm_unreachable("getSizeInBits called on extended MVT.");
334       case i1  :  return 1;
335       case v2i1:  return 2;
336       case v4i1:  return 4;
337       case i8  :
338       case v8i1: return 8;
339       case i16 :
340       case f16:
341       case v16i1:
342       case v2i8:
343       case v1i16: return 16;
344       case f32 :
345       case i32 :
346       case v4i8:
347       case v2i16:
348       case v2f16: 
349       case v1i32: return 32;
350       case x86mmx:
351       case f64 :
352       case i64 :
353       case v8i8:
354       case v4i16:
355       case v2i32:
356       case v1i64:
357       case v2f32: return 64;
358       case f80 :  return 80;
359       case f128:
360       case ppcf128:
361       case i128:
362       case v16i8:
363       case v8i16:
364       case v4i32:
365       case v2i64:
366       case v4f32:
367       case v2f64: return 128;
368       case v32i8:
369       case v16i16:
370       case v8i32:
371       case v4i64:
372       case v8f32:
373       case v4f64: return 256;
374       case v16i32:
375       case v8i64: return 512;
376       case v16i64:return 1024;
377       }
378     }
379
380     /// getStoreSize - Return the number of bytes overwritten by a store
381     /// of the specified value type.
382     unsigned getStoreSize() const {
383       return (getSizeInBits() + 7) / 8;
384     }
385
386     /// getStoreSizeInBits - Return the number of bits overwritten by a store
387     /// of the specified value type.
388     unsigned getStoreSizeInBits() const {
389       return getStoreSize() * 8;
390     }
391
392     /// Return true if this has more bits than VT.
393     bool bitsGT(MVT VT) const {
394       return getSizeInBits() > VT.getSizeInBits();
395     }
396
397     /// Return true if this has no less bits than VT.
398     bool bitsGE(MVT VT) const {
399       return getSizeInBits() >= VT.getSizeInBits();
400     }
401
402     /// Return true if this has less bits than VT.
403     bool bitsLT(MVT VT) const {
404       return getSizeInBits() < VT.getSizeInBits();
405     }
406
407     /// Return true if this has no more bits than VT.
408     bool bitsLE(MVT VT) const {
409       return getSizeInBits() <= VT.getSizeInBits();
410     }
411
412
413     static MVT getFloatingPointVT(unsigned BitWidth) {
414       switch (BitWidth) {
415       default:
416         llvm_unreachable("Bad bit width!");
417       case 16:
418         return MVT::f16;
419       case 32:
420         return MVT::f32;
421       case 64:
422         return MVT::f64;
423       case 80:
424         return MVT::f80;
425       case 128:
426         return MVT::f128;
427       }
428     }
429
430     static MVT getIntegerVT(unsigned BitWidth) {
431       switch (BitWidth) {
432       default:
433         return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
434       case 1:
435         return MVT::i1;
436       case 8:
437         return MVT::i8;
438       case 16:
439         return MVT::i16;
440       case 32:
441         return MVT::i32;
442       case 64:
443         return MVT::i64;
444       case 128:
445         return MVT::i128;
446       }
447     }
448
449     static MVT getVectorVT(MVT VT, unsigned NumElements) {
450       switch (VT.SimpleTy) {
451       default:
452         break;
453       case MVT::i1:
454         if (NumElements == 2)  return MVT::v2i1;
455         if (NumElements == 4)  return MVT::v4i1;
456         if (NumElements == 8)  return MVT::v8i1;
457         if (NumElements == 16) return MVT::v16i1;
458         break;
459       case MVT::i8:
460         if (NumElements == 2)  return MVT::v2i8;
461         if (NumElements == 4)  return MVT::v4i8;
462         if (NumElements == 8)  return MVT::v8i8;
463         if (NumElements == 16) return MVT::v16i8;
464         if (NumElements == 32) return MVT::v32i8;
465         break;
466       case MVT::i16:
467         if (NumElements == 1)  return MVT::v1i16;
468         if (NumElements == 2)  return MVT::v2i16;
469         if (NumElements == 4)  return MVT::v4i16;
470         if (NumElements == 8)  return MVT::v8i16;
471         if (NumElements == 16) return MVT::v16i16;
472         break;
473       case MVT::i32:
474         if (NumElements == 1)  return MVT::v1i32;
475         if (NumElements == 2)  return MVT::v2i32;
476         if (NumElements == 4)  return MVT::v4i32;
477         if (NumElements == 8)  return MVT::v8i32;
478         if (NumElements == 16) return MVT::v16i32;
479         break;
480       case MVT::i64:
481         if (NumElements == 1)  return MVT::v1i64;
482         if (NumElements == 2)  return MVT::v2i64;
483         if (NumElements == 4)  return MVT::v4i64;
484         if (NumElements == 8)  return MVT::v8i64;
485         if (NumElements == 16) return MVT::v16i64;
486         break;
487       case MVT::f16:
488         if (NumElements == 2)  return MVT::v2f16;
489         break;
490       case MVT::f32:
491         if (NumElements == 2)  return MVT::v2f32;
492         if (NumElements == 4)  return MVT::v4f32;
493         if (NumElements == 8)  return MVT::v8f32;
494         break;
495       case MVT::f64:
496         if (NumElements == 2)  return MVT::v2f64;
497         if (NumElements == 4)  return MVT::v4f64;
498         break;
499       }
500       return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
501     }
502
503     /// Return the value type corresponding to the specified type.  This returns
504     /// all pointers as iPTR.  If HandleUnknown is true, unknown types are
505     /// returned as Other, otherwise they are invalid.
506     static MVT getVT(Type *Ty, bool HandleUnknown = false);
507
508   };
509
510
511   /// EVT - Extended Value Type.  Capable of holding value types which are not
512   /// native for any processor (such as the i12345 type), as well as the types
513   /// a MVT can represent.
514   struct EVT {
515   private:
516     MVT V;
517     Type *LLVMTy;
518
519   public:
520     EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)),
521             LLVMTy(0) {}
522     EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(0) { }
523     EVT(MVT S) : V(S), LLVMTy(0) {}
524
525     bool operator==(EVT VT) const {
526       return !(*this != VT);
527     }
528     bool operator!=(EVT VT) const {
529       if (V.SimpleTy != VT.V.SimpleTy)
530         return true;
531       if (V.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
532         return LLVMTy != VT.LLVMTy;
533       return false;
534     }
535
536     /// getFloatingPointVT - Returns the EVT that represents a floating point
537     /// type with the given number of bits.  There are two floating point types
538     /// with 128 bits - this returns f128 rather than ppcf128.
539     static EVT getFloatingPointVT(unsigned BitWidth) {
540       return MVT::getFloatingPointVT(BitWidth);
541     }
542
543     /// getIntegerVT - Returns the EVT that represents an integer with the given
544     /// number of bits.
545     static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) {
546       MVT M = MVT::getIntegerVT(BitWidth);
547       if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
548         return M;
549       return getExtendedIntegerVT(Context, BitWidth);
550     }
551
552     /// getVectorVT - Returns the EVT that represents a vector NumElements in
553     /// length, where each element is of type VT.
554     static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements) {
555       MVT M = MVT::getVectorVT(VT.V, NumElements);
556       if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
557         return M;
558       return getExtendedVectorVT(Context, VT, NumElements);
559     }
560
561     /// changeVectorElementTypeToInteger - Return a vector with the same number
562     /// of elements as this vector, but with the element type converted to an
563     /// integer type with the same bitwidth.
564     EVT changeVectorElementTypeToInteger() const {
565       if (!isSimple())
566         return changeExtendedVectorElementTypeToInteger();
567       MVT EltTy = getSimpleVT().getVectorElementType();
568       unsigned BitWidth = EltTy.getSizeInBits();
569       MVT IntTy = MVT::getIntegerVT(BitWidth);
570       MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements());
571       assert(VecTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
572              "Simple vector VT not representable by simple integer vector VT!");
573       return VecTy;
574     }
575
576     /// isSimple - Test if the given EVT is simple (as opposed to being
577     /// extended).
578     bool isSimple() const {
579       return V.SimpleTy <= MVT::LastSimpleValueType;
580     }
581
582     /// isExtended - Test if the given EVT is extended (as opposed to
583     /// being simple).
584     bool isExtended() const {
585       return !isSimple();
586     }
587
588     /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
589     bool isFloatingPoint() const {
590       return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
591     }
592
593     /// isInteger - Return true if this is an integer, or a vector integer type.
594     bool isInteger() const {
595       return isSimple() ? V.isInteger() : isExtendedInteger();
596     }
597
598     /// isVector - Return true if this is a vector value type.
599     bool isVector() const {
600       return isSimple() ? V.isVector() : isExtendedVector();
601     }
602
603     /// is16BitVector - Return true if this is a 16-bit vector type.
604     bool is16BitVector() const {
605       return isSimple() ? V.is16BitVector() : isExtended16BitVector();
606     }
607
608     /// is32BitVector - Return true if this is a 32-bit vector type.
609     bool is32BitVector() const {
610       return isSimple() ? V.is32BitVector() : isExtended32BitVector();
611     }
612
613     /// is64BitVector - Return true if this is a 64-bit vector type.
614     bool is64BitVector() const {
615       return isSimple() ? V.is64BitVector() : isExtended64BitVector();
616     }
617
618     /// is128BitVector - Return true if this is a 128-bit vector type.
619     bool is128BitVector() const {
620       return isSimple() ? V.is128BitVector() : isExtended128BitVector();
621     }
622
623     /// is256BitVector - Return true if this is a 256-bit vector type.
624     bool is256BitVector() const {
625       return isSimple() ? V.is256BitVector() : isExtended256BitVector();
626     }
627
628     /// is512BitVector - Return true if this is a 512-bit vector type.
629     bool is512BitVector() const {
630       return isSimple() ? V.is512BitVector() : isExtended512BitVector();
631     }
632
633     /// is1024BitVector - Return true if this is a 1024-bit vector type.
634     bool is1024BitVector() const {
635       return isSimple() ? V.is1024BitVector() : isExtended1024BitVector();
636     }
637
638     /// isOverloaded - Return true if this is an overloaded type for TableGen.
639     bool isOverloaded() const {
640       return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
641     }
642
643     /// isByteSized - Return true if the bit size is a multiple of 8.
644     bool isByteSized() const {
645       return (getSizeInBits() & 7) == 0;
646     }
647
648     /// isRound - Return true if the size is a power-of-two number of bytes.
649     bool isRound() const {
650       unsigned BitSize = getSizeInBits();
651       return BitSize >= 8 && !(BitSize & (BitSize - 1));
652     }
653
654     /// bitsEq - Return true if this has the same number of bits as VT.
655     bool bitsEq(EVT VT) const {
656       if (EVT::operator==(VT)) return true;
657       return getSizeInBits() == VT.getSizeInBits();
658     }
659
660     /// bitsGT - Return true if this has more bits than VT.
661     bool bitsGT(EVT VT) const {
662       if (EVT::operator==(VT)) return false;
663       return getSizeInBits() > VT.getSizeInBits();
664     }
665
666     /// bitsGE - Return true if this has no less bits than VT.
667     bool bitsGE(EVT VT) const {
668       if (EVT::operator==(VT)) return true;
669       return getSizeInBits() >= VT.getSizeInBits();
670     }
671
672     /// bitsLT - Return true if this has less bits than VT.
673     bool bitsLT(EVT VT) const {
674       if (EVT::operator==(VT)) return false;
675       return getSizeInBits() < VT.getSizeInBits();
676     }
677
678     /// bitsLE - Return true if this has no more bits than VT.
679     bool bitsLE(EVT VT) const {
680       if (EVT::operator==(VT)) return true;
681       return getSizeInBits() <= VT.getSizeInBits();
682     }
683
684
685     /// getSimpleVT - Return the SimpleValueType held in the specified
686     /// simple EVT.
687     MVT getSimpleVT() const {
688       assert(isSimple() && "Expected a SimpleValueType!");
689       return V;
690     }
691
692     /// getScalarType - If this is a vector type, return the element type,
693     /// otherwise return this.
694     EVT getScalarType() const {
695       return isVector() ? getVectorElementType() : *this;
696     }
697
698     /// getVectorElementType - Given a vector type, return the type of
699     /// each element.
700     EVT getVectorElementType() const {
701       assert(isVector() && "Invalid vector type!");
702       if (isSimple())
703         return V.getVectorElementType();
704       return getExtendedVectorElementType();
705     }
706
707     /// getVectorNumElements - Given a vector type, return the number of
708     /// elements it contains.
709     unsigned getVectorNumElements() const {
710       assert(isVector() && "Invalid vector type!");
711       if (isSimple())
712         return V.getVectorNumElements();
713       return getExtendedVectorNumElements();
714     }
715
716     /// getSizeInBits - Return the size of the specified value type in bits.
717     unsigned getSizeInBits() const {
718       if (isSimple())
719         return V.getSizeInBits();
720       return getExtendedSizeInBits();
721     }
722
723     /// getStoreSize - Return the number of bytes overwritten by a store
724     /// of the specified value type.
725     unsigned getStoreSize() const {
726       return (getSizeInBits() + 7) / 8;
727     }
728
729     /// getStoreSizeInBits - Return the number of bits overwritten by a store
730     /// of the specified value type.
731     unsigned getStoreSizeInBits() const {
732       return getStoreSize() * 8;
733     }
734
735     /// getRoundIntegerType - Rounds the bit-width of the given integer EVT up
736     /// to the nearest power of two (and at least to eight), and returns the
737     /// integer EVT with that number of bits.
738     EVT getRoundIntegerType(LLVMContext &Context) const {
739       assert(isInteger() && !isVector() && "Invalid integer type!");
740       unsigned BitWidth = getSizeInBits();
741       if (BitWidth <= 8)
742         return EVT(MVT::i8);
743       return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
744     }
745
746     /// getHalfSizedIntegerVT - Finds the smallest simple value type that is
747     /// greater than or equal to half the width of this EVT. If no simple
748     /// value type can be found, an extended integer value type of half the
749     /// size (rounded up) is returned.
750     EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
751       assert(isInteger() && !isVector() && "Invalid integer type!");
752       unsigned EVTSize = getSizeInBits();
753       for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
754           IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) {
755         EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
756         if (HalfVT.getSizeInBits() * 2 >= EVTSize)
757           return HalfVT;
758       }
759       return getIntegerVT(Context, (EVTSize + 1) / 2);
760     }
761
762     /// isPow2VectorType - Returns true if the given vector is a power of 2.
763     bool isPow2VectorType() const {
764       unsigned NElts = getVectorNumElements();
765       return !(NElts & (NElts - 1));
766     }
767
768     /// getPow2VectorType - Widens the length of the given vector EVT up to
769     /// the nearest power of 2 and returns that type.
770     EVT getPow2VectorType(LLVMContext &Context) const {
771       if (!isPow2VectorType()) {
772         unsigned NElts = getVectorNumElements();
773         unsigned Pow2NElts = 1 <<  Log2_32_Ceil(NElts);
774         return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts);
775       }
776       else {
777         return *this;
778       }
779     }
780
781     /// getEVTString - This function returns value type as a string,
782     /// e.g. "i32".
783     std::string getEVTString() const;
784
785     /// getTypeForEVT - This method returns an LLVM type corresponding to the
786     /// specified EVT.  For integer types, this returns an unsigned type.  Note
787     /// that this will abort for types that cannot be represented.
788     Type *getTypeForEVT(LLVMContext &Context) const;
789
790     /// getEVT - Return the value type corresponding to the specified type.
791     /// This returns all pointers as iPTR.  If HandleUnknown is true, unknown
792     /// types are returned as Other, otherwise they are invalid.
793     static EVT getEVT(Type *Ty, bool HandleUnknown = false);
794
795     intptr_t getRawBits() {
796       if (isSimple())
797         return V.SimpleTy;
798       else
799         return (intptr_t)(LLVMTy);
800     }
801
802     /// compareRawBits - A meaningless but well-behaved order, useful for
803     /// constructing containers.
804     struct compareRawBits {
805       bool operator()(EVT L, EVT R) const {
806         if (L.V.SimpleTy == R.V.SimpleTy)
807           return L.LLVMTy < R.LLVMTy;
808         else
809           return L.V.SimpleTy < R.V.SimpleTy;
810       }
811     };
812
813   private:
814     // Methods for handling the Extended-type case in functions above.
815     // These are all out-of-line to prevent users of this header file
816     // from having a dependency on Type.h.
817     EVT changeExtendedVectorElementTypeToInteger() const;
818     static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
819     static EVT getExtendedVectorVT(LLVMContext &C, EVT VT,
820                                    unsigned NumElements);
821     bool isExtendedFloatingPoint() const;
822     bool isExtendedInteger() const;
823     bool isExtendedVector() const;
824     bool isExtended16BitVector() const;
825     bool isExtended32BitVector() const;
826     bool isExtended64BitVector() const;
827     bool isExtended128BitVector() const;
828     bool isExtended256BitVector() const;
829     bool isExtended512BitVector() const;
830     bool isExtended1024BitVector() const;
831     EVT getExtendedVectorElementType() const;
832     unsigned getExtendedVectorNumElements() const;
833     unsigned getExtendedSizeInBits() const;
834   };
835
836 } // End llvm namespace
837
838 #endif