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