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