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