Really REALLY finish adding const to the MachineRegisterInfo iterator range methods.
[oota-llvm.git] / include / llvm / CodeGen / MachineValueType.h
1 //===- CodeGen/MachineValueType.h - Machine-Level 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 machine-level target independent types which
11 // legal values in the code generator use.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_MACHINEVALUETYPE_H
16 #define LLVM_CODEGEN_MACHINEVALUETYPE_H
17
18 #include "llvm/Support/ErrorHandling.h"
19
20 namespace llvm {
21
22   class Type;
23
24   /// MVT - Machine Value Type. Every type that is supported natively by some
25   /// processor targeted by LLVM occurs here. This means that any legal value
26   /// type can be represented by an MVT.
27   class MVT {
28   public:
29     enum SimpleValueType {
30       // INVALID_SIMPLE_VALUE_TYPE - Simple value types less than zero are
31       // considered extended value types.
32       INVALID_SIMPLE_VALUE_TYPE = -1,
33
34       // If you change this numbering, you must change the values in
35       // ValueTypes.td as well!
36       Other          =   0,   // This is a non-standard value
37       i1             =   1,   // This is a 1 bit integer value
38       i8             =   2,   // This is an 8 bit integer value
39       i16            =   3,   // This is a 16 bit integer value
40       i32            =   4,   // This is a 32 bit integer value
41       i64            =   5,   // This is a 64 bit integer value
42       i128           =   6,   // This is a 128 bit integer value
43
44       FIRST_INTEGER_VALUETYPE = i1,
45       LAST_INTEGER_VALUETYPE  = i128,
46
47       f16            =   7,   // This is a 16 bit floating point value
48       f32            =   8,   // This is a 32 bit floating point value
49       f64            =   9,   // This is a 64 bit floating point value
50       f80            =  10,   // This is a 80 bit floating point value
51       f128           =  11,   // This is a 128 bit floating point value
52       ppcf128        =  12,   // This is a PPC 128-bit floating point value
53
54       FIRST_FP_VALUETYPE = f16,
55       LAST_FP_VALUETYPE  = ppcf128,
56
57       v2i1           =  13,   //  2 x i1
58       v4i1           =  14,   //  4 x i1
59       v8i1           =  15,   //  8 x i1
60       v16i1          =  16,   // 16 x i1
61       v32i1          =  17,   // 32 x i1
62       v64i1          =  18,   // 64 x i1
63
64       v1i8           =  19,   //  1 x i8
65       v2i8           =  20,   //  2 x i8
66       v4i8           =  21,   //  4 x i8
67       v8i8           =  22,   //  8 x i8
68       v16i8          =  23,   // 16 x i8
69       v32i8          =  24,   // 32 x i8
70       v64i8          =  25,   // 64 x i8
71       v1i16          =  26,   //  1 x i16
72       v2i16          =  27,   //  2 x i16
73       v4i16          =  28,   //  4 x i16
74       v8i16          =  29,   //  8 x i16
75       v16i16         =  30,   // 16 x i16
76       v32i16         =  31,   // 32 x i16
77       v1i32          =  32,   //  1 x i32
78       v2i32          =  33,   //  2 x i32
79       v4i32          =  34,   //  4 x i32
80       v8i32          =  35,   //  8 x i32
81       v16i32         =  36,   // 16 x i32
82       v1i64          =  37,   //  1 x i64
83       v2i64          =  38,   //  2 x i64
84       v4i64          =  39,   //  4 x i64
85       v8i64          =  40,   //  8 x i64
86       v16i64         =  41,   // 16 x i64
87
88       FIRST_INTEGER_VECTOR_VALUETYPE = v2i1,
89       LAST_INTEGER_VECTOR_VALUETYPE = v16i64,
90
91       v2f16          =  42,   //  2 x f16
92       v4f16          =  43,   //  4 x f16
93       v8f16          =  44,   //  8 x f16
94       v1f32          =  45,   //  1 x f32
95       v2f32          =  46,   //  2 x f32
96       v4f32          =  47,   //  4 x f32
97       v8f32          =  48,   //  8 x f32
98       v16f32         =  49,   // 16 x f32
99       v1f64          =  50,   //  1 x f64
100       v2f64          =  51,   //  2 x f64
101       v4f64          =  52,   //  4 x f64
102       v8f64          =  53,   //  8 x f64
103
104       FIRST_FP_VECTOR_VALUETYPE = v2f16,
105       LAST_FP_VECTOR_VALUETYPE = v8f64,
106
107       FIRST_VECTOR_VALUETYPE = v2i1,
108       LAST_VECTOR_VALUETYPE  = v8f64,
109
110       x86mmx         =  54,   // This is an X86 MMX value
111
112       Glue           =  55,   // This glues nodes together during pre-RA sched
113
114       isVoid         =  56,   // This has no value
115
116       Untyped        =  57,   // This value takes a register, but has
117                               // unspecified type.  The register class
118                               // will be determined by the opcode.
119
120       LAST_VALUETYPE =  58,   // This always remains at the end of the list.
121
122       // This is the current maximum for LAST_VALUETYPE.
123       // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
124       // This value must be a multiple of 32.
125       MAX_ALLOWED_VALUETYPE = 64,
126
127       // Metadata - This is MDNode or MDString.
128       Metadata       = 250,
129
130       // iPTRAny - An int value the size of the pointer of the current
131       // target to any address space. This must only be used internal to
132       // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
133       iPTRAny        = 251,
134
135       // vAny - A vector with any length and element size. This is used
136       // for intrinsics that have overloadings based on vector types.
137       // This is only for tblgen's consumption!
138       vAny           = 252,
139
140       // fAny - Any floating-point or vector floating-point value. This is used
141       // for intrinsics that have overloadings based on floating-point types.
142       // This is only for tblgen's consumption!
143       fAny           = 253,
144
145       // iAny - An integer or vector integer value of any bit width. This is
146       // used for intrinsics that have overloadings based on integer bit widths.
147       // This is only for tblgen's consumption!
148       iAny           = 254,
149
150       // iPTR - An int value the size of the pointer of the current
151       // target.  This should only be used internal to tblgen!
152       iPTR           = 255
153     };
154
155     SimpleValueType SimpleTy;
156
157     MVT() : SimpleTy((SimpleValueType)(INVALID_SIMPLE_VALUE_TYPE)) {}
158     MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
159
160     bool operator>(const MVT& S)  const { return SimpleTy >  S.SimpleTy; }
161     bool operator<(const MVT& S)  const { return SimpleTy <  S.SimpleTy; }
162     bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
163     bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
164     bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
165     bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
166
167     /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
168     bool isFloatingPoint() const {
169       return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
170                SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
171               (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE &&
172                SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE));
173     }
174
175     /// isInteger - Return true if this is an integer, or a vector integer type.
176     bool isInteger() const {
177       return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
178                SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
179               (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE &&
180                SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE));
181     }
182
183     /// isVector - Return true if this is a vector value type.
184     bool isVector() const {
185       return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
186               SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
187     }
188
189     /// is16BitVector - Return true if this is a 16-bit vector type.
190     bool is16BitVector() const {
191       return (SimpleTy == MVT::v2i8  || SimpleTy == MVT::v1i16 ||
192               SimpleTy == MVT::v16i1);
193     }
194
195     /// is32BitVector - Return true if this is a 32-bit vector type.
196     bool is32BitVector() const {
197       return (SimpleTy == MVT::v4i8  || SimpleTy == MVT::v2i16 ||
198               SimpleTy == MVT::v1i32);
199     }
200
201     /// is64BitVector - Return true if this is a 64-bit vector type.
202     bool is64BitVector() const {
203       return (SimpleTy == MVT::v8i8  || SimpleTy == MVT::v4i16 ||
204               SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
205               SimpleTy == MVT::v1f64 || SimpleTy == MVT::v2f32);
206     }
207
208     /// is128BitVector - Return true if this is a 128-bit vector type.
209     bool is128BitVector() const {
210       return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
211               SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 ||
212               SimpleTy == MVT::v4f32 || SimpleTy == MVT::v2f64);
213     }
214
215     /// is256BitVector - Return true if this is a 256-bit vector type.
216     bool is256BitVector() const {
217       return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64  ||
218               SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
219               SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
220     }
221
222     /// is512BitVector - Return true if this is a 512-bit vector type.
223     bool is512BitVector() const {
224       return (SimpleTy == MVT::v8f64 || SimpleTy == MVT::v16f32 ||
225               SimpleTy == MVT::v64i8 || SimpleTy == MVT::v32i16 ||
226               SimpleTy == MVT::v8i64 || SimpleTy == MVT::v16i32);
227     }
228
229     /// is1024BitVector - Return true if this is a 1024-bit vector type.
230     bool is1024BitVector() const {
231       return (SimpleTy == MVT::v16i64);
232     }
233
234     /// isOverloaded - Return true if this is an overloaded type for TableGen.
235     bool isOverloaded() const {
236       return (SimpleTy==MVT::iAny || SimpleTy==MVT::fAny ||
237               SimpleTy==MVT::vAny || SimpleTy==MVT::iPTRAny);
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     unsigned getScalarSizeInBits() const {
432       return getScalarType().getSizeInBits();
433     }
434
435     /// getStoreSize - Return the number of bytes overwritten by a store
436     /// of the specified value type.
437     unsigned getStoreSize() const {
438       return (getSizeInBits() + 7) / 8;
439     }
440
441     /// getStoreSizeInBits - Return the number of bits overwritten by a store
442     /// of the specified value type.
443     unsigned getStoreSizeInBits() const {
444       return getStoreSize() * 8;
445     }
446
447     /// Return true if this has more bits than VT.
448     bool bitsGT(MVT VT) const {
449       return getSizeInBits() > VT.getSizeInBits();
450     }
451
452     /// Return true if this has no less bits than VT.
453     bool bitsGE(MVT VT) const {
454       return getSizeInBits() >= VT.getSizeInBits();
455     }
456
457     /// Return true if this has less bits than VT.
458     bool bitsLT(MVT VT) const {
459       return getSizeInBits() < VT.getSizeInBits();
460     }
461
462     /// Return true if this has no more bits than VT.
463     bool bitsLE(MVT VT) const {
464       return getSizeInBits() <= VT.getSizeInBits();
465     }
466
467
468     static MVT getFloatingPointVT(unsigned BitWidth) {
469       switch (BitWidth) {
470       default:
471         llvm_unreachable("Bad bit width!");
472       case 16:
473         return MVT::f16;
474       case 32:
475         return MVT::f32;
476       case 64:
477         return MVT::f64;
478       case 80:
479         return MVT::f80;
480       case 128:
481         return MVT::f128;
482       }
483     }
484
485     static MVT getIntegerVT(unsigned BitWidth) {
486       switch (BitWidth) {
487       default:
488         return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
489       case 1:
490         return MVT::i1;
491       case 8:
492         return MVT::i8;
493       case 16:
494         return MVT::i16;
495       case 32:
496         return MVT::i32;
497       case 64:
498         return MVT::i64;
499       case 128:
500         return MVT::i128;
501       }
502     }
503
504     static MVT getVectorVT(MVT VT, unsigned NumElements) {
505       switch (VT.SimpleTy) {
506       default:
507         break;
508       case MVT::i1:
509         if (NumElements == 2)  return MVT::v2i1;
510         if (NumElements == 4)  return MVT::v4i1;
511         if (NumElements == 8)  return MVT::v8i1;
512         if (NumElements == 16) return MVT::v16i1;
513         if (NumElements == 32) return MVT::v32i1;
514         if (NumElements == 64) return MVT::v64i1;
515         break;
516       case MVT::i8:
517         if (NumElements == 1)  return MVT::v1i8;
518         if (NumElements == 2)  return MVT::v2i8;
519         if (NumElements == 4)  return MVT::v4i8;
520         if (NumElements == 8)  return MVT::v8i8;
521         if (NumElements == 16) return MVT::v16i8;
522         if (NumElements == 32) return MVT::v32i8;
523         if (NumElements == 64) return MVT::v64i8;
524         break;
525       case MVT::i16:
526         if (NumElements == 1)  return MVT::v1i16;
527         if (NumElements == 2)  return MVT::v2i16;
528         if (NumElements == 4)  return MVT::v4i16;
529         if (NumElements == 8)  return MVT::v8i16;
530         if (NumElements == 16) return MVT::v16i16;
531         if (NumElements == 32) return MVT::v32i16;
532         break;
533       case MVT::i32:
534         if (NumElements == 1)  return MVT::v1i32;
535         if (NumElements == 2)  return MVT::v2i32;
536         if (NumElements == 4)  return MVT::v4i32;
537         if (NumElements == 8)  return MVT::v8i32;
538         if (NumElements == 16) return MVT::v16i32;
539         break;
540       case MVT::i64:
541         if (NumElements == 1)  return MVT::v1i64;
542         if (NumElements == 2)  return MVT::v2i64;
543         if (NumElements == 4)  return MVT::v4i64;
544         if (NumElements == 8)  return MVT::v8i64;
545         if (NumElements == 16) return MVT::v16i64;
546         break;
547       case MVT::f16:
548         if (NumElements == 2)  return MVT::v2f16;
549         if (NumElements == 4)  return MVT::v4f16;
550         if (NumElements == 8)  return MVT::v8f16;
551         break;
552       case MVT::f32:
553         if (NumElements == 1)  return MVT::v1f32;
554         if (NumElements == 2)  return MVT::v2f32;
555         if (NumElements == 4)  return MVT::v4f32;
556         if (NumElements == 8)  return MVT::v8f32;
557         if (NumElements == 16) return MVT::v16f32;
558         break;
559       case MVT::f64:
560         if (NumElements == 1)  return MVT::v1f64;
561         if (NumElements == 2)  return MVT::v2f64;
562         if (NumElements == 4)  return MVT::v4f64;
563         if (NumElements == 8)  return MVT::v8f64;
564         break;
565       }
566       return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
567     }
568
569     /// Return the value type corresponding to the specified type.  This returns
570     /// all pointers as iPTR.  If HandleUnknown is true, unknown types are
571     /// returned as Other, otherwise they are invalid.
572     static MVT getVT(Type *Ty, bool HandleUnknown = false);
573
574   };
575
576 } // End llvm namespace
577
578 #endif