Replace tablegen uses of EVT with MVT. Add isOverloaded() to MVT to facilitate. Remov...
[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 an MVT.
33   class MVT {
34   public:
35     enum SimpleValueType {
36       // INVALID_SIMPLE_VALUE_TYPE - Simple value types less than zero are
37       // considered extended value types.
38       INVALID_SIMPLE_VALUE_TYPE = -1,
39
40       // If you change this numbering, you must change the values in
41       // ValueTypes.td as well!
42       Other          =   0,   // This is a non-standard value
43       i1             =   1,   // This is a 1 bit integer value
44       i8             =   2,   // This is an 8 bit integer value
45       i16            =   3,   // This is a 16 bit integer value
46       i32            =   4,   // This is a 32 bit integer value
47       i64            =   5,   // This is a 64 bit integer value
48       i128           =   6,   // This is a 128 bit integer value
49
50       FIRST_INTEGER_VALUETYPE = i1,
51       LAST_INTEGER_VALUETYPE  = i128,
52
53       f16            =   7,   // This is a 16 bit floating point value
54       f32            =   8,   // This is a 32 bit floating point value
55       f64            =   9,   // This is a 64 bit floating point value
56       f80            =  10,   // This is a 80 bit floating point value
57       f128           =  11,   // This is a 128 bit floating point value
58       ppcf128        =  12,   // This is a PPC 128-bit floating point value
59
60       FIRST_FP_VALUETYPE = f16,
61       LAST_FP_VALUETYPE  = ppcf128,
62
63       v2i1           =  13,   //  2 x i1
64       v4i1           =  14,   //  4 x i1
65       v8i1           =  15,   //  8 x i1
66       v16i1          =  16,   // 16 x i1
67       v32i1          =  17,   // 32 x i1
68       v64i1          =  18,   // 64 x i1
69
70       v1i8           =  19,   //  1 x i8
71       v2i8           =  20,   //  2 x i8
72       v4i8           =  21,   //  4 x i8
73       v8i8           =  22,   //  8 x i8
74       v16i8          =  23,   // 16 x i8
75       v32i8          =  24,   // 32 x i8
76       v64i8          =  25,   // 64 x i8
77       v1i16          =  26,   //  1 x i16
78       v2i16          =  27,   //  2 x i16
79       v4i16          =  28,   //  4 x i16
80       v8i16          =  29,   //  8 x i16
81       v16i16         =  30,   // 16 x i16
82       v32i16         =  31,   // 32 x i16
83       v1i32          =  32,   //  1 x i32
84       v2i32          =  33,   //  2 x i32
85       v4i32          =  34,   //  4 x i32
86       v8i32          =  35,   //  8 x i32
87       v16i32         =  36,   // 16 x i32
88       v1i64          =  37,   //  1 x i64
89       v2i64          =  38,   //  2 x i64
90       v4i64          =  39,   //  4 x i64
91       v8i64          =  40,   //  8 x i64
92       v16i64         =  41,   // 16 x i64
93
94       FIRST_INTEGER_VECTOR_VALUETYPE = v2i1,
95       LAST_INTEGER_VECTOR_VALUETYPE = v16i64,
96
97       v2f16          =  42,   //  2 x f16
98       v4f16          =  43,   //  4 x f16
99       v8f16          =  44,   //  8 x f16
100       v1f32          =  45,   //  1 x f32
101       v2f32          =  46,   //  2 x f32
102       v4f32          =  47,   //  4 x f32
103       v8f32          =  48,   //  8 x f32
104       v16f32         =  49,   // 16 x f32
105       v1f64          =  50,   //  1 x f64
106       v2f64          =  51,   //  2 x f64
107       v4f64          =  52,   //  4 x f64
108       v8f64          =  53,   //  8 x f64
109
110       FIRST_FP_VECTOR_VALUETYPE = v2f16,
111       LAST_FP_VECTOR_VALUETYPE = v8f64,
112
113       FIRST_VECTOR_VALUETYPE = v2i1,
114       LAST_VECTOR_VALUETYPE  = v8f64,
115
116       x86mmx         =  54,   // This is an X86 MMX value
117
118       Glue           =  55,   // This glues nodes together during pre-RA sched
119
120       isVoid         =  56,   // This has no value
121
122       Untyped        =  57,   // This value takes a register, but has
123                               // unspecified type.  The register class
124                               // will be determined by the opcode.
125
126       LAST_VALUETYPE =  58,   // This always remains at the end of the list.
127
128       // This is the current maximum for LAST_VALUETYPE.
129       // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
130       // This value must be a multiple of 32.
131       MAX_ALLOWED_VALUETYPE = 64,
132
133       // Metadata - This is MDNode or MDString.
134       Metadata       = 250,
135
136       // iPTRAny - An int value the size of the pointer of the current
137       // target to any address space. This must only be used internal to
138       // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
139       iPTRAny        = 251,
140
141       // vAny - A vector with any length and element size. This is used
142       // for intrinsics that have overloadings based on vector types.
143       // This is only for tblgen's consumption!
144       vAny           = 252,
145
146       // fAny - Any floating-point or vector floating-point value. This is used
147       // for intrinsics that have overloadings based on floating-point types.
148       // This is only for tblgen's consumption!
149       fAny           = 253,
150
151       // iAny - An integer or vector integer value of any bit width. This is
152       // used for intrinsics that have overloadings based on integer bit widths.
153       // This is only for tblgen's consumption!
154       iAny           = 254,
155
156       // iPTR - An int value the size of the pointer of the current
157       // target.  This should only be used internal to tblgen!
158       iPTR           = 255
159     };
160
161     SimpleValueType SimpleTy;
162
163     MVT() : SimpleTy((SimpleValueType)(INVALID_SIMPLE_VALUE_TYPE)) {}
164     MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
165
166     bool operator>(const MVT& S)  const { return SimpleTy >  S.SimpleTy; }
167     bool operator<(const MVT& S)  const { return SimpleTy <  S.SimpleTy; }
168     bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
169     bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
170     bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
171     bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
172
173     /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
174     bool isFloatingPoint() const {
175       return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
176                SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
177               (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE &&
178                SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE));
179     }
180
181     /// isInteger - Return true if this is an integer, or a vector integer type.
182     bool isInteger() const {
183       return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
184                SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
185               (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE &&
186                SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE));
187     }
188
189     /// isVector - Return true if this is a vector value type.
190     bool isVector() const {
191       return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
192               SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
193     }
194
195     /// is16BitVector - Return true if this is a 16-bit vector type.
196     bool is16BitVector() const {
197       return (SimpleTy == MVT::v2i8  || SimpleTy == MVT::v1i16 ||
198               SimpleTy == MVT::v16i1);
199     }
200
201     /// is32BitVector - Return true if this is a 32-bit vector type.
202     bool is32BitVector() const {
203       return (SimpleTy == MVT::v4i8  || SimpleTy == MVT::v2i16 ||
204               SimpleTy == MVT::v1i32);
205     }
206
207     /// is64BitVector - Return true if this is a 64-bit vector type.
208     bool is64BitVector() const {
209       return (SimpleTy == MVT::v8i8  || SimpleTy == MVT::v4i16 ||
210               SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
211               SimpleTy == MVT::v1f64 || SimpleTy == MVT::v2f32);
212     }
213
214     /// is128BitVector - Return true if this is a 128-bit vector type.
215     bool is128BitVector() const {
216       return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
217               SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 ||
218               SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64);
219     }
220
221     /// is256BitVector - Return true if this is a 256-bit vector type.
222     bool is256BitVector() const {
223       return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64  ||
224               SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
225               SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
226     }
227
228     /// is512BitVector - Return true if this is a 512-bit vector type.
229     bool is512BitVector() const {
230       return (SimpleTy == MVT::v8f64 || SimpleTy == MVT::v16f32 ||
231               SimpleTy == MVT::v64i8 || SimpleTy == MVT::v32i16 ||
232               SimpleTy == MVT::v8i64 || SimpleTy == MVT::v16i32);
233     }
234
235     /// is1024BitVector - Return true if this is a 1024-bit vector type.
236     bool is1024BitVector() const {
237       return (SimpleTy == MVT::v16i64);
238     }
239
240     /// isOverloaded - Return true if this is an overloaded type for TableGen.
241     bool isOverloaded() const {
242       return (SimpleTy==MVT::iAny || SimpleTy==MVT::fAny ||
243               SimpleTy==MVT::vAny || SimpleTy==MVT::iPTRAny);
244     }
245
246     /// isPow2VectorType - Returns true if the given vector is a power of 2.
247     bool isPow2VectorType() const {
248       unsigned NElts = getVectorNumElements();
249       return !(NElts & (NElts - 1));
250     }
251
252     /// getPow2VectorType - Widens the length of the given vector MVT up to
253     /// the nearest power of 2 and returns that type.
254     MVT getPow2VectorType() const {
255       if (isPow2VectorType())
256         return *this;
257
258       unsigned NElts = getVectorNumElements();
259       unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
260       return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
261     }
262
263     /// getScalarType - If this is a vector type, return the element type,
264     /// otherwise return this.
265     MVT getScalarType() const {
266       return isVector() ? getVectorElementType() : *this;
267     }
268
269     MVT getVectorElementType() const {
270       switch (SimpleTy) {
271       default:
272         llvm_unreachable("Not a vector MVT!");
273       case v2i1 :
274       case v4i1 :
275       case v8i1 :
276       case v16i1 :
277       case v32i1 :
278       case v64i1: return i1;
279       case v1i8 :
280       case v2i8 :
281       case v4i8 :
282       case v8i8 :
283       case v16i8:
284       case v32i8:
285       case v64i8: return i8;
286       case v1i16:
287       case v2i16:
288       case v4i16:
289       case v8i16:
290       case v16i16:
291       case v32i16: return i16;
292       case v1i32:
293       case v2i32:
294       case v4i32:
295       case v8i32:
296       case v16i32: return i32;
297       case v1i64:
298       case v2i64:
299       case v4i64:
300       case v8i64:
301       case v16i64: return i64;
302       case v2f16:
303       case v4f16:
304       case v8f16: return f16;
305       case v1f32:
306       case v2f32:
307       case v4f32:
308       case v8f32:
309       case v16f32: return f32;
310       case v1f64:
311       case v2f64:
312       case v4f64:
313       case v8f64: return f64;
314       }
315     }
316
317     unsigned getVectorNumElements() const {
318       switch (SimpleTy) {
319       default:
320         llvm_unreachable("Not a vector MVT!");
321       case v32i1:
322       case v32i8:
323       case v32i16: return 32;
324       case v64i1:
325       case v64i8: return 64;
326       case v16i1:
327       case v16i8:
328       case v16i16:
329       case v16i32:
330       case v16i64:
331       case v16f32: return 16;
332       case v8i1 :
333       case v8i8 :
334       case v8i16:
335       case v8i32:
336       case v8i64:
337       case v8f16:
338       case v8f32:
339       case v8f64: return 8;
340       case v4i1:
341       case v4i8:
342       case v4i16:
343       case v4i32:
344       case v4i64:
345       case v4f16:
346       case v4f32:
347       case v4f64: return 4;
348       case v2i1:
349       case v2i8:
350       case v2i16:
351       case v2i32:
352       case v2i64:
353       case v2f16:
354       case v2f32:
355       case v2f64: return 2;
356       case v1i8:
357       case v1i16:
358       case v1i32:
359       case v1i64:
360       case v1f32:
361       case v1f64: return 1;
362       }
363     }
364
365     unsigned getSizeInBits() const {
366       switch (SimpleTy) {
367       default:
368         llvm_unreachable("getSizeInBits called on extended MVT.");
369       case Other:
370         llvm_unreachable("Value type is non-standard value, Other.");
371       case iPTR:
372         llvm_unreachable("Value type size is target-dependent. Ask TLI.");
373       case iPTRAny:
374       case iAny:
375       case fAny:
376       case vAny:
377         llvm_unreachable("Value type is overloaded.");
378       case Metadata:
379         llvm_unreachable("Value type is metadata.");
380       case i1  :  return 1;
381       case v2i1:  return 2;
382       case v4i1:  return 4;
383       case i8  :
384       case v1i8:
385       case v8i1: return 8;
386       case i16 :
387       case f16:
388       case v16i1:
389       case v2i8:
390       case v1i16: return 16;
391       case f32 :
392       case i32 :
393       case v32i1:
394       case v4i8:
395       case v2i16:
396       case v2f16:
397       case v1f32:
398       case v1i32: return 32;
399       case x86mmx:
400       case f64 :
401       case i64 :
402       case v64i1:
403       case v8i8:
404       case v4i16:
405       case v2i32:
406       case v1i64:
407       case v4f16:
408       case v2f32:
409       case v1f64: return 64;
410       case f80 :  return 80;
411       case f128:
412       case ppcf128:
413       case i128:
414       case v16i8:
415       case v8i16:
416       case v4i32:
417       case v2i64:
418       case v8f16:
419       case v4f32:
420       case v2f64: return 128;
421       case v32i8:
422       case v16i16:
423       case v8i32:
424       case v4i64:
425       case v8f32:
426       case v4f64: return 256;
427       case v64i8:
428       case v32i16:
429       case v16i32:
430       case v8i64:
431       case v16f32:
432       case v8f64: return 512;
433       case v16i64:return 1024;
434       }
435     }
436
437     /// getStoreSize - Return the number of bytes overwritten by a store
438     /// of the specified value type.
439     unsigned getStoreSize() const {
440       return (getSizeInBits() + 7) / 8;
441     }
442
443     /// getStoreSizeInBits - Return the number of bits overwritten by a store
444     /// of the specified value type.
445     unsigned getStoreSizeInBits() const {
446       return getStoreSize() * 8;
447     }
448
449     /// Return true if this has more bits than VT.
450     bool bitsGT(MVT VT) const {
451       return getSizeInBits() > VT.getSizeInBits();
452     }
453
454     /// Return true if this has no less bits than VT.
455     bool bitsGE(MVT VT) const {
456       return getSizeInBits() >= VT.getSizeInBits();
457     }
458
459     /// Return true if this has less bits than VT.
460     bool bitsLT(MVT VT) const {
461       return getSizeInBits() < VT.getSizeInBits();
462     }
463
464     /// Return true if this has no more bits than VT.
465     bool bitsLE(MVT VT) const {
466       return getSizeInBits() <= VT.getSizeInBits();
467     }
468
469
470     static MVT getFloatingPointVT(unsigned BitWidth) {
471       switch (BitWidth) {
472       default:
473         llvm_unreachable("Bad bit width!");
474       case 16:
475         return MVT::f16;
476       case 32:
477         return MVT::f32;
478       case 64:
479         return MVT::f64;
480       case 80:
481         return MVT::f80;
482       case 128:
483         return MVT::f128;
484       }
485     }
486
487     static MVT getIntegerVT(unsigned BitWidth) {
488       switch (BitWidth) {
489       default:
490         return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
491       case 1:
492         return MVT::i1;
493       case 8:
494         return MVT::i8;
495       case 16:
496         return MVT::i16;
497       case 32:
498         return MVT::i32;
499       case 64:
500         return MVT::i64;
501       case 128:
502         return MVT::i128;
503       }
504     }
505
506     static MVT getVectorVT(MVT VT, unsigned NumElements) {
507       switch (VT.SimpleTy) {
508       default:
509         break;
510       case MVT::i1:
511         if (NumElements == 2)  return MVT::v2i1;
512         if (NumElements == 4)  return MVT::v4i1;
513         if (NumElements == 8)  return MVT::v8i1;
514         if (NumElements == 16) return MVT::v16i1;
515         if (NumElements == 32) return MVT::v32i1;
516         if (NumElements == 64) return MVT::v64i1;
517         break;
518       case MVT::i8:
519         if (NumElements == 1)  return MVT::v1i8;
520         if (NumElements == 2)  return MVT::v2i8;
521         if (NumElements == 4)  return MVT::v4i8;
522         if (NumElements == 8)  return MVT::v8i8;
523         if (NumElements == 16) return MVT::v16i8;
524         if (NumElements == 32) return MVT::v32i8;
525         if (NumElements == 64) return MVT::v64i8;
526         break;
527       case MVT::i16:
528         if (NumElements == 1)  return MVT::v1i16;
529         if (NumElements == 2)  return MVT::v2i16;
530         if (NumElements == 4)  return MVT::v4i16;
531         if (NumElements == 8)  return MVT::v8i16;
532         if (NumElements == 16) return MVT::v16i16;
533         if (NumElements == 32) return MVT::v32i16;
534         break;
535       case MVT::i32:
536         if (NumElements == 1)  return MVT::v1i32;
537         if (NumElements == 2)  return MVT::v2i32;
538         if (NumElements == 4)  return MVT::v4i32;
539         if (NumElements == 8)  return MVT::v8i32;
540         if (NumElements == 16) return MVT::v16i32;
541         break;
542       case MVT::i64:
543         if (NumElements == 1)  return MVT::v1i64;
544         if (NumElements == 2)  return MVT::v2i64;
545         if (NumElements == 4)  return MVT::v4i64;
546         if (NumElements == 8)  return MVT::v8i64;
547         if (NumElements == 16) return MVT::v16i64;
548         break;
549       case MVT::f16:
550         if (NumElements == 2)  return MVT::v2f16;
551         if (NumElements == 4)  return MVT::v4f16;
552         if (NumElements == 8)  return MVT::v8f16;
553         break;
554       case MVT::f32:
555         if (NumElements == 1)  return MVT::v1f32;
556         if (NumElements == 2)  return MVT::v2f32;
557         if (NumElements == 4)  return MVT::v4f32;
558         if (NumElements == 8)  return MVT::v8f32;
559         if (NumElements == 16) return MVT::v16f32;
560         break;
561       case MVT::f64:
562         if (NumElements == 1)  return MVT::v1f64;
563         if (NumElements == 2)  return MVT::v2f64;
564         if (NumElements == 4)  return MVT::v4f64;
565         if (NumElements == 8)  return MVT::v8f64;
566         break;
567       }
568       return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
569     }
570
571     /// Return the value type corresponding to the specified type.  This returns
572     /// all pointers as iPTR.  If HandleUnknown is true, unknown types are
573     /// returned as Other, otherwise they are invalid.
574     static MVT getVT(Type *Ty, bool HandleUnknown = false);
575
576   };
577
578
579   /// EVT - Extended Value Type.  Capable of holding value types which are not
580   /// native for any processor (such as the i12345 type), as well as the types
581   /// a MVT can represent.
582   struct EVT {
583   private:
584     MVT V;
585     Type *LLVMTy;
586
587   public:
588     EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)),
589             LLVMTy(0) {}
590     EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(0) { }
591     EVT(MVT S) : V(S), LLVMTy(0) {}
592
593     bool operator==(EVT VT) const {
594       return !(*this != VT);
595     }
596     bool operator!=(EVT VT) const {
597       if (V.SimpleTy != VT.V.SimpleTy)
598         return true;
599       if (V.SimpleTy < 0)
600         return LLVMTy != VT.LLVMTy;
601       return false;
602     }
603
604     /// getFloatingPointVT - Returns the EVT that represents a floating point
605     /// type with the given number of bits.  There are two floating point types
606     /// with 128 bits - this returns f128 rather than ppcf128.
607     static EVT getFloatingPointVT(unsigned BitWidth) {
608       return MVT::getFloatingPointVT(BitWidth);
609     }
610
611     /// getIntegerVT - Returns the EVT that represents an integer with the given
612     /// number of bits.
613     static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) {
614       MVT M = MVT::getIntegerVT(BitWidth);
615       if (M.SimpleTy >= 0)
616         return M;
617       return getExtendedIntegerVT(Context, BitWidth);
618     }
619
620     /// getVectorVT - Returns the EVT that represents a vector NumElements in
621     /// length, where each element is of type VT.
622     static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements) {
623       MVT M = MVT::getVectorVT(VT.V, NumElements);
624       if (M.SimpleTy >= 0)
625         return M;
626       return getExtendedVectorVT(Context, VT, NumElements);
627     }
628
629     /// changeVectorElementTypeToInteger - Return a vector with the same number
630     /// of elements as this vector, but with the element type converted to an
631     /// integer type with the same bitwidth.
632     EVT changeVectorElementTypeToInteger() const {
633       if (!isSimple())
634         return changeExtendedVectorElementTypeToInteger();
635       MVT EltTy = getSimpleVT().getVectorElementType();
636       unsigned BitWidth = EltTy.getSizeInBits();
637       MVT IntTy = MVT::getIntegerVT(BitWidth);
638       MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements());
639       assert(VecTy.SimpleTy >= 0 &&
640              "Simple vector VT not representable by simple integer vector VT!");
641       return VecTy;
642     }
643
644     /// isSimple - Test if the given EVT is simple (as opposed to being
645     /// extended).
646     bool isSimple() const {
647       return V.SimpleTy >= 0;
648     }
649
650     /// isExtended - Test if the given EVT is extended (as opposed to
651     /// being simple).
652     bool isExtended() const {
653       return !isSimple();
654     }
655
656     /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
657     bool isFloatingPoint() const {
658       return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
659     }
660
661     /// isInteger - Return true if this is an integer, or a vector integer type.
662     bool isInteger() const {
663       return isSimple() ? V.isInteger() : isExtendedInteger();
664     }
665
666     /// isVector - Return true if this is a vector value type.
667     bool isVector() const {
668       return isSimple() ? V.isVector() : isExtendedVector();
669     }
670
671     /// is16BitVector - Return true if this is a 16-bit vector type.
672     bool is16BitVector() const {
673       return isSimple() ? V.is16BitVector() : isExtended16BitVector();
674     }
675
676     /// is32BitVector - Return true if this is a 32-bit vector type.
677     bool is32BitVector() const {
678       return isSimple() ? V.is32BitVector() : isExtended32BitVector();
679     }
680
681     /// is64BitVector - Return true if this is a 64-bit vector type.
682     bool is64BitVector() const {
683       return isSimple() ? V.is64BitVector() : isExtended64BitVector();
684     }
685
686     /// is128BitVector - Return true if this is a 128-bit vector type.
687     bool is128BitVector() const {
688       return isSimple() ? V.is128BitVector() : isExtended128BitVector();
689     }
690
691     /// is256BitVector - Return true if this is a 256-bit vector type.
692     bool is256BitVector() const {
693       return isSimple() ? V.is256BitVector() : isExtended256BitVector();
694     }
695
696     /// is512BitVector - Return true if this is a 512-bit vector type.
697     bool is512BitVector() const {
698       return isSimple() ? V.is512BitVector() : isExtended512BitVector();
699     }
700
701     /// is1024BitVector - Return true if this is a 1024-bit vector type.
702     bool is1024BitVector() const {
703       return isSimple() ? V.is1024BitVector() : isExtended1024BitVector();
704     }
705
706     /// isOverloaded - Return true if this is an overloaded type for TableGen.
707     bool isOverloaded() const {
708       return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
709     }
710
711     /// isByteSized - Return true if the bit size is a multiple of 8.
712     bool isByteSized() const {
713       return (getSizeInBits() & 7) == 0;
714     }
715
716     /// isRound - Return true if the size is a power-of-two number of bytes.
717     bool isRound() const {
718       unsigned BitSize = getSizeInBits();
719       return BitSize >= 8 && !(BitSize & (BitSize - 1));
720     }
721
722     /// bitsEq - Return true if this has the same number of bits as VT.
723     bool bitsEq(EVT VT) const {
724       if (EVT::operator==(VT)) return true;
725       return getSizeInBits() == VT.getSizeInBits();
726     }
727
728     /// bitsGT - Return true if this has more bits than VT.
729     bool bitsGT(EVT VT) const {
730       if (EVT::operator==(VT)) return false;
731       return getSizeInBits() > VT.getSizeInBits();
732     }
733
734     /// bitsGE - Return true if this has no less bits than VT.
735     bool bitsGE(EVT VT) const {
736       if (EVT::operator==(VT)) return true;
737       return getSizeInBits() >= VT.getSizeInBits();
738     }
739
740     /// bitsLT - Return true if this has less bits than VT.
741     bool bitsLT(EVT VT) const {
742       if (EVT::operator==(VT)) return false;
743       return getSizeInBits() < VT.getSizeInBits();
744     }
745
746     /// bitsLE - Return true if this has no more bits than VT.
747     bool bitsLE(EVT VT) const {
748       if (EVT::operator==(VT)) return true;
749       return getSizeInBits() <= VT.getSizeInBits();
750     }
751
752
753     /// getSimpleVT - Return the SimpleValueType held in the specified
754     /// simple EVT.
755     MVT getSimpleVT() const {
756       assert(isSimple() && "Expected a SimpleValueType!");
757       return V;
758     }
759
760     /// getScalarType - If this is a vector type, return the element type,
761     /// otherwise return this.
762     EVT getScalarType() const {
763       return isVector() ? getVectorElementType() : *this;
764     }
765
766     /// getVectorElementType - Given a vector type, return the type of
767     /// each element.
768     EVT getVectorElementType() const {
769       assert(isVector() && "Invalid vector type!");
770       if (isSimple())
771         return V.getVectorElementType();
772       return getExtendedVectorElementType();
773     }
774
775     /// getVectorNumElements - Given a vector type, return the number of
776     /// elements it contains.
777     unsigned getVectorNumElements() const {
778       assert(isVector() && "Invalid vector type!");
779       if (isSimple())
780         return V.getVectorNumElements();
781       return getExtendedVectorNumElements();
782     }
783
784     /// getSizeInBits - Return the size of the specified value type in bits.
785     unsigned getSizeInBits() const {
786       if (isSimple())
787         return V.getSizeInBits();
788       return getExtendedSizeInBits();
789     }
790
791     /// getStoreSize - Return the number of bytes overwritten by a store
792     /// of the specified value type.
793     unsigned getStoreSize() const {
794       return (getSizeInBits() + 7) / 8;
795     }
796
797     /// getStoreSizeInBits - Return the number of bits overwritten by a store
798     /// of the specified value type.
799     unsigned getStoreSizeInBits() const {
800       return getStoreSize() * 8;
801     }
802
803     /// getRoundIntegerType - Rounds the bit-width of the given integer EVT up
804     /// to the nearest power of two (and at least to eight), and returns the
805     /// integer EVT with that number of bits.
806     EVT getRoundIntegerType(LLVMContext &Context) const {
807       assert(isInteger() && !isVector() && "Invalid integer type!");
808       unsigned BitWidth = getSizeInBits();
809       if (BitWidth <= 8)
810         return EVT(MVT::i8);
811       return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
812     }
813
814     /// getHalfSizedIntegerVT - Finds the smallest simple value type that is
815     /// greater than or equal to half the width of this EVT. If no simple
816     /// value type can be found, an extended integer value type of half the
817     /// size (rounded up) is returned.
818     EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
819       assert(isInteger() && !isVector() && "Invalid integer type!");
820       unsigned EVTSize = getSizeInBits();
821       for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
822           IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) {
823         EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
824         if (HalfVT.getSizeInBits() * 2 >= EVTSize)
825           return HalfVT;
826       }
827       return getIntegerVT(Context, (EVTSize + 1) / 2);
828     }
829
830     /// isPow2VectorType - Returns true if the given vector is a power of 2.
831     bool isPow2VectorType() const {
832       unsigned NElts = getVectorNumElements();
833       return !(NElts & (NElts - 1));
834     }
835
836     /// getPow2VectorType - Widens the length of the given vector EVT up to
837     /// the nearest power of 2 and returns that type.
838     EVT getPow2VectorType(LLVMContext &Context) const {
839       if (!isPow2VectorType()) {
840         unsigned NElts = getVectorNumElements();
841         unsigned Pow2NElts = 1 <<  Log2_32_Ceil(NElts);
842         return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts);
843       }
844       else {
845         return *this;
846       }
847     }
848
849     /// getEVTString - This function returns value type as a string,
850     /// e.g. "i32".
851     std::string getEVTString() const;
852
853     /// getTypeForEVT - This method returns an LLVM type corresponding to the
854     /// specified EVT.  For integer types, this returns an unsigned type.  Note
855     /// that this will abort for types that cannot be represented.
856     Type *getTypeForEVT(LLVMContext &Context) const;
857
858     /// getEVT - Return the value type corresponding to the specified type.
859     /// This returns all pointers as iPTR.  If HandleUnknown is true, unknown
860     /// types are returned as Other, otherwise they are invalid.
861     static EVT getEVT(Type *Ty, bool HandleUnknown = false);
862
863     intptr_t getRawBits() const {
864       if (isSimple())
865         return V.SimpleTy;
866       else
867         return (intptr_t)(LLVMTy);
868     }
869
870     /// compareRawBits - A meaningless but well-behaved order, useful for
871     /// constructing containers.
872     struct compareRawBits {
873       bool operator()(EVT L, EVT R) const {
874         if (L.V.SimpleTy == R.V.SimpleTy)
875           return L.LLVMTy < R.LLVMTy;
876         else
877           return L.V.SimpleTy < R.V.SimpleTy;
878       }
879     };
880
881   private:
882     // Methods for handling the Extended-type case in functions above.
883     // These are all out-of-line to prevent users of this header file
884     // from having a dependency on Type.h.
885     EVT changeExtendedVectorElementTypeToInteger() const;
886     static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
887     static EVT getExtendedVectorVT(LLVMContext &C, EVT VT,
888                                    unsigned NumElements);
889     bool isExtendedFloatingPoint() const LLVM_READONLY;
890     bool isExtendedInteger() const LLVM_READONLY;
891     bool isExtendedVector() const LLVM_READONLY;
892     bool isExtended16BitVector() const LLVM_READONLY;
893     bool isExtended32BitVector() const LLVM_READONLY;
894     bool isExtended64BitVector() const LLVM_READONLY;
895     bool isExtended128BitVector() const LLVM_READONLY;
896     bool isExtended256BitVector() const LLVM_READONLY;
897     bool isExtended512BitVector() const LLVM_READONLY;
898     bool isExtended1024BitVector() const LLVM_READONLY;
899     EVT getExtendedVectorElementType() const;
900     unsigned getExtendedVectorNumElements() const LLVM_READONLY;
901     unsigned getExtendedSizeInBits() const;
902   };
903
904 } // End llvm namespace
905
906 #endif