add support for generating v4i32 code
[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
21 namespace llvm {
22   class Type;
23
24 /// MVT namespace - This namespace defines the ValueType enum, which contains
25 /// the various low-level value types.
26 ///
27 namespace MVT {  // MVT = Machine Value Types
28   enum ValueType {
29     // If you change this numbering, you must change the values in Target.td as
30     // well!
31     Other          =   0,   // This is a non-standard value
32     i1             =   1,   // This is a 1 bit integer value
33     i8             =   2,   // This is an 8 bit integer value
34     i16            =   3,   // This is a 16 bit integer value
35     i32            =   4,   // This is a 32 bit integer value
36     i64            =   5,   // This is a 64 bit integer value
37     i128           =   6,   // This is a 128 bit integer value
38
39     f32            =   7,   // This is a 32 bit floating point value
40     f64            =   8,   // This is a 64 bit floating point value
41     f80            =   9,   // This is a 80 bit floating point value
42     f128           =  10,   // This is a 128 bit floating point value
43     Flag           =  11,   // This is a condition code or machine flag.
44
45     isVoid         =  12,   // This has no value
46     
47     Vector         =  13,   // This is an abstract vector type, which will
48                             // be expanded into a target vector type, or scalars
49                             // if no matching vector type is available.
50     v16i8          =  14,   // 16 x i8
51     v8i16          =  15,   //  8 x i16
52     v4i32          =  16,   //  4 x i32
53     v2i64          =  17,   //  2 x i64
54
55     v4f32          =  18,   //  4 x f32
56     v2f64          =  19,   //  2 x f64
57
58     LAST_VALUETYPE,         // This always remains at the end of the list.
59   };
60
61   static inline bool isInteger(ValueType VT) {
62     return (VT >= i1 && VT <= i128) || (VT >= v16i8 && VT <= v2i64);
63   }
64   static inline bool isFloatingPoint(ValueType VT) {
65     return (VT >= f32 && VT <= f128) || (VT >= v4f32 && VT <= v2f64);
66   }
67   static inline bool isVector(ValueType VT) {
68     return (VT >= v16i8 && VT <= v2f64);
69   }
70
71   /// getVectorType - Returns the ValueType that represents a vector NumElements
72   /// in length, where each element is of type VT.  If there is no ValueType
73   /// that represents this vector, a ValueType of Other is returned.
74   ///
75   static inline ValueType getVectorType(ValueType VT, unsigned NumElements) {
76     switch (VT) {
77     default: 
78       break;
79     case MVT::i32:
80       if (NumElements == 4) return MVT::v4i32;
81       break;
82     case MVT::f32:
83       if (NumElements == 4) return MVT::v4f32;
84       break;
85     }
86     return MVT::Other;
87   }
88   
89   static inline unsigned getSizeInBits(ValueType VT) {
90     switch (VT) {
91     default: assert(0 && "ValueType has no known size!");
92     case MVT::i1  : return 1;
93     case MVT::i8  : return 8;
94     case MVT::i16 : return 16;
95     case MVT::f32 :
96     case MVT::i32 : return 32;
97     case MVT::f64 :
98     case MVT::i64 : return 64;
99     case MVT::f80 : return 80;
100     case MVT::f128:
101     case MVT::i128: 
102     case MVT::v16i8:
103     case MVT::v8i16:
104     case MVT::v4i32:
105     case MVT::v2i64:
106     case MVT::v4f32:
107     case MVT::v2f64: return 128;
108     }
109   }
110
111   /// MVT::getValueTypeString - This function returns value type as a string,
112   /// e.g. "i32".
113   const char *getValueTypeString(ValueType VT);
114
115   /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
116   /// to the specified ValueType.  For integer types, this returns an unsigned
117   /// type.  Note that this will abort for types that cannot be represented.
118   const Type *getTypeForValueType(ValueType VT);
119 };
120
121 } // End llvm namespace
122
123 #endif