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