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