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