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::v16i8: return "v16i8";
42 case MVT::v8i16: return "v8i16";
43 case MVT::v4i32: return "v4i32";
44 case MVT::v2i64: return "v2i64";
45 case MVT::v4f32: return "v4f32";
46 case MVT::v2f64: return "v2f64";
50 /// MVT::getVectorType - Returns the ValueType that represents a vector
51 /// NumElements in length, where each element is of type VT. If there is no
52 /// ValueType that represents this vector, a ValueType of Other is returned.
54 MVT::ValueType MVT::getVectorType(ValueType VT, unsigned NumElements) {
59 if (NumElements == 8) return MVT::v8i8;
60 if (NumElements == 16) return MVT::v16i8;
63 if (NumElements == 4) return MVT::v4i16;
64 if (NumElements == 8) return MVT::v8i16;
67 if (NumElements == 2) return MVT::v2i32;
68 if (NumElements == 4) return MVT::v4i32;
71 if (NumElements == 2) return MVT::v2i64;
74 if (NumElements == 2) return MVT::v2f32;
75 if (NumElements == 4) return MVT::v4f32;
78 if (NumElements == 2) return MVT::v2f64;
84 /// MVT::getTypeForValueType - This method returns an LLVM type corresponding
85 /// to the specified ValueType. Note that this will abort for types that cannot
87 const Type *MVT::getTypeForValueType(MVT::ValueType VT) {
89 default: assert(0 && "ValueType does not correspond to LLVM type!");
90 case MVT::isVoid:return Type::VoidTy;
91 case MVT::i1: return Type::Int1Ty;
92 case MVT::i8: return Type::Int8Ty;
93 case MVT::i16: return Type::Int16Ty;
94 case MVT::i32: return Type::Int32Ty;
95 case MVT::i64: return Type::Int64Ty;
96 case MVT::f32: return Type::FloatTy;
97 case MVT::f64: return Type::DoubleTy;
98 case MVT::v8i8: return PackedType::get(Type::Int8Ty, 8);
99 case MVT::v4i16: return PackedType::get(Type::Int16Ty, 4);
100 case MVT::v2i32: return PackedType::get(Type::Int32Ty, 2);
101 case MVT::v16i8: return PackedType::get(Type::Int8Ty, 16);
102 case MVT::v8i16: return PackedType::get(Type::Int16Ty, 8);
103 case MVT::v4i32: return PackedType::get(Type::Int32Ty, 4);
104 case MVT::v2i64: return PackedType::get(Type::Int64Ty, 2);
105 case MVT::v4f32: return PackedType::get(Type::FloatTy, 4);
106 case MVT::v2f64: return PackedType::get(Type::DoubleTy, 2);