Remove a bunch more SparcV9 specific stuff
[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     v16i8          =  17,   // 16 x i8
56     v8i16          =  18,   //  8 x i16
57     v4i32          =  19,   //  4 x i32
58     v2i64          =  20,   //  2 x i64
59
60     v2f32          =  21,   //  2 x f32
61     v4f32          =  22,   //  4 x f32
62     v2f64          =  23,   //  2 x f64
63     FIRST_VECTOR_VALUETYPE = v8i8,
64     LAST_VECTOR_VALUETYPE  = v2f64,
65
66     LAST_VALUETYPE =  24,   // This always remains at the end of the list.
67
68     // iPTR - An int value the size of the pointer of the current
69     // target.  This should only be used internal to tblgen!
70     iPTR           = 255
71   };
72
73   /// MVT::isInteger - Return true if this is a simple integer, or a packed
74   /// vector integer type.
75   static inline bool isInteger(ValueType VT) {
76     return (VT >= i1 && VT <= i128) || (VT >= v8i8 && VT <= v2i64);
77   }
78
79   /// MVT::isFloatingPoint - Return true if this is a simple FP, or a packed
80   /// vector FP type.
81   static inline bool isFloatingPoint(ValueType VT) {
82     return (VT >= f32 && VT <= f128) || (VT >= v4f32 && VT <= v2f64);
83   }
84   
85   /// MVT::isVector - Return true if this is a packed vector type (i.e. not 
86   /// MVT::Vector).
87   static inline bool isVector(ValueType VT) {
88     return VT >= FIRST_VECTOR_VALUETYPE && VT <= LAST_VECTOR_VALUETYPE;
89   }
90   
91   /// MVT::getSizeInBits - Return the size of the specified value type in bits.
92   ///
93   static inline unsigned getSizeInBits(ValueType VT) {
94     switch (VT) {
95     default: assert(0 && "ValueType has no known size!");
96     case MVT::i1  :  return 1;
97     case MVT::i8  :  return 8;
98     case MVT::i16 :  return 16;
99     case MVT::f32 :
100     case MVT::i32 :  return 32;
101     case MVT::f64 :
102     case MVT::i64 :
103     case MVT::v8i8:
104     case MVT::v4i16:
105     case MVT::v2i32: 
106     case MVT::v2f32: return 64;
107     case MVT::f80 :  return 80;
108     case MVT::f128:
109     case MVT::i128: 
110     case MVT::v16i8:
111     case MVT::v8i16:
112     case MVT::v4i32:
113     case MVT::v2i64:
114     case MVT::v4f32:
115     case MVT::v2f64: return 128;
116     }
117   }
118   
119   /// MVT::getVectorType - Returns the ValueType that represents a vector
120   /// NumElements in length, where each element is of type VT.  If there is no
121   /// ValueType that represents this vector, a ValueType of Other is returned.
122   ///
123   static inline ValueType getVectorType(ValueType VT, unsigned NumElements) {
124     switch (VT) {
125     default: 
126       break;
127     case MVT::i8:
128       if (NumElements == 8)  return MVT::v8i8;
129       if (NumElements == 16) return MVT::v16i8;
130         break;
131     case MVT::i16:
132       if (NumElements == 4)  return MVT::v4i16;
133       if (NumElements == 8)  return MVT::v8i16;
134         break;
135     case MVT::i32:
136       if (NumElements == 2)  return MVT::v2i32;
137       if (NumElements == 4)  return MVT::v4i32;
138         break;
139     case MVT::i64:
140       if (NumElements == 2)  return MVT::v2i64;
141       break;
142     case MVT::f32:
143       if (NumElements == 2)  return MVT::v2f32;
144       if (NumElements == 4)  return MVT::v4f32;
145         break;
146     case MVT::f64:
147       if (NumElements == 2)  return MVT::v2f64;
148       break;
149     }
150     return MVT::Other;
151   }
152   
153   /// MVT::getVectorBaseType - Given a packed vector type, return the type of
154   /// each element.
155   static inline ValueType getVectorBaseType(ValueType VT) {
156     switch (VT) {
157     default: assert(0 && "Invalid vector type!");
158     case v8i8 :
159     case v16i8: return i8;
160     case v4i16:
161     case v8i16: return i16; 
162     case v2i32:
163     case v4i32: return i32;
164     case v2i64: return i64;
165     case v2f32:
166     case v4f32: return f32;
167     case v2f64: return f64;
168     }
169   }
170   
171   /// MVT::getVectorNumElements - Given a packed vector type, return the number
172   /// of elements it contains.
173   static inline unsigned getVectorNumElements(ValueType VT) {
174     switch (VT) {
175       default: assert(0 && "Invalid vector type!");
176       case v16i8: return 16;
177       case v8i8 :
178       case v8i16: return 8;
179       case v4i16:
180       case v4i32: 
181       case v4f32: return 4;
182       case v2i32:
183       case v2i64:
184       case v2f32:
185       case v2f64: return 2;
186     }
187   }
188   
189   /// MVT::getIntVectorWithNumElements - Return any integer vector type that has
190   /// the specified number of elements.
191   static inline ValueType getIntVectorWithNumElements(unsigned NumElts) {
192     switch (NumElts) {
193     default: assert(0 && "Invalid vector type!");
194     case  2: return v2i32;
195     case  4: return v4i16;
196     case  8: return v8i8;
197     case 16: return v16i8;
198     }
199   }
200   
201   
202   /// MVT::getIntVTBitMask - Return an integer with 1's every place there are
203   /// bits in the specified integer value type.
204   static inline uint64_t getIntVTBitMask(ValueType VT) {
205     assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
206     return ~0ULL >> (64-getSizeInBits(VT));
207   }
208   /// MVT::getIntVTSignBit - Return an integer with a 1 in the position of the
209   /// sign bit for the specified integer value type.
210   static inline uint64_t getIntVTSignBit(ValueType VT) {
211     assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
212     return 1ULL << (getSizeInBits(VT)-1);
213   }
214
215   /// MVT::getValueTypeString - This function returns value type as a string,
216   /// e.g. "i32".
217   const char *getValueTypeString(ValueType VT);
218
219   /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
220   /// to the specified ValueType.  For integer types, this returns an unsigned
221   /// type.  Note that this will abort for types that cannot be represented.
222   const Type *getTypeForValueType(ValueType VT);
223 }
224
225 } // End llvm namespace
226
227 #endif