Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ValueTypes.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-9/lib/clang/9.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-9~svn362543/build-llvm/lib/CodeGen -I /build/llvm-toolchain-snapshot-9~svn362543/lib/CodeGen -I /build/llvm-toolchain-snapshot-9~svn362543/build-llvm/include -I /build/llvm-toolchain-snapshot-9~svn362543/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/x86_64-linux-gnu/c++/6.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/backward -internal-isystem /usr/include/clang/9.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-9/lib/clang/9.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-9~svn362543/build-llvm/lib/CodeGen -fdebug-prefix-map=/build/llvm-toolchain-snapshot-9~svn362543=. -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -stack-protector 2 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2019-06-05-060531-1271-1 -x c++ /build/llvm-toolchain-snapshot-9~svn362543/lib/CodeGen/ValueTypes.cpp -faddrsig

/build/llvm-toolchain-snapshot-9~svn362543/lib/CodeGen/ValueTypes.cpp

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

/build/llvm-toolchain-snapshot-9~svn362543/include/llvm/CodeGen/ValueTypes.h

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