Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -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 -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/build-llvm/lib/CodeGen -resource-dir /usr/lib/llvm-13/lib/clang/13.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/build-llvm/lib/CodeGen -I /build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen -I /build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/build-llvm/include -I /build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-13/lib/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/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-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/build-llvm/lib/CodeGen -fdebug-prefix-map=/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b=. -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2021-06-17-010711-25934-1 -x c++ /build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp

/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/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"
14#include "llvm/Support/TypeSize.h"
15using namespace llvm;
16
17EVT EVT::changeExtendedTypeToInteger() const {
18 assert(isExtended() && "Type is not extended!")(static_cast <bool> (isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 18, __extension__ __PRETTY_FUNCTION__))
;
19 LLVMContext &Context = LLVMTy->getContext();
20 return getIntegerVT(Context, getSizeInBits());
21}
22
23EVT EVT::changeExtendedVectorElementTypeToInteger() const {
24 assert(isExtended() && "Type is not extended!")(static_cast <bool> (isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 24, __extension__ __PRETTY_FUNCTION__))
;
25 LLVMContext &Context = LLVMTy->getContext();
26 EVT IntTy = getIntegerVT(Context, getScalarSizeInBits());
27 return getVectorVT(Context, IntTy, getVectorElementCount());
28}
29
30EVT EVT::changeExtendedVectorElementType(EVT EltVT) const {
31 assert(isExtended() && "Type is not extended!")(static_cast <bool> (isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 31, __extension__ __PRETTY_FUNCTION__))
;
32 LLVMContext &Context = LLVMTy->getContext();
33 return getVectorVT(Context, EltVT, getVectorElementCount());
34}
35
36EVT EVT::getExtendedIntegerVT(LLVMContext &Context, unsigned BitWidth) {
37 EVT VT;
38 VT.LLVMTy = IntegerType::get(Context, BitWidth);
39 assert(VT.isExtended() && "Type is not extended!")(static_cast <bool> (VT.isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("VT.isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 39, __extension__ __PRETTY_FUNCTION__))
;
40 return VT;
41}
42
43EVT EVT::getExtendedVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements,
44 bool IsScalable) {
45 EVT ResultVT;
46 ResultVT.LLVMTy =
47 VectorType::get(VT.getTypeForEVT(Context), NumElements, IsScalable);
48 assert(ResultVT.isExtended() && "Type is not extended!")(static_cast <bool> (ResultVT.isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("ResultVT.isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 48, __extension__ __PRETTY_FUNCTION__))
;
49 return ResultVT;
50}
51
52EVT EVT::getExtendedVectorVT(LLVMContext &Context, EVT VT, ElementCount EC) {
53 EVT ResultVT;
54 ResultVT.LLVMTy = VectorType::get(VT.getTypeForEVT(Context), EC);
55 assert(ResultVT.isExtended() && "Type is not extended!")(static_cast <bool> (ResultVT.isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("ResultVT.isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 55, __extension__ __PRETTY_FUNCTION__))
;
56 return ResultVT;
57}
58
59bool EVT::isExtendedFloatingPoint() const {
60 assert(isExtended() && "Type is not extended!")(static_cast <bool> (isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 60, __extension__ __PRETTY_FUNCTION__))
;
61 return LLVMTy->isFPOrFPVectorTy();
62}
63
64bool EVT::isExtendedInteger() const {
65 assert(isExtended() && "Type is not extended!")(static_cast <bool> (isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 65, __extension__ __PRETTY_FUNCTION__))
;
66 return LLVMTy->isIntOrIntVectorTy();
67}
68
69bool EVT::isExtendedScalarInteger() const {
70 assert(isExtended() && "Type is not extended!")(static_cast <bool> (isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 70, __extension__ __PRETTY_FUNCTION__))
;
71 return LLVMTy->isIntegerTy();
72}
73
74bool EVT::isExtendedVector() const {
75 assert(isExtended() && "Type is not extended!")(static_cast <bool> (isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 75, __extension__ __PRETTY_FUNCTION__))
;
28
'?' condition is true
76 return LLVMTy->isVectorTy();
29
Called C++ object pointer is null
77}
78
79bool EVT::isExtended16BitVector() const {
80 return isExtendedVector() && getExtendedSizeInBits() == 16;
81}
82
83bool EVT::isExtended32BitVector() const {
84 return isExtendedVector() && getExtendedSizeInBits() == 32;
85}
86
87bool EVT::isExtended64BitVector() const {
88 return isExtendedVector() && getExtendedSizeInBits() == 64;
89}
90
91bool EVT::isExtended128BitVector() const {
92 return isExtendedVector() && getExtendedSizeInBits() == 128;
93}
94
95bool EVT::isExtended256BitVector() const {
96 return isExtendedVector() && getExtendedSizeInBits() == 256;
97}
98
99bool EVT::isExtended512BitVector() const {
100 return isExtendedVector() && getExtendedSizeInBits() == 512;
101}
102
103bool EVT::isExtended1024BitVector() const {
104 return isExtendedVector() && getExtendedSizeInBits() == 1024;
105}
106
107bool EVT::isExtended2048BitVector() const {
108 return isExtendedVector() && getExtendedSizeInBits() == 2048;
109}
110
111bool EVT::isExtendedFixedLengthVector() const {
112 return isExtendedVector() && isa<FixedVectorType>(LLVMTy);
113}
114
115bool EVT::isExtendedScalableVector() const {
116 return isExtendedVector() && isa<ScalableVectorType>(LLVMTy);
117}
118
119EVT EVT::getExtendedVectorElementType() const {
120 assert(isExtended() && "Type is not extended!")(static_cast <bool> (isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 120, __extension__ __PRETTY_FUNCTION__))
;
13
'?' condition is true
121 return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());
14
Field 'LLVMTy' is a 'VectorType'
15
Calling 'EVT::getEVT'
20
Returning from 'EVT::getEVT'
122}
123
124unsigned EVT::getExtendedVectorNumElements() const {
125 assert(isExtended() && "Type is not extended!")(static_cast <bool> (isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 125, __extension__ __PRETTY_FUNCTION__))
;
126 ElementCount EC = cast<VectorType>(LLVMTy)->getElementCount();
127 if (EC.isScalable()) {
128 WithColor::warning()
129 << "The code that requested the fixed number of elements has made the "
130 "assumption that this vector is not scalable. This assumption was "
131 "not correct, and this may lead to broken code\n";
132 }
133 return EC.getKnownMinValue();
134}
135
136ElementCount EVT::getExtendedVectorElementCount() const {
137 assert(isExtended() && "Type is not extended!")(static_cast <bool> (isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 137, __extension__ __PRETTY_FUNCTION__))
;
138 return cast<VectorType>(LLVMTy)->getElementCount();
139}
140
141TypeSize EVT::getExtendedSizeInBits() const {
142 assert(isExtended() && "Type is not extended!")(static_cast <bool> (isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 142, __extension__ __PRETTY_FUNCTION__))
;
143 if (IntegerType *ITy = dyn_cast<IntegerType>(LLVMTy))
144 return TypeSize::Fixed(ITy->getBitWidth());
145 if (VectorType *VTy = dyn_cast<VectorType>(LLVMTy))
146 return VTy->getPrimitiveSizeInBits();
147 llvm_unreachable("Unrecognized extended type!")::llvm::llvm_unreachable_internal("Unrecognized extended type!"
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 147)
;
148}
149
150/// getEVTString - This function returns value type as a string, e.g. "i32".
151std::string EVT::getEVTString() const {
152 switch (V.SimpleTy) {
1
Control jumps to the 'default' case at line 153
5
Control jumps to the 'default' case at line 153
24
Control jumps to the 'default' case at line 153
153 default:
154 if (isVector())
2
Taking true branch
6
Taking true branch
25
Calling 'EVT::isVector'
155 return (isScalableVector() ? "nxv" : "v") +
3
'?' condition is false
7
'?' condition is false
156 utostr(getVectorElementCount().getKnownMinValue()) +
157 getVectorElementType().getEVTString();
4
Calling 'EVT::getEVTString'
8
Calling 'EVT::getVectorElementType'
22
Returning from 'EVT::getVectorElementType'
23
Calling 'EVT::getEVTString'
158 if (isInteger())
159 return "i" + utostr(getSizeInBits());
160 if (isFloatingPoint())
161 return "f" + utostr(getSizeInBits());
162 llvm_unreachable("Invalid EVT!")::llvm::llvm_unreachable_internal("Invalid EVT!", "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 162)
;
163 case MVT::bf16: return "bf16";
164 case MVT::ppcf128: return "ppcf128";
165 case MVT::isVoid: return "isVoid";
166 case MVT::Other: return "ch";
167 case MVT::Glue: return "glue";
168 case MVT::x86mmx: return "x86mmx";
169 case MVT::x86amx: return "x86amx";
170 case MVT::Metadata: return "Metadata";
171 case MVT::Untyped: return "Untyped";
172 case MVT::funcref: return "funcref";
173 case MVT::externref: return "externref";
174 }
175}
176
177/// getTypeForEVT - This method returns an LLVM type corresponding to the
178/// specified EVT. For integer types, this returns an unsigned type. Note
179/// that this will abort for types that cannot be represented.
180Type *EVT::getTypeForEVT(LLVMContext &Context) const {
181 switch (V.SimpleTy) {
182 default:
183 assert(isExtended() && "Type is not extended!")(static_cast <bool> (isExtended() && "Type is not extended!"
) ? void (0) : __assert_fail ("isExtended() && \"Type is not extended!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 183, __extension__ __PRETTY_FUNCTION__))
;
184 return LLVMTy;
185 case MVT::isVoid: return Type::getVoidTy(Context);
186 case MVT::i1: return Type::getInt1Ty(Context);
187 case MVT::i8: return Type::getInt8Ty(Context);
188 case MVT::i16: return Type::getInt16Ty(Context);
189 case MVT::i32: return Type::getInt32Ty(Context);
190 case MVT::i64: return Type::getInt64Ty(Context);
191 case MVT::i128: return IntegerType::get(Context, 128);
192 case MVT::f16: return Type::getHalfTy(Context);
193 case MVT::bf16: return Type::getBFloatTy(Context);
194 case MVT::f32: return Type::getFloatTy(Context);
195 case MVT::f64: return Type::getDoubleTy(Context);
196 case MVT::f80: return Type::getX86_FP80Ty(Context);
197 case MVT::f128: return Type::getFP128Ty(Context);
198 case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
199 case MVT::x86mmx: return Type::getX86_MMXTy(Context);
200 case MVT::x86amx: return Type::getX86_AMXTy(Context);
201 case MVT::v1i1:
202 return FixedVectorType::get(Type::getInt1Ty(Context), 1);
203 case MVT::v2i1:
204 return FixedVectorType::get(Type::getInt1Ty(Context), 2);
205 case MVT::v4i1:
206 return FixedVectorType::get(Type::getInt1Ty(Context), 4);
207 case MVT::v8i1:
208 return FixedVectorType::get(Type::getInt1Ty(Context), 8);
209 case MVT::v16i1:
210 return FixedVectorType::get(Type::getInt1Ty(Context), 16);
211 case MVT::v32i1:
212 return FixedVectorType::get(Type::getInt1Ty(Context), 32);
213 case MVT::v64i1:
214 return FixedVectorType::get(Type::getInt1Ty(Context), 64);
215 case MVT::v128i1:
216 return FixedVectorType::get(Type::getInt1Ty(Context), 128);
217 case MVT::v256i1:
218 return FixedVectorType::get(Type::getInt1Ty(Context), 256);
219 case MVT::v512i1:
220 return FixedVectorType::get(Type::getInt1Ty(Context), 512);
221 case MVT::v1024i1:
222 return FixedVectorType::get(Type::getInt1Ty(Context), 1024);
223 case MVT::v1i8:
224 return FixedVectorType::get(Type::getInt8Ty(Context), 1);
225 case MVT::v2i8:
226 return FixedVectorType::get(Type::getInt8Ty(Context), 2);
227 case MVT::v4i8:
228 return FixedVectorType::get(Type::getInt8Ty(Context), 4);
229 case MVT::v8i8:
230 return FixedVectorType::get(Type::getInt8Ty(Context), 8);
231 case MVT::v16i8:
232 return FixedVectorType::get(Type::getInt8Ty(Context), 16);
233 case MVT::v32i8:
234 return FixedVectorType::get(Type::getInt8Ty(Context), 32);
235 case MVT::v64i8:
236 return FixedVectorType::get(Type::getInt8Ty(Context), 64);
237 case MVT::v128i8:
238 return FixedVectorType::get(Type::getInt8Ty(Context), 128);
239 case MVT::v256i8:
240 return FixedVectorType::get(Type::getInt8Ty(Context), 256);
241 case MVT::v512i8:
242 return FixedVectorType::get(Type::getInt8Ty(Context), 512);
243 case MVT::v1024i8:
244 return FixedVectorType::get(Type::getInt8Ty(Context), 1024);
245 case MVT::v1i16:
246 return FixedVectorType::get(Type::getInt16Ty(Context), 1);
247 case MVT::v2i16:
248 return FixedVectorType::get(Type::getInt16Ty(Context), 2);
249 case MVT::v3i16:
250 return FixedVectorType::get(Type::getInt16Ty(Context), 3);
251 case MVT::v4i16:
252 return FixedVectorType::get(Type::getInt16Ty(Context), 4);
253 case MVT::v8i16:
254 return FixedVectorType::get(Type::getInt16Ty(Context), 8);
255 case MVT::v16i16:
256 return FixedVectorType::get(Type::getInt16Ty(Context), 16);
257 case MVT::v32i16:
258 return FixedVectorType::get(Type::getInt16Ty(Context), 32);
259 case MVT::v64i16:
260 return FixedVectorType::get(Type::getInt16Ty(Context), 64);
261 case MVT::v128i16:
262 return FixedVectorType::get(Type::getInt16Ty(Context), 128);
263 case MVT::v256i16:
264 return FixedVectorType::get(Type::getInt16Ty(Context), 256);
265 case MVT::v512i16:
266 return FixedVectorType::get(Type::getInt16Ty(Context), 512);
267 case MVT::v1i32:
268 return FixedVectorType::get(Type::getInt32Ty(Context), 1);
269 case MVT::v2i32:
270 return FixedVectorType::get(Type::getInt32Ty(Context), 2);
271 case MVT::v3i32:
272 return FixedVectorType::get(Type::getInt32Ty(Context), 3);
273 case MVT::v4i32:
274 return FixedVectorType::get(Type::getInt32Ty(Context), 4);
275 case MVT::v5i32:
276 return FixedVectorType::get(Type::getInt32Ty(Context), 5);
277 case MVT::v6i32:
278 return FixedVectorType::get(Type::getInt32Ty(Context), 6);
279 case MVT::v7i32:
280 return FixedVectorType::get(Type::getInt32Ty(Context), 7);
281 case MVT::v8i32:
282 return FixedVectorType::get(Type::getInt32Ty(Context), 8);
283 case MVT::v16i32:
284 return FixedVectorType::get(Type::getInt32Ty(Context), 16);
285 case MVT::v32i32:
286 return FixedVectorType::get(Type::getInt32Ty(Context), 32);
287 case MVT::v64i32:
288 return FixedVectorType::get(Type::getInt32Ty(Context), 64);
289 case MVT::v128i32:
290 return FixedVectorType::get(Type::getInt32Ty(Context), 128);
291 case MVT::v256i32:
292 return FixedVectorType::get(Type::getInt32Ty(Context), 256);
293 case MVT::v512i32:
294 return FixedVectorType::get(Type::getInt32Ty(Context), 512);
295 case MVT::v1024i32:
296 return FixedVectorType::get(Type::getInt32Ty(Context), 1024);
297 case MVT::v2048i32:
298 return FixedVectorType::get(Type::getInt32Ty(Context), 2048);
299 case MVT::v1i64:
300 return FixedVectorType::get(Type::getInt64Ty(Context), 1);
301 case MVT::v2i64:
302 return FixedVectorType::get(Type::getInt64Ty(Context), 2);
303 case MVT::v4i64:
304 return FixedVectorType::get(Type::getInt64Ty(Context), 4);
305 case MVT::v8i64:
306 return FixedVectorType::get(Type::getInt64Ty(Context), 8);
307 case MVT::v16i64:
308 return FixedVectorType::get(Type::getInt64Ty(Context), 16);
309 case MVT::v32i64:
310 return FixedVectorType::get(Type::getInt64Ty(Context), 32);
311 case MVT::v64i64:
312 return FixedVectorType::get(Type::getInt64Ty(Context), 64);
313 case MVT::v128i64:
314 return FixedVectorType::get(Type::getInt64Ty(Context), 128);
315 case MVT::v256i64:
316 return FixedVectorType::get(Type::getInt64Ty(Context), 256);
317 case MVT::v1i128:
318 return FixedVectorType::get(Type::getInt128Ty(Context), 1);
319 case MVT::v1f16:
320 return FixedVectorType::get(Type::getHalfTy(Context), 1);
321 case MVT::v2f16:
322 return FixedVectorType::get(Type::getHalfTy(Context), 2);
323 case MVT::v3f16:
324 return FixedVectorType::get(Type::getHalfTy(Context), 3);
325 case MVT::v4f16:
326 return FixedVectorType::get(Type::getHalfTy(Context), 4);
327 case MVT::v8f16:
328 return FixedVectorType::get(Type::getHalfTy(Context), 8);
329 case MVT::v16f16:
330 return FixedVectorType::get(Type::getHalfTy(Context), 16);
331 case MVT::v32f16:
332 return FixedVectorType::get(Type::getHalfTy(Context), 32);
333 case MVT::v64f16:
334 return FixedVectorType::get(Type::getHalfTy(Context), 64);
335 case MVT::v128f16:
336 return FixedVectorType::get(Type::getHalfTy(Context), 128);
337 case MVT::v256f16:
338 return FixedVectorType::get(Type::getHalfTy(Context), 256);
339 case MVT::v512f16:
340 return FixedVectorType::get(Type::getHalfTy(Context), 512);
341 case MVT::v2bf16:
342 return FixedVectorType::get(Type::getBFloatTy(Context), 2);
343 case MVT::v3bf16:
344 return FixedVectorType::get(Type::getBFloatTy(Context), 3);
345 case MVT::v4bf16:
346 return FixedVectorType::get(Type::getBFloatTy(Context), 4);
347 case MVT::v8bf16:
348 return FixedVectorType::get(Type::getBFloatTy(Context), 8);
349 case MVT::v16bf16:
350 return FixedVectorType::get(Type::getBFloatTy(Context), 16);
351 case MVT::v32bf16:
352 return FixedVectorType::get(Type::getBFloatTy(Context), 32);
353 case MVT::v64bf16:
354 return FixedVectorType::get(Type::getBFloatTy(Context), 64);
355 case MVT::v128bf16:
356 return FixedVectorType::get(Type::getBFloatTy(Context), 128);
357 case MVT::v1f32:
358 return FixedVectorType::get(Type::getFloatTy(Context), 1);
359 case MVT::v2f32:
360 return FixedVectorType::get(Type::getFloatTy(Context), 2);
361 case MVT::v3f32:
362 return FixedVectorType::get(Type::getFloatTy(Context), 3);
363 case MVT::v4f32:
364 return FixedVectorType::get(Type::getFloatTy(Context), 4);
365 case MVT::v5f32:
366 return FixedVectorType::get(Type::getFloatTy(Context), 5);
367 case MVT::v6f32:
368 return FixedVectorType::get(Type::getFloatTy(Context), 6);
369 case MVT::v7f32:
370 return FixedVectorType::get(Type::getFloatTy(Context), 7);
371 case MVT::v8f32:
372 return FixedVectorType::get(Type::getFloatTy(Context), 8);
373 case MVT::v16f32:
374 return FixedVectorType::get(Type::getFloatTy(Context), 16);
375 case MVT::v32f32:
376 return FixedVectorType::get(Type::getFloatTy(Context), 32);
377 case MVT::v64f32:
378 return FixedVectorType::get(Type::getFloatTy(Context), 64);
379 case MVT::v128f32:
380 return FixedVectorType::get(Type::getFloatTy(Context), 128);
381 case MVT::v256f32:
382 return FixedVectorType::get(Type::getFloatTy(Context), 256);
383 case MVT::v512f32:
384 return FixedVectorType::get(Type::getFloatTy(Context), 512);
385 case MVT::v1024f32:
386 return FixedVectorType::get(Type::getFloatTy(Context), 1024);
387 case MVT::v2048f32:
388 return FixedVectorType::get(Type::getFloatTy(Context), 2048);
389 case MVT::v1f64:
390 return FixedVectorType::get(Type::getDoubleTy(Context), 1);
391 case MVT::v2f64:
392 return FixedVectorType::get(Type::getDoubleTy(Context), 2);
393 case MVT::v4f64:
394 return FixedVectorType::get(Type::getDoubleTy(Context), 4);
395 case MVT::v8f64:
396 return FixedVectorType::get(Type::getDoubleTy(Context), 8);
397 case MVT::v16f64:
398 return FixedVectorType::get(Type::getDoubleTy(Context), 16);
399 case MVT::v32f64:
400 return FixedVectorType::get(Type::getDoubleTy(Context), 32);
401 case MVT::v64f64:
402 return FixedVectorType::get(Type::getDoubleTy(Context), 64);
403 case MVT::v128f64:
404 return FixedVectorType::get(Type::getDoubleTy(Context), 128);
405 case MVT::v256f64:
406 return FixedVectorType::get(Type::getDoubleTy(Context), 256);
407 case MVT::nxv1i1:
408 return ScalableVectorType::get(Type::getInt1Ty(Context), 1);
409 case MVT::nxv2i1:
410 return ScalableVectorType::get(Type::getInt1Ty(Context), 2);
411 case MVT::nxv4i1:
412 return ScalableVectorType::get(Type::getInt1Ty(Context), 4);
413 case MVT::nxv8i1:
414 return ScalableVectorType::get(Type::getInt1Ty(Context), 8);
415 case MVT::nxv16i1:
416 return ScalableVectorType::get(Type::getInt1Ty(Context), 16);
417 case MVT::nxv32i1:
418 return ScalableVectorType::get(Type::getInt1Ty(Context), 32);
419 case MVT::nxv64i1:
420 return ScalableVectorType::get(Type::getInt1Ty(Context), 64);
421 case MVT::nxv1i8:
422 return ScalableVectorType::get(Type::getInt8Ty(Context), 1);
423 case MVT::nxv2i8:
424 return ScalableVectorType::get(Type::getInt8Ty(Context), 2);
425 case MVT::nxv4i8:
426 return ScalableVectorType::get(Type::getInt8Ty(Context), 4);
427 case MVT::nxv8i8:
428 return ScalableVectorType::get(Type::getInt8Ty(Context), 8);
429 case MVT::nxv16i8:
430 return ScalableVectorType::get(Type::getInt8Ty(Context), 16);
431 case MVT::nxv32i8:
432 return ScalableVectorType::get(Type::getInt8Ty(Context), 32);
433 case MVT::nxv64i8:
434 return ScalableVectorType::get(Type::getInt8Ty(Context), 64);
435 case MVT::nxv1i16:
436 return ScalableVectorType::get(Type::getInt16Ty(Context), 1);
437 case MVT::nxv2i16:
438 return ScalableVectorType::get(Type::getInt16Ty(Context), 2);
439 case MVT::nxv4i16:
440 return ScalableVectorType::get(Type::getInt16Ty(Context), 4);
441 case MVT::nxv8i16:
442 return ScalableVectorType::get(Type::getInt16Ty(Context), 8);
443 case MVT::nxv16i16:
444 return ScalableVectorType::get(Type::getInt16Ty(Context), 16);
445 case MVT::nxv32i16:
446 return ScalableVectorType::get(Type::getInt16Ty(Context), 32);
447 case MVT::nxv1i32:
448 return ScalableVectorType::get(Type::getInt32Ty(Context), 1);
449 case MVT::nxv2i32:
450 return ScalableVectorType::get(Type::getInt32Ty(Context), 2);
451 case MVT::nxv4i32:
452 return ScalableVectorType::get(Type::getInt32Ty(Context), 4);
453 case MVT::nxv8i32:
454 return ScalableVectorType::get(Type::getInt32Ty(Context), 8);
455 case MVT::nxv16i32:
456 return ScalableVectorType::get(Type::getInt32Ty(Context), 16);
457 case MVT::nxv32i32:
458 return ScalableVectorType::get(Type::getInt32Ty(Context), 32);
459 case MVT::nxv1i64:
460 return ScalableVectorType::get(Type::getInt64Ty(Context), 1);
461 case MVT::nxv2i64:
462 return ScalableVectorType::get(Type::getInt64Ty(Context), 2);
463 case MVT::nxv4i64:
464 return ScalableVectorType::get(Type::getInt64Ty(Context), 4);
465 case MVT::nxv8i64:
466 return ScalableVectorType::get(Type::getInt64Ty(Context), 8);
467 case MVT::nxv16i64:
468 return ScalableVectorType::get(Type::getInt64Ty(Context), 16);
469 case MVT::nxv32i64:
470 return ScalableVectorType::get(Type::getInt64Ty(Context), 32);
471 case MVT::nxv1f16:
472 return ScalableVectorType::get(Type::getHalfTy(Context), 1);
473 case MVT::nxv2f16:
474 return ScalableVectorType::get(Type::getHalfTy(Context), 2);
475 case MVT::nxv4f16:
476 return ScalableVectorType::get(Type::getHalfTy(Context), 4);
477 case MVT::nxv8f16:
478 return ScalableVectorType::get(Type::getHalfTy(Context), 8);
479 case MVT::nxv16f16:
480 return ScalableVectorType::get(Type::getHalfTy(Context), 16);
481 case MVT::nxv32f16:
482 return ScalableVectorType::get(Type::getHalfTy(Context), 32);
483 case MVT::nxv1bf16:
484 return ScalableVectorType::get(Type::getBFloatTy(Context), 1);
485 case MVT::nxv2bf16:
486 return ScalableVectorType::get(Type::getBFloatTy(Context), 2);
487 case MVT::nxv4bf16:
488 return ScalableVectorType::get(Type::getBFloatTy(Context), 4);
489 case MVT::nxv8bf16:
490 return ScalableVectorType::get(Type::getBFloatTy(Context), 8);
491 case MVT::nxv1f32:
492 return ScalableVectorType::get(Type::getFloatTy(Context), 1);
493 case MVT::nxv2f32:
494 return ScalableVectorType::get(Type::getFloatTy(Context), 2);
495 case MVT::nxv4f32:
496 return ScalableVectorType::get(Type::getFloatTy(Context), 4);
497 case MVT::nxv8f32:
498 return ScalableVectorType::get(Type::getFloatTy(Context), 8);
499 case MVT::nxv16f32:
500 return ScalableVectorType::get(Type::getFloatTy(Context), 16);
501 case MVT::nxv1f64:
502 return ScalableVectorType::get(Type::getDoubleTy(Context), 1);
503 case MVT::nxv2f64:
504 return ScalableVectorType::get(Type::getDoubleTy(Context), 2);
505 case MVT::nxv4f64:
506 return ScalableVectorType::get(Type::getDoubleTy(Context), 4);
507 case MVT::nxv8f64:
508 return ScalableVectorType::get(Type::getDoubleTy(Context), 8);
509 case MVT::Metadata: return Type::getMetadataTy(Context);
510 }
511}
512
513/// Return the value type corresponding to the specified type. This returns all
514/// pointers as MVT::iPTR. If HandleUnknown is true, unknown types are returned
515/// as Other, otherwise they are invalid.
516MVT MVT::getVT(Type *Ty, bool HandleUnknown){
517 switch (Ty->getTypeID()) {
518 default:
519 if (HandleUnknown) return MVT(MVT::Other);
520 llvm_unreachable("Unknown type!")::llvm::llvm_unreachable_internal("Unknown type!", "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/lib/CodeGen/ValueTypes.cpp"
, 520)
;
521 case Type::VoidTyID:
522 return MVT::isVoid;
523 case Type::IntegerTyID:
524 return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
525 case Type::HalfTyID: return MVT(MVT::f16);
526 case Type::BFloatTyID: return MVT(MVT::bf16);
527 case Type::FloatTyID: return MVT(MVT::f32);
528 case Type::DoubleTyID: return MVT(MVT::f64);
529 case Type::X86_FP80TyID: return MVT(MVT::f80);
530 case Type::X86_MMXTyID: return MVT(MVT::x86mmx);
531 case Type::X86_AMXTyID: return MVT(MVT::x86amx);
532 case Type::FP128TyID: return MVT(MVT::f128);
533 case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
534 case Type::PointerTyID: return MVT(MVT::iPTR);
535 case Type::FixedVectorTyID:
536 case Type::ScalableVectorTyID: {
537 VectorType *VTy = cast<VectorType>(Ty);
538 return getVectorVT(
539 getVT(VTy->getElementType(), /*HandleUnknown=*/ false),
540 VTy->getElementCount());
541 }
542 }
543}
544
545/// getEVT - Return the value type corresponding to the specified type. This
546/// returns all pointers as MVT::iPTR. If HandleUnknown is true, unknown types
547/// are returned as Other, otherwise they are invalid.
548EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
549 switch (Ty->getTypeID()) {
16
Control jumps to the 'default' case at line 550
550 default:
551 return MVT::getVT(Ty, HandleUnknown);
17
Calling constructor for 'EVT'
19
Returning from constructor for 'EVT'
552 case Type::IntegerTyID:
553 return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
554 case Type::FixedVectorTyID:
555 case Type::ScalableVectorTyID: {
556 VectorType *VTy = cast<VectorType>(Ty);
557 return getVectorVT(Ty->getContext(),
558 getEVT(VTy->getElementType(), /*HandleUnknown=*/ false),
559 VTy->getElementCount());
560 }
561 }
562}

/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/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 "llvm/Support/TypeSize.h"
22#include "llvm/Support/WithColor.h"
23#include <cassert>
24#include <cstdint>
25#include <string>
26
27namespace llvm {
28
29 class LLVMContext;
30 class Type;
31
32 /// Extended Value Type. Capable of holding value types which are not native
33 /// for any processor (such as the i12345 type), as well as the types an MVT
34 /// can represent.
35 struct EVT {
36 private:
37 MVT V = MVT::INVALID_SIMPLE_VALUE_TYPE;
38 Type *LLVMTy = nullptr;
18
Null pointer value stored to field 'LLVMTy'
39
40 public:
41 constexpr EVT() = default;
42 constexpr EVT(MVT::SimpleValueType SVT) : V(SVT) {}
43 constexpr EVT(MVT S) : V(S) {}
44
45 bool operator==(EVT VT) const {
46 return !(*this != VT);
47 }
48 bool operator!=(EVT VT) const {
49 if (V.SimpleTy != VT.V.SimpleTy)
50 return true;
51 if (V.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
52 return LLVMTy != VT.LLVMTy;
53 return false;
54 }
55
56 /// Returns the EVT that represents a floating-point type with the given
57 /// number of bits. There are two floating-point types with 128 bits - this
58 /// returns f128 rather than ppcf128.
59 static EVT getFloatingPointVT(unsigned BitWidth) {
60 return MVT::getFloatingPointVT(BitWidth);
61 }
62
63 /// Returns the EVT that represents an integer with the given number of
64 /// bits.
65 static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) {
66 MVT M = MVT::getIntegerVT(BitWidth);
67 if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
68 return M;
69 return getExtendedIntegerVT(Context, BitWidth);
70 }
71
72 /// Returns the EVT that represents a vector NumElements in length, where
73 /// each element is of type VT.
74 static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements,
75 bool IsScalable = false) {
76 MVT M = MVT::getVectorVT(VT.V, NumElements, IsScalable);
77 if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
78 return M;
79 return getExtendedVectorVT(Context, VT, NumElements, IsScalable);
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, ElementCount EC) {
85 MVT M = MVT::getVectorVT(VT.V, EC);
86 if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
87 return M;
88 return getExtendedVectorVT(Context, VT, EC);
89 }
90
91 /// Return a vector with the same number of elements as this vector, but
92 /// with the element type converted to an integer type with the same
93 /// bitwidth.
94 EVT changeVectorElementTypeToInteger() const {
95 if (isSimple())
96 return getSimpleVT().changeVectorElementTypeToInteger();
97 return changeExtendedVectorElementTypeToInteger();
98 }
99
100 /// Return a VT for a vector type whose attributes match ourselves
101 /// with the exception of the element type that is chosen by the caller.
102 EVT changeVectorElementType(EVT EltVT) const {
103 if (isSimple()) {
104 assert(EltVT.isSimple() &&(static_cast <bool> (EltVT.isSimple() && "Can't change simple vector VT to have extended element VT"
) ? void (0) : __assert_fail ("EltVT.isSimple() && \"Can't change simple vector VT to have extended element VT\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 105, __extension__ __PRETTY_FUNCTION__))
105 "Can't change simple vector VT to have extended element VT")(static_cast <bool> (EltVT.isSimple() && "Can't change simple vector VT to have extended element VT"
) ? void (0) : __assert_fail ("EltVT.isSimple() && \"Can't change simple vector VT to have extended element VT\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 105, __extension__ __PRETTY_FUNCTION__))
;
106 return getSimpleVT().changeVectorElementType(EltVT.getSimpleVT());
107 }
108 return changeExtendedVectorElementType(EltVT);
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 getSimpleVT().changeTypeToInteger();
120 return changeExtendedTypeToInteger();
121 }
122
123 /// Test if the given EVT is simple (as opposed to being extended).
124 bool isSimple() const {
125 return V.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE;
126 }
127
128 /// Test if the given EVT is extended (as opposed to being simple).
129 bool isExtended() const {
130 return !isSimple();
131 }
132
133 /// Return true if this is a FP or a vector FP type.
134 bool isFloatingPoint() const {
135 return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
136 }
137
138 /// Return true if this is an integer or a vector integer type.
139 bool isInteger() const {
140 return isSimple() ? V.isInteger() : isExtendedInteger();
141 }
142
143 /// Return true if this is an integer, but not a vector.
144 bool isScalarInteger() const {
145 return isSimple() ? V.isScalarInteger() : isExtendedScalarInteger();
146 }
147
148 /// Return true if this is a vector value type.
149 bool isVector() const {
150 return isSimple() ? V.isVector() : isExtendedVector();
26
'?' condition is false
27
Calling 'EVT::isExtendedVector'
151 }
152
153 /// Return true if this is a vector type where the runtime
154 /// length is machine dependent
155 bool isScalableVector() const {
156 return isSimple() ? V.isScalableVector() : isExtendedScalableVector();
157 }
158
159 bool isFixedLengthVector() const {
160 return isSimple() ? V.isFixedLengthVector()
161 : isExtendedFixedLengthVector();
162 }
163
164 /// Return true if this is a 16-bit vector type.
165 bool is16BitVector() const {
166 return isSimple() ? V.is16BitVector() : isExtended16BitVector();
167 }
168
169 /// Return true if this is a 32-bit vector type.
170 bool is32BitVector() const {
171 return isSimple() ? V.is32BitVector() : isExtended32BitVector();
172 }
173
174 /// Return true if this is a 64-bit vector type.
175 bool is64BitVector() const {
176 return isSimple() ? V.is64BitVector() : isExtended64BitVector();
177 }
178
179 /// Return true if this is a 128-bit vector type.
180 bool is128BitVector() const {
181 return isSimple() ? V.is128BitVector() : isExtended128BitVector();
182 }
183
184 /// Return true if this is a 256-bit vector type.
185 bool is256BitVector() const {
186 return isSimple() ? V.is256BitVector() : isExtended256BitVector();
187 }
188
189 /// Return true if this is a 512-bit vector type.
190 bool is512BitVector() const {
191 return isSimple() ? V.is512BitVector() : isExtended512BitVector();
192 }
193
194 /// Return true if this is a 1024-bit vector type.
195 bool is1024BitVector() const {
196 return isSimple() ? V.is1024BitVector() : isExtended1024BitVector();
197 }
198
199 /// Return true if this is a 2048-bit vector type.
200 bool is2048BitVector() const {
201 return isSimple() ? V.is2048BitVector() : isExtended2048BitVector();
202 }
203
204 /// Return true if this is an overloaded type for TableGen.
205 bool isOverloaded() const {
206 return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
207 }
208
209 /// Return true if the bit size is a multiple of 8.
210 bool isByteSized() const { return getSizeInBits().isKnownMultipleOf(8); }
211
212 /// Return true if the size is a power-of-two number of bytes.
213 bool isRound() const {
214 if (isScalableVector())
215 return false;
216 unsigned BitSize = getSizeInBits();
217 return BitSize >= 8 && !(BitSize & (BitSize - 1));
218 }
219
220 /// Return true if this has the same number of bits as VT.
221 bool bitsEq(EVT VT) const {
222 if (EVT::operator==(VT)) return true;
223 return getSizeInBits() == VT.getSizeInBits();
224 }
225
226 /// Return true if we know at compile time this has more bits than VT.
227 bool knownBitsGT(EVT VT) const {
228 return TypeSize::isKnownGT(getSizeInBits(), VT.getSizeInBits());
229 }
230
231 /// Return true if we know at compile time this has more than or the same
232 /// bits as VT.
233 bool knownBitsGE(EVT VT) const {
234 return TypeSize::isKnownGE(getSizeInBits(), VT.getSizeInBits());
235 }
236
237 /// Return true if we know at compile time this has fewer bits than VT.
238 bool knownBitsLT(EVT VT) const {
239 return TypeSize::isKnownLT(getSizeInBits(), VT.getSizeInBits());
240 }
241
242 /// Return true if we know at compile time this has fewer than or the same
243 /// bits as VT.
244 bool knownBitsLE(EVT VT) const {
245 return TypeSize::isKnownLE(getSizeInBits(), VT.getSizeInBits());
246 }
247
248 /// Return true if this has more bits than VT.
249 bool bitsGT(EVT VT) const {
250 if (EVT::operator==(VT)) return false;
251 assert(isScalableVector() == VT.isScalableVector() &&(static_cast <bool> (isScalableVector() == VT.isScalableVector
() && "Comparison between scalable and fixed types") ?
void (0) : __assert_fail ("isScalableVector() == VT.isScalableVector() && \"Comparison between scalable and fixed types\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 252, __extension__ __PRETTY_FUNCTION__))
252 "Comparison between scalable and fixed types")(static_cast <bool> (isScalableVector() == VT.isScalableVector
() && "Comparison between scalable and fixed types") ?
void (0) : __assert_fail ("isScalableVector() == VT.isScalableVector() && \"Comparison between scalable and fixed types\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 252, __extension__ __PRETTY_FUNCTION__))
;
253 return knownBitsGT(VT);
254 }
255
256 /// Return true if this has no less bits than VT.
257 bool bitsGE(EVT VT) const {
258 if (EVT::operator==(VT)) return true;
259 assert(isScalableVector() == VT.isScalableVector() &&(static_cast <bool> (isScalableVector() == VT.isScalableVector
() && "Comparison between scalable and fixed types") ?
void (0) : __assert_fail ("isScalableVector() == VT.isScalableVector() && \"Comparison between scalable and fixed types\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 260, __extension__ __PRETTY_FUNCTION__))
260 "Comparison between scalable and fixed types")(static_cast <bool> (isScalableVector() == VT.isScalableVector
() && "Comparison between scalable and fixed types") ?
void (0) : __assert_fail ("isScalableVector() == VT.isScalableVector() && \"Comparison between scalable and fixed types\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 260, __extension__ __PRETTY_FUNCTION__))
;
261 return knownBitsGE(VT);
262 }
263
264 /// Return true if this has less bits than VT.
265 bool bitsLT(EVT VT) const {
266 if (EVT::operator==(VT)) return false;
267 assert(isScalableVector() == VT.isScalableVector() &&(static_cast <bool> (isScalableVector() == VT.isScalableVector
() && "Comparison between scalable and fixed types") ?
void (0) : __assert_fail ("isScalableVector() == VT.isScalableVector() && \"Comparison between scalable and fixed types\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 268, __extension__ __PRETTY_FUNCTION__))
268 "Comparison between scalable and fixed types")(static_cast <bool> (isScalableVector() == VT.isScalableVector
() && "Comparison between scalable and fixed types") ?
void (0) : __assert_fail ("isScalableVector() == VT.isScalableVector() && \"Comparison between scalable and fixed types\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 268, __extension__ __PRETTY_FUNCTION__))
;
269 return knownBitsLT(VT);
270 }
271
272 /// Return true if this has no more bits than VT.
273 bool bitsLE(EVT VT) const {
274 if (EVT::operator==(VT)) return true;
275 assert(isScalableVector() == VT.isScalableVector() &&(static_cast <bool> (isScalableVector() == VT.isScalableVector
() && "Comparison between scalable and fixed types") ?
void (0) : __assert_fail ("isScalableVector() == VT.isScalableVector() && \"Comparison between scalable and fixed types\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 276, __extension__ __PRETTY_FUNCTION__))
276 "Comparison between scalable and fixed types")(static_cast <bool> (isScalableVector() == VT.isScalableVector
() && "Comparison between scalable and fixed types") ?
void (0) : __assert_fail ("isScalableVector() == VT.isScalableVector() && \"Comparison between scalable and fixed types\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 276, __extension__ __PRETTY_FUNCTION__))
;
277 return knownBitsLE(VT);
278 }
279
280 /// Return the SimpleValueType held in the specified simple EVT.
281 MVT getSimpleVT() const {
282 assert(isSimple() && "Expected a SimpleValueType!")(static_cast <bool> (isSimple() && "Expected a SimpleValueType!"
) ? void (0) : __assert_fail ("isSimple() && \"Expected a SimpleValueType!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 282, __extension__ __PRETTY_FUNCTION__))
;
283 return V;
284 }
285
286 /// If this is a vector type, return the element type, otherwise return
287 /// this.
288 EVT getScalarType() const {
289 return isVector() ? getVectorElementType() : *this;
290 }
291
292 /// Given a vector type, return the type of each element.
293 EVT getVectorElementType() const {
294 assert(isVector() && "Invalid vector type!")(static_cast <bool> (isVector() && "Invalid vector type!"
) ? void (0) : __assert_fail ("isVector() && \"Invalid vector type!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 294, __extension__ __PRETTY_FUNCTION__))
;
9
Assuming the condition is true
10
'?' condition is true
295 if (isSimple())
11
Taking false branch
296 return V.getVectorElementType();
297 return getExtendedVectorElementType();
12
Calling 'EVT::getExtendedVectorElementType'
21
Returning from 'EVT::getExtendedVectorElementType'
298 }
299
300 /// Given a vector type, return the number of elements it contains.
301 unsigned getVectorNumElements() const {
302 assert(isVector() && "Invalid vector type!")(static_cast <bool> (isVector() && "Invalid vector type!"
) ? void (0) : __assert_fail ("isVector() && \"Invalid vector type!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 302, __extension__ __PRETTY_FUNCTION__))
;
303
304 if (isScalableVector())
305 llvm::reportInvalidSizeRequest(
306 "Possible incorrect use of EVT::getVectorNumElements() for "
307 "scalable vector. Scalable flag may be dropped, use "
308 "EVT::getVectorElementCount() instead");
309
310 return isSimple() ? V.getVectorNumElements()
311 : getExtendedVectorNumElements();
312 }
313
314 // Given a (possibly scalable) vector type, return the ElementCount
315 ElementCount getVectorElementCount() const {
316 assert((isVector()) && "Invalid vector type!")(static_cast <bool> ((isVector()) && "Invalid vector type!"
) ? void (0) : __assert_fail ("(isVector()) && \"Invalid vector type!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 316, __extension__ __PRETTY_FUNCTION__))
;
317 if (isSimple())
318 return V.getVectorElementCount();
319
320 return getExtendedVectorElementCount();
321 }
322
323 /// Given a vector type, return the minimum number of elements it contains.
324 unsigned getVectorMinNumElements() const {
325 return getVectorElementCount().getKnownMinValue();
326 }
327
328 /// Return the size of the specified value type in bits.
329 ///
330 /// If the value type is a scalable vector type, the scalable property will
331 /// be set and the runtime size will be a positive integer multiple of the
332 /// base size.
333 TypeSize getSizeInBits() const {
334 if (isSimple())
335 return V.getSizeInBits();
336 return getExtendedSizeInBits();
337 }
338
339 /// Return the size of the specified fixed width value type in bits. The
340 /// function will assert if the type is scalable.
341 uint64_t getFixedSizeInBits() const {
342 return getSizeInBits().getFixedSize();
343 }
344
345 uint64_t getScalarSizeInBits() const {
346 return getScalarType().getSizeInBits().getFixedSize();
347 }
348
349 /// Return the number of bytes overwritten by a store of the specified value
350 /// type.
351 ///
352 /// If the value type is a scalable vector type, the scalable property will
353 /// be set and the runtime size will be a positive integer multiple of the
354 /// base size.
355 TypeSize getStoreSize() const {
356 TypeSize BaseSize = getSizeInBits();
357 return {(BaseSize.getKnownMinSize() + 7) / 8, BaseSize.isScalable()};
358 }
359
360 /// Return the number of bits overwritten by a store of the specified value
361 /// type.
362 ///
363 /// If the value type is a scalable vector type, the scalable property will
364 /// be set and the runtime size will be a positive integer multiple of the
365 /// base size.
366 TypeSize getStoreSizeInBits() const {
367 return getStoreSize() * 8;
368 }
369
370 /// Rounds the bit-width of the given integer EVT up to the nearest power of
371 /// two (and at least to eight), and returns the integer EVT with that
372 /// number of bits.
373 EVT getRoundIntegerType(LLVMContext &Context) const {
374 assert(isInteger() && !isVector() && "Invalid integer type!")(static_cast <bool> (isInteger() && !isVector()
&& "Invalid integer type!") ? void (0) : __assert_fail
("isInteger() && !isVector() && \"Invalid integer type!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 374, __extension__ __PRETTY_FUNCTION__))
;
375 unsigned BitWidth = getSizeInBits();
376 if (BitWidth <= 8)
377 return EVT(MVT::i8);
378 return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
379 }
380
381 /// Finds the smallest simple value type that is greater than or equal to
382 /// half the width of this EVT. If no simple value type can be found, an
383 /// extended integer value type of half the size (rounded up) is returned.
384 EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
385 assert(isInteger() && !isVector() && "Invalid integer type!")(static_cast <bool> (isInteger() && !isVector()
&& "Invalid integer type!") ? void (0) : __assert_fail
("isInteger() && !isVector() && \"Invalid integer type!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 385, __extension__ __PRETTY_FUNCTION__))
;
386 unsigned EVTSize = getSizeInBits();
387 for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
388 IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) {
389 EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
390 if (HalfVT.getSizeInBits() * 2 >= EVTSize)
391 return HalfVT;
392 }
393 return getIntegerVT(Context, (EVTSize + 1) / 2);
394 }
395
396 /// Return a VT for an integer vector type with the size of the
397 /// elements doubled. The typed returned may be an extended type.
398 EVT widenIntegerVectorElementType(LLVMContext &Context) const {
399 EVT EltVT = getVectorElementType();
400 EltVT = EVT::getIntegerVT(Context, 2 * EltVT.getSizeInBits());
401 return EVT::getVectorVT(Context, EltVT, getVectorElementCount());
402 }
403
404 // Return a VT for a vector type with the same element type but
405 // half the number of elements. The type returned may be an
406 // extended type.
407 EVT getHalfNumVectorElementsVT(LLVMContext &Context) const {
408 EVT EltVT = getVectorElementType();
409 auto EltCnt = getVectorElementCount();
410 assert(EltCnt.isKnownEven() && "Splitting vector, but not in half!")(static_cast <bool> (EltCnt.isKnownEven() && "Splitting vector, but not in half!"
) ? void (0) : __assert_fail ("EltCnt.isKnownEven() && \"Splitting vector, but not in half!\""
, "/build/llvm-toolchain-snapshot-13~++20210616111117+5c1639fe064b/llvm/include/llvm/CodeGen/ValueTypes.h"
, 410, __extension__ __PRETTY_FUNCTION__))
;
411 return EVT::getVectorVT(Context, EltVT, EltCnt.divideCoefficientBy(2));
412 }
413
414 // Return a VT for a vector type with the same element type but
415 // double the number of elements. The type returned may be an
416 // extended type.
417 EVT getDoubleNumVectorElementsVT(LLVMContext &Context) const {
418 EVT EltVT = getVectorElementType();
419 auto EltCnt = getVectorElementCount();
420 return EVT::getVectorVT(Context, EltVT, EltCnt * 2);
421 }
422
423 /// Returns true if the given vector is a power of 2.
424 bool isPow2VectorType() const {
425 unsigned NElts = getVectorMinNumElements();
426 return !(NElts & (NElts - 1));
427 }
428
429 /// Widens the length of the given vector EVT up to the nearest power of 2
430 /// and returns that type.
431 EVT getPow2VectorType(LLVMContext &Context) const {
432 if (!isPow2VectorType()) {
433 ElementCount NElts = getVectorElementCount();
434 unsigned NewMinCount = 1 << Log2_32_Ceil(NElts.getKnownMinValue());
435 NElts = ElementCount::get(NewMinCount, NElts.isScalable());
436 return EVT::getVectorVT(Context, getVectorElementType(), NElts);
437 }
438 else {
439 return *this;
440 }
441 }
442
443 /// This function returns value type as a string, e.g. "i32".
444 std::string getEVTString() const;
445
446 /// This method returns an LLVM type corresponding to the specified EVT.
447 /// For integer types, this returns an unsigned type. Note that this will
448 /// abort for types that cannot be represented.
449 Type *getTypeForEVT(LLVMContext &Context) const;
450
451 /// Return the value type corresponding to the specified type.
452 /// This returns all pointers as iPTR. If HandleUnknown is true, unknown
453 /// types are returned as Other, otherwise they are invalid.
454 static EVT getEVT(Type *Ty, bool HandleUnknown = false);
455
456 intptr_t getRawBits() const {
457 if (isSimple())
458 return V.SimpleTy;
459 else
460 return (intptr_t)(LLVMTy);
461 }
462
463 /// A meaningless but well-behaved order, useful for constructing
464 /// containers.
465 struct compareRawBits {
466 bool operator()(EVT L, EVT R) const {
467 if (L.V.SimpleTy == R.V.SimpleTy)
468 return L.LLVMTy < R.LLVMTy;
469 else
470 return L.V.SimpleTy < R.V.SimpleTy;
471 }
472 };
473
474 private:
475 // Methods for handling the Extended-type case in functions above.
476 // These are all out-of-line to prevent users of this header file
477 // from having a dependency on Type.h.
478 EVT changeExtendedTypeToInteger() const;
479 EVT changeExtendedVectorElementType(EVT EltVT) const;
480 EVT changeExtendedVectorElementTypeToInteger() const;
481 static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
482 static EVT getExtendedVectorVT(LLVMContext &C, EVT VT, unsigned NumElements,
483 bool IsScalable);
484 static EVT getExtendedVectorVT(LLVMContext &Context, EVT VT,
485 ElementCount EC);
486 bool isExtendedFloatingPoint() const LLVM_READONLY__attribute__((__pure__));
487 bool isExtendedInteger() const LLVM_READONLY__attribute__((__pure__));
488 bool isExtendedScalarInteger() const LLVM_READONLY__attribute__((__pure__));
489 bool isExtendedVector() const LLVM_READONLY__attribute__((__pure__));
490 bool isExtended16BitVector() const LLVM_READONLY__attribute__((__pure__));
491 bool isExtended32BitVector() const LLVM_READONLY__attribute__((__pure__));
492 bool isExtended64BitVector() const LLVM_READONLY__attribute__((__pure__));
493 bool isExtended128BitVector() const LLVM_READONLY__attribute__((__pure__));
494 bool isExtended256BitVector() const LLVM_READONLY__attribute__((__pure__));
495 bool isExtended512BitVector() const LLVM_READONLY__attribute__((__pure__));
496 bool isExtended1024BitVector() const LLVM_READONLY__attribute__((__pure__));
497 bool isExtended2048BitVector() const LLVM_READONLY__attribute__((__pure__));
498 bool isExtendedFixedLengthVector() const LLVM_READONLY__attribute__((__pure__));
499 bool isExtendedScalableVector() const LLVM_READONLY__attribute__((__pure__));
500 EVT getExtendedVectorElementType() const;
501 unsigned getExtendedVectorNumElements() const LLVM_READONLY__attribute__((__pure__));
502 ElementCount getExtendedVectorElementCount() const LLVM_READONLY__attribute__((__pure__));
503 TypeSize getExtendedSizeInBits() const LLVM_READONLY__attribute__((__pure__));
504 };
505
506} // end namespace llvm
507
508#endif // LLVM_CODEGEN_VALUETYPES_H