More dead code removal (using -Wunreachable-code)
[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     }
450
451     /// changeVectorElementTypeToInteger - Return a vector with the same number
452     /// of elements as this vector, but with the element type converted to an
453     /// integer type with the same bitwidth.
454     EVT changeVectorElementTypeToInteger() const {
455       if (!isSimple())
456         return changeExtendedVectorElementTypeToInteger();
457       MVT EltTy = getSimpleVT().getVectorElementType();
458       unsigned BitWidth = EltTy.getSizeInBits();
459       MVT IntTy = MVT::getIntegerVT(BitWidth);
460       MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements());
461       assert(VecTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
462              "Simple vector VT not representable by simple integer vector VT!");
463       return VecTy;
464     }
465
466     /// isSimple - Test if the given EVT is simple (as opposed to being
467     /// extended).
468     bool isSimple() const {
469       return V.SimpleTy <= MVT::LastSimpleValueType;
470     }
471
472     /// isExtended - Test if the given EVT is extended (as opposed to
473     /// being simple).
474     bool isExtended() const {
475       return !isSimple();
476     }
477
478     /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
479     bool isFloatingPoint() const {
480       return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
481     }
482
483     /// isInteger - Return true if this is an integer, or a vector integer type.
484     bool isInteger() const {
485       return isSimple() ? V.isInteger() : isExtendedInteger();
486     }
487
488     /// isVector - Return true if this is a vector value type.
489     bool isVector() const {
490       return isSimple() ? V.isVector() : isExtendedVector();
491     }
492
493     /// is64BitVector - Return true if this is a 64-bit vector type.
494     bool is64BitVector() const {
495       if (!isSimple())
496         return isExtended64BitVector();
497
498       return (V == MVT::v8i8  || V==MVT::v4i16 || V==MVT::v2i32 ||
499               V == MVT::v1i64 || V==MVT::v2f32);
500     }
501
502     /// is128BitVector - Return true if this is a 128-bit vector type.
503     bool is128BitVector() const {
504       if (!isSimple())
505         return isExtended128BitVector();
506       return (V==MVT::v16i8 || V==MVT::v8i16 || V==MVT::v4i32 ||
507               V==MVT::v2i64 || V==MVT::v4f32 || V==MVT::v2f64);
508     }
509
510     /// is256BitVector - Return true if this is a 256-bit vector type.
511     inline bool is256BitVector() const {
512       if (!isSimple())
513         return isExtended256BitVector();
514       return (V == MVT::v8f32  || V == MVT::v4f64 || V == MVT::v32i8 ||
515               V == MVT::v16i16 || V == MVT::v8i32 || V == MVT::v4i64);
516     }
517
518     /// is512BitVector - Return true if this is a 512-bit vector type.
519     inline bool is512BitVector() const {
520       return isSimple() ? (V == MVT::v8i64) : isExtended512BitVector();
521     }
522
523     /// isOverloaded - Return true if this is an overloaded type for TableGen.
524     bool isOverloaded() const {
525       return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
526     }
527
528     /// isByteSized - Return true if the bit size is a multiple of 8.
529     bool isByteSized() const {
530       return (getSizeInBits() & 7) == 0;
531     }
532
533     /// isRound - Return true if the size is a power-of-two number of bytes.
534     bool isRound() const {
535       unsigned BitSize = getSizeInBits();
536       return BitSize >= 8 && !(BitSize & (BitSize - 1));
537     }
538
539     /// bitsEq - Return true if this has the same number of bits as VT.
540     bool bitsEq(EVT VT) const {
541       if (EVT::operator==(VT)) return true;
542       return getSizeInBits() == VT.getSizeInBits();
543     }
544
545     /// bitsGT - Return true if this has more bits than VT.
546     bool bitsGT(EVT VT) const {
547       if (EVT::operator==(VT)) return false;
548       return getSizeInBits() > VT.getSizeInBits();
549     }
550
551     /// bitsGE - Return true if this has no less bits than VT.
552     bool bitsGE(EVT VT) const {
553       if (EVT::operator==(VT)) return true;
554       return getSizeInBits() >= VT.getSizeInBits();
555     }
556
557     /// bitsLT - Return true if this has less bits than VT.
558     bool bitsLT(EVT VT) const {
559       if (EVT::operator==(VT)) return false;
560       return getSizeInBits() < VT.getSizeInBits();
561     }
562
563     /// bitsLE - Return true if this has no more bits than VT.
564     bool bitsLE(EVT VT) const {
565       if (EVT::operator==(VT)) return true;
566       return getSizeInBits() <= VT.getSizeInBits();
567     }
568
569
570     /// getSimpleVT - Return the SimpleValueType held in the specified
571     /// simple EVT.
572     MVT getSimpleVT() const {
573       assert(isSimple() && "Expected a SimpleValueType!");
574       return V;
575     }
576
577     /// getScalarType - If this is a vector type, return the element type,
578     /// otherwise return this.
579     EVT getScalarType() const {
580       return isVector() ? getVectorElementType() : *this;
581     }
582
583     /// getVectorElementType - Given a vector type, return the type of
584     /// each element.
585     EVT getVectorElementType() const {
586       assert(isVector() && "Invalid vector type!");
587       if (isSimple())
588         return V.getVectorElementType();
589       return getExtendedVectorElementType();
590     }
591
592     /// getVectorNumElements - Given a vector type, return the number of
593     /// elements it contains.
594     unsigned getVectorNumElements() const {
595       assert(isVector() && "Invalid vector type!");
596       if (isSimple())
597         return V.getVectorNumElements();
598       return getExtendedVectorNumElements();
599     }
600
601     /// getSizeInBits - Return the size of the specified value type in bits.
602     unsigned getSizeInBits() const {
603       if (isSimple())
604         return V.getSizeInBits();
605       return getExtendedSizeInBits();
606     }
607
608     /// getStoreSize - Return the number of bytes overwritten by a store
609     /// of the specified value type.
610     unsigned getStoreSize() const {
611       return (getSizeInBits() + 7) / 8;
612     }
613
614     /// getStoreSizeInBits - Return the number of bits overwritten by a store
615     /// of the specified value type.
616     unsigned getStoreSizeInBits() const {
617       return getStoreSize() * 8;
618     }
619
620     /// getRoundIntegerType - Rounds the bit-width of the given integer EVT up
621     /// to the nearest power of two (and at least to eight), and returns the
622     /// integer EVT with that number of bits.
623     EVT getRoundIntegerType(LLVMContext &Context) const {
624       assert(isInteger() && !isVector() && "Invalid integer type!");
625       unsigned BitWidth = getSizeInBits();
626       if (BitWidth <= 8)
627         return EVT(MVT::i8);
628       return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
629     }
630
631     /// getHalfSizedIntegerVT - Finds the smallest simple value type that is
632     /// greater than or equal to half the width of this EVT. If no simple
633     /// value type can be found, an extended integer value type of half the
634     /// size (rounded up) is returned.
635     EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
636       assert(isInteger() && !isVector() && "Invalid integer type!");
637       unsigned EVTSize = getSizeInBits();
638       for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
639           IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) {
640         EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
641         if (HalfVT.getSizeInBits() * 2 >= EVTSize)
642           return HalfVT;
643       }
644       return getIntegerVT(Context, (EVTSize + 1) / 2);
645     }
646
647     /// isPow2VectorType - Returns true if the given vector is a power of 2.
648     bool isPow2VectorType() const {
649       unsigned NElts = getVectorNumElements();
650       return !(NElts & (NElts - 1));
651     }
652
653     /// getPow2VectorType - Widens the length of the given vector EVT up to
654     /// the nearest power of 2 and returns that type.
655     EVT getPow2VectorType(LLVMContext &Context) const {
656       if (!isPow2VectorType()) {
657         unsigned NElts = getVectorNumElements();
658         unsigned Pow2NElts = 1 <<  Log2_32_Ceil(NElts);
659         return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts);
660       }
661       else {
662         return *this;
663       }
664     }
665
666     /// getEVTString - This function returns value type as a string,
667     /// e.g. "i32".
668     std::string getEVTString() const;
669
670     /// getTypeForEVT - This method returns an LLVM type corresponding to the
671     /// specified EVT.  For integer types, this returns an unsigned type.  Note
672     /// that this will abort for types that cannot be represented.
673     Type *getTypeForEVT(LLVMContext &Context) const;
674
675     /// getEVT - Return the value type corresponding to the specified type.
676     /// This returns all pointers as iPTR.  If HandleUnknown is true, unknown
677     /// types are returned as Other, otherwise they are invalid.
678     static EVT getEVT(Type *Ty, bool HandleUnknown = false);
679
680     intptr_t getRawBits() {
681       if (isSimple())
682         return V.SimpleTy;
683       else
684         return (intptr_t)(LLVMTy);
685     }
686
687     /// compareRawBits - A meaningless but well-behaved order, useful for
688     /// constructing containers.
689     struct compareRawBits {
690       bool operator()(EVT L, EVT R) const {
691         if (L.V.SimpleTy == R.V.SimpleTy)
692           return L.LLVMTy < R.LLVMTy;
693         else
694           return L.V.SimpleTy < R.V.SimpleTy;
695       }
696     };
697
698   private:
699     // Methods for handling the Extended-type case in functions above.
700     // These are all out-of-line to prevent users of this header file
701     // from having a dependency on Type.h.
702     EVT changeExtendedVectorElementTypeToInteger() const;
703     static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
704     static EVT getExtendedVectorVT(LLVMContext &C, EVT VT,
705                                    unsigned NumElements);
706     bool isExtendedFloatingPoint() const;
707     bool isExtendedInteger() const;
708     bool isExtendedVector() const;
709     bool isExtended64BitVector() const;
710     bool isExtended128BitVector() const;
711     bool isExtended256BitVector() const;
712     bool isExtended512BitVector() const;
713     EVT getExtendedVectorElementType() const;
714     unsigned getExtendedVectorNumElements() const;
715     unsigned getExtendedSizeInBits() const;
716   };
717
718 } // End llvm namespace
719
720 #endif