Do not use typeinfo to identify pass in pass manager.
[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 was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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 <cassert>
20 #include "llvm/Support/DataTypes.h"
21
22 namespace llvm {
23   class Type;
24
25 /// MVT namespace - This namespace defines the ValueType enum, which contains
26 /// the various low-level value types.
27 ///
28 namespace MVT {  // MVT = Machine Value Types
29   enum ValueType {
30     // If you change this numbering, you must change the values in ValueTypes.td
31     // well!
32     Other          =   0,   // This is a non-standard value
33     i1             =   1,   // This is a 1 bit integer value
34     i8             =   2,   // This is an 8 bit integer value
35     i16            =   3,   // This is a 16 bit integer value
36     i32            =   4,   // This is a 32 bit integer value
37     i64            =   5,   // This is a 64 bit integer value
38     i128           =   6,   // This is a 128 bit integer value
39
40     f32            =   7,   // This is a 32 bit floating point value
41     f64            =   8,   // This is a 64 bit floating point value
42     f80            =   9,   // This is a 80 bit floating point value
43     f128           =  10,   // This is a 128 bit floating point value
44     Flag           =  11,   // This is a condition code or machine flag.
45
46     isVoid         =  12,   // This has no value
47     
48     Vector         =  13,   // This is an abstract vector type, which will
49                             // be expanded into a target vector type, or scalars
50                             // if no matching vector type is available.
51
52     v8i8           =  14,   //  8 x i8
53     v4i16          =  15,   //  4 x i16
54     v2i32          =  16,   //  2 x i32
55     v1i64          =  17,   //  1 x i64
56     v16i8          =  18,   // 16 x i8
57     v8i16          =  19,   //  8 x i16
58     v4i32          =  20,   //  4 x i32
59     v2i64          =  21,   //  2 x i64
60
61     v2f32          =  22,   //  2 x f32
62     v4f32          =  23,   //  4 x f32
63     v2f64          =  24,   //  2 x f64
64     FIRST_VECTOR_VALUETYPE = v8i8,
65     LAST_VECTOR_VALUETYPE  = v2f64,
66
67     LAST_VALUETYPE =  25,   // This always remains at the end of the list.
68
69     // iAny - An integer value of any bit width. This is used for intrinsics
70     // that have overloadings based on integer bit widths. This is only for
71     // tblgen's consumption!
72     iAny           = 254,   
73
74     // iPTR - An int value the size of the pointer of the current
75     // target.  This should only be used internal to tblgen!
76     iPTR           = 255
77   };
78
79   /// MVT::isInteger - Return true if this is a simple integer, or a packed
80   /// vector integer type.
81   static inline bool isInteger(ValueType VT) {
82     return (VT >= i1 && VT <= i128) || (VT >= v8i8 && VT <= v2i64);
83   }
84
85   /// MVT::isFloatingPoint - Return true if this is a simple FP, or a packed
86   /// vector FP type.
87   static inline bool isFloatingPoint(ValueType VT) {
88     return (VT >= f32 && VT <= f128) || (VT >= v2f32 && VT <= v2f64);
89   }
90   
91   /// MVT::isVector - Return true if this is a packed vector type (i.e. not 
92   /// MVT::Vector).
93   static inline bool isVector(ValueType VT) {
94     return VT >= FIRST_VECTOR_VALUETYPE && VT <= LAST_VECTOR_VALUETYPE;
95   }
96   
97   /// MVT::getSizeInBits - Return the size of the specified value type in bits.
98   ///
99   static inline unsigned getSizeInBits(ValueType VT) {
100     switch (VT) {
101     default: assert(0 && "ValueType has no known size!");
102     case MVT::i1  :  return 1;
103     case MVT::i8  :  return 8;
104     case MVT::i16 :  return 16;
105     case MVT::f32 :
106     case MVT::i32 :  return 32;
107     case MVT::f64 :
108     case MVT::i64 :
109     case MVT::v8i8:
110     case MVT::v4i16:
111     case MVT::v2i32: 
112     case MVT::v1i64:
113     case MVT::v2f32: return 64;
114     case MVT::f80 :  return 80;
115     case MVT::f128:
116     case MVT::i128: 
117     case MVT::v16i8:
118     case MVT::v8i16:
119     case MVT::v4i32:
120     case MVT::v2i64:
121     case MVT::v4f32:
122     case MVT::v2f64: return 128;
123     }
124   }
125   
126   /// MVT::getVectorType - Returns the ValueType that represents a vector
127   /// NumElements in length, where each element is of type VT.  If there is no
128   /// ValueType that represents this vector, a ValueType of Other is returned.
129   ///
130   ValueType getVectorType(ValueType VT, unsigned NumElements);
131     
132   /// MVT::getVectorBaseType - Given a packed vector type, return the type of
133   /// each element.
134   static inline ValueType getVectorBaseType(ValueType VT) {
135     switch (VT) {
136     default: assert(0 && "Invalid vector type!");
137     case v8i8 :
138     case v16i8: return i8;
139     case v4i16:
140     case v8i16: return i16; 
141     case v2i32:
142     case v4i32: return i32;
143     case v1i64:
144     case v2i64: return i64;
145     case v2f32:
146     case v4f32: return f32;
147     case v2f64: return f64;
148     }
149   }
150   
151   /// MVT::getVectorNumElements - Given a packed vector type, return the number
152   /// of elements it contains.
153   static inline unsigned getVectorNumElements(ValueType VT) {
154     switch (VT) {
155     default: assert(0 && "Invalid vector type!");
156     case v16i8: return 16;
157     case v8i8 :
158     case v8i16: return 8;
159     case v4i16:
160     case v4i32: 
161     case v4f32: return 4;
162     case v2i32:
163     case v2i64:
164     case v2f32:
165     case v2f64: return 2;
166     case v1i64: return 1;
167     }
168   }
169   
170   /// MVT::getIntVectorWithNumElements - Return any integer vector type that has
171   /// the specified number of elements.
172   static inline ValueType getIntVectorWithNumElements(unsigned NumElts) {
173     switch (NumElts) {
174     default: assert(0 && "Invalid vector type!");
175     case  1: return v1i64;
176     case  2: return v2i32;
177     case  4: return v4i16;
178     case  8: return v8i8;
179     case 16: return v16i8;
180     }
181   }
182   
183   
184   /// MVT::getIntVTBitMask - Return an integer with 1's every place there are
185   /// bits in the specified integer value type.
186   static inline uint64_t getIntVTBitMask(ValueType VT) {
187     assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
188     return ~uint64_t(0UL) >> (64-getSizeInBits(VT));
189   }
190   /// MVT::getIntVTSignBit - Return an integer with a 1 in the position of the
191   /// sign bit for the specified integer value type.
192   static inline uint64_t getIntVTSignBit(ValueType VT) {
193     assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
194     return uint64_t(1UL) << (getSizeInBits(VT)-1);
195   }
196
197   /// MVT::getValueTypeString - This function returns value type as a string,
198   /// e.g. "i32".
199   const char *getValueTypeString(ValueType VT);
200
201   /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
202   /// to the specified ValueType.  For integer types, this returns an unsigned
203   /// type.  Note that this will abort for types that cannot be represented.
204   const Type *getTypeForValueType(ValueType VT);
205   
206   /// MVT::getValueType - Return the value type corresponding to the specified
207   /// type.  This returns all vectors as MVT::Vector and all pointers as
208   /// MVT::iPTR.  If HandleUnknown is true, unknown types are returned as Other,
209   /// otherwise they are invalid.
210   ValueType getValueType(const Type *Ty, bool HandleUnknown = false);
211 }
212
213 } // End llvm namespace
214
215 #endif