Bug Summary

File:build/source/llvm/lib/CodeGen/ValueTypes.cpp
Warning:line 78, 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 -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name ValueTypes.cpp -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 -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/source/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-17/lib/clang/17 -D _DEBUG -D _GLIBCXX_ASSERTIONS -D _GNU_SOURCE -D _LIBCPP_ENABLE_ASSERTIONS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I lib/CodeGen -I /build/source/llvm/lib/CodeGen -I include -I /build/source/llvm/include -D _FORTIFY_SOURCE=2 -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-17/lib/clang/17/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 -fmacro-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/source/= -fcoverage-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/source/= -source-date-epoch 1683717183 -O2 -Wno-unused-command-line-argument -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 -Wno-misleading-indentation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/source/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/source/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -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-2023-05-10-133810-16478-1 -x c++ /build/source/llvm/lib/CodeGen/ValueTypes.cpp

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

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