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"
16 using namespace llvm;
17
changeExtendedTypeToInteger() const18 EVT EVT::changeExtendedTypeToInteger() const {
19 assert(isExtended() && "Type is not extended!");
20 LLVMContext &Context = LLVMTy->getContext();
21 return getIntegerVT(Context, getSizeInBits());
22 }
23
changeExtendedVectorElementTypeToInteger() const24 EVT EVT::changeExtendedVectorElementTypeToInteger() const {
25 assert(isExtended() && "Type is not extended!");
26 LLVMContext &Context = LLVMTy->getContext();
27 EVT IntTy = getIntegerVT(Context, getScalarSizeInBits());
28 return getVectorVT(Context, IntTy, getVectorElementCount());
29 }
30
changeExtendedVectorElementType(EVT EltVT) const31 EVT EVT::changeExtendedVectorElementType(EVT EltVT) const {
32 assert(isExtended() && "Type is not extended!");
33 LLVMContext &Context = LLVMTy->getContext();
34 return getVectorVT(Context, EltVT, getVectorElementCount());
35 }
36
getExtendedIntegerVT(LLVMContext & Context,unsigned BitWidth)37 EVT EVT::getExtendedIntegerVT(LLVMContext &Context, unsigned BitWidth) {
38 EVT VT;
39 VT.LLVMTy = IntegerType::get(Context, BitWidth);
40 assert(VT.isExtended() && "Type is not extended!");
41 return VT;
42 }
43
getExtendedVectorVT(LLVMContext & Context,EVT VT,unsigned NumElements,bool IsScalable)44 EVT 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!");
50 return ResultVT;
51 }
52
getExtendedVectorVT(LLVMContext & Context,EVT VT,ElementCount EC)53 EVT 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!");
57 return ResultVT;
58 }
59
isExtendedFloatingPoint() const60 bool EVT::isExtendedFloatingPoint() const {
61 assert(isExtended() && "Type is not extended!");
62 return LLVMTy->isFPOrFPVectorTy();
63 }
64
isExtendedInteger() const65 bool EVT::isExtendedInteger() const {
66 assert(isExtended() && "Type is not extended!");
67 return LLVMTy->isIntOrIntVectorTy();
68 }
69
isExtendedScalarInteger() const70 bool EVT::isExtendedScalarInteger() const {
71 assert(isExtended() && "Type is not extended!");
72 return LLVMTy->isIntegerTy();
73 }
74
isExtendedVector() const75 bool EVT::isExtendedVector() const {
76 assert(isExtended() && "Type is not extended!");
77 return LLVMTy->isVectorTy();
78 }
79
isExtended16BitVector() const80 bool EVT::isExtended16BitVector() const {
81 return isExtendedVector() && getExtendedSizeInBits() == 16;
82 }
83
isExtended32BitVector() const84 bool EVT::isExtended32BitVector() const {
85 return isExtendedVector() && getExtendedSizeInBits() == 32;
86 }
87
isExtended64BitVector() const88 bool EVT::isExtended64BitVector() const {
89 return isExtendedVector() && getExtendedSizeInBits() == 64;
90 }
91
isExtended128BitVector() const92 bool EVT::isExtended128BitVector() const {
93 return isExtendedVector() && getExtendedSizeInBits() == 128;
94 }
95
isExtended256BitVector() const96 bool EVT::isExtended256BitVector() const {
97 return isExtendedVector() && getExtendedSizeInBits() == 256;
98 }
99
isExtended512BitVector() const100 bool EVT::isExtended512BitVector() const {
101 return isExtendedVector() && getExtendedSizeInBits() == 512;
102 }
103
isExtended1024BitVector() const104 bool EVT::isExtended1024BitVector() const {
105 return isExtendedVector() && getExtendedSizeInBits() == 1024;
106 }
107
isExtended2048BitVector() const108 bool EVT::isExtended2048BitVector() const {
109 return isExtendedVector() && getExtendedSizeInBits() == 2048;
110 }
111
isExtendedFixedLengthVector() const112 bool EVT::isExtendedFixedLengthVector() const {
113 return isExtendedVector() && isa<FixedVectorType>(LLVMTy);
114 }
115
isExtendedScalableVector() const116 bool EVT::isExtendedScalableVector() const {
117 return isExtendedVector() && isa<ScalableVectorType>(LLVMTy);
118 }
119
getExtendedVectorElementType() const120 EVT EVT::getExtendedVectorElementType() const {
121 assert(isExtended() && "Type is not extended!");
122 return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());
123 }
124
getExtendedVectorNumElements() const125 unsigned EVT::getExtendedVectorNumElements() const {
126 assert(isExtended() && "Type is not extended!");
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
getExtendedVectorElementCount() const137 ElementCount EVT::getExtendedVectorElementCount() const {
138 assert(isExtended() && "Type is not extended!");
139 return cast<VectorType>(LLVMTy)->getElementCount();
140 }
141
getExtendedSizeInBits() const142 TypeSize EVT::getExtendedSizeInBits() const {
143 assert(isExtended() && "Type is not extended!");
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!");
149 }
150
151 /// getEVTString - This function returns value type as a string, e.g. "i32".
getEVTString() const152 std::string EVT::getEVTString() const {
153 switch (V.SimpleTy) {
154 default:
155 if (isVector())
156 return (isScalableVector() ? "nxv" : "v") +
157 utostr(getVectorElementCount().getKnownMinValue()) +
158 getVectorElementType().getEVTString();
159 if (isInteger())
160 return "i" + utostr(getSizeInBits());
161 if (isFloatingPoint())
162 return "f" + utostr(getSizeInBits());
163 llvm_unreachable("Invalid EVT!");
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.
getTypeForEVT(LLVMContext & Context) const182 Type *EVT::getTypeForEVT(LLVMContext &Context) const {
183 // clang-format off
184 switch (V.SimpleTy) {
185 default:
186 assert(isExtended() && "Type is not extended!");
187 return LLVMTy;
188 case MVT::isVoid: return Type::getVoidTy(Context);
189 case MVT::i1: return Type::getInt1Ty(Context);
190 case MVT::i2: return Type::getIntNTy(Context, 2);
191 case MVT::i4: return Type::getIntNTy(Context, 4);
192 case MVT::i8: return Type::getInt8Ty(Context);
193 case MVT::i16: return Type::getInt16Ty(Context);
194 case MVT::i32: return Type::getInt32Ty(Context);
195 case MVT::i64: return Type::getInt64Ty(Context);
196 case MVT::i128: return IntegerType::get(Context, 128);
197 case MVT::f16: return Type::getHalfTy(Context);
198 case MVT::bf16: return Type::getBFloatTy(Context);
199 case MVT::f32: return Type::getFloatTy(Context);
200 case MVT::f64: return Type::getDoubleTy(Context);
201 case MVT::f80: return Type::getX86_FP80Ty(Context);
202 case MVT::f128: return Type::getFP128Ty(Context);
203 case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
204 case MVT::x86mmx: return Type::getX86_MMXTy(Context);
205 case MVT::x86amx: return Type::getX86_AMXTy(Context);
206 case MVT::i64x8: return IntegerType::get(Context, 512);
207 case MVT::externref:
208 // pointer to opaque struct in addrspace(10)
209 return PointerType::get(StructType::create(Context), 10);
210 case MVT::funcref:
211 // pointer to i8 addrspace(20)
212 return PointerType::get(Type::getInt8Ty(Context), 20);
213 case MVT::v1i1:
214 return FixedVectorType::get(Type::getInt1Ty(Context), 1);
215 case MVT::v2i1:
216 return FixedVectorType::get(Type::getInt1Ty(Context), 2);
217 case MVT::v4i1:
218 return FixedVectorType::get(Type::getInt1Ty(Context), 4);
219 case MVT::v8i1:
220 return FixedVectorType::get(Type::getInt1Ty(Context), 8);
221 case MVT::v16i1:
222 return FixedVectorType::get(Type::getInt1Ty(Context), 16);
223 case MVT::v32i1:
224 return FixedVectorType::get(Type::getInt1Ty(Context), 32);
225 case MVT::v64i1:
226 return FixedVectorType::get(Type::getInt1Ty(Context), 64);
227 case MVT::v128i1:
228 return FixedVectorType::get(Type::getInt1Ty(Context), 128);
229 case MVT::v256i1:
230 return FixedVectorType::get(Type::getInt1Ty(Context), 256);
231 case MVT::v512i1:
232 return FixedVectorType::get(Type::getInt1Ty(Context), 512);
233 case MVT::v1024i1:
234 return FixedVectorType::get(Type::getInt1Ty(Context), 1024);
235 case MVT::v2048i1:
236 return FixedVectorType::get(Type::getInt1Ty(Context), 2048);
237 case MVT::v128i2:
238 return FixedVectorType::get(Type::getIntNTy(Context, 2), 128);
239 case MVT::v256i2:
240 return FixedVectorType::get(Type::getIntNTy(Context, 2), 256);
241 case MVT::v64i4:
242 return FixedVectorType::get(Type::getIntNTy(Context, 4), 64);
243 case MVT::v128i4:
244 return FixedVectorType::get(Type::getIntNTy(Context, 4), 128);
245 case MVT::v1i8:
246 return FixedVectorType::get(Type::getInt8Ty(Context), 1);
247 case MVT::v2i8:
248 return FixedVectorType::get(Type::getInt8Ty(Context), 2);
249 case MVT::v4i8:
250 return FixedVectorType::get(Type::getInt8Ty(Context), 4);
251 case MVT::v8i8:
252 return FixedVectorType::get(Type::getInt8Ty(Context), 8);
253 case MVT::v16i8:
254 return FixedVectorType::get(Type::getInt8Ty(Context), 16);
255 case MVT::v32i8:
256 return FixedVectorType::get(Type::getInt8Ty(Context), 32);
257 case MVT::v64i8:
258 return FixedVectorType::get(Type::getInt8Ty(Context), 64);
259 case MVT::v128i8:
260 return FixedVectorType::get(Type::getInt8Ty(Context), 128);
261 case MVT::v256i8:
262 return FixedVectorType::get(Type::getInt8Ty(Context), 256);
263 case MVT::v512i8:
264 return FixedVectorType::get(Type::getInt8Ty(Context), 512);
265 case MVT::v1024i8:
266 return FixedVectorType::get(Type::getInt8Ty(Context), 1024);
267 case MVT::v1i16:
268 return FixedVectorType::get(Type::getInt16Ty(Context), 1);
269 case MVT::v2i16:
270 return FixedVectorType::get(Type::getInt16Ty(Context), 2);
271 case MVT::v3i16:
272 return FixedVectorType::get(Type::getInt16Ty(Context), 3);
273 case MVT::v4i16:
274 return FixedVectorType::get(Type::getInt16Ty(Context), 4);
275 case MVT::v8i16:
276 return FixedVectorType::get(Type::getInt16Ty(Context), 8);
277 case MVT::v16i16:
278 return FixedVectorType::get(Type::getInt16Ty(Context), 16);
279 case MVT::v32i16:
280 return FixedVectorType::get(Type::getInt16Ty(Context), 32);
281 case MVT::v64i16:
282 return FixedVectorType::get(Type::getInt16Ty(Context), 64);
283 case MVT::v128i16:
284 return FixedVectorType::get(Type::getInt16Ty(Context), 128);
285 case MVT::v256i16:
286 return FixedVectorType::get(Type::getInt16Ty(Context), 256);
287 case MVT::v512i16:
288 return FixedVectorType::get(Type::getInt16Ty(Context), 512);
289 case MVT::v1i32:
290 return FixedVectorType::get(Type::getInt32Ty(Context), 1);
291 case MVT::v2i32:
292 return FixedVectorType::get(Type::getInt32Ty(Context), 2);
293 case MVT::v3i32:
294 return FixedVectorType::get(Type::getInt32Ty(Context), 3);
295 case MVT::v4i32:
296 return FixedVectorType::get(Type::getInt32Ty(Context), 4);
297 case MVT::v5i32:
298 return FixedVectorType::get(Type::getInt32Ty(Context), 5);
299 case MVT::v6i32:
300 return FixedVectorType::get(Type::getInt32Ty(Context), 6);
301 case MVT::v7i32:
302 return FixedVectorType::get(Type::getInt32Ty(Context), 7);
303 case MVT::v8i32:
304 return FixedVectorType::get(Type::getInt32Ty(Context), 8);
305 case MVT::v9i32:
306 return FixedVectorType::get(Type::getInt32Ty(Context), 9);
307 case MVT::v10i32:
308 return FixedVectorType::get(Type::getInt32Ty(Context), 10);
309 case MVT::v11i32:
310 return FixedVectorType::get(Type::getInt32Ty(Context), 11);
311 case MVT::v12i32:
312 return FixedVectorType::get(Type::getInt32Ty(Context), 12);
313 case MVT::v16i32:
314 return FixedVectorType::get(Type::getInt32Ty(Context), 16);
315 case MVT::v32i32:
316 return FixedVectorType::get(Type::getInt32Ty(Context), 32);
317 case MVT::v64i32:
318 return FixedVectorType::get(Type::getInt32Ty(Context), 64);
319 case MVT::v128i32:
320 return FixedVectorType::get(Type::getInt32Ty(Context), 128);
321 case MVT::v256i32:
322 return FixedVectorType::get(Type::getInt32Ty(Context), 256);
323 case MVT::v512i32:
324 return FixedVectorType::get(Type::getInt32Ty(Context), 512);
325 case MVT::v1024i32:
326 return FixedVectorType::get(Type::getInt32Ty(Context), 1024);
327 case MVT::v2048i32:
328 return FixedVectorType::get(Type::getInt32Ty(Context), 2048);
329 case MVT::v1i64:
330 return FixedVectorType::get(Type::getInt64Ty(Context), 1);
331 case MVT::v2i64:
332 return FixedVectorType::get(Type::getInt64Ty(Context), 2);
333 case MVT::v3i64:
334 return FixedVectorType::get(Type::getInt64Ty(Context), 3);
335 case MVT::v4i64:
336 return FixedVectorType::get(Type::getInt64Ty(Context), 4);
337 case MVT::v8i64:
338 return FixedVectorType::get(Type::getInt64Ty(Context), 8);
339 case MVT::v16i64:
340 return FixedVectorType::get(Type::getInt64Ty(Context), 16);
341 case MVT::v32i64:
342 return FixedVectorType::get(Type::getInt64Ty(Context), 32);
343 case MVT::v64i64:
344 return FixedVectorType::get(Type::getInt64Ty(Context), 64);
345 case MVT::v128i64:
346 return FixedVectorType::get(Type::getInt64Ty(Context), 128);
347 case MVT::v256i64:
348 return FixedVectorType::get(Type::getInt64Ty(Context), 256);
349 case MVT::v1i128:
350 return FixedVectorType::get(Type::getInt128Ty(Context), 1);
351 case MVT::v1f16:
352 return FixedVectorType::get(Type::getHalfTy(Context), 1);
353 case MVT::v2f16:
354 return FixedVectorType::get(Type::getHalfTy(Context), 2);
355 case MVT::v3f16:
356 return FixedVectorType::get(Type::getHalfTy(Context), 3);
357 case MVT::v4f16:
358 return FixedVectorType::get(Type::getHalfTy(Context), 4);
359 case MVT::v8f16:
360 return FixedVectorType::get(Type::getHalfTy(Context), 8);
361 case MVT::v16f16:
362 return FixedVectorType::get(Type::getHalfTy(Context), 16);
363 case MVT::v32f16:
364 return FixedVectorType::get(Type::getHalfTy(Context), 32);
365 case MVT::v64f16:
366 return FixedVectorType::get(Type::getHalfTy(Context), 64);
367 case MVT::v128f16:
368 return FixedVectorType::get(Type::getHalfTy(Context), 128);
369 case MVT::v256f16:
370 return FixedVectorType::get(Type::getHalfTy(Context), 256);
371 case MVT::v512f16:
372 return FixedVectorType::get(Type::getHalfTy(Context), 512);
373 case MVT::v2bf16:
374 return FixedVectorType::get(Type::getBFloatTy(Context), 2);
375 case MVT::v3bf16:
376 return FixedVectorType::get(Type::getBFloatTy(Context), 3);
377 case MVT::v4bf16:
378 return FixedVectorType::get(Type::getBFloatTy(Context), 4);
379 case MVT::v8bf16:
380 return FixedVectorType::get(Type::getBFloatTy(Context), 8);
381 case MVT::v16bf16:
382 return FixedVectorType::get(Type::getBFloatTy(Context), 16);
383 case MVT::v32bf16:
384 return FixedVectorType::get(Type::getBFloatTy(Context), 32);
385 case MVT::v64bf16:
386 return FixedVectorType::get(Type::getBFloatTy(Context), 64);
387 case MVT::v128bf16:
388 return FixedVectorType::get(Type::getBFloatTy(Context), 128);
389 case MVT::v1f32:
390 return FixedVectorType::get(Type::getFloatTy(Context), 1);
391 case MVT::v2f32:
392 return FixedVectorType::get(Type::getFloatTy(Context), 2);
393 case MVT::v3f32:
394 return FixedVectorType::get(Type::getFloatTy(Context), 3);
395 case MVT::v4f32:
396 return FixedVectorType::get(Type::getFloatTy(Context), 4);
397 case MVT::v5f32:
398 return FixedVectorType::get(Type::getFloatTy(Context), 5);
399 case MVT::v6f32:
400 return FixedVectorType::get(Type::getFloatTy(Context), 6);
401 case MVT::v7f32:
402 return FixedVectorType::get(Type::getFloatTy(Context), 7);
403 case MVT::v8f32:
404 return FixedVectorType::get(Type::getFloatTy(Context), 8);
405 case MVT::v9f32:
406 return FixedVectorType::get(Type::getFloatTy(Context), 9);
407 case MVT::v10f32:
408 return FixedVectorType::get(Type::getFloatTy(Context), 10);
409 case MVT::v11f32:
410 return FixedVectorType::get(Type::getFloatTy(Context), 11);
411 case MVT::v12f32:
412 return FixedVectorType::get(Type::getFloatTy(Context), 12);
413 case MVT::v16f32:
414 return FixedVectorType::get(Type::getFloatTy(Context), 16);
415 case MVT::v32f32:
416 return FixedVectorType::get(Type::getFloatTy(Context), 32);
417 case MVT::v64f32:
418 return FixedVectorType::get(Type::getFloatTy(Context), 64);
419 case MVT::v128f32:
420 return FixedVectorType::get(Type::getFloatTy(Context), 128);
421 case MVT::v256f32:
422 return FixedVectorType::get(Type::getFloatTy(Context), 256);
423 case MVT::v512f32:
424 return FixedVectorType::get(Type::getFloatTy(Context), 512);
425 case MVT::v1024f32:
426 return FixedVectorType::get(Type::getFloatTy(Context), 1024);
427 case MVT::v2048f32:
428 return FixedVectorType::get(Type::getFloatTy(Context), 2048);
429 case MVT::v1f64:
430 return FixedVectorType::get(Type::getDoubleTy(Context), 1);
431 case MVT::v2f64:
432 return FixedVectorType::get(Type::getDoubleTy(Context), 2);
433 case MVT::v3f64:
434 return FixedVectorType::get(Type::getDoubleTy(Context), 3);
435 case MVT::v4f64:
436 return FixedVectorType::get(Type::getDoubleTy(Context), 4);
437 case MVT::v8f64:
438 return FixedVectorType::get(Type::getDoubleTy(Context), 8);
439 case MVT::v16f64:
440 return FixedVectorType::get(Type::getDoubleTy(Context), 16);
441 case MVT::v32f64:
442 return FixedVectorType::get(Type::getDoubleTy(Context), 32);
443 case MVT::v64f64:
444 return FixedVectorType::get(Type::getDoubleTy(Context), 64);
445 case MVT::v128f64:
446 return FixedVectorType::get(Type::getDoubleTy(Context), 128);
447 case MVT::v256f64:
448 return FixedVectorType::get(Type::getDoubleTy(Context), 256);
449 case MVT::nxv1i1:
450 return ScalableVectorType::get(Type::getInt1Ty(Context), 1);
451 case MVT::nxv2i1:
452 return ScalableVectorType::get(Type::getInt1Ty(Context), 2);
453 case MVT::nxv4i1:
454 return ScalableVectorType::get(Type::getInt1Ty(Context), 4);
455 case MVT::nxv8i1:
456 return ScalableVectorType::get(Type::getInt1Ty(Context), 8);
457 case MVT::nxv16i1:
458 return ScalableVectorType::get(Type::getInt1Ty(Context), 16);
459 case MVT::nxv32i1:
460 return ScalableVectorType::get(Type::getInt1Ty(Context), 32);
461 case MVT::nxv64i1:
462 return ScalableVectorType::get(Type::getInt1Ty(Context), 64);
463 case MVT::nxv1i8:
464 return ScalableVectorType::get(Type::getInt8Ty(Context), 1);
465 case MVT::nxv2i8:
466 return ScalableVectorType::get(Type::getInt8Ty(Context), 2);
467 case MVT::nxv4i8:
468 return ScalableVectorType::get(Type::getInt8Ty(Context), 4);
469 case MVT::nxv8i8:
470 return ScalableVectorType::get(Type::getInt8Ty(Context), 8);
471 case MVT::nxv16i8:
472 return ScalableVectorType::get(Type::getInt8Ty(Context), 16);
473 case MVT::nxv32i8:
474 return ScalableVectorType::get(Type::getInt8Ty(Context), 32);
475 case MVT::nxv64i8:
476 return ScalableVectorType::get(Type::getInt8Ty(Context), 64);
477 case MVT::nxv1i16:
478 return ScalableVectorType::get(Type::getInt16Ty(Context), 1);
479 case MVT::nxv2i16:
480 return ScalableVectorType::get(Type::getInt16Ty(Context), 2);
481 case MVT::nxv4i16:
482 return ScalableVectorType::get(Type::getInt16Ty(Context), 4);
483 case MVT::nxv8i16:
484 return ScalableVectorType::get(Type::getInt16Ty(Context), 8);
485 case MVT::nxv16i16:
486 return ScalableVectorType::get(Type::getInt16Ty(Context), 16);
487 case MVT::nxv32i16:
488 return ScalableVectorType::get(Type::getInt16Ty(Context), 32);
489 case MVT::nxv1i32:
490 return ScalableVectorType::get(Type::getInt32Ty(Context), 1);
491 case MVT::nxv2i32:
492 return ScalableVectorType::get(Type::getInt32Ty(Context), 2);
493 case MVT::nxv4i32:
494 return ScalableVectorType::get(Type::getInt32Ty(Context), 4);
495 case MVT::nxv8i32:
496 return ScalableVectorType::get(Type::getInt32Ty(Context), 8);
497 case MVT::nxv16i32:
498 return ScalableVectorType::get(Type::getInt32Ty(Context), 16);
499 case MVT::nxv32i32:
500 return ScalableVectorType::get(Type::getInt32Ty(Context), 32);
501 case MVT::nxv1i64:
502 return ScalableVectorType::get(Type::getInt64Ty(Context), 1);
503 case MVT::nxv2i64:
504 return ScalableVectorType::get(Type::getInt64Ty(Context), 2);
505 case MVT::nxv4i64:
506 return ScalableVectorType::get(Type::getInt64Ty(Context), 4);
507 case MVT::nxv8i64:
508 return ScalableVectorType::get(Type::getInt64Ty(Context), 8);
509 case MVT::nxv16i64:
510 return ScalableVectorType::get(Type::getInt64Ty(Context), 16);
511 case MVT::nxv32i64:
512 return ScalableVectorType::get(Type::getInt64Ty(Context), 32);
513 case MVT::nxv1f16:
514 return ScalableVectorType::get(Type::getHalfTy(Context), 1);
515 case MVT::nxv2f16:
516 return ScalableVectorType::get(Type::getHalfTy(Context), 2);
517 case MVT::nxv4f16:
518 return ScalableVectorType::get(Type::getHalfTy(Context), 4);
519 case MVT::nxv8f16:
520 return ScalableVectorType::get(Type::getHalfTy(Context), 8);
521 case MVT::nxv16f16:
522 return ScalableVectorType::get(Type::getHalfTy(Context), 16);
523 case MVT::nxv32f16:
524 return ScalableVectorType::get(Type::getHalfTy(Context), 32);
525 case MVT::nxv1bf16:
526 return ScalableVectorType::get(Type::getBFloatTy(Context), 1);
527 case MVT::nxv2bf16:
528 return ScalableVectorType::get(Type::getBFloatTy(Context), 2);
529 case MVT::nxv4bf16:
530 return ScalableVectorType::get(Type::getBFloatTy(Context), 4);
531 case MVT::nxv8bf16:
532 return ScalableVectorType::get(Type::getBFloatTy(Context), 8);
533 case MVT::nxv16bf16:
534 return ScalableVectorType::get(Type::getBFloatTy(Context), 16);
535 case MVT::nxv32bf16:
536 return ScalableVectorType::get(Type::getBFloatTy(Context), 32);
537 case MVT::nxv1f32:
538 return ScalableVectorType::get(Type::getFloatTy(Context), 1);
539 case MVT::nxv2f32:
540 return ScalableVectorType::get(Type::getFloatTy(Context), 2);
541 case MVT::nxv4f32:
542 return ScalableVectorType::get(Type::getFloatTy(Context), 4);
543 case MVT::nxv8f32:
544 return ScalableVectorType::get(Type::getFloatTy(Context), 8);
545 case MVT::nxv16f32:
546 return ScalableVectorType::get(Type::getFloatTy(Context), 16);
547 case MVT::nxv1f64:
548 return ScalableVectorType::get(Type::getDoubleTy(Context), 1);
549 case MVT::nxv2f64:
550 return ScalableVectorType::get(Type::getDoubleTy(Context), 2);
551 case MVT::nxv4f64:
552 return ScalableVectorType::get(Type::getDoubleTy(Context), 4);
553 case MVT::nxv8f64:
554 return ScalableVectorType::get(Type::getDoubleTy(Context), 8);
555 case MVT::Metadata: return Type::getMetadataTy(Context);
556 }
557 // clang-format on
558 }
559
560 /// Return the value type corresponding to the specified type. This returns all
561 /// pointers as MVT::iPTR. If HandleUnknown is true, unknown types are returned
562 /// as Other, otherwise they are invalid.
getVT(Type * Ty,bool HandleUnknown)563 MVT MVT::getVT(Type *Ty, bool HandleUnknown){
564 switch (Ty->getTypeID()) {
565 default:
566 if (HandleUnknown) return MVT(MVT::Other);
567 llvm_unreachable("Unknown type!");
568 case Type::VoidTyID:
569 return MVT::isVoid;
570 case Type::IntegerTyID:
571 return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
572 case Type::HalfTyID: return MVT(MVT::f16);
573 case Type::BFloatTyID: return MVT(MVT::bf16);
574 case Type::FloatTyID: return MVT(MVT::f32);
575 case Type::DoubleTyID: return MVT(MVT::f64);
576 case Type::X86_FP80TyID: return MVT(MVT::f80);
577 case Type::X86_MMXTyID: return MVT(MVT::x86mmx);
578 case Type::X86_AMXTyID: return MVT(MVT::x86amx);
579 case Type::FP128TyID: return MVT(MVT::f128);
580 case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
581 case Type::PointerTyID: return MVT(MVT::iPTR);
582 case Type::FixedVectorTyID:
583 case Type::ScalableVectorTyID: {
584 VectorType *VTy = cast<VectorType>(Ty);
585 return getVectorVT(
586 getVT(VTy->getElementType(), /*HandleUnknown=*/ false),
587 VTy->getElementCount());
588 }
589 }
590 }
591
592 /// getEVT - Return the value type corresponding to the specified type. This
593 /// returns all pointers as MVT::iPTR. If HandleUnknown is true, unknown types
594 /// are returned as Other, otherwise they are invalid.
getEVT(Type * Ty,bool HandleUnknown)595 EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
596 switch (Ty->getTypeID()) {
597 default:
598 return MVT::getVT(Ty, HandleUnknown);
599 case Type::IntegerTyID:
600 return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
601 case Type::FixedVectorTyID:
602 case Type::ScalableVectorTyID: {
603 VectorType *VTy = cast<VectorType>(Ty);
604 return getVectorVT(Ty->getContext(),
605 getEVT(VTy->getElementType(), /*HandleUnknown=*/ false),
606 VTy->getElementCount());
607 }
608 }
609 }
610