LLVM 24.0.0git
Type.cpp
Go to the documentation of this file.
1//===- Type.cpp - Implement the Type class --------------------------------===//
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// This file implements the Type class for the IR library.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/IR/Type.h"
14#include "LLVMContextImpl.h"
15#include "llvm/ADT/APInt.h"
16#include "llvm/ADT/SetVector.h"
18#include "llvm/ADT/StringMap.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/IR/Constant.h"
21#include "llvm/IR/Constants.h"
23#include "llvm/IR/LLVMContext.h"
24#include "llvm/IR/Value.h"
26#include "llvm/Support/Error.h"
30#include <cassert>
31
32using namespace llvm;
33
34//===----------------------------------------------------------------------===//
35// Type Class Implementation
36//===----------------------------------------------------------------------===//
37
39 switch (IDNumber) {
40 case VoidTyID : return getVoidTy(C);
41 case HalfTyID : return getHalfTy(C);
42 case BFloatTyID : return getBFloatTy(C);
43 case FloatTyID : return getFloatTy(C);
44 case DoubleTyID : return getDoubleTy(C);
45 case X86_FP80TyID : return getX86_FP80Ty(C);
46 case FP128TyID : return getFP128Ty(C);
47 case PPC_FP128TyID : return getPPC_FP128Ty(C);
48 case LabelTyID : return getLabelTy(C);
49 case MetadataTyID : return getMetadataTy(C);
50 case X86_AMXTyID : return getX86_AMXTy(C);
51 case TokenTyID : return getTokenTy(C);
52 default:
53 return nullptr;
54 }
55}
56
57bool Type::isByteTy(unsigned BitWidth) const {
58 return isByteTy() && cast<ByteType>(this)->getBitWidth() == BitWidth;
59}
60
61bool Type::isScalableTy() const {
62 switch (getTypeID()) {
64 return true;
65 case TargetExtTyID:
66 return isScalableTargetExtTy();
67 case ArrayTyID:
68 return cast<ArrayType>(this)->getElementType()->isScalableTy();
69 case StructTyID:
70 return cast<StructType>(this)->isScalableTy();
71 default:
72 return false;
73 }
74}
75
77 if (const auto *ATy = dyn_cast<ArrayType>(this))
78 return ATy->getElementType()->containsNonGlobalTargetExtType();
79 if (const auto *STy = dyn_cast<StructType>(this))
80 return STy->containsNonGlobalTargetExtType();
81 if (auto *TT = dyn_cast<TargetExtType>(this))
82 return !TT->hasProperty(TargetExtType::CanBeGlobal);
83 return false;
84}
85
87 if (const auto *ATy = dyn_cast<ArrayType>(this))
88 return ATy->getElementType()->containsNonLocalTargetExtType();
89 if (const auto *STy = dyn_cast<StructType>(this))
90 return STy->containsNonLocalTargetExtType();
91 if (auto *TT = dyn_cast<TargetExtType>(this))
92 return !TT->hasProperty(TargetExtType::CanBeLocal);
93 return false;
94}
95
97 switch (getTypeID()) {
98 case HalfTyID: return APFloat::IEEEhalf();
99 case BFloatTyID: return APFloat::BFloat();
100 case FloatTyID: return APFloat::IEEEsingle();
101 case DoubleTyID: return APFloat::IEEEdouble();
102 case X86_FP80TyID: return APFloat::x87DoubleExtended();
103 case FP128TyID: return APFloat::IEEEquad();
104 case PPC_FP128TyID: return APFloat::PPCDoubleDouble();
105 default: llvm_unreachable("Invalid floating type");
106 }
107}
108
109bool Type::isScalableTargetExtTy() const {
110 if (auto *TT = dyn_cast<TargetExtType>(this))
111 return isa<ScalableVectorType>(TT->getLayoutType());
112 return false;
113}
114
118 return llvm::Type::getHalfTy(C);
131 default:
132 llvm_unreachable("unhandled float format");
133 }
134}
135
136bool Type::isRISCVVectorTupleTy() const {
137 if (!isTargetExtTy())
138 return false;
139
140 return cast<TargetExtType>(this)->getName() == "riscv.vector.tuple";
141}
142
143bool Type::canLosslesslyBitCastTo(Type *Ty) const {
144 // Identity cast means no change so return true
145 if (this == Ty)
146 return true;
147
148 // They are not convertible unless they are at least first class types
149 if (!this->isFirstClassType() || !Ty->isFirstClassType())
150 return false;
151
152 // Vector -> Vector conversions are always lossless if the two vector types
153 // have the same size, otherwise not.
154 if (isa<VectorType>(this) && isa<VectorType>(Ty))
155 return getPrimitiveSizeInBits() == Ty->getPrimitiveSizeInBits();
156
157 // 8192-bit fixed width vector types can be losslessly converted to x86amx.
158 if (((isa<FixedVectorType>(this)) && Ty->isX86_AMXTy()) &&
159 getPrimitiveSizeInBits().getFixedValue() == 8192)
160 return true;
161 if ((isX86_AMXTy() && isa<FixedVectorType>(Ty)) &&
162 Ty->getPrimitiveSizeInBits().getFixedValue() == 8192)
163 return true;
164
165 // Conservatively assume we can't losslessly convert between pointers with
166 // different address spaces.
167 return false;
168}
169
170bool Type::isEmptyTy() const {
171 if (auto *ATy = dyn_cast<ArrayType>(this)) {
172 unsigned NumElements = ATy->getNumElements();
173 return NumElements == 0 || ATy->getElementType()->isEmptyTy();
174 }
175
176 if (auto *STy = dyn_cast<StructType>(this)) {
177 unsigned NumElements = STy->getNumElements();
178 for (unsigned i = 0; i < NumElements; ++i)
179 if (!STy->getElementType(i)->isEmptyTy())
180 return false;
181 return true;
182 }
183
184 return false;
185}
186
188 switch (getTypeID()) {
189 case Type::HalfTyID:
190 return TypeSize::getFixed(16);
191 case Type::BFloatTyID:
192 return TypeSize::getFixed(16);
193 case Type::FloatTyID:
194 return TypeSize::getFixed(32);
195 case Type::DoubleTyID:
196 return TypeSize::getFixed(64);
197 case Type::X86_FP80TyID:
198 return TypeSize::getFixed(80);
199 case Type::FP128TyID:
200 return TypeSize::getFixed(128);
201 case Type::PPC_FP128TyID:
202 return TypeSize::getFixed(128);
203 case Type::X86_AMXTyID:
204 return TypeSize::getFixed(8192);
205 case Type::ByteTyID:
206 return TypeSize::getFixed(cast<ByteType>(this)->getBitWidth());
207 case Type::IntegerTyID:
208 return TypeSize::getFixed(cast<IntegerType>(this)->getBitWidth());
209 case Type::FixedVectorTyID:
210 case Type::ScalableVectorTyID: {
211 const VectorType *VTy = cast<VectorType>(this);
212 ElementCount EC = VTy->getElementCount();
213 TypeSize ETS = VTy->getElementType()->getPrimitiveSizeInBits();
214 assert(!ETS.isScalable() && "Vector type should have fixed-width elements");
215 return {ETS.getFixedValue() * EC.getKnownMinValue(), EC.isScalable()};
216 }
217 default:
218 return TypeSize::getFixed(0);
219 }
220}
221
222int Type::getFPMantissaWidth() const {
223 if (auto *VTy = dyn_cast<VectorType>(this))
224 return VTy->getElementType()->getFPMantissaWidth();
225 assert(isFloatingPointTy() && "Not a floating point type!");
226 if (getTypeID() == HalfTyID) return 11;
227 if (getTypeID() == BFloatTyID) return 8;
228 if (getTypeID() == FloatTyID) return 24;
229 if (getTypeID() == DoubleTyID) return 53;
230 if (getTypeID() == X86_FP80TyID) return 64;
231 if (getTypeID() == FP128TyID) return 113;
232 assert(getTypeID() == PPC_FP128TyID && "unknown fp type");
233 return -1;
234}
235
236bool Type::isFirstClassType() const {
237 switch (getTypeID()) {
238 default:
239 return true;
240 case FunctionTyID:
241 case VoidTyID:
242 return false;
243 case StructTyID: {
244 auto *ST = cast<StructType>(this);
245 return !ST->isOpaque();
246 }
247 }
248}
249
250bool Type::isSizedDerivedType() const {
251 if (auto *ATy = dyn_cast<ArrayType>(this))
252 return ATy->getElementType()->isSized();
253
254 if (auto *VTy = dyn_cast<VectorType>(this))
255 return VTy->getElementType()->isSized();
256
257 if (auto *TTy = dyn_cast<TargetExtType>(this))
258 return TTy->getLayoutType()->isSized();
259
260 return cast<StructType>(this)->isSized();
261}
262
263//===----------------------------------------------------------------------===//
264// Primitive 'Type' data
265//===----------------------------------------------------------------------===//
266
267Type *Type::getVoidTy(LLVMContext &C) { return &C.pImpl->VoidTy; }
268Type *Type::getLabelTy(LLVMContext &C) { return &C.pImpl->LabelTy; }
269Type *Type::getHalfTy(LLVMContext &C) { return &C.pImpl->HalfTy; }
270Type *Type::getBFloatTy(LLVMContext &C) { return &C.pImpl->BFloatTy; }
271Type *Type::getFloatTy(LLVMContext &C) { return &C.pImpl->FloatTy; }
272Type *Type::getDoubleTy(LLVMContext &C) { return &C.pImpl->DoubleTy; }
273Type *Type::getMetadataTy(LLVMContext &C) { return &C.pImpl->MetadataTy; }
274Type *Type::getTokenTy(LLVMContext &C) { return &C.pImpl->TokenTy; }
275Type *Type::getX86_FP80Ty(LLVMContext &C) { return &C.pImpl->X86_FP80Ty; }
276Type *Type::getFP128Ty(LLVMContext &C) { return &C.pImpl->FP128Ty; }
277Type *Type::getPPC_FP128Ty(LLVMContext &C) { return &C.pImpl->PPC_FP128Ty; }
278Type *Type::getX86_AMXTy(LLVMContext &C) { return &C.pImpl->X86_AMXTy; }
279
280ByteType *Type::getByte1Ty(LLVMContext &C) { return &C.pImpl->Byte1Ty; }
281ByteType *Type::getByte8Ty(LLVMContext &C) { return &C.pImpl->Byte8Ty; }
282ByteType *Type::getByte16Ty(LLVMContext &C) { return &C.pImpl->Byte16Ty; }
283ByteType *Type::getByte32Ty(LLVMContext &C) { return &C.pImpl->Byte32Ty; }
284ByteType *Type::getByte64Ty(LLVMContext &C) { return &C.pImpl->Byte64Ty; }
285ByteType *Type::getByte128Ty(LLVMContext &C) { return &C.pImpl->Byte128Ty; }
286
288 return ByteType::get(C, N);
289}
290
291IntegerType *Type::getInt1Ty(LLVMContext &C) { return &C.pImpl->Int1Ty; }
292IntegerType *Type::getInt8Ty(LLVMContext &C) { return &C.pImpl->Int8Ty; }
293IntegerType *Type::getInt16Ty(LLVMContext &C) { return &C.pImpl->Int16Ty; }
294IntegerType *Type::getInt32Ty(LLVMContext &C) { return &C.pImpl->Int32Ty; }
295IntegerType *Type::getInt64Ty(LLVMContext &C) { return &C.pImpl->Int64Ty; }
296IntegerType *Type::getInt128Ty(LLVMContext &C) { return &C.pImpl->Int128Ty; }
297
299 return IntegerType::get(C, N);
300}
301
302Type *Type::getIntFromByteType(Type *Ty) {
303 assert(Ty->isByteOrByteVectorTy() && "Expected a byte or byte vector type.");
304 unsigned NumBits = Ty->getScalarSizeInBits();
305 IntegerType *IntTy = IntegerType::get(Ty->getContext(), NumBits);
306 if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
307 return VectorType::get(IntTy, VecTy);
308 return IntTy;
309}
310
311Type *Type::getByteFromIntType(Type *Ty) {
312 assert(!Ty->isPtrOrPtrVectorTy() &&
313 "Expected a non-pointer or non-pointer vector type.");
314 unsigned NumBits = Ty->getScalarSizeInBits();
315 ByteType *ByteTy = ByteType::get(Ty->getContext(), NumBits);
316 if (VectorType *VecTy = dyn_cast<VectorType>(Ty))
317 return VectorType::get(ByteTy, VecTy);
318 return ByteTy;
319}
320
322 return TargetExtType::get(C, "wasm.externref", {}, {});
323}
324
326 return TargetExtType::get(C, "wasm.funcref", {}, {});
327}
328
329//===----------------------------------------------------------------------===//
330// IntegerType Implementation
331//===----------------------------------------------------------------------===//
332
333IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) {
334 assert(NumBits >= MIN_INT_BITS && "bitwidth too small");
335 assert(NumBits <= MAX_INT_BITS && "bitwidth too large");
336
337 // Check for the built-in integer types
338 switch (NumBits) {
339 case 1: return Type::getInt1Ty(C);
340 case 8: return Type::getInt8Ty(C);
341 case 16: return Type::getInt16Ty(C);
342 case 32: return Type::getInt32Ty(C);
343 case 64: return Type::getInt64Ty(C);
344 case 128: return Type::getInt128Ty(C);
345 default:
346 break;
347 }
348
349 IntegerType *&Entry = C.pImpl->IntegerTypes[NumBits];
350
351 if (!Entry)
352 Entry = new (C.pImpl->Alloc) IntegerType(C, NumBits);
353
354 return Entry;
355}
356
358
359//===----------------------------------------------------------------------===//
360// ByteType Implementation
361//===----------------------------------------------------------------------===//
362
363ByteType *ByteType::get(LLVMContext &C, unsigned NumBits) {
364 assert(NumBits >= MIN_BYTE_BITS && "bitwidth too small");
365 assert(NumBits <= MAX_BYTE_BITS && "bitwidth too large");
366
367 // Check for the built-in byte types
368 switch (NumBits) {
369 case 8:
370 return Type::getByte8Ty(C);
371 case 16:
372 return Type::getByte16Ty(C);
373 case 32:
374 return Type::getByte32Ty(C);
375 case 64:
376 return Type::getByte64Ty(C);
377 case 128:
378 return Type::getByte128Ty(C);
379 default:
380 break;
381 }
382
383 ByteType *&Entry = C.pImpl->ByteTypes[NumBits];
384
385 if (!Entry)
386 Entry = new (C.pImpl->Alloc) ByteType(C, NumBits);
387
388 return Entry;
389}
390
392
393//===----------------------------------------------------------------------===//
394// FunctionType Implementation
395//===----------------------------------------------------------------------===//
396
398 bool IsVarArgs)
399 : Type(Result->getContext(), FunctionTyID) {
400 Type **SubTys = reinterpret_cast<Type**>(this+1);
401 assert(isValidReturnType(Result) && "invalid return type for function");
402 setSubclassData(IsVarArgs);
403
404 SubTys[0] = Result;
405
406 for (unsigned i = 0, e = Params.size(); i != e; ++i) {
407 assert(isValidArgumentType(Params[i]) &&
408 "Not a valid type for function argument!");
409 SubTys[i+1] = Params[i];
410 }
411
412 ContainedTys = SubTys;
413 NumContainedTys = Params.size() + 1; // + 1 for result type
414}
415
416// This is the factory function for the FunctionType class.
417FunctionType *FunctionType::get(Type *ReturnType,
418 ArrayRef<Type*> Params, bool isVarArg) {
419 LLVMContextImpl *pImpl = ReturnType->getContext().pImpl;
420 const FunctionTypeKeyInfo::KeyTy Key(ReturnType, Params, isVarArg);
421 FunctionType *FT;
422 // Since we only want to allocate a fresh function type in case none is found
423 // and we don't want to perform two lookups (one for checking if existent and
424 // one for inserting the newly allocated one), here we instead lookup based on
425 // Key and update the reference to the function type in-place to a newly
426 // allocated one if not found.
427 auto Insertion = pImpl->FunctionTypes.insert_as(nullptr, Key);
428 if (Insertion.second) {
429 // The function type was not found. Allocate one and update FunctionTypes
430 // in-place.
431 FT = (FunctionType *)pImpl->Alloc.Allocate(
432 sizeof(FunctionType) + sizeof(Type *) * (Params.size() + 1),
433 alignof(FunctionType));
434 new (FT) FunctionType(ReturnType, Params, isVarArg);
435 *Insertion.first = FT;
436 } else {
437 // The function type was found. Just return it.
438 FT = *Insertion.first;
439 }
440 return FT;
441}
442
443FunctionType *FunctionType::get(Type *Result, bool isVarArg) {
444 return get(Result, {}, isVarArg);
445}
446
447bool FunctionType::isValidReturnType(Type *RetTy) {
448 return !RetTy->isFunctionTy() && !RetTy->isLabelTy() &&
449 !RetTy->isMetadataTy();
450}
451
452bool FunctionType::isValidArgumentType(Type *ArgTy) {
453 return ArgTy->isFirstClassType() && !ArgTy->isLabelTy();
454}
455
456//===----------------------------------------------------------------------===//
457// StructType Implementation
458//===----------------------------------------------------------------------===//
459
460// Primitive Constructors.
461
463 bool isPacked) {
464 LLVMContextImpl *pImpl = Context.pImpl;
465 const AnonStructTypeKeyInfo::KeyTy Key(ETypes, isPacked);
466
467 StructType *ST;
468 // Since we only want to allocate a fresh struct type in case none is found
469 // and we don't want to perform two lookups (one for checking if existent and
470 // one for inserting the newly allocated one), here we instead lookup based on
471 // Key and update the reference to the struct type in-place to a newly
472 // allocated one if not found.
473 auto Insertion = pImpl->AnonStructTypes.insert_as(nullptr, Key);
474 if (Insertion.second) {
475 // The struct type was not found. Allocate one and update AnonStructTypes
476 // in-place.
477 ST = new (Context.pImpl->Alloc) StructType(Context);
478 ST->setSubclassData(SCDB_IsLiteral); // Literal struct.
479 ST->setBody(ETypes, isPacked);
480 *Insertion.first = ST;
481 } else {
482 // The struct type was found. Just return it.
483 ST = *Insertion.first;
484 }
485
486 return ST;
487}
488
489bool StructType::isScalableTy() const {
490 if ((getSubclassData() & SCDB_ContainsScalableVector) != 0)
491 return true;
492
493 if ((getSubclassData() & SCDB_NotContainsScalableVector) != 0)
494 return false;
495
496 for (Type *Ty : elements()) {
497 if (Ty->isScalableTy()) {
498 const_cast<StructType *>(this)->setSubclassData(
499 getSubclassData() | SCDB_ContainsScalableVector);
500 return true;
501 }
502 }
503
504 // For structures that are opaque, return false but do not set the
505 // SCDB_NotContainsScalableVector flag since it may gain scalable vector type
506 // when it becomes non-opaque.
507 if (!isOpaque())
508 const_cast<StructType *>(this)->setSubclassData(
509 getSubclassData() | SCDB_NotContainsScalableVector);
510 return false;
511}
512
514 if ((getSubclassData() & SCDB_ContainsNonGlobalTargetExtType) != 0)
515 return true;
516
517 if ((getSubclassData() & SCDB_NotContainsNonGlobalTargetExtType) != 0)
518 return false;
519
520 for (Type *Ty : elements()) {
521 if (Ty->containsNonGlobalTargetExtType()) {
522 const_cast<StructType *>(this)->setSubclassData(
523 getSubclassData() | SCDB_ContainsNonGlobalTargetExtType);
524 return true;
525 }
526 }
527
528 // For structures that are opaque, return false but do not set the
529 // SCDB_NotContainsNonGlobalTargetExtType flag since it may gain non-global
530 // target extension types when it becomes non-opaque.
531 if (!isOpaque())
532 const_cast<StructType *>(this)->setSubclassData(
533 getSubclassData() | SCDB_NotContainsNonGlobalTargetExtType);
534 return false;
535}
536
538 if ((getSubclassData() & SCDB_ContainsNonLocalTargetExtType) != 0)
539 return true;
540
541 if ((getSubclassData() & SCDB_NotContainsNonLocalTargetExtType) != 0)
542 return false;
543
544 for (Type *Ty : elements()) {
545 if (Ty->containsNonLocalTargetExtType()) {
546 const_cast<StructType *>(this)->setSubclassData(
547 getSubclassData() | SCDB_ContainsNonLocalTargetExtType);
548 return true;
549 }
550 }
551
552 // For structures that are opaque, return false but do not set the
553 // SCDB_NotContainsNonLocalTargetExtType flag since it may gain non-local
554 // target extension types when it becomes non-opaque.
555 if (!isOpaque())
556 const_cast<StructType *>(this)->setSubclassData(
557 getSubclassData() | SCDB_NotContainsNonLocalTargetExtType);
558 return false;
559}
560
562 if (getNumElements() <= 0 || !isa<ScalableVectorType>(elements().front()))
563 return false;
564 return containsHomogeneousTypes();
565}
566
568 ArrayRef<Type *> ElementTys = elements();
569 return !ElementTys.empty() && all_equal(ElementTys);
570}
571
572void StructType::setBody(ArrayRef<Type*> Elements, bool isPacked) {
573 cantFail(setBodyOrError(Elements, isPacked));
574}
575
576Error StructType::setBodyOrError(ArrayRef<Type *> Elements, bool isPacked) {
577 assert(isOpaque() && "Struct body already set!");
578
579 if (auto E = checkBody(Elements))
580 return E;
581
582 setSubclassData(getSubclassData() | SCDB_HasBody);
583 if (isPacked)
584 setSubclassData(getSubclassData() | SCDB_Packed);
585
586 NumContainedTys = Elements.size();
587 ContainedTys = Elements.empty()
588 ? nullptr
589 : Elements.copy(getContext().pImpl->Alloc).data();
590
591 return Error::success();
592}
593
595 SmallSetVector<Type *, 4> Worklist(Elements.begin(), Elements.end());
596 for (unsigned I = 0; I < Worklist.size(); ++I) {
597 Type *Ty = Worklist[I];
598 if (Ty == this)
599 return createStringError(Twine("identified structure type '") +
600 getName() + "' is recursive");
601 Worklist.insert_range(Ty->subtypes());
602 }
603 return Error::success();
604}
605
607 if (Name == getName()) return;
608
609 StringMap<StructType *> &SymbolTable = getContext().pImpl->NamedStructTypes;
610
612
613 // If this struct already had a name, remove its symbol table entry. Don't
614 // delete the data yet because it may be part of the new name.
616 SymbolTable.remove((EntryTy *)SymbolTableEntry);
617
618 // If this is just removing the name, we're done.
619 if (Name.empty()) {
620 if (SymbolTableEntry) {
621 // Delete the old string data.
622 ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator());
623 SymbolTableEntry = nullptr;
624 }
625 return;
626 }
627
628 // Look up the entry for the name.
629 auto IterBool =
630 getContext().pImpl->NamedStructTypes.insert(std::make_pair(Name, this));
631
632 // While we have a name collision, try a random rename.
633 if (!IterBool.second) {
634 SmallString<64> TempStr(Name);
635 TempStr.push_back('.');
636 raw_svector_ostream TmpStream(TempStr);
637 unsigned NameSize = Name.size();
638
639 do {
640 TempStr.resize(NameSize + 1);
641 TmpStream << getContext().pImpl->NamedStructTypesUniqueID++;
642
643 IterBool = getContext().pImpl->NamedStructTypes.insert(
644 std::make_pair(TmpStream.str(), this));
645 } while (!IterBool.second);
646 }
647
648 // Delete the old string data.
650 ((EntryTy *)SymbolTableEntry)->Destroy(SymbolTable.getAllocator());
651 SymbolTableEntry = &*IterBool.first;
652}
653
654//===----------------------------------------------------------------------===//
655// StructType Helper functions.
656
658 StructType *ST = new (Context.pImpl->Alloc) StructType(Context);
659 if (!Name.empty())
660 ST->setName(Name);
661 return ST;
662}
663
664StructType *StructType::get(LLVMContext &Context, bool isPacked) {
665 return get(Context, {}, isPacked);
666}
667
669 StringRef Name, bool isPacked) {
670 StructType *ST = create(Context, Name);
671 ST->setBody(Elements, isPacked);
672 return ST;
673}
674
676 return create(Context, Elements, StringRef());
677}
678
680 return create(Context, StringRef());
681}
682
684 bool isPacked) {
685 assert(!Elements.empty() &&
686 "This method may not be invoked with an empty list");
687 return create(Elements[0]->getContext(), Elements, Name, isPacked);
688}
689
691 assert(!Elements.empty() &&
692 "This method may not be invoked with an empty list");
693 return create(Elements[0]->getContext(), Elements, StringRef());
694}
695
696bool StructType::isSized() const {
697 if ((getSubclassData() & SCDB_IsSized) != 0)
698 return true;
699 if (isOpaque())
700 return false;
701
702 // Okay, our struct is sized if all of the elements are, but if one of the
703 // elements is opaque, the struct isn't sized *yet*, but may become sized in
704 // the future, so just bail out without caching.
705 // The ONLY special case inside a struct that is considered sized is when the
706 // elements are homogeneous of a scalable vector type.
707 if (containsHomogeneousScalableVectorTypes()) {
708 const_cast<StructType *>(this)->setSubclassData(getSubclassData() |
709 SCDB_IsSized);
710 return true;
711 }
712 for (Type *Ty : elements()) {
713 // If the struct contains a scalable vector type, don't consider it sized.
714 // This prevents it from being used in loads/stores/allocas/GEPs. The ONLY
715 // special case right now is a structure of homogenous scalable vector
716 // types and is handled by the if-statement before this for-loop.
717 if (Ty->isScalableTy())
718 return false;
719 if (!Ty->isSized())
720 return false;
721 }
722
723 // Here we cheat a bit and cast away const-ness. The goal is to memoize when
724 // we find a sized type, as types can only move from opaque to sized, not the
725 // other way.
726 const_cast<StructType*>(this)->setSubclassData(
727 getSubclassData() | SCDB_IsSized);
728 return true;
729}
730
732 assert(!isLiteral() && "Literal structs never have names");
733 if (!SymbolTableEntry) return StringRef();
734
735 return ((StringMapEntry<StructType*> *)SymbolTableEntry)->getKey();
736}
737
739 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
740 !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() &&
741 !ElemTy->isTokenTy();
742}
743
745 if (this == Other) return true;
746
747 if (isPacked() != Other->isPacked())
748 return false;
749
750 return elements() == Other->elements();
751}
752
753Type *StructType::getTypeAtIndex(const Value *V) const {
754 unsigned Idx = (unsigned)cast<Constant>(V)->getUniqueInteger().getZExtValue();
755 assert(indexValid(Idx) && "Invalid structure index!");
756 return getElementType(Idx);
757}
758
759bool StructType::indexValid(const Value *V) const {
760 // Structure indexes require (vectors of) 32-bit integer constants. In the
761 // vector case all of the indices must be equal.
762 if (!V->getType()->isIntOrIntVectorTy(32))
763 return false;
764 if (isa<ScalableVectorType>(V->getType()))
765 return false;
766 const Constant *C = dyn_cast<Constant>(V);
767 if (C && V->getType()->isVectorTy())
768 C = C->getSplatValue();
770 return CU && CU->getZExtValue() < getNumElements();
771}
772
774 return C.pImpl->NamedStructTypes.lookup(Name);
775}
776
777//===----------------------------------------------------------------------===//
778// ArrayType Implementation
779//===----------------------------------------------------------------------===//
780
781ArrayType::ArrayType(Type *ElType, uint64_t NumEl)
782 : Type(ElType->getContext(), ArrayTyID), ContainedType(ElType),
783 NumElements(NumEl) {
784 ContainedTys = &ContainedType;
785 NumContainedTys = 1;
786}
787
788ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) {
789 assert(isValidElementType(ElementType) && "Invalid type for array element!");
790
791 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
792 ArrayType *&Entry =
793 pImpl->ArrayTypes[std::make_pair(ElementType, NumElements)];
794
795 if (!Entry)
796 Entry = new (pImpl->Alloc) ArrayType(ElementType, NumElements);
797 return Entry;
798}
799
801 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
802 !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy() &&
803 !ElemTy->isTokenTy() && !ElemTy->isX86_AMXTy();
804}
805
806//===----------------------------------------------------------------------===//
807// VectorType Implementation
808//===----------------------------------------------------------------------===//
809
810VectorType::VectorType(Type *ElType, unsigned EQ, Type::TypeID TID)
811 : Type(ElType->getContext(), TID), ContainedType(ElType),
812 ElementQuantity(EQ) {
813 ContainedTys = &ContainedType;
814 NumContainedTys = 1;
815}
816
817VectorType *VectorType::get(Type *ElementType, ElementCount EC) {
818 if (EC.isScalable())
819 return ScalableVectorType::get(ElementType, EC.getKnownMinValue());
820 else
821 return FixedVectorType::get(ElementType, EC.getKnownMinValue());
822}
823
825 if (ElemTy->isIntegerTy() || ElemTy->isFloatingPointTy() ||
826 ElemTy->isPointerTy() || ElemTy->getTypeID() == TypedPointerTyID ||
827 ElemTy->isByteTy())
828 return true;
829 if (auto *TTy = dyn_cast<TargetExtType>(ElemTy))
830 return TTy->hasProperty(TargetExtType::CanBeVectorElement);
831 return false;
832}
833
834//===----------------------------------------------------------------------===//
835// FixedVectorType Implementation
836//===----------------------------------------------------------------------===//
837
838FixedVectorType *FixedVectorType::get(Type *ElementType, unsigned NumElts) {
839 assert(NumElts > 0 && "#Elements of a VectorType must be greater than 0");
840 assert(isValidElementType(ElementType) && "Element type of a VectorType must "
841 "be an integer, floating point, "
842 "pointer type, or a valid target "
843 "extension type.");
844
845 auto EC = ElementCount::getFixed(NumElts);
846
847 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
848 VectorType *&Entry = ElementType->getContext()
849 .pImpl->VectorTypes[std::make_pair(ElementType, EC)];
850
851 if (!Entry)
852 Entry = new (pImpl->Alloc) FixedVectorType(ElementType, NumElts);
853 return cast<FixedVectorType>(Entry);
854}
855
856//===----------------------------------------------------------------------===//
857// ScalableVectorType Implementation
858//===----------------------------------------------------------------------===//
859
861 unsigned MinNumElts) {
862 assert(MinNumElts > 0 && "#Elements of a VectorType must be greater than 0");
863 assert(isValidElementType(ElementType) && "Element type of a VectorType must "
864 "be an integer, floating point, or "
865 "pointer type.");
866
867 auto EC = ElementCount::getScalable(MinNumElts);
868
869 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
870 VectorType *&Entry = ElementType->getContext()
871 .pImpl->VectorTypes[std::make_pair(ElementType, EC)];
872
873 if (!Entry)
874 Entry = new (pImpl->Alloc) ScalableVectorType(ElementType, MinNumElts);
875 return cast<ScalableVectorType>(Entry);
876}
877
878//===----------------------------------------------------------------------===//
879// PointerType Implementation
880//===----------------------------------------------------------------------===//
881
883 LLVMContextImpl *CImpl = C.pImpl;
884
885 // Since AddressSpace #0 is the common case, we special case it.
887 : CImpl->PointerTypes[AddressSpace];
888
889 if (!Entry)
890 Entry = new (CImpl->Alloc) PointerType(C, AddressSpace);
891 return Entry;
892}
893
894PointerType::PointerType(LLVMContext &C, unsigned AddrSpace)
895 : Type(C, PointerTyID) {
896 setSubclassData(AddrSpace);
897}
898
900 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
901 !ElemTy->isMetadataTy() && !ElemTy->isTokenTy() &&
902 !ElemTy->isX86_AMXTy();
903}
904
906 return isValidElementType(ElemTy) && !ElemTy->isFunctionTy();
907}
908
909//===----------------------------------------------------------------------===//
910// TargetExtType Implementation
911//===----------------------------------------------------------------------===//
912
913TargetExtType::TargetExtType(LLVMContext &C, StringRef Name,
915 : Type(C, TargetExtTyID), Name(C.pImpl->Saver.save(Name)) {
916 NumContainedTys = Types.size();
917
918 // Parameter storage immediately follows the class in allocation.
919 Type **Params = reinterpret_cast<Type **>(this + 1);
920 ContainedTys = Params;
921 for (Type *T : Types)
922 *Params++ = T;
923
924 setSubclassData(Ints.size());
925 unsigned *IntParamSpace = reinterpret_cast<unsigned *>(Params);
926 IntParams = IntParamSpace;
927 for (unsigned IntParam : Ints)
928 *IntParamSpace++ = IntParam;
929}
930
932 ArrayRef<Type *> Types,
933 ArrayRef<unsigned> Ints) {
934 return cantFail(getOrError(C, Name, Types, Ints));
935}
936
937Expected<TargetExtType *> TargetExtType::getOrError(LLVMContext &C,
938 StringRef Name,
939 ArrayRef<Type *> Types,
940 ArrayRef<unsigned> Ints) {
941 const TargetExtTypeKeyInfo::KeyTy Key(Name, Types, Ints);
943 // Since we only want to allocate a fresh target type in case none is found
944 // and we don't want to perform two lookups (one for checking if existent and
945 // one for inserting the newly allocated one), here we instead lookup based on
946 // Key and update the reference to the target type in-place to a newly
947 // allocated one if not found.
948 auto [Iter, Inserted] = C.pImpl->TargetExtTypes.insert_as(nullptr, Key);
949 if (Inserted) {
950 // The target type was not found. Allocate one and update TargetExtTypes
951 // in-place.
952 TT = (TargetExtType *)C.pImpl->Alloc.Allocate(
953 sizeof(TargetExtType) + sizeof(Type *) * Types.size() +
954 sizeof(unsigned) * Ints.size(),
955 alignof(TargetExtType));
956 new (TT) TargetExtType(C, Name, Types, Ints);
957 *Iter = TT;
958 return checkParams(TT);
959 }
960
961 // The target type was found. Just return it.
962 return *Iter;
963}
964
965Expected<TargetExtType *> TargetExtType::checkParams(TargetExtType *TTy) {
966 // Opaque types in the AArch64 name space.
967 if (TTy->Name == "aarch64.svcount" &&
968 (TTy->getNumTypeParameters() != 0 || TTy->getNumIntParameters() != 0))
969 return createStringError(
970 "target extension type aarch64.svcount should have no parameters");
971
972 // Opaque types in the RISC-V name space.
973 if (TTy->Name == "riscv.vector.tuple" &&
974 (TTy->getNumTypeParameters() != 1 || TTy->getNumIntParameters() != 1))
975 return createStringError(
976 "target extension type riscv.vector.tuple should have one "
977 "type parameter and one integer parameter");
978
979 // Opaque types in the AMDGPU name space.
980 if (TTy->Name == "amdgcn.named.barrier" &&
981 (TTy->getNumTypeParameters() != 0 || TTy->getNumIntParameters() != 1)) {
982 return createStringError("target extension type amdgcn.named.barrier "
983 "should have no type parameters "
984 "and one integer parameter");
985 }
986 if (TTy->Name == "amdgpu.stridemark" &&
987 (TTy->getNumTypeParameters() != 0 || TTy->getNumIntParameters() > 1)) {
988 return createStringError("target extension type amdgpu.stridemark "
989 "should have no type parameters "
990 "and at most one integer parameter");
991 }
992
993 return TTy;
994}
995
996namespace {
997struct TargetTypeInfo {
998 Type *LayoutType;
999 uint64_t Properties;
1000
1001 template <typename... ArgTys>
1002 TargetTypeInfo(Type *LayoutType, ArgTys... Properties)
1003 : LayoutType(LayoutType), Properties((0 | ... | Properties)) {
1004 assert((!(this->Properties & TargetExtType::CanBeVectorElement) ||
1005 LayoutType->isSized()) &&
1006 "Vector element type must be sized");
1007 }
1008};
1009} // anonymous namespace
1010
1011static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
1012 LLVMContext &C = Ty->getContext();
1013 StringRef Name = Ty->getName();
1014 if (Name == "spirv.Image" || Name == "spirv.SignedImage")
1015 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal,
1017 if (Name == "spirv.Type") {
1018 assert(Ty->getNumIntParameters() == 3 &&
1019 "Wrong number of parameters for spirv.Type");
1020
1021 auto Size = Ty->getIntParameter(1);
1022 auto Alignment = Ty->getIntParameter(2);
1023
1024 llvm::Type *LayoutType = nullptr;
1025 if (Size > 0 && Alignment > 0) {
1026 LayoutType =
1027 ArrayType::get(Type::getIntNTy(C, Alignment), Size * 8 / Alignment);
1028 } else {
1029 // LLVM expects variables that can be allocated to have an alignment and
1030 // size. Default to using a 32-bit int as the layout type if none are
1031 // present.
1032 LayoutType = Type::getInt32Ty(C);
1033 }
1034
1035 return TargetTypeInfo(LayoutType, TargetExtType::CanBeGlobal,
1037 }
1038 if (Name == "spirv.IntegralConstant" || Name == "spirv.Literal")
1039 return TargetTypeInfo(Type::getVoidTy(C));
1040 if (Name == "spirv.Padding")
1041 return TargetTypeInfo(
1042 ArrayType::get(Type::getInt8Ty(C), Ty->getIntParameter(0)),
1044 if (Name.starts_with("spirv.")) {
1045 if (Name.ends_with("TypedPointerType"))
1046 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::HasZeroInit,
1050 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::HasZeroInit,
1053 }
1054
1055 // Opaque types in the AArch64 name space.
1056 if (Name == "aarch64.svcount")
1057 return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16),
1060
1061 // RISC-V vector tuple type. The layout is represented as the type that needs
1062 // the same number of vector registers(VREGS) as this tuple type, represented
1063 // as <vscale x (RVVBitsPerBlock * VREGS / 8) x i8>.
1064 if (Name == "riscv.vector.tuple") {
1065 unsigned TotalNumElts =
1066 std::max(cast<ScalableVectorType>(Ty->getTypeParameter(0))
1067 ->getMinNumElements(),
1069 Ty->getIntParameter(0);
1070 return TargetTypeInfo(
1073 }
1074
1075 // DirectX resources
1076 if (Name == "dx.Padding")
1077 return TargetTypeInfo(
1078 ArrayType::get(Type::getInt8Ty(C), Ty->getIntParameter(0)),
1080 if (Name.starts_with("dx."))
1081 return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal,
1083
1084 // Opaque types in the AMDGPU name space.
1085 // NOTE: If the size of the type is changed, it must be also updated in
1086 // AMDGPUMemoryUtils.h !
1087 if (Name == "amdgcn.named.barrier")
1088 return TargetTypeInfo(Type::getInt8Ty(C), TargetExtType::CanBeGlobal);
1089 if (Name == "amdgpu.stridemark")
1090 return TargetTypeInfo(Type::getVoidTy(C), TargetExtType::IsTokenLike);
1091
1092 // Type used to test vector element target extension property.
1093 // Can be removed once a public target extension type uses CanBeVectorElement.
1094 if (Name == "llvm.test.vectorelement") {
1095 return TargetTypeInfo(Type::getInt32Ty(C), TargetExtType::CanBeLocal,
1097 }
1098
1099 // Opaque types in the WebAssembly name space.
1100 if (Name == "wasm.funcref" || Name == "wasm.externref")
1101 return TargetTypeInfo(PointerType::getUnqual(C), TargetExtType::HasZeroInit,
1104
1105 return TargetTypeInfo(Type::getVoidTy(C));
1106}
1107
1108bool Type::isTokenLikeTy() const {
1109 if (isTokenTy())
1110 return true;
1111 if (auto *TT = dyn_cast<TargetExtType>(this))
1112 return TT->hasProperty(TargetExtType::Property::IsTokenLike);
1113 return false;
1114}
1115
1116Type *TargetExtType::getLayoutType() const {
1117 return getTargetTypeInfo(this).LayoutType;
1118}
1119
1120bool TargetExtType::hasProperty(Property Prop) const {
1121 uint64_t Properties = getTargetTypeInfo(this).Properties;
1122 return (Properties & Prop) == Prop;
1123}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
uint64_t uint64_t
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
static char getTypeID(Type *Ty)
@ FunctionTyID
Functions.
@ ArrayTyID
Arrays.
@ PointerTyID
Pointers.
@ TargetExtTyID
Target extension type.
#define I(x, y, z)
Definition MD5.cpp:57
Type::TypeID TypeID
#define T
const uint64_t BitWidth
static StringRef getName(Value *V)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty)
Definition Type.cpp:1011
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallString class.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
ArrayType(const Node *Base_, Node *Dimension_)
FunctionType(const Node *Ret_, NodeArray Params_, Qualifiers CVQuals_, FunctionRefQual RefQual_, const Node *ExceptionSpec_)
PointerType(const Node *Pointee_)
VectorType(const Node *BaseType_, const Node *Dimension_)
static LLVM_ABI Semantics SemanticsToEnum(const llvm::fltSemantics &Sem)
Definition APFloat.cpp:460
Class for arbitrary precision integers.
Definition APInt.h:78
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
Definition APInt.h:230
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
bool empty() const
Check if the array is empty.
Definition ArrayRef.h:136
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition Type.cpp:800
Class to represent byte types.
static LLVM_ABI ByteType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing a ByteType.
Definition Type.cpp:363
LLVM_ABI APInt getMask() const
For example, this is 0xFF for an 8 bit byte, 0xFFFF for b16, etc.
Definition Type.cpp:391
This is the shared class of boolean and integer constants.
Definition Constants.h:87
static constexpr ElementCount getScalable(ScalarTy MinVal)
Definition TypeSize.h:309
static constexpr ElementCount getFixed(ScalarTy MinVal)
Definition TypeSize.h:306
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Class to represent fixed width SIMD vectors.
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition Type.cpp:838
static LLVM_ABI bool isValidArgumentType(Type *ArgTy)
Return true if the specified type is valid as an argument type.
Definition Type.cpp:452
static LLVM_ABI bool isValidReturnType(Type *RetTy)
Return true if the specified type is valid as a return type.
Definition Type.cpp:447
bool isVarArg() const
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:333
LLVM_ABI APInt getMask() const
For example, this is 0xFF for an 8 bit integer, 0xFFFF for i16, etc.
Definition Type.cpp:357
StructTypeSet AnonStructTypes
DenseMap< std::pair< Type *, uint64_t >, ArrayType * > ArrayTypes
DenseMap< unsigned, PointerType * > PointerTypes
FunctionTypeSet FunctionTypes
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
static LLVM_ABI bool isLoadableOrStorableType(Type *ElemTy)
Return true if we can load or store from a pointer to this type.
Definition Type.cpp:905
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
Definition Type.cpp:882
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition Type.cpp:899
Class to represent scalable SIMD vectors.
static LLVM_ABI ScalableVectorType * get(Type *ElementType, unsigned MinNumElts)
Definition Type.cpp:860
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:346
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:28
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:129
void remove(MapEntryTy *KeyValue)
remove - Remove the specified key/value pair from the map, but do not erase it.
Definition StringMap.h:413
AllocatorTy & getAllocator()
StringMapEntry< ValueTy > MapEntryTy
Definition StringMap.h:133
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Class to represent struct types.
LLVM_ABI bool indexValid(const Value *V) const
Definition Type.cpp:759
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition Type.cpp:462
LLVM_ABI void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type, which must not make the type recursive.
Definition Type.cpp:572
LLVM_ABI bool containsHomogeneousScalableVectorTypes() const
Returns true if this struct contains homogeneous scalable vector types.
Definition Type.cpp:561
LLVM_ABI bool containsNonLocalTargetExtType() const
Return true if this type is or contains a target extension type that disallows being used as a local.
Definition Type.cpp:537
LLVM_ABI bool containsNonGlobalTargetExtType() const
Return true if this type is or contains a target extension type that disallows being used as a global...
Definition Type.cpp:513
LLVM_ABI Error checkBody(ArrayRef< Type * > Elements)
Return an error if the body for an opaque identified type would make it recursive.
Definition Type.cpp:594
LLVM_ABI bool containsHomogeneousTypes() const
Return true if this struct is non-empty and all element types are the same.
Definition Type.cpp:567
static LLVM_ABI StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
Definition Type.cpp:773
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition Type.cpp:657
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition Type.cpp:738
LLVM_ABI void setName(StringRef Name)
Change the name of this type to the specified name, or to a name with a suffix if there is a collisio...
Definition Type.cpp:606
LLVM_ABI bool isLayoutIdentical(StructType *Other) const
Return true if this is layout identical to the specified struct.
Definition Type.cpp:744
LLVM_ABI Error setBodyOrError(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type or return an error if it would make the type recursive.
Definition Type.cpp:576
LLVM_ABI Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
Definition Type.cpp:753
LLVM_ABI bool isScalableTy() const
Returns true if this struct contains a scalable vector.
Definition Type.cpp:489
LLVM_ABI bool isSized() const
isSized - Return true if this is a sized type.
Definition Type.cpp:696
LLVM_ABI StringRef getName() const
Return the name for this struct type if it has an identity.
Definition Type.cpp:731
Symbol info for RuntimeDyld.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
unsigned getNumIntParameters() const
static LLVM_ABI TargetExtType * get(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types={}, ArrayRef< unsigned > Ints={})
Return a target extension type having the specified name and optional type and integer parameters.
Definition Type.cpp:931
unsigned getNumTypeParameters() const
static LLVM_ABI Expected< TargetExtType * > checkParams(TargetExtType *TTy)
Check that a newly created target extension type has the expected number of type parameters and integ...
Definition Type.cpp:965
LLVM_ABI bool hasProperty(Property Prop) const
Returns true if the target extension type contains the given property.
Definition Type.cpp:1120
@ IsTokenLike
In particular, it cannot be used in select and phi instructions.
@ HasZeroInit
zeroinitializer is valid for this target extension type.
@ CanBeVectorElement
This type may be used as an element in a vector.
@ CanBeGlobal
This type may be used as the value type of a global variable.
@ CanBeLocal
This type may be allocated on the stack, either as the allocated type of an alloca instruction or as ...
static LLVM_ABI Expected< TargetExtType * > getOrError(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types={}, ArrayRef< unsigned > Ints={})
Return a target extension type having the specified name and optional type and integer parameters,...
Definition Type.cpp:937
LLVM_ABI Type * getLayoutType() const
Returns an underlying layout type for the target extension type.
Definition Type.cpp:1116
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI ByteType * getByte16Ty(LLVMContext &C)
Definition Type.cpp:282
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:295
static LLVM_ABI Type * getX86_AMXTy(LLVMContext &C)
Definition Type.cpp:278
LLVM_ABI bool isEmptyTy() const
Return true if this type is empty, that is, it has no elements or all of its elements are empty.
Definition Type.cpp:170
bool isByteTy() const
True if this is an instance of ByteType.
Definition Type.h:237
static LLVM_ABI Type * getWasm_ExternrefTy(LLVMContext &C)
Definition Type.cpp:321
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
Definition Type.cpp:273
static LLVM_ABI Type * getTokenTy(LLVMContext &C)
Definition Type.cpp:274
static LLVM_ABI IntegerType * getInt128Ty(LLVMContext &C)
Definition Type.cpp:296
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:294
static LLVM_ABI Type * getPPC_FP128Ty(LLVMContext &C)
Definition Type.cpp:277
static LLVM_ABI Type * getFP128Ty(LLVMContext &C)
Definition Type.cpp:276
static LLVM_ABI Type * getLabelTy(LLVMContext &C)
Definition Type.cpp:268
LLVM_ABI bool isTokenLikeTy() const
Returns true if this is 'token' or a token-like target type.s.
Definition Type.cpp:1108
static LLVM_ABI Type * getByteFromIntType(Type *)
Returns a byte (vector of byte) type with the same size of an integer of the given integer (vector of...
Definition Type.cpp:311
TypeID
Definitions of all of the base types for the Type system.
Definition Type.h:55
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
Definition Type.h:67
@ FunctionTyID
Functions.
Definition Type.h:73
@ ArrayTyID
Arrays.
Definition Type.h:76
@ TypedPointerTyID
Typed pointer used by some GPU targets.
Definition Type.h:79
@ HalfTyID
16-bit floating point type
Definition Type.h:57
@ TargetExtTyID
Target extension type.
Definition Type.h:80
@ VoidTyID
type with no size
Definition Type.h:64
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition Type.h:78
@ LabelTyID
Labels.
Definition Type.h:65
@ FloatTyID
32-bit floating point type
Definition Type.h:59
@ StructTyID
Structures.
Definition Type.h:75
@ BFloatTyID
16-bit floating point type (7-bit significand)
Definition Type.h:58
@ DoubleTyID
64-bit floating point type
Definition Type.h:60
@ X86_FP80TyID
80-bit floating point type (X87)
Definition Type.h:61
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
Definition Type.h:63
@ MetadataTyID
Metadata.
Definition Type.h:66
@ TokenTyID
Tokens.
Definition Type.h:68
@ FP128TyID
128-bit floating point type (112-bit significand)
Definition Type.h:62
static LLVM_ABI ByteType * getByte32Ty(LLVMContext &C)
Definition Type.cpp:283
LLVM_ABI bool canLosslesslyBitCastTo(Type *Ty) const
Return true if this type could be converted with a lossless BitCast to type 'Ty'.
Definition Type.cpp:143
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:267
LLVM_ABI bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
Definition Type.cpp:236
static LLVM_ABI Type * getFloatingPointTy(LLVMContext &C, const fltSemantics &S)
Definition Type.cpp:115
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:292
Type(LLVMContext &C, TypeID tid)
Definition Type.h:95
LLVM_ABI bool isRISCVVectorTupleTy() const
Definition Type.cpp:136
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Definition Type.cpp:187
bool isTargetExtTy() const
Return true if this is a target extension type.
Definition Type.h:205
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Definition Type.cpp:293
static LLVM_ABI Type * getPrimitiveType(LLVMContext &C, TypeID IDNumber)
Return a type based on an identifier.
Definition Type.cpp:38
static LLVM_ABI Type * getIntFromByteType(Type *)
Returns an integer (vector of integer) type with the same size of a byte of the given byte (vector of...
Definition Type.cpp:302
static LLVM_ABI ByteType * getByte8Ty(LLVMContext &C)
Definition Type.cpp:281
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
Definition Type.cpp:291
friend class LLVMContextImpl
Definition Type.h:93
static LLVM_ABI ByteType * getByte128Ty(LLVMContext &C)
Definition Type.cpp:285
static LLVM_ABI ByteType * getByte1Ty(LLVMContext &C)
Definition Type.cpp:280
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition Type.h:186
bool isX86_AMXTy() const
Return true if this is X86 AMX.
Definition Type.h:202
LLVM_ABI bool isScalableTy() const
Return true if this is a type whose size is a known multiple of vscale.
Definition Type.cpp:61
bool isTokenTy() const
Return true if this is 'token'.
Definition Type.h:231
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:298
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:272
static LLVM_ABI Type * getX86_FP80Ty(LLVMContext &C)
Definition Type.cpp:275
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:271
LLVM_ABI int getFPMantissaWidth() const
Return the width of the mantissa of this type.
Definition Type.cpp:222
static LLVM_ABI ByteType * getByteNTy(LLVMContext &C, unsigned N)
Definition Type.cpp:287
LLVM_ABI const fltSemantics & getFltSemantics() const
Definition Type.cpp:96
static LLVM_ABI Type * getWasm_FuncrefTy(LLVMContext &C)
Definition Type.cpp:325
static LLVM_ABI ByteType * getByte64Ty(LLVMContext &C)
Definition Type.cpp:284
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
Definition Type.cpp:270
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Definition Type.cpp:269
LLVM_ABI bool containsNonLocalTargetExtType() const
Return true if this type is or contains a target extension type that disallows being used as a local.
Definition Type.cpp:86
LLVM_ABI bool containsNonGlobalTargetExtType() const
Return true if this type is or contains a target extension type that disallows being used as a global...
Definition Type.cpp:76
LLVM_ABI bool isScalableTargetExtTy() const
Return true if this is a target extension type with a scalable layout.
Definition Type.cpp:109
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
static LLVM_ABI bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
std::pair< iterator, bool > insert_as(const ValueT &V, const LookupKeyT &LookupKey)
Alternative version of insert that uses a different (and possibly less expensive) key type.
Definition DenseSet.h:221
constexpr ScalarTy getFixedValue() const
Definition TypeSize.h:201
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
Definition TypeSize.h:169
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Key
PAL metadata keys.
@ Entry
Definition COFF.h:862
static constexpr unsigned RVVBytesPerBlock
constexpr bool isPacked(const T &...O)
Definition SIDefines.h:343
constexpr size_t NameSize
Definition XCOFF.h:30
ElementType
The element type of an SRV or UAV resource.
Definition DXILABI.h:68
EnumSet< Property > Properties
LLVM_ABI Instruction & front() const
unsigned getNumElements(Type *Ty)
Definition SLPUtils.cpp:117
bool isValidElementType(Type *Ty, bool ReVec)
Predicate for the element types that the SLP vectorizer supports.
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1321
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Other
Any other memory.
Definition ModRef.h:68
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.
Definition STLExtras.h:2182
#define N
#define EQ(a, b)
Definition regexec.c:65