LLVM 19.0.0git
ValueTypes.cpp
Go to the documentation of this file.
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
12#include "llvm/IR/Type.h"
13#include "llvm/Support/Debug.h"
17using namespace llvm;
18
19EVT EVT::changeExtendedTypeToInteger() const {
20 assert(isExtended() && "Type is not extended!");
21 LLVMContext &Context = LLVMTy->getContext();
22 return getIntegerVT(Context, getSizeInBits());
23}
24
25EVT 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());
30}
31
32EVT EVT::changeExtendedVectorElementType(EVT EltVT) const {
33 assert(isExtended() && "Type is not extended!");
34 LLVMContext &Context = LLVMTy->getContext();
35 return getVectorVT(Context, EltVT, getVectorElementCount());
36}
37
38EVT 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;
43}
44
45EVT 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;
52}
53
54EVT 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;
59}
60
61bool EVT::isExtendedFloatingPoint() const {
62 assert(isExtended() && "Type is not extended!");
63 return LLVMTy->isFPOrFPVectorTy();
64}
65
66bool EVT::isExtendedInteger() const {
67 assert(isExtended() && "Type is not extended!");
68 return LLVMTy->isIntOrIntVectorTy();
69}
70
71bool EVT::isExtendedScalarInteger() const {
72 assert(isExtended() && "Type is not extended!");
73 return LLVMTy->isIntegerTy();
74}
75
76bool EVT::isExtendedVector() const {
77 assert(isExtended() && "Type is not extended!");
78 return LLVMTy->isVectorTy();
79}
80
81bool EVT::isExtended16BitVector() const {
82 return isExtendedVector() &&
83 getExtendedSizeInBits() == TypeSize::getFixed(16);
84}
85
86bool EVT::isExtended32BitVector() const {
87 return isExtendedVector() &&
88 getExtendedSizeInBits() == TypeSize::getFixed(32);
89}
90
91bool EVT::isExtended64BitVector() const {
92 return isExtendedVector() &&
93 getExtendedSizeInBits() == TypeSize::getFixed(64);
94}
95
96bool EVT::isExtended128BitVector() const {
97 return isExtendedVector() &&
98 getExtendedSizeInBits() == TypeSize::getFixed(128);
99}
100
101bool EVT::isExtended256BitVector() const {
102 return isExtendedVector() &&
103 getExtendedSizeInBits() == TypeSize::getFixed(256);
104}
105
106bool EVT::isExtended512BitVector() const {
107 return isExtendedVector() &&
108 getExtendedSizeInBits() == TypeSize::getFixed(512);
109}
110
111bool EVT::isExtended1024BitVector() const {
112 return isExtendedVector() &&
113 getExtendedSizeInBits() == TypeSize::getFixed(1024);
114}
115
116bool EVT::isExtended2048BitVector() const {
117 return isExtendedVector() &&
118 getExtendedSizeInBits() == TypeSize::getFixed(2048);
119}
120
121bool EVT::isExtendedFixedLengthVector() const {
122 return isExtendedVector() && isa<FixedVectorType>(LLVMTy);
123}
124
125bool EVT::isExtendedScalableVector() const {
126 return isExtendedVector() && isa<ScalableVectorType>(LLVMTy);
127}
128
129EVT EVT::getExtendedVectorElementType() const {
130 assert(isExtended() && "Type is not extended!");
131 return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());
132}
133
134unsigned EVT::getExtendedVectorNumElements() const {
135 assert(isExtended() && "Type is not extended!");
136 ElementCount EC = cast<VectorType>(LLVMTy)->getElementCount();
137 if (EC.isScalable()) {
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";
142 }
143 return EC.getKnownMinValue();
144}
145
146ElementCount EVT::getExtendedVectorElementCount() const {
147 assert(isExtended() && "Type is not extended!");
148 return cast<VectorType>(LLVMTy)->getElementCount();
149}
150
151TypeSize 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!");
158}
159
160/// getEVTString - This function returns value type as a string, e.g. "i32".
161std::string EVT::getEVTString() const {
162 switch (V.SimpleTy) {
163 default:
164 if (isVector())
165 return (isScalableVector() ? "nxv" : "v") +
166 utostr(getVectorElementCount().getKnownMinValue()) +
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::exnref: return "exnref";
185 case MVT::externref: return "externref";
186 case MVT::aarch64svcount:
187 return "aarch64svcount";
188 case MVT::spirvbuiltin:
189 return "spirvbuiltin";
190 }
191}
192
193#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
194void EVT::dump() const {
195 print(dbgs());
196 dbgs() << "\n";
197}
198#endif
199
200/// getTypeForEVT - This method returns an LLVM type corresponding to the
201/// specified EVT. For integer types, this returns an unsigned type. Note
202/// that this will abort for types that cannot be represented.
204 // clang-format off
205 switch (V.SimpleTy) {
206 default:
207 assert(isExtended() && "Type is not extended!");
208 return LLVMTy;
209 case MVT::isVoid: return Type::getVoidTy(Context);
210 case MVT::i1: return Type::getInt1Ty(Context);
211 case MVT::i2: return Type::getIntNTy(Context, 2);
212 case MVT::i4: return Type::getIntNTy(Context, 4);
213 case MVT::i8: return Type::getInt8Ty(Context);
214 case MVT::i16: return Type::getInt16Ty(Context);
215 case MVT::i32: return Type::getInt32Ty(Context);
216 case MVT::i64: return Type::getInt64Ty(Context);
217 case MVT::i128: return IntegerType::get(Context, 128);
218 case MVT::f16: return Type::getHalfTy(Context);
219 case MVT::bf16: return Type::getBFloatTy(Context);
220 case MVT::f32: return Type::getFloatTy(Context);
221 case MVT::f64: return Type::getDoubleTy(Context);
222 case MVT::f80: return Type::getX86_FP80Ty(Context);
223 case MVT::f128: return Type::getFP128Ty(Context);
224 case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
225 case MVT::x86mmx: return Type::getX86_MMXTy(Context);
226 case MVT::aarch64svcount:
227 return TargetExtType::get(Context, "aarch64.svcount");
228 case MVT::x86amx: return Type::getX86_AMXTy(Context);
229 case MVT::i64x8: return IntegerType::get(Context, 512);
230 case MVT::externref: return Type::getWasm_ExternrefTy(Context);
231 case MVT::funcref: return Type::getWasm_FuncrefTy(Context);
232 case MVT::v1i1:
233 return FixedVectorType::get(Type::getInt1Ty(Context), 1);
234 case MVT::v2i1:
235 return FixedVectorType::get(Type::getInt1Ty(Context), 2);
236 case MVT::v3i1:
237 return FixedVectorType::get(Type::getInt1Ty(Context), 3);
238 case MVT::v4i1:
239 return FixedVectorType::get(Type::getInt1Ty(Context), 4);
240 case MVT::v8i1:
241 return FixedVectorType::get(Type::getInt1Ty(Context), 8);
242 case MVT::v16i1:
243 return FixedVectorType::get(Type::getInt1Ty(Context), 16);
244 case MVT::v32i1:
245 return FixedVectorType::get(Type::getInt1Ty(Context), 32);
246 case MVT::v64i1:
247 return FixedVectorType::get(Type::getInt1Ty(Context), 64);
248 case MVT::v128i1:
249 return FixedVectorType::get(Type::getInt1Ty(Context), 128);
250 case MVT::v256i1:
251 return FixedVectorType::get(Type::getInt1Ty(Context), 256);
252 case MVT::v512i1:
253 return FixedVectorType::get(Type::getInt1Ty(Context), 512);
254 case MVT::v1024i1:
255 return FixedVectorType::get(Type::getInt1Ty(Context), 1024);
256 case MVT::v2048i1:
257 return FixedVectorType::get(Type::getInt1Ty(Context), 2048);
258 case MVT::v128i2:
259 return FixedVectorType::get(Type::getIntNTy(Context, 2), 128);
260 case MVT::v256i2:
261 return FixedVectorType::get(Type::getIntNTy(Context, 2), 256);
262 case MVT::v64i4:
263 return FixedVectorType::get(Type::getIntNTy(Context, 4), 64);
264 case MVT::v128i4:
265 return FixedVectorType::get(Type::getIntNTy(Context, 4), 128);
266 case MVT::v1i8:
267 return FixedVectorType::get(Type::getInt8Ty(Context), 1);
268 case MVT::v2i8:
269 return FixedVectorType::get(Type::getInt8Ty(Context), 2);
270 case MVT::v3i8:
271 return FixedVectorType::get(Type::getInt8Ty(Context), 3);
272 case MVT::v4i8:
273 return FixedVectorType::get(Type::getInt8Ty(Context), 4);
274 case MVT::v8i8:
275 return FixedVectorType::get(Type::getInt8Ty(Context), 8);
276 case MVT::v16i8:
277 return FixedVectorType::get(Type::getInt8Ty(Context), 16);
278 case MVT::v32i8:
279 return FixedVectorType::get(Type::getInt8Ty(Context), 32);
280 case MVT::v64i8:
281 return FixedVectorType::get(Type::getInt8Ty(Context), 64);
282 case MVT::v128i8:
283 return FixedVectorType::get(Type::getInt8Ty(Context), 128);
284 case MVT::v256i8:
285 return FixedVectorType::get(Type::getInt8Ty(Context), 256);
286 case MVT::v512i8:
287 return FixedVectorType::get(Type::getInt8Ty(Context), 512);
288 case MVT::v1024i8:
289 return FixedVectorType::get(Type::getInt8Ty(Context), 1024);
290 case MVT::v1i16:
291 return FixedVectorType::get(Type::getInt16Ty(Context), 1);
292 case MVT::v2i16:
293 return FixedVectorType::get(Type::getInt16Ty(Context), 2);
294 case MVT::v3i16:
295 return FixedVectorType::get(Type::getInt16Ty(Context), 3);
296 case MVT::v4i16:
297 return FixedVectorType::get(Type::getInt16Ty(Context), 4);
298 case MVT::v8i16:
299 return FixedVectorType::get(Type::getInt16Ty(Context), 8);
300 case MVT::v16i16:
301 return FixedVectorType::get(Type::getInt16Ty(Context), 16);
302 case MVT::v32i16:
303 return FixedVectorType::get(Type::getInt16Ty(Context), 32);
304 case MVT::v64i16:
305 return FixedVectorType::get(Type::getInt16Ty(Context), 64);
306 case MVT::v128i16:
307 return FixedVectorType::get(Type::getInt16Ty(Context), 128);
308 case MVT::v256i16:
309 return FixedVectorType::get(Type::getInt16Ty(Context), 256);
310 case MVT::v512i16:
311 return FixedVectorType::get(Type::getInt16Ty(Context), 512);
312 case MVT::v1i32:
313 return FixedVectorType::get(Type::getInt32Ty(Context), 1);
314 case MVT::v2i32:
315 return FixedVectorType::get(Type::getInt32Ty(Context), 2);
316 case MVT::v3i32:
317 return FixedVectorType::get(Type::getInt32Ty(Context), 3);
318 case MVT::v4i32:
319 return FixedVectorType::get(Type::getInt32Ty(Context), 4);
320 case MVT::v5i32:
321 return FixedVectorType::get(Type::getInt32Ty(Context), 5);
322 case MVT::v6i32:
323 return FixedVectorType::get(Type::getInt32Ty(Context), 6);
324 case MVT::v7i32:
325 return FixedVectorType::get(Type::getInt32Ty(Context), 7);
326 case MVT::v8i32:
327 return FixedVectorType::get(Type::getInt32Ty(Context), 8);
328 case MVT::v9i32:
329 return FixedVectorType::get(Type::getInt32Ty(Context), 9);
330 case MVT::v10i32:
331 return FixedVectorType::get(Type::getInt32Ty(Context), 10);
332 case MVT::v11i32:
333 return FixedVectorType::get(Type::getInt32Ty(Context), 11);
334 case MVT::v12i32:
335 return FixedVectorType::get(Type::getInt32Ty(Context), 12);
336 case MVT::v16i32:
337 return FixedVectorType::get(Type::getInt32Ty(Context), 16);
338 case MVT::v32i32:
339 return FixedVectorType::get(Type::getInt32Ty(Context), 32);
340 case MVT::v64i32:
341 return FixedVectorType::get(Type::getInt32Ty(Context), 64);
342 case MVT::v128i32:
343 return FixedVectorType::get(Type::getInt32Ty(Context), 128);
344 case MVT::v256i32:
345 return FixedVectorType::get(Type::getInt32Ty(Context), 256);
346 case MVT::v512i32:
347 return FixedVectorType::get(Type::getInt32Ty(Context), 512);
348 case MVT::v1024i32:
349 return FixedVectorType::get(Type::getInt32Ty(Context), 1024);
350 case MVT::v2048i32:
351 return FixedVectorType::get(Type::getInt32Ty(Context), 2048);
352 case MVT::v1i64:
353 return FixedVectorType::get(Type::getInt64Ty(Context), 1);
354 case MVT::v2i64:
355 return FixedVectorType::get(Type::getInt64Ty(Context), 2);
356 case MVT::v3i64:
357 return FixedVectorType::get(Type::getInt64Ty(Context), 3);
358 case MVT::v4i64:
359 return FixedVectorType::get(Type::getInt64Ty(Context), 4);
360 case MVT::v8i64:
361 return FixedVectorType::get(Type::getInt64Ty(Context), 8);
362 case MVT::v16i64:
363 return FixedVectorType::get(Type::getInt64Ty(Context), 16);
364 case MVT::v32i64:
365 return FixedVectorType::get(Type::getInt64Ty(Context), 32);
366 case MVT::v64i64:
367 return FixedVectorType::get(Type::getInt64Ty(Context), 64);
368 case MVT::v128i64:
369 return FixedVectorType::get(Type::getInt64Ty(Context), 128);
370 case MVT::v256i64:
371 return FixedVectorType::get(Type::getInt64Ty(Context), 256);
372 case MVT::v1i128:
373 return FixedVectorType::get(Type::getInt128Ty(Context), 1);
374 case MVT::v1f16:
375 return FixedVectorType::get(Type::getHalfTy(Context), 1);
376 case MVT::v2f16:
377 return FixedVectorType::get(Type::getHalfTy(Context), 2);
378 case MVT::v3f16:
379 return FixedVectorType::get(Type::getHalfTy(Context), 3);
380 case MVT::v4f16:
381 return FixedVectorType::get(Type::getHalfTy(Context), 4);
382 case MVT::v8f16:
383 return FixedVectorType::get(Type::getHalfTy(Context), 8);
384 case MVT::v16f16:
385 return FixedVectorType::get(Type::getHalfTy(Context), 16);
386 case MVT::v32f16:
387 return FixedVectorType::get(Type::getHalfTy(Context), 32);
388 case MVT::v64f16:
389 return FixedVectorType::get(Type::getHalfTy(Context), 64);
390 case MVT::v128f16:
391 return FixedVectorType::get(Type::getHalfTy(Context), 128);
392 case MVT::v256f16:
393 return FixedVectorType::get(Type::getHalfTy(Context), 256);
394 case MVT::v512f16:
395 return FixedVectorType::get(Type::getHalfTy(Context), 512);
396 case MVT::v2bf16:
397 return FixedVectorType::get(Type::getBFloatTy(Context), 2);
398 case MVT::v3bf16:
399 return FixedVectorType::get(Type::getBFloatTy(Context), 3);
400 case MVT::v4bf16:
401 return FixedVectorType::get(Type::getBFloatTy(Context), 4);
402 case MVT::v8bf16:
403 return FixedVectorType::get(Type::getBFloatTy(Context), 8);
404 case MVT::v16bf16:
405 return FixedVectorType::get(Type::getBFloatTy(Context), 16);
406 case MVT::v32bf16:
407 return FixedVectorType::get(Type::getBFloatTy(Context), 32);
408 case MVT::v64bf16:
409 return FixedVectorType::get(Type::getBFloatTy(Context), 64);
410 case MVT::v128bf16:
411 return FixedVectorType::get(Type::getBFloatTy(Context), 128);
412 case MVT::v1f32:
413 return FixedVectorType::get(Type::getFloatTy(Context), 1);
414 case MVT::v2f32:
415 return FixedVectorType::get(Type::getFloatTy(Context), 2);
416 case MVT::v3f32:
417 return FixedVectorType::get(Type::getFloatTy(Context), 3);
418 case MVT::v4f32:
419 return FixedVectorType::get(Type::getFloatTy(Context), 4);
420 case MVT::v5f32:
421 return FixedVectorType::get(Type::getFloatTy(Context), 5);
422 case MVT::v6f32:
423 return FixedVectorType::get(Type::getFloatTy(Context), 6);
424 case MVT::v7f32:
425 return FixedVectorType::get(Type::getFloatTy(Context), 7);
426 case MVT::v8f32:
427 return FixedVectorType::get(Type::getFloatTy(Context), 8);
428 case MVT::v9f32:
429 return FixedVectorType::get(Type::getFloatTy(Context), 9);
430 case MVT::v10f32:
431 return FixedVectorType::get(Type::getFloatTy(Context), 10);
432 case MVT::v11f32:
433 return FixedVectorType::get(Type::getFloatTy(Context), 11);
434 case MVT::v12f32:
435 return FixedVectorType::get(Type::getFloatTy(Context), 12);
436 case MVT::v16f32:
437 return FixedVectorType::get(Type::getFloatTy(Context), 16);
438 case MVT::v32f32:
439 return FixedVectorType::get(Type::getFloatTy(Context), 32);
440 case MVT::v64f32:
441 return FixedVectorType::get(Type::getFloatTy(Context), 64);
442 case MVT::v128f32:
443 return FixedVectorType::get(Type::getFloatTy(Context), 128);
444 case MVT::v256f32:
445 return FixedVectorType::get(Type::getFloatTy(Context), 256);
446 case MVT::v512f32:
447 return FixedVectorType::get(Type::getFloatTy(Context), 512);
448 case MVT::v1024f32:
449 return FixedVectorType::get(Type::getFloatTy(Context), 1024);
450 case MVT::v2048f32:
451 return FixedVectorType::get(Type::getFloatTy(Context), 2048);
452 case MVT::v1f64:
453 return FixedVectorType::get(Type::getDoubleTy(Context), 1);
454 case MVT::v2f64:
455 return FixedVectorType::get(Type::getDoubleTy(Context), 2);
456 case MVT::v3f64:
457 return FixedVectorType::get(Type::getDoubleTy(Context), 3);
458 case MVT::v4f64:
459 return FixedVectorType::get(Type::getDoubleTy(Context), 4);
460 case MVT::v8f64:
461 return FixedVectorType::get(Type::getDoubleTy(Context), 8);
462 case MVT::v16f64:
463 return FixedVectorType::get(Type::getDoubleTy(Context), 16);
464 case MVT::v32f64:
465 return FixedVectorType::get(Type::getDoubleTy(Context), 32);
466 case MVT::v64f64:
467 return FixedVectorType::get(Type::getDoubleTy(Context), 64);
468 case MVT::v128f64:
469 return FixedVectorType::get(Type::getDoubleTy(Context), 128);
470 case MVT::v256f64:
471 return FixedVectorType::get(Type::getDoubleTy(Context), 256);
472 case MVT::nxv1i1:
473 return ScalableVectorType::get(Type::getInt1Ty(Context), 1);
474 case MVT::nxv2i1:
475 return ScalableVectorType::get(Type::getInt1Ty(Context), 2);
476 case MVT::nxv4i1:
477 return ScalableVectorType::get(Type::getInt1Ty(Context), 4);
478 case MVT::nxv8i1:
479 return ScalableVectorType::get(Type::getInt1Ty(Context), 8);
480 case MVT::nxv16i1:
481 return ScalableVectorType::get(Type::getInt1Ty(Context), 16);
482 case MVT::nxv32i1:
483 return ScalableVectorType::get(Type::getInt1Ty(Context), 32);
484 case MVT::nxv64i1:
485 return ScalableVectorType::get(Type::getInt1Ty(Context), 64);
486 case MVT::nxv1i8:
487 return ScalableVectorType::get(Type::getInt8Ty(Context), 1);
488 case MVT::nxv2i8:
489 return ScalableVectorType::get(Type::getInt8Ty(Context), 2);
490 case MVT::nxv4i8:
491 return ScalableVectorType::get(Type::getInt8Ty(Context), 4);
492 case MVT::nxv8i8:
493 return ScalableVectorType::get(Type::getInt8Ty(Context), 8);
494 case MVT::nxv16i8:
495 return ScalableVectorType::get(Type::getInt8Ty(Context), 16);
496 case MVT::nxv32i8:
497 return ScalableVectorType::get(Type::getInt8Ty(Context), 32);
498 case MVT::nxv64i8:
499 return ScalableVectorType::get(Type::getInt8Ty(Context), 64);
500 case MVT::nxv1i16:
501 return ScalableVectorType::get(Type::getInt16Ty(Context), 1);
502 case MVT::nxv2i16:
503 return ScalableVectorType::get(Type::getInt16Ty(Context), 2);
504 case MVT::nxv4i16:
505 return ScalableVectorType::get(Type::getInt16Ty(Context), 4);
506 case MVT::nxv8i16:
507 return ScalableVectorType::get(Type::getInt16Ty(Context), 8);
508 case MVT::nxv16i16:
509 return ScalableVectorType::get(Type::getInt16Ty(Context), 16);
510 case MVT::nxv32i16:
511 return ScalableVectorType::get(Type::getInt16Ty(Context), 32);
512 case MVT::nxv1i32:
513 return ScalableVectorType::get(Type::getInt32Ty(Context), 1);
514 case MVT::nxv2i32:
515 return ScalableVectorType::get(Type::getInt32Ty(Context), 2);
516 case MVT::nxv4i32:
517 return ScalableVectorType::get(Type::getInt32Ty(Context), 4);
518 case MVT::nxv8i32:
519 return ScalableVectorType::get(Type::getInt32Ty(Context), 8);
520 case MVT::nxv16i32:
521 return ScalableVectorType::get(Type::getInt32Ty(Context), 16);
522 case MVT::nxv32i32:
523 return ScalableVectorType::get(Type::getInt32Ty(Context), 32);
524 case MVT::nxv1i64:
525 return ScalableVectorType::get(Type::getInt64Ty(Context), 1);
526 case MVT::nxv2i64:
527 return ScalableVectorType::get(Type::getInt64Ty(Context), 2);
528 case MVT::nxv4i64:
529 return ScalableVectorType::get(Type::getInt64Ty(Context), 4);
530 case MVT::nxv8i64:
531 return ScalableVectorType::get(Type::getInt64Ty(Context), 8);
532 case MVT::nxv16i64:
533 return ScalableVectorType::get(Type::getInt64Ty(Context), 16);
534 case MVT::nxv32i64:
535 return ScalableVectorType::get(Type::getInt64Ty(Context), 32);
536 case MVT::nxv1f16:
537 return ScalableVectorType::get(Type::getHalfTy(Context), 1);
538 case MVT::nxv2f16:
539 return ScalableVectorType::get(Type::getHalfTy(Context), 2);
540 case MVT::nxv4f16:
541 return ScalableVectorType::get(Type::getHalfTy(Context), 4);
542 case MVT::nxv8f16:
543 return ScalableVectorType::get(Type::getHalfTy(Context), 8);
544 case MVT::nxv16f16:
545 return ScalableVectorType::get(Type::getHalfTy(Context), 16);
546 case MVT::nxv32f16:
547 return ScalableVectorType::get(Type::getHalfTy(Context), 32);
548 case MVT::nxv1bf16:
549 return ScalableVectorType::get(Type::getBFloatTy(Context), 1);
550 case MVT::nxv2bf16:
551 return ScalableVectorType::get(Type::getBFloatTy(Context), 2);
552 case MVT::nxv4bf16:
553 return ScalableVectorType::get(Type::getBFloatTy(Context), 4);
554 case MVT::nxv8bf16:
555 return ScalableVectorType::get(Type::getBFloatTy(Context), 8);
556 case MVT::nxv16bf16:
557 return ScalableVectorType::get(Type::getBFloatTy(Context), 16);
558 case MVT::nxv32bf16:
559 return ScalableVectorType::get(Type::getBFloatTy(Context), 32);
560 case MVT::nxv1f32:
561 return ScalableVectorType::get(Type::getFloatTy(Context), 1);
562 case MVT::nxv2f32:
563 return ScalableVectorType::get(Type::getFloatTy(Context), 2);
564 case MVT::nxv4f32:
565 return ScalableVectorType::get(Type::getFloatTy(Context), 4);
566 case MVT::nxv8f32:
567 return ScalableVectorType::get(Type::getFloatTy(Context), 8);
568 case MVT::nxv16f32:
569 return ScalableVectorType::get(Type::getFloatTy(Context), 16);
570 case MVT::nxv1f64:
571 return ScalableVectorType::get(Type::getDoubleTy(Context), 1);
572 case MVT::nxv2f64:
573 return ScalableVectorType::get(Type::getDoubleTy(Context), 2);
574 case MVT::nxv4f64:
575 return ScalableVectorType::get(Type::getDoubleTy(Context), 4);
576 case MVT::nxv8f64:
577 return ScalableVectorType::get(Type::getDoubleTy(Context), 8);
578 case MVT::Metadata: return Type::getMetadataTy(Context);
579 }
580 // clang-format on
581}
582
583/// Return the value type corresponding to the specified type.
584/// If HandleUnknown is true, unknown types are returned as Other, otherwise
585/// they are invalid.
586/// NB: This includes pointer types, which require a DataLayout to convert
587/// to a concrete value type.
588MVT MVT::getVT(Type *Ty, bool HandleUnknown){
589 assert(Ty != nullptr && "Invalid type");
590 switch (Ty->getTypeID()) {
591 default:
592 if (HandleUnknown) return MVT(MVT::Other);
593 llvm_unreachable("Unknown type!");
594 case Type::VoidTyID:
595 return MVT::isVoid;
597 return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
598 case Type::HalfTyID: return MVT(MVT::f16);
599 case Type::BFloatTyID: return MVT(MVT::bf16);
600 case Type::FloatTyID: return MVT(MVT::f32);
601 case Type::DoubleTyID: return MVT(MVT::f64);
602 case Type::X86_FP80TyID: return MVT(MVT::f80);
603 case Type::X86_MMXTyID: return MVT(MVT::x86mmx);
604 case Type::TargetExtTyID: {
605 TargetExtType *TargetExtTy = cast<TargetExtType>(Ty);
606 if (TargetExtTy->getName() == "aarch64.svcount")
607 return MVT(MVT::aarch64svcount);
608 else if (TargetExtTy->getName().starts_with("spirv."))
609 return MVT(MVT::spirvbuiltin);
610 if (HandleUnknown)
611 return MVT(MVT::Other);
612 llvm_unreachable("Unknown target ext type!");
613 }
614 case Type::X86_AMXTyID: return MVT(MVT::x86amx);
615 case Type::FP128TyID: return MVT(MVT::f128);
616 case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
619 VectorType *VTy = cast<VectorType>(Ty);
620 return getVectorVT(
621 getVT(VTy->getElementType(), /*HandleUnknown=*/ false),
622 VTy->getElementCount());
623 }
624 }
625}
626
627/// getEVT - Return the value type corresponding to the specified type.
628/// If HandleUnknown is true, unknown types are returned as Other, otherwise
629/// they are invalid.
630/// NB: This includes pointer types, which require a DataLayout to convert
631/// to a concrete value type.
632EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
633 switch (Ty->getTypeID()) {
634 default:
635 return MVT::getVT(Ty, HandleUnknown);
636 case Type::TokenTyID:
637 return MVT::Untyped;
639 return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
642 VectorType *VTy = cast<VectorType>(Ty);
643 return getVectorVT(Ty->getContext(),
644 getEVT(VTy->getElementType(), /*HandleUnknown=*/ false),
645 VTy->getElementCount());
646 }
647 }
648}
649
650#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
651void MVT::dump() const {
652 print(dbgs());
653 dbgs() << "\n";
654}
655#endif
656
659 OS << "invalid";
660 else
661 OS << EVT(*this).getEVTString();
662}
663
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This file contains some functions that are useful when dealing with strings.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition: Type.cpp:692
Class to represent integer types.
Definition: DerivedTypes.h:40
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:278
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Machine Value Type.
void dump() const
Support for debugging, callable in GDB: VT.dump()
Definition: ValueTypes.cpp:651
SimpleValueType SimpleTy
@ INVALID_SIMPLE_VALUE_TYPE
constexpr MVT()=default
static MVT getVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
Definition: ValueTypes.cpp:588
static MVT getVectorVT(MVT VT, unsigned NumElements)
static MVT getIntegerVT(unsigned BitWidth)
void print(raw_ostream &OS) const
Implement operator<<.
Definition: ValueTypes.cpp:657
static ScalableVectorType * get(Type *ElementType, unsigned MinNumElts)
Definition: Type.cpp:713
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:258
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Definition: DerivedTypes.h:720
static TargetExtType * get(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types=std::nullopt, ArrayRef< unsigned > Ints=std::nullopt)
Return a target extension type having the specified name and optional type and integer parameters.
Definition: Type.cpp:796
StringRef getName() const
Return the name for this target extension type.
Definition: DerivedTypes.h:741
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition: TypeSize.h:342
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static Type * getHalfTy(LLVMContext &C)
static Type * getDoubleTy(LLVMContext &C)
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:265
static Type * getX86_FP80Ty(LLVMContext &C)
static Type * getBFloatTy(LLVMContext &C)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:234
static IntegerType * getInt1Ty(LLVMContext &C)
static Type * getX86_AMXTy(LLVMContext &C)
static Type * getMetadataTy(LLVMContext &C)
@ X86_MMXTyID
MMX vectors (64 bits, X86 specific)
Definition: Type.h:66
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition: Type.h:67
@ HalfTyID
16-bit floating point type
Definition: Type.h:56
@ TargetExtTyID
Target extension type.
Definition: Type.h:79
@ VoidTyID
type with no size
Definition: Type.h:63
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition: Type.h:77
@ FloatTyID
32-bit floating point type
Definition: Type.h:58
@ IntegerTyID
Arbitrary bit width integers.
Definition: Type.h:71
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition: Type.h:76
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition: Type.h:57
@ DoubleTyID
64-bit floating point type
Definition: Type.h:59
@ X86_FP80TyID
80-bit floating point type (X87)
Definition: Type.h:60
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
@ TokenTyID
Tokens.
Definition: Type.h:68
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition: Type.h:61
static Type * getX86_MMXTy(LLVMContext &C)
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
static Type * getVoidTy(LLVMContext &C)
static Type * getFP128Ty(LLVMContext &C)
static IntegerType * getInt16Ty(LLVMContext &C)
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:129
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt128Ty(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
static Type * getFloatTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:228
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:137
static Type * getWasm_FuncrefTy(LLVMContext &C)
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition: Type.h:216
static Type * getPPC_FP128Ty(LLVMContext &C)
static Type * getWasm_ExternrefTy(LLVMContext &C)
Base class of all SIMD vector types.
Definition: DerivedTypes.h:403
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Definition: DerivedTypes.h:641
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:676
Type * getElementType() const
Definition: DerivedTypes.h:436
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
Definition: WithColor.cpp:85
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:191
Extended Value Type.
Definition: ValueTypes.h:34
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
Definition: ValueTypes.h:73
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition: ValueTypes.h:146
ElementCount getVectorElementCount() const
Definition: ValueTypes.h:340
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:358
uint64_t getScalarSizeInBits() const
Definition: ValueTypes.h:370
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
Definition: ValueTypes.cpp:632
void dump() const
Support for debugging, callable in GDB: VT.dump()
Definition: ValueTypes.cpp:194
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
Definition: ValueTypes.h:64
std::string getEVTString() const
This function returns value type as a string, e.g. "i32".
Definition: ValueTypes.cpp:161
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:167
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Definition: ValueTypes.cpp:203
bool isScalableVector() const
Return true if this is a vector type where the runtime length is machine dependent.
Definition: ValueTypes.h:173
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:318
bool isExtended() const
Test if the given EVT is extended (as opposed to being simple).
Definition: ValueTypes.h:141
void print(raw_ostream &OS) const
Implement operator<<.
Definition: ValueTypes.h:481
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:151