1 //===-- ValueTypes.cpp - Implementation of MVT::ValueType methods ---------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file implements methods in the CodeGen/ValueTypes.h header.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/ValueTypes.h"
15 #include "llvm/Type.h"
16 #include "llvm/DerivedTypes.h"
19 /// MVT::getValueTypeString - This function returns value type as a string,
21 const char *MVT::getValueTypeString(MVT::ValueType VT) {
23 default: assert(0 && "Invalid ValueType!");
24 case MVT::i1: return "i1";
25 case MVT::i8: return "i8";
26 case MVT::i16: return "i16";
27 case MVT::i32: return "i32";
28 case MVT::i64: return "i64";
29 case MVT::i128: return "i128";
30 case MVT::f32: return "f32";
31 case MVT::f64: return "f64";
32 case MVT::f80: return "f80";
33 case MVT::f128: return "f128";
34 case MVT::isVoid:return "isVoid";
35 case MVT::Other: return "ch";
36 case MVT::Flag: return "flag";
37 case MVT::Vector:return "vec";
38 case MVT::v8i8: return "v8i8";
39 case MVT::v4i16: return "v4i16";
40 case MVT::v2i32: return "v2i32";
41 case MVT::v1i64: return "v1i64";
42 case MVT::v16i8: return "v16i8";
43 case MVT::v8i16: return "v8i16";
44 case MVT::v4i32: return "v4i32";
45 case MVT::v2i64: return "v2i64";
46 case MVT::v4f32: return "v4f32";
47 case MVT::v2f64: return "v2f64";
51 /// MVT::getVectorType - Returns the ValueType that represents a vector
52 /// NumElements in length, where each element is of type VT. If there is no
53 /// ValueType that represents this vector, a ValueType of Other is returned.
55 MVT::ValueType MVT::getVectorType(ValueType VT, unsigned NumElements) {
60 if (NumElements == 8) return MVT::v8i8;
61 if (NumElements == 16) return MVT::v16i8;
64 if (NumElements == 4) return MVT::v4i16;
65 if (NumElements == 8) return MVT::v8i16;
68 if (NumElements == 2) return MVT::v2i32;
69 if (NumElements == 4) return MVT::v4i32;
72 if (NumElements == 1) return MVT::v1i64;
73 if (NumElements == 2) return MVT::v2i64;
76 if (NumElements == 2) return MVT::v2f32;
77 if (NumElements == 4) return MVT::v4f32;
80 if (NumElements == 2) return MVT::v2f64;
86 /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
87 /// to the specified ValueType. Note that this will abort for types that cannot
89 const Type *MVT::getTypeForValueType(MVT::ValueType VT) {
91 default: assert(0 && "ValueType does not correspond to LLVM type!");
92 case MVT::isVoid:return Type::VoidTy;
93 case MVT::i1: return Type::Int1Ty;
94 case MVT::i8: return Type::Int8Ty;
95 case MVT::i16: return Type::Int16Ty;
96 case MVT::i32: return Type::Int32Ty;
97 case MVT::i64: return Type::Int64Ty;
98 case MVT::i128: return IntegerType::get(128);
99 case MVT::f32: return Type::FloatTy;
100 case MVT::f64: return Type::DoubleTy;
101 case MVT::v8i8: return VectorType::get(Type::Int8Ty, 8);
102 case MVT::v4i16: return VectorType::get(Type::Int16Ty, 4);
103 case MVT::v2i32: return VectorType::get(Type::Int32Ty, 2);
104 case MVT::v1i64: return VectorType::get(Type::Int64Ty, 1);
105 case MVT::v16i8: return VectorType::get(Type::Int8Ty, 16);
106 case MVT::v8i16: return VectorType::get(Type::Int16Ty, 8);
107 case MVT::v4i32: return VectorType::get(Type::Int32Ty, 4);
108 case MVT::v2i64: return VectorType::get(Type::Int64Ty, 2);
109 case MVT::v4f32: return VectorType::get(Type::FloatTy, 4);
110 case MVT::v2f64: return VectorType::get(Type::DoubleTy, 2);
114 /// MVT::getValueType - Return the value type corresponding to the specified
115 /// type. This returns all vectors as MVT::Vector and all pointers as
117 MVT::ValueType MVT::getValueType(const Type *Ty) {
118 switch (Ty->getTypeID()) {
119 default: assert(0 && "Unknown type!");
122 case Type::IntegerTyID:
123 switch (cast<IntegerType>(Ty)->getBitWidth()) {
125 // FIXME: Return MVT::iANY.
126 assert(0 && "Invalid width for value type");
127 case 1: return MVT::i1;
128 case 8: return MVT::i8;
129 case 16: return MVT::i16;
130 case 32: return MVT::i32;
131 case 64: return MVT::i64;
132 case 128: return MVT::i128;
135 case Type::FloatTyID: return MVT::f32;
136 case Type::DoubleTyID: return MVT::f64;
137 case Type::PointerTyID: return MVT::iPTR;
138 case Type::VectorTyID: return MVT::Vector;