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-14~++20210828111110+16086d47c0d0/build-llvm/lib/CodeGen -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/build-llvm/lib/CodeGen -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/llvm/lib/CodeGen -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/build-llvm/include -I /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/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-14/lib/clang/14.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-14~++20210828111110+16086d47c0d0/build-llvm/lib/CodeGen -fdebug-prefix-map=/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0=. -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-08-28-193554-24367-1 -x c++ /build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/llvm/lib/CodeGen/ValueTypes.cpp

/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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-14~++20210828111110+16086d47c0d0/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::i64x8: return "i64x8";
171 case MVT::Metadata: return "Metadata";
172 case MVT::Untyped: return "Untyped";
173 case MVT::funcref: return "funcref";
174 case MVT::externref: return "externref";
175 }
176}
177
178/// getTypeForEVT - This method returns an LLVM type corresponding to the
179/// specified EVT. For integer types, this returns an unsigned type. Note
180/// that this will abort for types that cannot be represented.
181Type *EVT::getTypeForEVT(LLVMContext &Context) const {
182 switch (V.SimpleTy) {
183 default:
184 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-14~++20210828111110+16086d47c0d0/llvm/lib/CodeGen/ValueTypes.cpp"
, 184, __extension__ __PRETTY_FUNCTION__))
;
185 return LLVMTy;
186 case MVT::isVoid: return Type::getVoidTy(Context);
187 case MVT::i1: return Type::getInt1Ty(Context);
188 case MVT::i8: return Type::getInt8Ty(Context);
189 case MVT::i16: return Type::getInt16Ty(Context);
190 case MVT::i32: return Type::getInt32Ty(Context);
191 case MVT::i64: return Type::getInt64Ty(Context);
192 case MVT::i128: return IntegerType::get(Context, 128);
193 case MVT::f16: return Type::getHalfTy(Context);
194 case MVT::bf16: return Type::getBFloatTy(Context);
195 case MVT::f32: return Type::getFloatTy(Context);
196 case MVT::f64: return Type::getDoubleTy(Context);
197 case MVT::f80: return Type::getX86_FP80Ty(Context);
198 case MVT::f128: return Type::getFP128Ty(Context);
199 case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
200 case MVT::x86mmx: return Type::getX86_MMXTy(Context);
201 case MVT::x86amx: return Type::getX86_AMXTy(Context);
202 case MVT::i64x8: return IntegerType::get(Context, 512);
203 case MVT::externref:
204 return PointerType::get(StructType::create(Context), 10);
205 case MVT::funcref:
206 return PointerType::get(StructType::create(Context), 20);
207 case MVT::v1i1:
208 return FixedVectorType::get(Type::getInt1Ty(Context), 1);
209 case MVT::v2i1:
210 return FixedVectorType::get(Type::getInt1Ty(Context), 2);
211 case MVT::v4i1:
212 return FixedVectorType::get(Type::getInt1Ty(Context), 4);
213 case MVT::v8i1:
214 return FixedVectorType::get(Type::getInt1Ty(Context), 8);
215 case MVT::v16i1:
216 return FixedVectorType::get(Type::getInt1Ty(Context), 16);
217 case MVT::v32i1:
218 return FixedVectorType::get(Type::getInt1Ty(Context), 32);
219 case MVT::v64i1:
220 return FixedVectorType::get(Type::getInt1Ty(Context), 64);
221 case MVT::v128i1:
222 return FixedVectorType::get(Type::getInt1Ty(Context), 128);
223 case MVT::v256i1:
224 return FixedVectorType::get(Type::getInt1Ty(Context), 256);
225 case MVT::v512i1:
226 return FixedVectorType::get(Type::getInt1Ty(Context), 512);
227 case MVT::v1024i1:
228 return FixedVectorType::get(Type::getInt1Ty(Context), 1024);
229 case MVT::v1i8:
230 return FixedVectorType::get(Type::getInt8Ty(Context), 1);
231 case MVT::v2i8:
232 return FixedVectorType::get(Type::getInt8Ty(Context), 2);
233 case MVT::v4i8:
234 return FixedVectorType::get(Type::getInt8Ty(Context), 4);
235 case MVT::v8i8:
236 return FixedVectorType::get(Type::getInt8Ty(Context), 8);
237 case MVT::v16i8:
238 return FixedVectorType::get(Type::getInt8Ty(Context), 16);
239 case MVT::v32i8:
240 return FixedVectorType::get(Type::getInt8Ty(Context), 32);
241 case MVT::v64i8:
242 return FixedVectorType::get(Type::getInt8Ty(Context), 64);
243 case MVT::v128i8:
244 return FixedVectorType::get(Type::getInt8Ty(Context), 128);
245 case MVT::v256i8:
246 return FixedVectorType::get(Type::getInt8Ty(Context), 256);
247 case MVT::v512i8:
248 return FixedVectorType::get(Type::getInt8Ty(Context), 512);
249 case MVT::v1024i8:
250 return FixedVectorType::get(Type::getInt8Ty(Context), 1024);
251 case MVT::v1i16:
252 return FixedVectorType::get(Type::getInt16Ty(Context), 1);
253 case MVT::v2i16:
254 return FixedVectorType::get(Type::getInt16Ty(Context), 2);
255 case MVT::v3i16:
256 return FixedVectorType::get(Type::getInt16Ty(Context), 3);
257 case MVT::v4i16:
258 return FixedVectorType::get(Type::getInt16Ty(Context), 4);
259 case MVT::v8i16:
260 return FixedVectorType::get(Type::getInt16Ty(Context), 8);
261 case MVT::v16i16:
262 return FixedVectorType::get(Type::getInt16Ty(Context), 16);
263 case MVT::v32i16:
264 return FixedVectorType::get(Type::getInt16Ty(Context), 32);
265 case MVT::v64i16:
266 return FixedVectorType::get(Type::getInt16Ty(Context), 64);
267 case MVT::v128i16:
268 return FixedVectorType::get(Type::getInt16Ty(Context), 128);
269 case MVT::v256i16:
270 return FixedVectorType::get(Type::getInt16Ty(Context), 256);
271 case MVT::v512i16:
272 return FixedVectorType::get(Type::getInt16Ty(Context), 512);
273 case MVT::v1i32:
274 return FixedVectorType::get(Type::getInt32Ty(Context), 1);
275 case MVT::v2i32:
276 return FixedVectorType::get(Type::getInt32Ty(Context), 2);
277 case MVT::v3i32:
278 return FixedVectorType::get(Type::getInt32Ty(Context), 3);
279 case MVT::v4i32:
280 return FixedVectorType::get(Type::getInt32Ty(Context), 4);
281 case MVT::v5i32:
282 return FixedVectorType::get(Type::getInt32Ty(Context), 5);
283 case MVT::v6i32:
284 return FixedVectorType::get(Type::getInt32Ty(Context), 6);
285 case MVT::v7i32:
286 return FixedVectorType::get(Type::getInt32Ty(Context), 7);
287 case MVT::v8i32:
288 return FixedVectorType::get(Type::getInt32Ty(Context), 8);
289 case MVT::v16i32:
290 return FixedVectorType::get(Type::getInt32Ty(Context), 16);
291 case MVT::v32i32:
292 return FixedVectorType::get(Type::getInt32Ty(Context), 32);
293 case MVT::v64i32:
294 return FixedVectorType::get(Type::getInt32Ty(Context), 64);
295 case MVT::v128i32:
296 return FixedVectorType::get(Type::getInt32Ty(Context), 128);
297 case MVT::v256i32:
298 return FixedVectorType::get(Type::getInt32Ty(Context), 256);
299 case MVT::v512i32:
300 return FixedVectorType::get(Type::getInt32Ty(Context), 512);
301 case MVT::v1024i32:
302 return FixedVectorType::get(Type::getInt32Ty(Context), 1024);
303 case MVT::v2048i32:
304 return FixedVectorType::get(Type::getInt32Ty(Context), 2048);
305 case MVT::v1i64:
306 return FixedVectorType::get(Type::getInt64Ty(Context), 1);
307 case MVT::v2i64:
308 return FixedVectorType::get(Type::getInt64Ty(Context), 2);
309 case MVT::v3i64:
310 return FixedVectorType::get(Type::getInt64Ty(Context), 3);
311 case MVT::v4i64:
312 return FixedVectorType::get(Type::getInt64Ty(Context), 4);
313 case MVT::v8i64:
314 return FixedVectorType::get(Type::getInt64Ty(Context), 8);
315 case MVT::v16i64:
316 return FixedVectorType::get(Type::getInt64Ty(Context), 16);
317 case MVT::v32i64:
318 return FixedVectorType::get(Type::getInt64Ty(Context), 32);
319 case MVT::v64i64:
320 return FixedVectorType::get(Type::getInt64Ty(Context), 64);
321 case MVT::v128i64:
322 return FixedVectorType::get(Type::getInt64Ty(Context), 128);
323 case MVT::v256i64:
324 return FixedVectorType::get(Type::getInt64Ty(Context), 256);
325 case MVT::v1i128:
326 return FixedVectorType::get(Type::getInt128Ty(Context), 1);
327 case MVT::v1f16:
328 return FixedVectorType::get(Type::getHalfTy(Context), 1);
329 case MVT::v2f16:
330 return FixedVectorType::get(Type::getHalfTy(Context), 2);
331 case MVT::v3f16:
332 return FixedVectorType::get(Type::getHalfTy(Context), 3);
333 case MVT::v4f16:
334 return FixedVectorType::get(Type::getHalfTy(Context), 4);
335 case MVT::v8f16:
336 return FixedVectorType::get(Type::getHalfTy(Context), 8);
337 case MVT::v16f16:
338 return FixedVectorType::get(Type::getHalfTy(Context), 16);
339 case MVT::v32f16:
340 return FixedVectorType::get(Type::getHalfTy(Context), 32);
341 case MVT::v64f16:
342 return FixedVectorType::get(Type::getHalfTy(Context), 64);
343 case MVT::v128f16:
344 return FixedVectorType::get(Type::getHalfTy(Context), 128);
345 case MVT::v256f16:
346 return FixedVectorType::get(Type::getHalfTy(Context), 256);
347 case MVT::v512f16:
348 return FixedVectorType::get(Type::getHalfTy(Context), 512);
349 case MVT::v2bf16:
350 return FixedVectorType::get(Type::getBFloatTy(Context), 2);
351 case MVT::v3bf16:
352 return FixedVectorType::get(Type::getBFloatTy(Context), 3);
353 case MVT::v4bf16:
354 return FixedVectorType::get(Type::getBFloatTy(Context), 4);
355 case MVT::v8bf16:
356 return FixedVectorType::get(Type::getBFloatTy(Context), 8);
357 case MVT::v16bf16:
358 return FixedVectorType::get(Type::getBFloatTy(Context), 16);
359 case MVT::v32bf16:
360 return FixedVectorType::get(Type::getBFloatTy(Context), 32);
361 case MVT::v64bf16:
362 return FixedVectorType::get(Type::getBFloatTy(Context), 64);
363 case MVT::v128bf16:
364 return FixedVectorType::get(Type::getBFloatTy(Context), 128);
365 case MVT::v1f32:
366 return FixedVectorType::get(Type::getFloatTy(Context), 1);
367 case MVT::v2f32:
368 return FixedVectorType::get(Type::getFloatTy(Context), 2);
369 case MVT::v3f32:
370 return FixedVectorType::get(Type::getFloatTy(Context), 3);
371 case MVT::v4f32:
372 return FixedVectorType::get(Type::getFloatTy(Context), 4);
373 case MVT::v5f32:
374 return FixedVectorType::get(Type::getFloatTy(Context), 5);
375 case MVT::v6f32:
376 return FixedVectorType::get(Type::getFloatTy(Context), 6);
377 case MVT::v7f32:
378 return FixedVectorType::get(Type::getFloatTy(Context), 7);
379 case MVT::v8f32:
380 return FixedVectorType::get(Type::getFloatTy(Context), 8);
381 case MVT::v16f32:
382 return FixedVectorType::get(Type::getFloatTy(Context), 16);
383 case MVT::v32f32:
384 return FixedVectorType::get(Type::getFloatTy(Context), 32);
385 case MVT::v64f32:
386 return FixedVectorType::get(Type::getFloatTy(Context), 64);
387 case MVT::v128f32:
388 return FixedVectorType::get(Type::getFloatTy(Context), 128);
389 case MVT::v256f32:
390 return FixedVectorType::get(Type::getFloatTy(Context), 256);
391 case MVT::v512f32:
392 return FixedVectorType::get(Type::getFloatTy(Context), 512);
393 case MVT::v1024f32:
394 return FixedVectorType::get(Type::getFloatTy(Context), 1024);
395 case MVT::v2048f32:
396 return FixedVectorType::get(Type::getFloatTy(Context), 2048);
397 case MVT::v1f64:
398 return FixedVectorType::get(Type::getDoubleTy(Context), 1);
399 case MVT::v2f64:
400 return FixedVectorType::get(Type::getDoubleTy(Context), 2);
401 case MVT::v3f64:
402 return FixedVectorType::get(Type::getDoubleTy(Context), 3);
403 case MVT::v4f64:
404 return FixedVectorType::get(Type::getDoubleTy(Context), 4);
405 case MVT::v8f64:
406 return FixedVectorType::get(Type::getDoubleTy(Context), 8);
407 case MVT::v16f64:
408 return FixedVectorType::get(Type::getDoubleTy(Context), 16);
409 case MVT::v32f64:
410 return FixedVectorType::get(Type::getDoubleTy(Context), 32);
411 case MVT::v64f64:
412 return FixedVectorType::get(Type::getDoubleTy(Context), 64);
413 case MVT::v128f64:
414 return FixedVectorType::get(Type::getDoubleTy(Context), 128);
415 case MVT::v256f64:
416 return FixedVectorType::get(Type::getDoubleTy(Context), 256);
417 case MVT::nxv1i1:
418 return ScalableVectorType::get(Type::getInt1Ty(Context), 1);
419 case MVT::nxv2i1:
420 return ScalableVectorType::get(Type::getInt1Ty(Context), 2);
421 case MVT::nxv4i1:
422 return ScalableVectorType::get(Type::getInt1Ty(Context), 4);
423 case MVT::nxv8i1:
424 return ScalableVectorType::get(Type::getInt1Ty(Context), 8);
425 case MVT::nxv16i1:
426 return ScalableVectorType::get(Type::getInt1Ty(Context), 16);
427 case MVT::nxv32i1:
428 return ScalableVectorType::get(Type::getInt1Ty(Context), 32);
429 case MVT::nxv64i1:
430 return ScalableVectorType::get(Type::getInt1Ty(Context), 64);
431 case MVT::nxv1i8:
432 return ScalableVectorType::get(Type::getInt8Ty(Context), 1);
433 case MVT::nxv2i8:
434 return ScalableVectorType::get(Type::getInt8Ty(Context), 2);
435 case MVT::nxv4i8:
436 return ScalableVectorType::get(Type::getInt8Ty(Context), 4);
437 case MVT::nxv8i8:
438 return ScalableVectorType::get(Type::getInt8Ty(Context), 8);
439 case MVT::nxv16i8:
440 return ScalableVectorType::get(Type::getInt8Ty(Context), 16);
441 case MVT::nxv32i8:
442 return ScalableVectorType::get(Type::getInt8Ty(Context), 32);
443 case MVT::nxv64i8:
444 return ScalableVectorType::get(Type::getInt8Ty(Context), 64);
445 case MVT::nxv1i16:
446 return ScalableVectorType::get(Type::getInt16Ty(Context), 1);
447 case MVT::nxv2i16:
448 return ScalableVectorType::get(Type::getInt16Ty(Context), 2);
449 case MVT::nxv4i16:
450 return ScalableVectorType::get(Type::getInt16Ty(Context), 4);
451 case MVT::nxv8i16:
452 return ScalableVectorType::get(Type::getInt16Ty(Context), 8);
453 case MVT::nxv16i16:
454 return ScalableVectorType::get(Type::getInt16Ty(Context), 16);
455 case MVT::nxv32i16:
456 return ScalableVectorType::get(Type::getInt16Ty(Context), 32);
457 case MVT::nxv1i32:
458 return ScalableVectorType::get(Type::getInt32Ty(Context), 1);
459 case MVT::nxv2i32:
460 return ScalableVectorType::get(Type::getInt32Ty(Context), 2);
461 case MVT::nxv4i32:
462 return ScalableVectorType::get(Type::getInt32Ty(Context), 4);
463 case MVT::nxv8i32:
464 return ScalableVectorType::get(Type::getInt32Ty(Context), 8);
465 case MVT::nxv16i32:
466 return ScalableVectorType::get(Type::getInt32Ty(Context), 16);
467 case MVT::nxv32i32:
468 return ScalableVectorType::get(Type::getInt32Ty(Context), 32);
469 case MVT::nxv1i64:
470 return ScalableVectorType::get(Type::getInt64Ty(Context), 1);
471 case MVT::nxv2i64:
472 return ScalableVectorType::get(Type::getInt64Ty(Context), 2);
473 case MVT::nxv4i64:
474 return ScalableVectorType::get(Type::getInt64Ty(Context), 4);
475 case MVT::nxv8i64:
476 return ScalableVectorType::get(Type::getInt64Ty(Context), 8);
477 case MVT::nxv16i64:
478 return ScalableVectorType::get(Type::getInt64Ty(Context), 16);
479 case MVT::nxv32i64:
480 return ScalableVectorType::get(Type::getInt64Ty(Context), 32);
481 case MVT::nxv1f16:
482 return ScalableVectorType::get(Type::getHalfTy(Context), 1);
483 case MVT::nxv2f16:
484 return ScalableVectorType::get(Type::getHalfTy(Context), 2);
485 case MVT::nxv4f16:
486 return ScalableVectorType::get(Type::getHalfTy(Context), 4);
487 case MVT::nxv8f16:
488 return ScalableVectorType::get(Type::getHalfTy(Context), 8);
489 case MVT::nxv16f16:
490 return ScalableVectorType::get(Type::getHalfTy(Context), 16);
491 case MVT::nxv32f16:
492 return ScalableVectorType::get(Type::getHalfTy(Context), 32);
493 case MVT::nxv1bf16:
494 return ScalableVectorType::get(Type::getBFloatTy(Context), 1);
495 case MVT::nxv2bf16:
496 return ScalableVectorType::get(Type::getBFloatTy(Context), 2);
497 case MVT::nxv4bf16:
498 return ScalableVectorType::get(Type::getBFloatTy(Context), 4);
499 case MVT::nxv8bf16:
500 return ScalableVectorType::get(Type::getBFloatTy(Context), 8);
501 case MVT::nxv1f32:
502 return ScalableVectorType::get(Type::getFloatTy(Context), 1);
503 case MVT::nxv2f32:
504 return ScalableVectorType::get(Type::getFloatTy(Context), 2);
505 case MVT::nxv4f32:
506 return ScalableVectorType::get(Type::getFloatTy(Context), 4);
507 case MVT::nxv8f32:
508 return ScalableVectorType::get(Type::getFloatTy(Context), 8);
509 case MVT::nxv16f32:
510 return ScalableVectorType::get(Type::getFloatTy(Context), 16);
511 case MVT::nxv1f64:
512 return ScalableVectorType::get(Type::getDoubleTy(Context), 1);
513 case MVT::nxv2f64:
514 return ScalableVectorType::get(Type::getDoubleTy(Context), 2);
515 case MVT::nxv4f64:
516 return ScalableVectorType::get(Type::getDoubleTy(Context), 4);
517 case MVT::nxv8f64:
518 return ScalableVectorType::get(Type::getDoubleTy(Context), 8);
519 case MVT::Metadata: return Type::getMetadataTy(Context);
520 }
521}
522
523/// Return the value type corresponding to the specified type. This returns all
524/// pointers as MVT::iPTR. If HandleUnknown is true, unknown types are returned
525/// as Other, otherwise they are invalid.
526MVT MVT::getVT(Type *Ty, bool HandleUnknown){
527 switch (Ty->getTypeID()) {
528 default:
529 if (HandleUnknown) return MVT(MVT::Other);
530 llvm_unreachable("Unknown type!")::llvm::llvm_unreachable_internal("Unknown type!", "/build/llvm-toolchain-snapshot-14~++20210828111110+16086d47c0d0/llvm/lib/CodeGen/ValueTypes.cpp"
, 530)
;
531 case Type::VoidTyID:
532 return MVT::isVoid;
533 case Type::IntegerTyID:
534 return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
535 case Type::HalfTyID: return MVT(MVT::f16);
536 case Type::BFloatTyID: return MVT(MVT::bf16);
537 case Type::FloatTyID: return MVT(MVT::f32);
538 case Type::DoubleTyID: return MVT(MVT::f64);
539 case Type::X86_FP80TyID: return MVT(MVT::f80);
540 case Type::X86_MMXTyID: return MVT(MVT::x86mmx);
541 case Type::X86_AMXTyID: return MVT(MVT::x86amx);
542 case Type::FP128TyID: return MVT(MVT::f128);
543 case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
544 case Type::PointerTyID: return MVT(MVT::iPTR);
545 case Type::FixedVectorTyID:
546 case Type::ScalableVectorTyID: {
547 VectorType *VTy = cast<VectorType>(Ty);
548 return getVectorVT(
549 getVT(VTy->getElementType(), /*HandleUnknown=*/ false),
550 VTy->getElementCount());
551 }
552 }
553}
554
555/// getEVT - Return the value type corresponding to the specified type. This
556/// returns all pointers as MVT::iPTR. If HandleUnknown is true, unknown types
557/// are returned as Other, otherwise they are invalid.
558EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
559 switch (Ty->getTypeID()) {
16
Control jumps to the 'default' case at line 560
560 default:
561 return MVT::getVT(Ty, HandleUnknown);
17
Calling constructor for 'EVT'
19
Returning from constructor for 'EVT'
562 case Type::IntegerTyID:
563 return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
564 case Type::FixedVectorTyID:
565 case Type::ScalableVectorTyID: {
566 VectorType *VTy = cast<VectorType>(Ty);
567 return getVectorVT(Ty->getContext(),
568 getEVT(VTy->getElementType(), /*HandleUnknown=*/ false),
569 VTy->getElementCount());
570 }
571 }
572}

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