Bug Summary

File:build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/llvm/lib/CodeGen/ValueTypes.cpp
Warning:line 77, 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-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 -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/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/build-llvm -resource-dir /usr/lib/llvm-15/lib/clang/15.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I lib/CodeGen -I /build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/llvm/lib/CodeGen -I include -I /build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/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-15/lib/clang/15.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 -fmacro-prefix-map=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/build-llvm=build-llvm -fmacro-prefix-map=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/= -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/build-llvm=build-llvm -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/= -O3 -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 -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/build-llvm -fdebug-prefix-map=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/build-llvm=build-llvm -fdebug-prefix-map=/build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/= -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-2022-04-20-140412-16051-1 -x c++ /build/llvm-toolchain-snapshot-15~++20220420111733+e13d2efed663/llvm/lib/CodeGen/ValueTypes.cpp

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

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