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