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