Added x86 integer vector types: 64-bit packed byte integer (v16i8), 64-bit
[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 Target.td as
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     v8i8           =  14,   //  8 x i8
52     v4i16          =  15,   //  4 x i16
53     v2i32          =  16,   //  2 x i32
54     v16i8          =  17,   // 16 x i8
55     v8i16          =  18,   //  8 x i16
56     v4i32          =  19,   //  4 x i32
57     v2i64          =  20,   //  2 x i64
58
59     v4f32          =  21,   //  4 x f32
60     v2f64          =  22,   //  2 x f64
61
62     LAST_VALUETYPE,         // This always remains at the end of the list.
63   };
64
65   static inline bool isInteger(ValueType VT) {
66     return (VT >= i1 && VT <= i128) || (VT >= v16i8 && VT <= v2i64);
67   }
68   static inline bool isFloatingPoint(ValueType VT) {
69     return (VT >= f32 && VT <= f128) || (VT >= v4f32 && VT <= v2f64);
70   }
71   static inline bool isVector(ValueType VT) {
72     return (VT >= v16i8 && VT <= v2f64);
73   }
74   
75   /// getVectorType - Returns the ValueType that represents a vector NumElements
76   /// in length, where each element is of type VT.  If there is no ValueType
77   /// that represents this vector, a ValueType of Other is returned.
78   ///
79   static inline ValueType getVectorType(ValueType VT, unsigned NumElements) {
80     switch (VT) {
81     default: 
82       break;
83     case MVT::i32:
84       if (NumElements == 4) return MVT::v4i32;
85       break;
86     case MVT::f32:
87       if (NumElements == 4) return MVT::v4f32;
88       break;
89     }
90     return MVT::Other;
91   }
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:return 64;
106     case MVT::f80 : return 80;
107     case MVT::f128:
108     case MVT::i128: 
109     case MVT::v16i8:
110     case MVT::v8i16:
111     case MVT::v4i32:
112     case MVT::v2i64:
113     case MVT::v4f32:
114     case MVT::v2f64: return 128;
115     }
116   }
117   
118   /// getIntVTBitMask - Return an integer with 1's every place there are bits
119   /// in the specified integer value type.
120   static inline uint64_t getIntVTBitMask(ValueType VT) {
121     assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
122     return ~0ULL >> (64-getSizeInBits(VT));
123   }
124   /// getIntVTSignBit - Return an integer with a 1 in the position of the sign
125   /// bit for the specified integer value type.
126   static inline uint64_t getIntVTSignBit(ValueType VT) {
127     assert(isInteger(VT) && !isVector(VT) && "Only applies to int scalars!");
128     return 1ULL << (getSizeInBits(VT)-1);
129   }
130
131   /// MVT::getValueTypeString - This function returns value type as a string,
132   /// e.g. "i32".
133   const char *getValueTypeString(ValueType VT);
134
135   /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
136   /// to the specified ValueType.  For integer types, this returns an unsigned
137   /// type.  Note that this will abort for types that cannot be represented.
138   const Type *getTypeForValueType(ValueType VT);
139 };
140
141 } // End llvm namespace
142
143 #endif