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