Implement AArch64 vector load/store multiple N-element structure class SIMD(lselem).
[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     /// isPow2VectorType - Returns true if the given vector is a power of 2.
241     bool isPow2VectorType() const {
242       unsigned NElts = getVectorNumElements();
243       return !(NElts & (NElts - 1));
244     }
245
246     /// getPow2VectorType - Widens the length of the given vector MVT up to
247     /// the nearest power of 2 and returns that type.
248     MVT getPow2VectorType() const {
249       if (isPow2VectorType())
250         return *this;
251
252       unsigned NElts = getVectorNumElements();
253       unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
254       return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
255     }
256
257     /// getScalarType - If this is a vector type, return the element type,
258     /// otherwise return this.
259     MVT getScalarType() const {
260       return isVector() ? getVectorElementType() : *this;
261     }
262
263     MVT getVectorElementType() const {
264       switch (SimpleTy) {
265       default:
266         llvm_unreachable("Not a vector MVT!");
267       case v2i1 :
268       case v4i1 :
269       case v8i1 :
270       case v16i1 :
271       case v32i1 :
272       case v64i1: return i1;
273       case v1i8 :
274       case v2i8 :
275       case v4i8 :
276       case v8i8 :
277       case v16i8:
278       case v32i8:
279       case v64i8: return i8;
280       case v1i16:
281       case v2i16:
282       case v4i16:
283       case v8i16:
284       case v16i16:
285       case v32i16: return i16;
286       case v1i32:
287       case v2i32:
288       case v4i32:
289       case v8i32:
290       case v16i32: return i32;
291       case v1i64:
292       case v2i64:
293       case v4i64:
294       case v8i64:
295       case v16i64: return i64;
296       case v2f16:
297       case v4f16:
298       case v8f16: return f16;
299       case v1f32:
300       case v2f32:
301       case v4f32:
302       case v8f32:
303       case v16f32: return f32;
304       case v1f64:
305       case v2f64:
306       case v4f64:
307       case v8f64: return f64;
308       }
309     }
310
311     unsigned getVectorNumElements() const {
312       switch (SimpleTy) {
313       default:
314         llvm_unreachable("Not a vector MVT!");
315       case v32i1:
316       case v32i8:
317       case v32i16: return 32;
318       case v64i1:
319       case v64i8: return 64;
320       case v16i1:
321       case v16i8:
322       case v16i16:
323       case v16i32:
324       case v16i64:
325       case v16f32: return 16;
326       case v8i1 :
327       case v8i8 :
328       case v8i16:
329       case v8i32:
330       case v8i64:
331       case v8f16:
332       case v8f32:
333       case v8f64: return 8;
334       case v4i1:
335       case v4i8:
336       case v4i16:
337       case v4i32:
338       case v4i64:
339       case v4f16:
340       case v4f32:
341       case v4f64: return 4;
342       case v2i1:
343       case v2i8:
344       case v2i16:
345       case v2i32:
346       case v2i64:
347       case v2f16:
348       case v2f32:
349       case v2f64: return 2;
350       case v1i8:
351       case v1i16:
352       case v1i32:
353       case v1i64:
354       case v1f32:
355       case v1f64: return 1;
356       }
357     }
358
359     unsigned getSizeInBits() const {
360       switch (SimpleTy) {
361       default:
362         llvm_unreachable("getSizeInBits called on extended MVT.");
363       case Other:
364         llvm_unreachable("Value type is non-standard value, Other.");
365       case iPTR:
366         llvm_unreachable("Value type size is target-dependent. Ask TLI.");
367       case iPTRAny:
368       case iAny:
369       case fAny:
370       case vAny:
371         llvm_unreachable("Value type is overloaded.");
372       case Metadata:
373         llvm_unreachable("Value type is metadata.");
374       case i1  :  return 1;
375       case v2i1:  return 2;
376       case v4i1:  return 4;
377       case i8  :
378       case v1i8:
379       case v8i1: return 8;
380       case i16 :
381       case f16:
382       case v16i1:
383       case v2i8:
384       case v1i16: return 16;
385       case f32 :
386       case i32 :
387       case v32i1:
388       case v4i8:
389       case v2i16:
390       case v2f16:
391       case v1f32:
392       case v1i32: return 32;
393       case x86mmx:
394       case f64 :
395       case i64 :
396       case v64i1:
397       case v8i8:
398       case v4i16:
399       case v2i32:
400       case v1i64:
401       case v4f16:
402       case v2f32:
403       case v1f64: return 64;
404       case f80 :  return 80;
405       case f128:
406       case ppcf128:
407       case i128:
408       case v16i8:
409       case v8i16:
410       case v4i32:
411       case v2i64:
412       case v8f16:
413       case v4f32:
414       case v2f64: return 128;
415       case v32i8:
416       case v16i16:
417       case v8i32:
418       case v4i64:
419       case v8f32:
420       case v4f64: return 256;
421       case v64i8:
422       case v32i16:
423       case v16i32:
424       case v8i64:
425       case v16f32:
426       case v8f64: return 512;
427       case v16i64:return 1024;
428       }
429     }
430
431     /// getStoreSize - Return the number of bytes overwritten by a store
432     /// of the specified value type.
433     unsigned getStoreSize() const {
434       return (getSizeInBits() + 7) / 8;
435     }
436
437     /// getStoreSizeInBits - Return the number of bits overwritten by a store
438     /// of the specified value type.
439     unsigned getStoreSizeInBits() const {
440       return getStoreSize() * 8;
441     }
442
443     /// Return true if this has more bits than VT.
444     bool bitsGT(MVT VT) const {
445       return getSizeInBits() > VT.getSizeInBits();
446     }
447
448     /// Return true if this has no less bits than VT.
449     bool bitsGE(MVT VT) const {
450       return getSizeInBits() >= VT.getSizeInBits();
451     }
452
453     /// Return true if this has less bits than VT.
454     bool bitsLT(MVT VT) const {
455       return getSizeInBits() < VT.getSizeInBits();
456     }
457
458     /// Return true if this has no more bits than VT.
459     bool bitsLE(MVT VT) const {
460       return getSizeInBits() <= VT.getSizeInBits();
461     }
462
463
464     static MVT getFloatingPointVT(unsigned BitWidth) {
465       switch (BitWidth) {
466       default:
467         llvm_unreachable("Bad bit width!");
468       case 16:
469         return MVT::f16;
470       case 32:
471         return MVT::f32;
472       case 64:
473         return MVT::f64;
474       case 80:
475         return MVT::f80;
476       case 128:
477         return MVT::f128;
478       }
479     }
480
481     static MVT getIntegerVT(unsigned BitWidth) {
482       switch (BitWidth) {
483       default:
484         return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
485       case 1:
486         return MVT::i1;
487       case 8:
488         return MVT::i8;
489       case 16:
490         return MVT::i16;
491       case 32:
492         return MVT::i32;
493       case 64:
494         return MVT::i64;
495       case 128:
496         return MVT::i128;
497       }
498     }
499
500     static MVT getVectorVT(MVT VT, unsigned NumElements) {
501       switch (VT.SimpleTy) {
502       default:
503         break;
504       case MVT::i1:
505         if (NumElements == 2)  return MVT::v2i1;
506         if (NumElements == 4)  return MVT::v4i1;
507         if (NumElements == 8)  return MVT::v8i1;
508         if (NumElements == 16) return MVT::v16i1;
509         if (NumElements == 32) return MVT::v32i1;
510         if (NumElements == 64) return MVT::v64i1;
511         break;
512       case MVT::i8:
513         if (NumElements == 1)  return MVT::v1i8;
514         if (NumElements == 2)  return MVT::v2i8;
515         if (NumElements == 4)  return MVT::v4i8;
516         if (NumElements == 8)  return MVT::v8i8;
517         if (NumElements == 16) return MVT::v16i8;
518         if (NumElements == 32) return MVT::v32i8;
519         if (NumElements == 64) return MVT::v64i8;
520         break;
521       case MVT::i16:
522         if (NumElements == 1)  return MVT::v1i16;
523         if (NumElements == 2)  return MVT::v2i16;
524         if (NumElements == 4)  return MVT::v4i16;
525         if (NumElements == 8)  return MVT::v8i16;
526         if (NumElements == 16) return MVT::v16i16;
527         if (NumElements == 32) return MVT::v32i16;
528         break;
529       case MVT::i32:
530         if (NumElements == 1)  return MVT::v1i32;
531         if (NumElements == 2)  return MVT::v2i32;
532         if (NumElements == 4)  return MVT::v4i32;
533         if (NumElements == 8)  return MVT::v8i32;
534         if (NumElements == 16) return MVT::v16i32;
535         break;
536       case MVT::i64:
537         if (NumElements == 1)  return MVT::v1i64;
538         if (NumElements == 2)  return MVT::v2i64;
539         if (NumElements == 4)  return MVT::v4i64;
540         if (NumElements == 8)  return MVT::v8i64;
541         if (NumElements == 16) return MVT::v16i64;
542         break;
543       case MVT::f16:
544         if (NumElements == 2)  return MVT::v2f16;
545         if (NumElements == 4)  return MVT::v4f16;
546         if (NumElements == 8)  return MVT::v8f16;
547         break;
548       case MVT::f32:
549         if (NumElements == 1)  return MVT::v1f32;
550         if (NumElements == 2)  return MVT::v2f32;
551         if (NumElements == 4)  return MVT::v4f32;
552         if (NumElements == 8)  return MVT::v8f32;
553         if (NumElements == 16) return MVT::v16f32;
554         break;
555       case MVT::f64:
556         if (NumElements == 1)  return MVT::v1f64;
557         if (NumElements == 2)  return MVT::v2f64;
558         if (NumElements == 4)  return MVT::v4f64;
559         if (NumElements == 8)  return MVT::v8f64;
560         break;
561       }
562       return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
563     }
564
565     /// Return the value type corresponding to the specified type.  This returns
566     /// all pointers as iPTR.  If HandleUnknown is true, unknown types are
567     /// returned as Other, otherwise they are invalid.
568     static MVT getVT(Type *Ty, bool HandleUnknown = false);
569
570   };
571
572
573   /// EVT - Extended Value Type.  Capable of holding value types which are not
574   /// native for any processor (such as the i12345 type), as well as the types
575   /// a MVT can represent.
576   struct EVT {
577   private:
578     MVT V;
579     Type *LLVMTy;
580
581   public:
582     EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)),
583             LLVMTy(0) {}
584     EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(0) { }
585     EVT(MVT S) : V(S), LLVMTy(0) {}
586
587     bool operator==(EVT VT) const {
588       return !(*this != VT);
589     }
590     bool operator!=(EVT VT) const {
591       if (V.SimpleTy != VT.V.SimpleTy)
592         return true;
593       if (V.SimpleTy < 0)
594         return LLVMTy != VT.LLVMTy;
595       return false;
596     }
597
598     /// getFloatingPointVT - Returns the EVT that represents a floating point
599     /// type with the given number of bits.  There are two floating point types
600     /// with 128 bits - this returns f128 rather than ppcf128.
601     static EVT getFloatingPointVT(unsigned BitWidth) {
602       return MVT::getFloatingPointVT(BitWidth);
603     }
604
605     /// getIntegerVT - Returns the EVT that represents an integer with the given
606     /// number of bits.
607     static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) {
608       MVT M = MVT::getIntegerVT(BitWidth);
609       if (M.SimpleTy >= 0)
610         return M;
611       return getExtendedIntegerVT(Context, BitWidth);
612     }
613
614     /// getVectorVT - Returns the EVT that represents a vector NumElements in
615     /// length, where each element is of type VT.
616     static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements) {
617       MVT M = MVT::getVectorVT(VT.V, NumElements);
618       if (M.SimpleTy >= 0)
619         return M;
620       return getExtendedVectorVT(Context, VT, NumElements);
621     }
622
623     /// changeVectorElementTypeToInteger - Return a vector with the same number
624     /// of elements as this vector, but with the element type converted to an
625     /// integer type with the same bitwidth.
626     EVT changeVectorElementTypeToInteger() const {
627       if (!isSimple())
628         return changeExtendedVectorElementTypeToInteger();
629       MVT EltTy = getSimpleVT().getVectorElementType();
630       unsigned BitWidth = EltTy.getSizeInBits();
631       MVT IntTy = MVT::getIntegerVT(BitWidth);
632       MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements());
633       assert(VecTy.SimpleTy >= 0 &&
634              "Simple vector VT not representable by simple integer vector VT!");
635       return VecTy;
636     }
637
638     /// isSimple - Test if the given EVT is simple (as opposed to being
639     /// extended).
640     bool isSimple() const {
641       return V.SimpleTy >= 0;
642     }
643
644     /// isExtended - Test if the given EVT is extended (as opposed to
645     /// being simple).
646     bool isExtended() const {
647       return !isSimple();
648     }
649
650     /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
651     bool isFloatingPoint() const {
652       return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
653     }
654
655     /// isInteger - Return true if this is an integer, or a vector integer type.
656     bool isInteger() const {
657       return isSimple() ? V.isInteger() : isExtendedInteger();
658     }
659
660     /// isVector - Return true if this is a vector value type.
661     bool isVector() const {
662       return isSimple() ? V.isVector() : isExtendedVector();
663     }
664
665     /// is16BitVector - Return true if this is a 16-bit vector type.
666     bool is16BitVector() const {
667       return isSimple() ? V.is16BitVector() : isExtended16BitVector();
668     }
669
670     /// is32BitVector - Return true if this is a 32-bit vector type.
671     bool is32BitVector() const {
672       return isSimple() ? V.is32BitVector() : isExtended32BitVector();
673     }
674
675     /// is64BitVector - Return true if this is a 64-bit vector type.
676     bool is64BitVector() const {
677       return isSimple() ? V.is64BitVector() : isExtended64BitVector();
678     }
679
680     /// is128BitVector - Return true if this is a 128-bit vector type.
681     bool is128BitVector() const {
682       return isSimple() ? V.is128BitVector() : isExtended128BitVector();
683     }
684
685     /// is256BitVector - Return true if this is a 256-bit vector type.
686     bool is256BitVector() const {
687       return isSimple() ? V.is256BitVector() : isExtended256BitVector();
688     }
689
690     /// is512BitVector - Return true if this is a 512-bit vector type.
691     bool is512BitVector() const {
692       return isSimple() ? V.is512BitVector() : isExtended512BitVector();
693     }
694
695     /// is1024BitVector - Return true if this is a 1024-bit vector type.
696     bool is1024BitVector() const {
697       return isSimple() ? V.is1024BitVector() : isExtended1024BitVector();
698     }
699
700     /// isOverloaded - Return true if this is an overloaded type for TableGen.
701     bool isOverloaded() const {
702       return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
703     }
704
705     /// isByteSized - Return true if the bit size is a multiple of 8.
706     bool isByteSized() const {
707       return (getSizeInBits() & 7) == 0;
708     }
709
710     /// isRound - Return true if the size is a power-of-two number of bytes.
711     bool isRound() const {
712       unsigned BitSize = getSizeInBits();
713       return BitSize >= 8 && !(BitSize & (BitSize - 1));
714     }
715
716     /// bitsEq - Return true if this has the same number of bits as VT.
717     bool bitsEq(EVT VT) const {
718       if (EVT::operator==(VT)) return true;
719       return getSizeInBits() == VT.getSizeInBits();
720     }
721
722     /// bitsGT - Return true if this has more bits than VT.
723     bool bitsGT(EVT VT) const {
724       if (EVT::operator==(VT)) return false;
725       return getSizeInBits() > VT.getSizeInBits();
726     }
727
728     /// bitsGE - Return true if this has no less bits than VT.
729     bool bitsGE(EVT VT) const {
730       if (EVT::operator==(VT)) return true;
731       return getSizeInBits() >= VT.getSizeInBits();
732     }
733
734     /// bitsLT - Return true if this has less bits than VT.
735     bool bitsLT(EVT VT) const {
736       if (EVT::operator==(VT)) return false;
737       return getSizeInBits() < VT.getSizeInBits();
738     }
739
740     /// bitsLE - Return true if this has no more bits than VT.
741     bool bitsLE(EVT VT) const {
742       if (EVT::operator==(VT)) return true;
743       return getSizeInBits() <= VT.getSizeInBits();
744     }
745
746
747     /// getSimpleVT - Return the SimpleValueType held in the specified
748     /// simple EVT.
749     MVT getSimpleVT() const {
750       assert(isSimple() && "Expected a SimpleValueType!");
751       return V;
752     }
753
754     /// getScalarType - If this is a vector type, return the element type,
755     /// otherwise return this.
756     EVT getScalarType() const {
757       return isVector() ? getVectorElementType() : *this;
758     }
759
760     /// getVectorElementType - Given a vector type, return the type of
761     /// each element.
762     EVT getVectorElementType() const {
763       assert(isVector() && "Invalid vector type!");
764       if (isSimple())
765         return V.getVectorElementType();
766       return getExtendedVectorElementType();
767     }
768
769     /// getVectorNumElements - Given a vector type, return the number of
770     /// elements it contains.
771     unsigned getVectorNumElements() const {
772       assert(isVector() && "Invalid vector type!");
773       if (isSimple())
774         return V.getVectorNumElements();
775       return getExtendedVectorNumElements();
776     }
777
778     /// getSizeInBits - Return the size of the specified value type in bits.
779     unsigned getSizeInBits() const {
780       if (isSimple())
781         return V.getSizeInBits();
782       return getExtendedSizeInBits();
783     }
784
785     /// getStoreSize - Return the number of bytes overwritten by a store
786     /// of the specified value type.
787     unsigned getStoreSize() const {
788       return (getSizeInBits() + 7) / 8;
789     }
790
791     /// getStoreSizeInBits - Return the number of bits overwritten by a store
792     /// of the specified value type.
793     unsigned getStoreSizeInBits() const {
794       return getStoreSize() * 8;
795     }
796
797     /// getRoundIntegerType - Rounds the bit-width of the given integer EVT up
798     /// to the nearest power of two (and at least to eight), and returns the
799     /// integer EVT with that number of bits.
800     EVT getRoundIntegerType(LLVMContext &Context) const {
801       assert(isInteger() && !isVector() && "Invalid integer type!");
802       unsigned BitWidth = getSizeInBits();
803       if (BitWidth <= 8)
804         return EVT(MVT::i8);
805       return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
806     }
807
808     /// getHalfSizedIntegerVT - Finds the smallest simple value type that is
809     /// greater than or equal to half the width of this EVT. If no simple
810     /// value type can be found, an extended integer value type of half the
811     /// size (rounded up) is returned.
812     EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
813       assert(isInteger() && !isVector() && "Invalid integer type!");
814       unsigned EVTSize = getSizeInBits();
815       for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
816           IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) {
817         EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
818         if (HalfVT.getSizeInBits() * 2 >= EVTSize)
819           return HalfVT;
820       }
821       return getIntegerVT(Context, (EVTSize + 1) / 2);
822     }
823
824     /// isPow2VectorType - Returns true if the given vector is a power of 2.
825     bool isPow2VectorType() const {
826       unsigned NElts = getVectorNumElements();
827       return !(NElts & (NElts - 1));
828     }
829
830     /// getPow2VectorType - Widens the length of the given vector EVT up to
831     /// the nearest power of 2 and returns that type.
832     EVT getPow2VectorType(LLVMContext &Context) const {
833       if (!isPow2VectorType()) {
834         unsigned NElts = getVectorNumElements();
835         unsigned Pow2NElts = 1 <<  Log2_32_Ceil(NElts);
836         return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts);
837       }
838       else {
839         return *this;
840       }
841     }
842
843     /// getEVTString - This function returns value type as a string,
844     /// e.g. "i32".
845     std::string getEVTString() const;
846
847     /// getTypeForEVT - This method returns an LLVM type corresponding to the
848     /// specified EVT.  For integer types, this returns an unsigned type.  Note
849     /// that this will abort for types that cannot be represented.
850     Type *getTypeForEVT(LLVMContext &Context) const;
851
852     /// getEVT - Return the value type corresponding to the specified type.
853     /// This returns all pointers as iPTR.  If HandleUnknown is true, unknown
854     /// types are returned as Other, otherwise they are invalid.
855     static EVT getEVT(Type *Ty, bool HandleUnknown = false);
856
857     intptr_t getRawBits() const {
858       if (isSimple())
859         return V.SimpleTy;
860       else
861         return (intptr_t)(LLVMTy);
862     }
863
864     /// compareRawBits - A meaningless but well-behaved order, useful for
865     /// constructing containers.
866     struct compareRawBits {
867       bool operator()(EVT L, EVT R) const {
868         if (L.V.SimpleTy == R.V.SimpleTy)
869           return L.LLVMTy < R.LLVMTy;
870         else
871           return L.V.SimpleTy < R.V.SimpleTy;
872       }
873     };
874
875   private:
876     // Methods for handling the Extended-type case in functions above.
877     // These are all out-of-line to prevent users of this header file
878     // from having a dependency on Type.h.
879     EVT changeExtendedVectorElementTypeToInteger() const;
880     static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
881     static EVT getExtendedVectorVT(LLVMContext &C, EVT VT,
882                                    unsigned NumElements);
883     bool isExtendedFloatingPoint() const;
884     bool isExtendedInteger() const;
885     bool isExtendedVector() const;
886     bool isExtended16BitVector() const;
887     bool isExtended32BitVector() const;
888     bool isExtended64BitVector() const;
889     bool isExtended128BitVector() const;
890     bool isExtended256BitVector() const;
891     bool isExtended512BitVector() const;
892     bool isExtended1024BitVector() const;
893     EVT getExtendedVectorElementType() const;
894     unsigned getExtendedVectorNumElements() const;
895     unsigned getExtendedSizeInBits() const;
896   };
897
898 } // End llvm namespace
899
900 #endif