Bug Summary

File:lib/IR/ValueTypes.cpp
Warning:line 65, column 10
Called C++ object pointer is null

Annotated Source Code

/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp

1//===----------- ValueTypes.cpp - Implementation of EVT methods -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements methods in the CodeGen/ValueTypes.h header.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/ValueTypes.h"
15#include "llvm/ADT/StringExtras.h"
16#include "llvm/IR/DerivedTypes.h"
17#include "llvm/IR/LLVMContext.h"
18#include "llvm/IR/Type.h"
19#include "llvm/Support/ErrorHandling.h"
20using namespace llvm;
21
22EVT EVT::changeExtendedTypeToInteger() const {
23 LLVMContext &Context = LLVMTy->getContext();
24 return getIntegerVT(Context, getSizeInBits());
25}
26
27EVT EVT::changeExtendedVectorElementTypeToInteger() const {
28 LLVMContext &Context = LLVMTy->getContext();
29 EVT IntTy = getIntegerVT(Context, getScalarSizeInBits());
30 return getVectorVT(Context, IntTy, getVectorNumElements());
31}
32
33EVT EVT::getExtendedIntegerVT(LLVMContext &Context, unsigned BitWidth) {
34 EVT VT;
35 VT.LLVMTy = IntegerType::get(Context, BitWidth);
36 assert(VT.isExtended() && "Type is not extended!")((VT.isExtended() && "Type is not extended!") ? static_cast
<void> (0) : __assert_fail ("VT.isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 36, __PRETTY_FUNCTION__))
;
37 return VT;
38}
39
40EVT EVT::getExtendedVectorVT(LLVMContext &Context, EVT VT,
41 unsigned NumElements) {
42 EVT ResultVT;
43 ResultVT.LLVMTy = VectorType::get(VT.getTypeForEVT(Context), NumElements);
44 assert(ResultVT.isExtended() && "Type is not extended!")((ResultVT.isExtended() && "Type is not extended!") ?
static_cast<void> (0) : __assert_fail ("ResultVT.isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 44, __PRETTY_FUNCTION__))
;
45 return ResultVT;
46}
47
48bool EVT::isExtendedFloatingPoint() const {
49 assert(isExtended() && "Type is not extended!")((isExtended() && "Type is not extended!") ? static_cast
<void> (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 49, __PRETTY_FUNCTION__))
;
50 return LLVMTy->isFPOrFPVectorTy();
51}
52
53bool EVT::isExtendedInteger() const {
54 assert(isExtended() && "Type is not extended!")((isExtended() && "Type is not extended!") ? static_cast
<void> (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 54, __PRETTY_FUNCTION__))
;
55 return LLVMTy->isIntOrIntVectorTy();
56}
57
58bool EVT::isExtendedScalarInteger() const {
59 assert(isExtended() && "Type is not extended!")((isExtended() && "Type is not extended!") ? static_cast
<void> (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 59, __PRETTY_FUNCTION__))
;
60 return LLVMTy->isIntegerTy();
61}
62
63bool EVT::isExtendedVector() const {
64 assert(isExtended() && "Type is not extended!")((isExtended() && "Type is not extended!") ? static_cast
<void> (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 64, __PRETTY_FUNCTION__))
;
65 return LLVMTy->isVectorTy();
12
Called C++ object pointer is null
66}
67
68bool EVT::isExtended16BitVector() const {
69 return isExtendedVector() && getExtendedSizeInBits() == 16;
70}
71
72bool EVT::isExtended32BitVector() const {
73 return isExtendedVector() && getExtendedSizeInBits() == 32;
74}
75
76bool EVT::isExtended64BitVector() const {
77 return isExtendedVector() && getExtendedSizeInBits() == 64;
78}
79
80bool EVT::isExtended128BitVector() const {
81 return isExtendedVector() && getExtendedSizeInBits() == 128;
82}
83
84bool EVT::isExtended256BitVector() const {
85 return isExtendedVector() && getExtendedSizeInBits() == 256;
86}
87
88bool EVT::isExtended512BitVector() const {
89 return isExtendedVector() && getExtendedSizeInBits() == 512;
90}
91
92bool EVT::isExtended1024BitVector() const {
93 return isExtendedVector() && getExtendedSizeInBits() == 1024;
94}
95
96bool EVT::isExtended2048BitVector() const {
97 return isExtendedVector() && getExtendedSizeInBits() == 2048;
98}
99
100EVT EVT::getExtendedVectorElementType() const {
101 assert(isExtended() && "Type is not extended!")((isExtended() && "Type is not extended!") ? static_cast
<void> (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 101, __PRETTY_FUNCTION__))
;
102 return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());
103}
104
105unsigned EVT::getExtendedVectorNumElements() const {
106 assert(isExtended() && "Type is not extended!")((isExtended() && "Type is not extended!") ? static_cast
<void> (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 106, __PRETTY_FUNCTION__))
;
107 return cast<VectorType>(LLVMTy)->getNumElements();
108}
109
110unsigned EVT::getExtendedSizeInBits() const {
111 assert(isExtended() && "Type is not extended!")((isExtended() && "Type is not extended!") ? static_cast
<void> (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 111, __PRETTY_FUNCTION__))
;
112 if (IntegerType *ITy = dyn_cast<IntegerType>(LLVMTy))
113 return ITy->getBitWidth();
114 if (VectorType *VTy = dyn_cast<VectorType>(LLVMTy))
115 return VTy->getBitWidth();
116 llvm_unreachable("Unrecognized extended type!")::llvm::llvm_unreachable_internal("Unrecognized extended type!"
, "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 116)
;
117}
118
119/// getEVTString - This function returns value type as a string, e.g. "i32".
120std::string EVT::getEVTString() const {
121 switch (V.SimpleTy) {
1
Control jumps to the 'default' case at line 122
4
Control jumps to the 'default' case at line 122
8
Control jumps to the 'default' case at line 122
122 default:
123 if (isVector())
2
Taking true branch
5
Taking true branch
9
Calling 'EVT::isVector'
124 return "v" + utostr(getVectorNumElements()) +
125 getVectorElementType().getEVTString();
3
Calling 'EVT::getEVTString'
6
Null pointer value stored to field 'LLVMTy'
7
Calling 'EVT::getEVTString'
126 if (isInteger())
127 return "i" + utostr(getSizeInBits());
128 llvm_unreachable("Invalid EVT!")::llvm::llvm_unreachable_internal("Invalid EVT!", "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 128)
;
129 case MVT::i1: return "i1";
130 case MVT::i8: return "i8";
131 case MVT::i16: return "i16";
132 case MVT::i32: return "i32";
133 case MVT::i64: return "i64";
134 case MVT::i128: return "i128";
135 case MVT::f16: return "f16";
136 case MVT::f32: return "f32";
137 case MVT::f64: return "f64";
138 case MVT::f80: return "f80";
139 case MVT::f128: return "f128";
140 case MVT::ppcf128: return "ppcf128";
141 case MVT::isVoid: return "isVoid";
142 case MVT::Other: return "ch";
143 case MVT::Glue: return "glue";
144 case MVT::x86mmx: return "x86mmx";
145 case MVT::v1i1: return "v1i1";
146 case MVT::v2i1: return "v2i1";
147 case MVT::v4i1: return "v4i1";
148 case MVT::v8i1: return "v8i1";
149 case MVT::v16i1: return "v16i1";
150 case MVT::v32i1: return "v32i1";
151 case MVT::v64i1: return "v64i1";
152 case MVT::v512i1: return "v512i1";
153 case MVT::v1024i1: return "v1024i1";
154 case MVT::v1i8: return "v1i8";
155 case MVT::v2i8: return "v2i8";
156 case MVT::v4i8: return "v4i8";
157 case MVT::v8i8: return "v8i8";
158 case MVT::v16i8: return "v16i8";
159 case MVT::v32i8: return "v32i8";
160 case MVT::v64i8: return "v64i8";
161 case MVT::v128i8: return "v128i8";
162 case MVT::v256i8: return "v256i8";
163 case MVT::v1i16: return "v1i16";
164 case MVT::v2i16: return "v2i16";
165 case MVT::v4i16: return "v4i16";
166 case MVT::v8i16: return "v8i16";
167 case MVT::v16i16: return "v16i16";
168 case MVT::v32i16: return "v32i16";
169 case MVT::v64i16: return "v64i16";
170 case MVT::v128i16: return "v128i16";
171 case MVT::v1i32: return "v1i32";
172 case MVT::v2i32: return "v2i32";
173 case MVT::v4i32: return "v4i32";
174 case MVT::v8i32: return "v8i32";
175 case MVT::v16i32: return "v16i32";
176 case MVT::v32i32: return "v32i32";
177 case MVT::v64i32: return "v64i32";
178 case MVT::v1i64: return "v1i64";
179 case MVT::v2i64: return "v2i64";
180 case MVT::v4i64: return "v4i64";
181 case MVT::v8i64: return "v8i64";
182 case MVT::v16i64: return "v16i64";
183 case MVT::v32i64: return "v32i64";
184 case MVT::v1i128: return "v1i128";
185 case MVT::v1f32: return "v1f32";
186 case MVT::v2f32: return "v2f32";
187 case MVT::v2f16: return "v2f16";
188 case MVT::v4f16: return "v4f16";
189 case MVT::v8f16: return "v8f16";
190 case MVT::v4f32: return "v4f32";
191 case MVT::v8f32: return "v8f32";
192 case MVT::v16f32: return "v16f32";
193 case MVT::v1f64: return "v1f64";
194 case MVT::v2f64: return "v2f64";
195 case MVT::v4f64: return "v4f64";
196 case MVT::v8f64: return "v8f64";
197 case MVT::Metadata:return "Metadata";
198 case MVT::Untyped: return "Untyped";
199 }
200}
201
202/// getTypeForEVT - This method returns an LLVM type corresponding to the
203/// specified EVT. For integer types, this returns an unsigned type. Note
204/// that this will abort for types that cannot be represented.
205Type *EVT::getTypeForEVT(LLVMContext &Context) const {
206 switch (V.SimpleTy) {
207 default:
208 assert(isExtended() && "Type is not extended!")((isExtended() && "Type is not extended!") ? static_cast
<void> (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 208, __PRETTY_FUNCTION__))
;
209 return LLVMTy;
210 case MVT::isVoid: return Type::getVoidTy(Context);
211 case MVT::i1: return Type::getInt1Ty(Context);
212 case MVT::i8: return Type::getInt8Ty(Context);
213 case MVT::i16: return Type::getInt16Ty(Context);
214 case MVT::i32: return Type::getInt32Ty(Context);
215 case MVT::i64: return Type::getInt64Ty(Context);
216 case MVT::i128: return IntegerType::get(Context, 128);
217 case MVT::f16: return Type::getHalfTy(Context);
218 case MVT::f32: return Type::getFloatTy(Context);
219 case MVT::f64: return Type::getDoubleTy(Context);
220 case MVT::f80: return Type::getX86_FP80Ty(Context);
221 case MVT::f128: return Type::getFP128Ty(Context);
222 case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
223 case MVT::x86mmx: return Type::getX86_MMXTy(Context);
224 case MVT::v1i1: return VectorType::get(Type::getInt1Ty(Context), 1);
225 case MVT::v2i1: return VectorType::get(Type::getInt1Ty(Context), 2);
226 case MVT::v4i1: return VectorType::get(Type::getInt1Ty(Context), 4);
227 case MVT::v8i1: return VectorType::get(Type::getInt1Ty(Context), 8);
228 case MVT::v16i1: return VectorType::get(Type::getInt1Ty(Context), 16);
229 case MVT::v32i1: return VectorType::get(Type::getInt1Ty(Context), 32);
230 case MVT::v64i1: return VectorType::get(Type::getInt1Ty(Context), 64);
231 case MVT::v512i1: return VectorType::get(Type::getInt1Ty(Context), 512);
232 case MVT::v1024i1: return VectorType::get(Type::getInt1Ty(Context), 1024);
233 case MVT::v1i8: return VectorType::get(Type::getInt8Ty(Context), 1);
234 case MVT::v2i8: return VectorType::get(Type::getInt8Ty(Context), 2);
235 case MVT::v4i8: return VectorType::get(Type::getInt8Ty(Context), 4);
236 case MVT::v8i8: return VectorType::get(Type::getInt8Ty(Context), 8);
237 case MVT::v16i8: return VectorType::get(Type::getInt8Ty(Context), 16);
238 case MVT::v32i8: return VectorType::get(Type::getInt8Ty(Context), 32);
239 case MVT::v64i8: return VectorType::get(Type::getInt8Ty(Context), 64);
240 case MVT::v128i8: return VectorType::get(Type::getInt8Ty(Context), 128);
241 case MVT::v256i8: return VectorType::get(Type::getInt8Ty(Context), 256);
242 case MVT::v1i16: return VectorType::get(Type::getInt16Ty(Context), 1);
243 case MVT::v2i16: return VectorType::get(Type::getInt16Ty(Context), 2);
244 case MVT::v4i16: return VectorType::get(Type::getInt16Ty(Context), 4);
245 case MVT::v8i16: return VectorType::get(Type::getInt16Ty(Context), 8);
246 case MVT::v16i16: return VectorType::get(Type::getInt16Ty(Context), 16);
247 case MVT::v32i16: return VectorType::get(Type::getInt16Ty(Context), 32);
248 case MVT::v64i16: return VectorType::get(Type::getInt16Ty(Context), 64);
249 case MVT::v128i16: return VectorType::get(Type::getInt16Ty(Context), 128);
250 case MVT::v1i32: return VectorType::get(Type::getInt32Ty(Context), 1);
251 case MVT::v2i32: return VectorType::get(Type::getInt32Ty(Context), 2);
252 case MVT::v4i32: return VectorType::get(Type::getInt32Ty(Context), 4);
253 case MVT::v8i32: return VectorType::get(Type::getInt32Ty(Context), 8);
254 case MVT::v16i32: return VectorType::get(Type::getInt32Ty(Context), 16);
255 case MVT::v32i32: return VectorType::get(Type::getInt32Ty(Context), 32);
256 case MVT::v64i32: return VectorType::get(Type::getInt32Ty(Context), 64);
257 case MVT::v1i64: return VectorType::get(Type::getInt64Ty(Context), 1);
258 case MVT::v2i64: return VectorType::get(Type::getInt64Ty(Context), 2);
259 case MVT::v4i64: return VectorType::get(Type::getInt64Ty(Context), 4);
260 case MVT::v8i64: return VectorType::get(Type::getInt64Ty(Context), 8);
261 case MVT::v16i64: return VectorType::get(Type::getInt64Ty(Context), 16);
262 case MVT::v32i64: return VectorType::get(Type::getInt64Ty(Context), 32);
263 case MVT::v1i128: return VectorType::get(Type::getInt128Ty(Context), 1);
264 case MVT::v2f16: return VectorType::get(Type::getHalfTy(Context), 2);
265 case MVT::v4f16: return VectorType::get(Type::getHalfTy(Context), 4);
266 case MVT::v8f16: return VectorType::get(Type::getHalfTy(Context), 8);
267 case MVT::v1f32: return VectorType::get(Type::getFloatTy(Context), 1);
268 case MVT::v2f32: return VectorType::get(Type::getFloatTy(Context), 2);
269 case MVT::v4f32: return VectorType::get(Type::getFloatTy(Context), 4);
270 case MVT::v8f32: return VectorType::get(Type::getFloatTy(Context), 8);
271 case MVT::v16f32: return VectorType::get(Type::getFloatTy(Context), 16);
272 case MVT::v1f64: return VectorType::get(Type::getDoubleTy(Context), 1);
273 case MVT::v2f64: return VectorType::get(Type::getDoubleTy(Context), 2);
274 case MVT::v4f64: return VectorType::get(Type::getDoubleTy(Context), 4);
275 case MVT::v8f64: return VectorType::get(Type::getDoubleTy(Context), 8);
276 case MVT::Metadata: return Type::getMetadataTy(Context);
277 }
278}
279
280/// Return the value type corresponding to the specified type. This returns all
281/// pointers as MVT::iPTR. If HandleUnknown is true, unknown types are returned
282/// as Other, otherwise they are invalid.
283MVT MVT::getVT(Type *Ty, bool HandleUnknown){
284 switch (Ty->getTypeID()) {
285 default:
286 if (HandleUnknown) return MVT(MVT::Other);
287 llvm_unreachable("Unknown type!")::llvm::llvm_unreachable_internal("Unknown type!", "/build/llvm-toolchain-snapshot-6.0~svn318211/lib/IR/ValueTypes.cpp"
, 287)
;
288 case Type::VoidTyID:
289 return MVT::isVoid;
290 case Type::IntegerTyID:
291 return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
292 case Type::HalfTyID: return MVT(MVT::f16);
293 case Type::FloatTyID: return MVT(MVT::f32);
294 case Type::DoubleTyID: return MVT(MVT::f64);
295 case Type::X86_FP80TyID: return MVT(MVT::f80);
296 case Type::X86_MMXTyID: return MVT(MVT::x86mmx);
297 case Type::FP128TyID: return MVT(MVT::f128);
298 case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
299 case Type::PointerTyID: return MVT(MVT::iPTR);
300 case Type::VectorTyID: {
301 VectorType *VTy = cast<VectorType>(Ty);
302 return getVectorVT(
303 getVT(VTy->getElementType(), false), VTy->getNumElements());
304 }
305 }
306}
307
308/// getEVT - Return the value type corresponding to the specified type. This
309/// returns all pointers as MVT::iPTR. If HandleUnknown is true, unknown types
310/// are returned as Other, otherwise they are invalid.
311EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
312 switch (Ty->getTypeID()) {
313 default:
314 return MVT::getVT(Ty, HandleUnknown);
315 case Type::IntegerTyID:
316 return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
317 case Type::VectorTyID: {
318 VectorType *VTy = cast<VectorType>(Ty);
319 return getVectorVT(Ty->getContext(), getEVT(VTy->getElementType(), false),
320 VTy->getNumElements());
321 }
322 }
323}

/build/llvm-toolchain-snapshot-6.0~svn318211/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 is distributed under the University of Illinois Open Source
6// 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 "llvm/CodeGen/MachineValueType.h"
20#include "llvm/Support/Compiler.h"
21#include "llvm/Support/MathExtras.h"
22#include <cassert>
23#include <cstdint>
24#include <string>
25
26namespace llvm {
27
28 class LLVMContext;
29 class Type;
30
31 /// Extended Value Type. Capable of holding value types which are not native
32 /// for any processor (such as the i12345 type), as well as the types an MVT
33 /// can represent.
34 struct EVT {
35 private:
36 MVT V = MVT::INVALID_SIMPLE_VALUE_TYPE;
37 Type *LLVMTy = nullptr;
38
39 public:
40 constexpr EVT() = default;
41 constexpr EVT(MVT::SimpleValueType SVT) : V(SVT) {}
42 constexpr EVT(MVT S) : V(S) {}
43
44 bool operator==(EVT VT) const {
45 return !(*this != VT);
46 }
47 bool operator!=(EVT VT) const {
48 if (V.SimpleTy != VT.V.SimpleTy)
49 return true;
50 if (V.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
51 return LLVMTy != VT.LLVMTy;
52 return false;
53 }
54
55 /// Returns the EVT that represents a floating-point type with the given
56 /// number of bits. There are two floating-point types with 128 bits - this
57 /// returns f128 rather than ppcf128.
58 static EVT getFloatingPointVT(unsigned BitWidth) {
59 return MVT::getFloatingPointVT(BitWidth);
60 }
61
62 /// Returns the EVT that represents an integer with the given number of
63 /// bits.
64 static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) {
65 MVT M = MVT::getIntegerVT(BitWidth);
66 if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
67 return M;
68 return getExtendedIntegerVT(Context, BitWidth);
69 }
70
71 /// Returns the EVT that represents a vector NumElements in length, where
72 /// each element is of type VT.
73 static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements,
74 bool IsScalable = false) {
75 MVT M = MVT::getVectorVT(VT.V, NumElements, IsScalable);
76 if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
77 return M;
78
79 assert(!IsScalable && "We don't support extended scalable types yet")((!IsScalable && "We don't support extended scalable types yet"
) ? static_cast<void> (0) : __assert_fail ("!IsScalable && \"We don't support extended scalable types yet\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 79, __PRETTY_FUNCTION__))
;
80 return getExtendedVectorVT(Context, VT, NumElements);
81 }
82
83 /// Returns the EVT that represents a vector EC.Min elements in length,
84 /// where each element is of type VT.
85 static EVT getVectorVT(LLVMContext &Context, EVT VT, MVT::ElementCount EC) {
86 MVT M = MVT::getVectorVT(VT.V, EC);
87 if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
88 return M;
89 assert (!EC.Scalable && "We don't support extended scalable types yet")((!EC.Scalable && "We don't support extended scalable types yet"
) ? static_cast<void> (0) : __assert_fail ("!EC.Scalable && \"We don't support extended scalable types yet\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 89, __PRETTY_FUNCTION__))
;
90 return getExtendedVectorVT(Context, VT, EC.Min);
91 }
92
93 /// Return a vector with the same number of elements as this vector, but
94 /// with the element type converted to an integer type with the same
95 /// bitwidth.
96 EVT changeVectorElementTypeToInteger() const {
97 if (!isSimple()) {
98 assert (!isScalableVector() &&((!isScalableVector() && "We don't support extended scalable types yet"
) ? static_cast<void> (0) : __assert_fail ("!isScalableVector() && \"We don't support extended scalable types yet\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 99, __PRETTY_FUNCTION__))
99 "We don't support extended scalable types yet")((!isScalableVector() && "We don't support extended scalable types yet"
) ? static_cast<void> (0) : __assert_fail ("!isScalableVector() && \"We don't support extended scalable types yet\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 99, __PRETTY_FUNCTION__))
;
100 return changeExtendedVectorElementTypeToInteger();
101 }
102 MVT EltTy = getSimpleVT().getVectorElementType();
103 unsigned BitWidth = EltTy.getSizeInBits();
104 MVT IntTy = MVT::getIntegerVT(BitWidth);
105 MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements(),
106 isScalableVector());
107 assert(VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&((VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
"Simple vector VT not representable by simple integer vector VT!"
) ? static_cast<void> (0) : __assert_fail ("VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE && \"Simple vector VT not representable by simple integer vector VT!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 108, __PRETTY_FUNCTION__))
108 "Simple vector VT not representable by simple integer vector VT!")((VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
"Simple vector VT not representable by simple integer vector VT!"
) ? static_cast<void> (0) : __assert_fail ("VecTy.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE && \"Simple vector VT not representable by simple integer vector VT!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 108, __PRETTY_FUNCTION__))
;
109 return VecTy;
110 }
111
112 /// Return the type converted to an equivalently sized integer or vector
113 /// with integer element type. Similar to changeVectorElementTypeToInteger,
114 /// but also handles scalars.
115 EVT changeTypeToInteger() {
116 if (isVector())
117 return changeVectorElementTypeToInteger();
118
119 if (isSimple())
120 return MVT::getIntegerVT(getSizeInBits());
121
122 return changeExtendedTypeToInteger();
123 }
124
125 /// Test if the given EVT is simple (as opposed to being extended).
126 bool isSimple() const {
127 return V.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE;
128 }
129
130 /// Test if the given EVT is extended (as opposed to being simple).
131 bool isExtended() const {
132 return !isSimple();
133 }
134
135 /// Return true if this is a FP or a vector FP type.
136 bool isFloatingPoint() const {
137 return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
138 }
139
140 /// Return true if this is an integer or a vector integer type.
141 bool isInteger() const {
142 return isSimple() ? V.isInteger() : isExtendedInteger();
143 }
144
145 /// Return true if this is an integer, but not a vector.
146 bool isScalarInteger() const {
147 return isSimple() ? V.isScalarInteger() : isExtendedScalarInteger();
148 }
149
150 /// Return true if this is a vector value type.
151 bool isVector() const {
152 return isSimple() ? V.isVector() : isExtendedVector();
10
'?' condition is false
11
Calling 'EVT::isExtendedVector'
153 }
154
155 /// Return true if this is a vector type where the runtime
156 /// length is machine dependent
157 bool isScalableVector() const {
158 // FIXME: We don't support extended scalable types yet, because the
159 // matching IR type doesn't exist. Once it has been added, this can
160 // be changed to call isExtendedScalableVector.
161 if (!isSimple())
162 return false;
163 return V.isScalableVector();
164 }
165
166 /// Return true if this is a 16-bit vector type.
167 bool is16BitVector() const {
168 return isSimple() ? V.is16BitVector() : isExtended16BitVector();
169 }
170
171 /// Return true if this is a 32-bit vector type.
172 bool is32BitVector() const {
173 return isSimple() ? V.is32BitVector() : isExtended32BitVector();
174 }
175
176 /// Return true if this is a 64-bit vector type.
177 bool is64BitVector() const {
178 return isSimple() ? V.is64BitVector() : isExtended64BitVector();
179 }
180
181 /// Return true if this is a 128-bit vector type.
182 bool is128BitVector() const {
183 return isSimple() ? V.is128BitVector() : isExtended128BitVector();
184 }
185
186 /// Return true if this is a 256-bit vector type.
187 bool is256BitVector() const {
188 return isSimple() ? V.is256BitVector() : isExtended256BitVector();
189 }
190
191 /// Return true if this is a 512-bit vector type.
192 bool is512BitVector() const {
193 return isSimple() ? V.is512BitVector() : isExtended512BitVector();
194 }
195
196 /// Return true if this is a 1024-bit vector type.
197 bool is1024BitVector() const {
198 return isSimple() ? V.is1024BitVector() : isExtended1024BitVector();
199 }
200
201 /// Return true if this is a 2048-bit vector type.
202 bool is2048BitVector() const {
203 return isSimple() ? V.is2048BitVector() : isExtended2048BitVector();
204 }
205
206 /// Return true if this is an overloaded type for TableGen.
207 bool isOverloaded() const {
208 return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
209 }
210
211 /// Return true if the bit size is a multiple of 8.
212 bool isByteSized() const {
213 return (getSizeInBits() & 7) == 0;
214 }
215
216 /// Return true if the size is a power-of-two number of bytes.
217 bool isRound() const {
218 unsigned BitSize = getSizeInBits();
219 return BitSize >= 8 && !(BitSize & (BitSize - 1));
220 }
221
222 /// Return true if this has the same number of bits as VT.
223 bool bitsEq(EVT VT) const {
224 if (EVT::operator==(VT)) return true;
225 return getSizeInBits() == VT.getSizeInBits();
226 }
227
228 /// Return true if this has more bits than VT.
229 bool bitsGT(EVT VT) const {
230 if (EVT::operator==(VT)) return false;
231 return getSizeInBits() > VT.getSizeInBits();
232 }
233
234 /// Return true if this has no less bits than VT.
235 bool bitsGE(EVT VT) const {
236 if (EVT::operator==(VT)) return true;
237 return getSizeInBits() >= VT.getSizeInBits();
238 }
239
240 /// Return true if this has less bits than VT.
241 bool bitsLT(EVT VT) const {
242 if (EVT::operator==(VT)) return false;
243 return getSizeInBits() < VT.getSizeInBits();
244 }
245
246 /// Return true if this has no more bits than VT.
247 bool bitsLE(EVT VT) const {
248 if (EVT::operator==(VT)) return true;
249 return getSizeInBits() <= VT.getSizeInBits();
250 }
251
252 /// Return the SimpleValueType held in the specified simple EVT.
253 MVT getSimpleVT() const {
254 assert(isSimple() && "Expected a SimpleValueType!")((isSimple() && "Expected a SimpleValueType!") ? static_cast
<void> (0) : __assert_fail ("isSimple() && \"Expected a SimpleValueType!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 254, __PRETTY_FUNCTION__))
;
255 return V;
256 }
257
258 /// If this is a vector type, return the element type, otherwise return
259 /// this.
260 EVT getScalarType() const {
261 return isVector() ? getVectorElementType() : *this;
262 }
263
264 /// Given a vector type, return the type of each element.
265 EVT getVectorElementType() const {
266 assert(isVector() && "Invalid vector type!")((isVector() && "Invalid vector type!") ? static_cast
<void> (0) : __assert_fail ("isVector() && \"Invalid vector type!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 266, __PRETTY_FUNCTION__))
;
267 if (isSimple())
268 return V.getVectorElementType();
269 return getExtendedVectorElementType();
270 }
271
272 /// Given a vector type, return the number of elements it contains.
273 unsigned getVectorNumElements() const {
274 assert(isVector() && "Invalid vector type!")((isVector() && "Invalid vector type!") ? static_cast
<void> (0) : __assert_fail ("isVector() && \"Invalid vector type!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 274, __PRETTY_FUNCTION__))
;
275 if (isSimple())
276 return V.getVectorNumElements();
277 return getExtendedVectorNumElements();
278 }
279
280 // Given a (possibly scalable) vector type, return the ElementCount
281 MVT::ElementCount getVectorElementCount() const {
282 assert((isVector()) && "Invalid vector type!")(((isVector()) && "Invalid vector type!") ? static_cast
<void> (0) : __assert_fail ("(isVector()) && \"Invalid vector type!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 282, __PRETTY_FUNCTION__))
;
283 if (isSimple())
284 return V.getVectorElementCount();
285
286 assert(!isScalableVector() &&((!isScalableVector() && "We don't support extended scalable types yet"
) ? static_cast<void> (0) : __assert_fail ("!isScalableVector() && \"We don't support extended scalable types yet\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 287, __PRETTY_FUNCTION__))
287 "We don't support extended scalable types yet")((!isScalableVector() && "We don't support extended scalable types yet"
) ? static_cast<void> (0) : __assert_fail ("!isScalableVector() && \"We don't support extended scalable types yet\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 287, __PRETTY_FUNCTION__))
;
288 return {getExtendedVectorNumElements(), false};
289 }
290
291 /// Return the size of the specified value type in bits.
292 unsigned getSizeInBits() const {
293 if (isSimple())
294 return V.getSizeInBits();
295 return getExtendedSizeInBits();
296 }
297
298 unsigned getScalarSizeInBits() const {
299 return getScalarType().getSizeInBits();
300 }
301
302 /// Return the number of bytes overwritten by a store of the specified value
303 /// type.
304 unsigned getStoreSize() const {
305 return (getSizeInBits() + 7) / 8;
306 }
307
308 /// Return the number of bits overwritten by a store of the specified value
309 /// type.
310 unsigned getStoreSizeInBits() const {
311 return getStoreSize() * 8;
312 }
313
314 /// Rounds the bit-width of the given integer EVT up to the nearest power of
315 /// two (and at least to eight), and returns the integer EVT with that
316 /// number of bits.
317 EVT getRoundIntegerType(LLVMContext &Context) const {
318 assert(isInteger() && !isVector() && "Invalid integer type!")((isInteger() && !isVector() && "Invalid integer type!"
) ? static_cast<void> (0) : __assert_fail ("isInteger() && !isVector() && \"Invalid integer type!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 318, __PRETTY_FUNCTION__))
;
319 unsigned BitWidth = getSizeInBits();
320 if (BitWidth <= 8)
321 return EVT(MVT::i8);
322 return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
323 }
324
325 /// Finds the smallest simple value type that is greater than or equal to
326 /// half the width of this EVT. If no simple value type can be found, an
327 /// extended integer value type of half the size (rounded up) is returned.
328 EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
329 assert(isInteger() && !isVector() && "Invalid integer type!")((isInteger() && !isVector() && "Invalid integer type!"
) ? static_cast<void> (0) : __assert_fail ("isInteger() && !isVector() && \"Invalid integer type!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 329, __PRETTY_FUNCTION__))
;
330 unsigned EVTSize = getSizeInBits();
331 for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
332 IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) {
333 EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
334 if (HalfVT.getSizeInBits() * 2 >= EVTSize)
335 return HalfVT;
336 }
337 return getIntegerVT(Context, (EVTSize + 1) / 2);
338 }
339
340 /// Return a VT for an integer vector type with the size of the
341 /// elements doubled. The typed returned may be an extended type.
342 EVT widenIntegerVectorElementType(LLVMContext &Context) const {
343 EVT EltVT = getVectorElementType();
344 EltVT = EVT::getIntegerVT(Context, 2 * EltVT.getSizeInBits());
345 return EVT::getVectorVT(Context, EltVT, getVectorElementCount());
346 }
347
348 // Return a VT for a vector type with the same element type but
349 // half the number of elements. The type returned may be an
350 // extended type.
351 EVT getHalfNumVectorElementsVT(LLVMContext &Context) const {
352 EVT EltVT = getVectorElementType();
353 auto EltCnt = getVectorElementCount();
354 assert(!(EltCnt.Min & 1) && "Splitting vector, but not in half!")((!(EltCnt.Min & 1) && "Splitting vector, but not in half!"
) ? static_cast<void> (0) : __assert_fail ("!(EltCnt.Min & 1) && \"Splitting vector, but not in half!\""
, "/build/llvm-toolchain-snapshot-6.0~svn318211/include/llvm/CodeGen/ValueTypes.h"
, 354, __PRETTY_FUNCTION__))
;
355 return EVT::getVectorVT(Context, EltVT, EltCnt / 2);
356 }
357
358 /// Returns true if the given vector is a power of 2.
359 bool isPow2VectorType() const {
360 unsigned NElts = getVectorNumElements();
361 return !(NElts & (NElts - 1));
362 }
363
364 /// Widens the length of the given vector EVT up to the nearest power of 2
365 /// and returns that type.
366 EVT getPow2VectorType(LLVMContext &Context) const {
367 if (!isPow2VectorType()) {
368 unsigned NElts = getVectorNumElements();
369 unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
370 return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts,
371 isScalableVector());
372 }
373 else {
374 return *this;
375 }
376 }
377
378 /// This function returns value type as a string, e.g. "i32".
379 std::string getEVTString() const;
380
381 /// This method returns an LLVM type corresponding to the specified EVT.
382 /// For integer types, this returns an unsigned type. Note that this will
383 /// abort for types that cannot be represented.
384 Type *getTypeForEVT(LLVMContext &Context) const;
385
386 /// Return the value type corresponding to the specified type.
387 /// This returns all pointers as iPTR. If HandleUnknown is true, unknown
388 /// types are returned as Other, otherwise they are invalid.
389 static EVT getEVT(Type *Ty, bool HandleUnknown = false);
390
391 intptr_t getRawBits() const {
392 if (isSimple())
393 return V.SimpleTy;
394 else
395 return (intptr_t)(LLVMTy);
396 }
397
398 /// A meaningless but well-behaved order, useful for constructing
399 /// containers.
400 struct compareRawBits {
401 bool operator()(EVT L, EVT R) const {
402 if (L.V.SimpleTy == R.V.SimpleTy)
403 return L.LLVMTy < R.LLVMTy;
404 else
405 return L.V.SimpleTy < R.V.SimpleTy;
406 }
407 };
408
409 private:
410 // Methods for handling the Extended-type case in functions above.
411 // These are all out-of-line to prevent users of this header file
412 // from having a dependency on Type.h.
413 EVT changeExtendedTypeToInteger() const;
414 EVT changeExtendedVectorElementTypeToInteger() const;
415 static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
416 static EVT getExtendedVectorVT(LLVMContext &C, EVT VT,
417 unsigned NumElements);
418 bool isExtendedFloatingPoint() const LLVM_READONLY__attribute__((__pure__));
419 bool isExtendedInteger() const LLVM_READONLY__attribute__((__pure__));
420 bool isExtendedScalarInteger() const LLVM_READONLY__attribute__((__pure__));
421 bool isExtendedVector() const LLVM_READONLY__attribute__((__pure__));
422 bool isExtended16BitVector() const LLVM_READONLY__attribute__((__pure__));
423 bool isExtended32BitVector() const LLVM_READONLY__attribute__((__pure__));
424 bool isExtended64BitVector() const LLVM_READONLY__attribute__((__pure__));
425 bool isExtended128BitVector() const LLVM_READONLY__attribute__((__pure__));
426 bool isExtended256BitVector() const LLVM_READONLY__attribute__((__pure__));
427 bool isExtended512BitVector() const LLVM_READONLY__attribute__((__pure__));
428 bool isExtended1024BitVector() const LLVM_READONLY__attribute__((__pure__));
429 bool isExtended2048BitVector() const LLVM_READONLY__attribute__((__pure__));
430 EVT getExtendedVectorElementType() const;
431 unsigned getExtendedVectorNumElements() const LLVM_READONLY__attribute__((__pure__));
432 unsigned getExtendedSizeInBits() const LLVM_READONLY__attribute__((__pure__));
433 };
434
435} // end namespace llvm
436
437#endif // LLVM_CODEGEN_VALUETYPES_H