1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
//===----------- ValueTypes.cpp - Implementation of MVT methods -----------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements methods in the CodeGen/ValueTypes.h header.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringExtras.h"
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/Type.h"
#include "llvm/DerivedTypes.h"
using namespace llvm;
MVT MVT::getExtendedIntegerVT(unsigned BitWidth) {
MVT VT;
VT.LLVMTy = IntegerType::get(BitWidth);
assert(VT.isExtended() && "Type is not extended!");
return VT;
}
MVT MVT::getExtendedVectorVT(MVT VT, unsigned NumElements) {
MVT ResultVT;
ResultVT.LLVMTy = VectorType::get(VT.getTypeForMVT(), NumElements);
assert(ResultVT.isExtended() && "Type is not extended!");
return ResultVT;
}
bool MVT::isExtendedFloatingPoint() const {
assert(isExtended() && "Type is not extended!");
return LLVMTy->isFPOrFPVector();
}
bool MVT::isExtendedInteger() const {
assert(isExtended() && "Type is not extended!");
return LLVMTy->isIntOrIntVector();
}
bool MVT::isExtendedVector() const {
assert(isExtended() && "Type is not extended!");
return isa<VectorType>(LLVMTy);
}
bool MVT::isExtended64BitVector() const {
return isExtendedVector() && getSizeInBits() == 64;
}
bool MVT::isExtended128BitVector() const {
return isExtendedVector() && getSizeInBits() == 128;
}
MVT MVT::getExtendedVectorElementType() const {
assert(isExtended() && "Type is not extended!");
return MVT::getMVT(cast<VectorType>(LLVMTy)->getElementType());
}
unsigned MVT::getExtendedVectorNumElements() const {
assert(isExtended() && "Type is not extended!");
return cast<VectorType>(LLVMTy)->getNumElements();
}
unsigned MVT::getExtendedSizeInBits() const {
assert(isExtended() && "Type is not extended!");
if (const IntegerType *ITy = dyn_cast<IntegerType>(LLVMTy))
return ITy->getBitWidth();
if (const VectorType *VTy = dyn_cast<VectorType>(LLVMTy))
return VTy->getBitWidth();
assert(false && "Unrecognized extended type!");
return 0; // Suppress warnings.
}
/// getMVTString - This function returns value type as a string, e.g. "i32".
std::string MVT::getMVTString() const {
switch (V) {
default:
if (isVector())
return "v" + utostr(getVectorNumElements()) +
getVectorElementType().getMVTString();
if (isInteger())
return "i" + utostr(getSizeInBits());
assert(0 && "Invalid MVT!");
return "?";
case MVT::i1: return "i1";
case MVT::i8: return "i8";
case MVT::i16: return "i16";
case MVT::i32: return "i32";
case MVT::i64: return "i64";
case MVT::i128: return "i128";
case MVT::f32: return "f32";
case MVT::f64: return "f64";
case MVT::f80: return "f80";
case MVT::f128: return "f128";
case MVT::ppcf128: return "ppcf128";
case MVT::isVoid: return "isVoid";
case MVT::Other: return "ch";
case MVT::Flag: return "flag";
case MVT::v8i8: return "v8i8";
case MVT::v4i16: return "v4i16";
case MVT::v2i32: return "v2i32";
case MVT::v1i64: return "v1i64";
case MVT::v16i8: return "v16i8";
case MVT::v8i16: return "v8i16";
case MVT::v4i32: return "v4i32";
case MVT::v2i64: return "v2i64";
case MVT::v2f32: return "v2f32";
case MVT::v4f32: return "v4f32";
case MVT::v2f64: return "v2f64";
case MVT::v3i32: return "v3i32";
case MVT::v3f32: return "v3f32";
}
}
/// getTypeForMVT - This method returns an LLVM type corresponding to the
/// specified MVT. For integer types, this returns an unsigned type. Note
/// that this will abort for types that cannot be represented.
const Type *MVT::getTypeForMVT() const {
switch (V) {
default:
assert(isExtended() && "Type is not extended!");
return LLVMTy;
case MVT::isVoid: return Type::VoidTy;
case MVT::i1: return Type::Int1Ty;
case MVT::i8: return Type::Int8Ty;
case MVT::i16: return Type::Int16Ty;
case MVT::i32: return Type::Int32Ty;
case MVT::i64: return Type::Int64Ty;
case MVT::i128: return IntegerType::get(128);
case MVT::f32: return Type::FloatTy;
case MVT::f64: return Type::DoubleTy;
case MVT::f80: return Type::X86_FP80Ty;
case MVT::f128: return Type::FP128Ty;
case MVT::ppcf128: return Type::PPC_FP128Ty;
case MVT::v8i8: return VectorType::get(Type::Int8Ty, 8);
case MVT::v4i16: return VectorType::get(Type::Int16Ty, 4);
case MVT::v2i32: return VectorType::get(Type::Int32Ty, 2);
case MVT::v1i64: return VectorType::get(Type::Int64Ty, 1);
case MVT::v16i8: return VectorType::get(Type::Int8Ty, 16);
case MVT::v8i16: return VectorType::get(Type::Int16Ty, 8);
case MVT::v4i32: return VectorType::get(Type::Int32Ty, 4);
case MVT::v2i64: return VectorType::get(Type::Int64Ty, 2);
case MVT::v2f32: return VectorType::get(Type::FloatTy, 2);
case MVT::v4f32: return VectorType::get(Type::FloatTy, 4);
case MVT::v2f64: return VectorType::get(Type::DoubleTy, 2);
case MVT::v3i32: return VectorType::get(Type::Int32Ty, 3);
case MVT::v3f32: return VectorType::get(Type::FloatTy, 3);
}
}
/// getMVT - Return the value type corresponding to the specified type. This
/// returns all pointers as MVT::iPTR. If HandleUnknown is true, unknown types
/// are returned as Other, otherwise they are invalid.
MVT MVT::getMVT(const Type *Ty, bool HandleUnknown){
switch (Ty->getTypeID()) {
default:
if (HandleUnknown) return MVT::Other;
assert(0 && "Unknown type!");
return MVT::isVoid;
case Type::VoidTyID:
return MVT::isVoid;
case Type::IntegerTyID:
return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
case Type::FloatTyID: return MVT::f32;
case Type::DoubleTyID: return MVT::f64;
case Type::X86_FP80TyID: return MVT::f80;
case Type::FP128TyID: return MVT::f128;
case Type::PPC_FP128TyID: return MVT::ppcf128;
case Type::PointerTyID: return MVT::iPTR;
case Type::VectorTyID: {
const VectorType *VTy = cast<VectorType>(Ty);
return getVectorVT(getMVT(VTy->getElementType(), false),
VTy->getNumElements());
}
}
}
|