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