41 case VoidTyID :
return getVoidTy(
C);
42 case HalfTyID :
return getHalfTy(
C);
43 case BFloatTyID :
return getBFloatTy(
C);
46 case X86_FP80TyID :
return getX86_FP80Ty(
C);
47 case FP128TyID :
return getFP128Ty(
C);
48 case PPC_FP128TyID :
return getPPC_FP128Ty(
C);
49 case LabelTyID :
return getLabelTy(
C);
50 case MetadataTyID :
return getMetadataTy(
C);
51 case X86_AMXTyID :
return getX86_AMXTy(
C);
52 case TokenTyID :
return getTokenTy(
C);
58bool Type::isIntegerTy(
unsigned Bitwidth)
const {
59 return isIntegerTy() && cast<IntegerType>(
this)->getBitWidth() == Bitwidth;
63 if (
const auto *ATy = dyn_cast<ArrayType>(
this))
64 return ATy->getElementType()->isScalableTy(Visited);
65 if (
const auto *STy = dyn_cast<StructType>(
this))
66 return STy->isScalableTy(Visited);
67 return getTypeID() == ScalableVectorTyID || isScalableTargetExtTy();
70bool Type::isScalableTy()
const {
72 return isScalableTy(Visited);
75bool Type::containsNonGlobalTargetExtType(
77 if (
const auto *ATy = dyn_cast<ArrayType>(
this))
78 return ATy->getElementType()->containsNonGlobalTargetExtType(Visited);
79 if (
const auto *STy = dyn_cast<StructType>(
this))
80 return STy->containsNonGlobalTargetExtType(Visited);
81 if (
auto *TT = dyn_cast<TargetExtType>(
this))
82 return !
TT->hasProperty(TargetExtType::CanBeGlobal);
86bool Type::containsNonGlobalTargetExtType()
const {
88 return containsNonGlobalTargetExtType(Visited);
91bool Type::containsNonLocalTargetExtType(
93 if (
const auto *ATy = dyn_cast<ArrayType>(
this))
94 return ATy->getElementType()->containsNonLocalTargetExtType(Visited);
95 if (
const auto *STy = dyn_cast<StructType>(
this))
96 return STy->containsNonLocalTargetExtType(Visited);
97 if (
auto *TT = dyn_cast<TargetExtType>(
this))
98 return !
TT->hasProperty(TargetExtType::CanBeLocal);
102bool Type::containsNonLocalTargetExtType()
const {
104 return containsNonLocalTargetExtType(Visited);
109 case HalfTyID:
return APFloat::IEEEhalf();
110 case BFloatTyID:
return APFloat::BFloat();
111 case FloatTyID:
return APFloat::IEEEsingle();
112 case DoubleTyID:
return APFloat::IEEEdouble();
113 case X86_FP80TyID:
return APFloat::x87DoubleExtended();
114 case FP128TyID:
return APFloat::IEEEquad();
115 case PPC_FP128TyID:
return APFloat::PPCDoubleDouble();
120bool Type::isIEEE()
const {
124bool Type::isScalableTargetExtTy()
const {
125 if (
auto *TT = dyn_cast<TargetExtType>(
this))
126 return isa<ScalableVectorType>(
TT->getLayoutType());
132 if (&S == &APFloat::IEEEhalf())
133 Ty = Type::getHalfTy(
C);
134 else if (&S == &APFloat::BFloat())
135 Ty = Type::getBFloatTy(
C);
136 else if (&S == &APFloat::IEEEsingle())
137 Ty = Type::getFloatTy(
C);
138 else if (&S == &APFloat::IEEEdouble())
139 Ty = Type::getDoubleTy(
C);
140 else if (&S == &APFloat::x87DoubleExtended())
141 Ty = Type::getX86_FP80Ty(
C);
142 else if (&S == &APFloat::IEEEquad())
143 Ty = Type::getFP128Ty(
C);
145 assert(&S == &APFloat::PPCDoubleDouble() &&
"Unknown FP format");
146 Ty = Type::getPPC_FP128Ty(
C);
151bool Type::isRISCVVectorTupleTy()
const {
152 if (!isTargetExtTy())
155 return cast<TargetExtType>(
this)->getName() ==
"riscv.vector.tuple";
158bool Type::canLosslesslyBitCastTo(
Type *Ty)
const {
169 if (isa<VectorType>(
this) && isa<VectorType>(Ty))
173 if (((isa<FixedVectorType>(
this)) && Ty->
isX86_AMXTy()) &&
174 getPrimitiveSizeInBits().getFixedValue() == 8192)
176 if ((isX86_AMXTy() && isa<FixedVectorType>(Ty)) &&
185bool Type::isEmptyTy()
const {
186 if (
auto *ATy = dyn_cast<ArrayType>(
this)) {
187 unsigned NumElements = ATy->getNumElements();
188 return NumElements == 0 || ATy->getElementType()->isEmptyTy();
191 if (
auto *STy = dyn_cast<StructType>(
this)) {
192 unsigned NumElements = STy->getNumElements();
193 for (
unsigned i = 0; i < NumElements; ++i)
194 if (!STy->getElementType(i)->isEmptyTy())
202TypeSize Type::getPrimitiveSizeInBits()
const {
205 return TypeSize::getFixed(16);
206 case Type::BFloatTyID:
207 return TypeSize::getFixed(16);
208 case Type::FloatTyID:
209 return TypeSize::getFixed(32);
210 case Type::DoubleTyID:
211 return TypeSize::getFixed(64);
212 case Type::X86_FP80TyID:
213 return TypeSize::getFixed(80);
214 case Type::FP128TyID:
215 return TypeSize::getFixed(128);
216 case Type::PPC_FP128TyID:
217 return TypeSize::getFixed(128);
218 case Type::X86_AMXTyID:
219 return TypeSize::getFixed(8192);
220 case Type::IntegerTyID:
221 return TypeSize::getFixed(cast<IntegerType>(
this)->
getBitWidth());
222 case Type::FixedVectorTyID:
223 case Type::ScalableVectorTyID: {
224 const VectorType *VTy = cast<VectorType>(
this);
226 TypeSize ETS = VTy->getElementType()->getPrimitiveSizeInBits();
227 assert(!ETS.
isScalable() &&
"Vector type should have fixed-width elements");
231 return TypeSize::getFixed(0);
235unsigned Type::getScalarSizeInBits()
const {
237 return getScalarType()->getPrimitiveSizeInBits().getFixedValue();
240int Type::getFPMantissaWidth()
const {
241 if (
auto *VTy = dyn_cast<VectorType>(
this))
242 return VTy->getElementType()->getFPMantissaWidth();
243 assert(isFloatingPointTy() &&
"Not a floating point type!");
248 if (
getTypeID() == X86_FP80TyID)
return 64;
249 if (
getTypeID() == FP128TyID)
return 113;
255 if (
auto *ATy = dyn_cast<ArrayType>(
this))
256 return ATy->getElementType()->isSized(Visited);
258 if (
auto *VTy = dyn_cast<VectorType>(
this))
259 return VTy->getElementType()->isSized(Visited);
261 if (
auto *TTy = dyn_cast<TargetExtType>(
this))
262 return TTy->getLayoutType()->isSized(Visited);
264 return cast<StructType>(
this)->isSized(Visited);
292 return IntegerType::get(
C,
N);
312 assert(NumBits >= MIN_INT_BITS &&
"bitwidth too small");
313 assert(NumBits <= MAX_INT_BITS &&
"bitwidth too large");
317 case 1:
return cast<IntegerType>(Type::getInt1Ty(
C));
318 case 8:
return cast<IntegerType>(Type::getInt8Ty(
C));
319 case 16:
return cast<IntegerType>(Type::getInt16Ty(
C));
320 case 32:
return cast<IntegerType>(Type::getInt32Ty(
C));
321 case 64:
return cast<IntegerType>(Type::getInt64Ty(
C));
322 case 128:
return cast<IntegerType>(Type::getInt128Ty(
C));
335APInt IntegerType::getMask()
const {
return APInt::getAllOnes(
getBitWidth()); }
344 Type **SubTys =
reinterpret_cast<Type**
>(
this+1);
345 assert(isValidReturnType(Result) &&
"invalid return type for function");
346 setSubclassData(IsVarArgs);
350 for (
unsigned i = 0, e = Params.
size(); i != e; ++i) {
351 assert(isValidArgumentType(Params[i]) &&
352 "Not a valid type for function argument!");
353 SubTys[i+1] = Params[i];
356 ContainedTys = SubTys;
357 NumContainedTys = Params.
size() + 1;
372 if (Insertion.second) {
379 *Insertion.first = FT;
382 FT = *Insertion.first;
388 return get(Result, {}, isVarArg);
391bool FunctionType::isValidReturnType(
Type *
RetTy) {
392 return !
RetTy->isFunctionTy() && !
RetTy->isLabelTy() &&
393 !
RetTy->isMetadataTy();
396bool FunctionType::isValidArgumentType(
Type *ArgTy) {
418 if (Insertion.second) {
422 ST->setSubclassData(SCDB_IsLiteral);
423 ST->setBody(ETypes, isPacked);
424 *Insertion.first =
ST;
427 ST = *Insertion.first;
434 if ((getSubclassData() & SCDB_ContainsScalableVector) != 0)
437 if ((getSubclassData() & SCDB_NotContainsScalableVector) != 0)
440 if (!Visited.
insert(
this).second)
443 for (
Type *Ty : elements()) {
445 const_cast<StructType *
>(
this)->setSubclassData(
446 getSubclassData() | SCDB_ContainsScalableVector);
456 getSubclassData() | SCDB_NotContainsScalableVector);
460bool StructType::containsNonGlobalTargetExtType(
462 if ((getSubclassData() & SCDB_ContainsNonGlobalTargetExtType) != 0)
465 if ((getSubclassData() & SCDB_NotContainsNonGlobalTargetExtType) != 0)
468 if (!Visited.
insert(
this).second)
471 for (
Type *Ty : elements()) {
473 const_cast<StructType *
>(
this)->setSubclassData(
474 getSubclassData() | SCDB_ContainsNonGlobalTargetExtType);
484 getSubclassData() | SCDB_NotContainsNonGlobalTargetExtType);
488bool StructType::containsNonLocalTargetExtType(
490 if ((getSubclassData() & SCDB_ContainsNonLocalTargetExtType) != 0)
493 if ((getSubclassData() & SCDB_NotContainsNonLocalTargetExtType) != 0)
496 if (!Visited.
insert(
this).second)
499 for (
Type *Ty : elements()) {
501 const_cast<StructType *
>(
this)->setSubclassData(
502 getSubclassData() | SCDB_ContainsNonLocalTargetExtType);
512 getSubclassData() | SCDB_NotContainsNonLocalTargetExtType);
516bool StructType::containsHomogeneousScalableVectorTypes()
const {
517 if (
getNumElements() <= 0 || !isa<ScalableVectorType>(elements().front()))
519 return containsHomogeneousTypes();
522bool StructType::containsHomogeneousTypes()
const {
528 cantFail(setBodyOrError(Elements, isPacked));
532 assert(isOpaque() &&
"Struct body already set!");
534 if (
auto E = checkBody(Elements))
537 setSubclassData(getSubclassData() | SCDB_HasBody);
539 setSubclassData(getSubclassData() | SCDB_Packed);
546 return Error::success();
551 for (
unsigned I = 0;
I < Worklist.size(); ++
I) {
552 Type *Ty = Worklist[
I];
558 return Error::success();
585 getContext().pImpl->NamedStructTypes.insert(std::make_pair(
Name,
this));
588 if (!IterBool.second) {
590 TempStr.push_back(
'.');
595 TempStr.resize(NameSize + 1);
596 TmpStream << getContext().pImpl->NamedStructTypesUniqueID++;
598 IterBool = getContext().pImpl->NamedStructTypes.insert(
599 std::make_pair(TmpStream.str(),
this));
600 }
while (!IterBool.second);
620 return get(Context, {}, isPacked);
626 ST->setBody(Elements, isPacked);
631 return create(Context, Elements,
StringRef());
641 "This method may not be invoked with an empty list");
642 return create(Elements[0]->getContext(), Elements,
Name, isPacked);
647 "This method may not be invoked with an empty list");
648 return create(Elements[0]->getContext(), Elements,
StringRef());
652 if ((getSubclassData() & SCDB_IsSized) != 0)
665 if (containsHomogeneousScalableVectorTypes()) {
666 const_cast<StructType *
>(
this)->setSubclassData(getSubclassData() |
670 for (
Type *Ty : elements()) {
684 const_cast<StructType*
>(
this)->setSubclassData(
685 getSubclassData() | SCDB_IsSized);
690 assert(!isLiteral() &&
"Literal structs never have names");
696bool StructType::isValidElementType(
Type *ElemTy) {
703 if (
this ==
Other)
return true;
705 if (isPacked() !=
Other->isPacked())
708 return elements() ==
Other->elements();
711Type *StructType::getTypeAtIndex(
const Value *V)
const {
712 unsigned Idx = (
unsigned)cast<Constant>(V)->getUniqueInteger().getZExtValue();
713 assert(indexValid(
Idx) &&
"Invalid structure index!");
714 return getElementType(
Idx);
717bool StructType::indexValid(
const Value *V)
const {
720 if (!
V->getType()->isIntOrIntVectorTy(32))
722 if (isa<ScalableVectorType>(
V->getType()))
724 const Constant *
C = dyn_cast<Constant>(V);
725 if (
C &&
V->getType()->isVectorTy())
726 C =
C->getSplatValue();
732 return C.pImpl->NamedStructTypes.lookup(
Name);
740 :
Type(ElType->getContext(), ArrayTyID), ContainedType(ElType),
742 ContainedTys = &ContainedType;
751 pImpl->
ArrayTypes[std::make_pair(ElementType, NumElements)];
758bool ArrayType::isValidElementType(
Type *ElemTy) {
769 :
Type(ElType->getContext(), TID), ContainedType(ElType),
770 ElementQuantity(
EQ) {
771 ContainedTys = &ContainedType;
777 return ScalableVectorType::get(ElementType,
EC.getKnownMinValue());
779 return FixedVectorType::get(ElementType,
EC.getKnownMinValue());
782bool VectorType::isValidElementType(
Type *ElemTy) {
792 assert(NumElts > 0 &&
"#Elements of a VectorType must be greater than 0");
794 "be an integer, floating point, or "
797 auto EC = ElementCount::getFixed(NumElts);
801 .pImpl->VectorTypes[std::make_pair(ElementType, EC)];
805 return cast<FixedVectorType>(Entry);
813 unsigned MinNumElts) {
814 assert(MinNumElts > 0 &&
"#Elements of a VectorType must be greater than 0");
816 "be an integer, floating point, or "
819 auto EC = ElementCount::getScalable(MinNumElts);
823 .pImpl->VectorTypes[std::make_pair(ElementType, EC)];
827 return cast<ScalableVectorType>(Entry);
835 assert(EltTy &&
"Can't get a pointer to <null> type!");
855 :
Type(
C, PointerTyID) {
856 setSubclassData(AddrSpace);
859PointerType *Type::getPointerTo(
unsigned AddrSpace)
const {
860 return PointerType::get(
const_cast<Type*
>(
this), AddrSpace);
863bool PointerType::isValidElementType(
Type *ElemTy) {
869bool PointerType::isLoadableOrStorableType(
Type *ElemTy) {
880 NumContainedTys =
Types.size();
883 Type **Params =
reinterpret_cast<Type **
>(
this + 1);
884 ContainedTys = Params;
885 for (
Type *
T : Types)
888 setSubclassData(Ints.
size());
889 unsigned *IntParamSpace =
reinterpret_cast<unsigned *
>(Params);
890 IntParams = IntParamSpace;
891 for (
unsigned IntParam : Ints)
892 *IntParamSpace++ = IntParam;
912 auto [Iter,
Inserted] =
C.pImpl->TargetExtTypes.insert_as(
nullptr, Key);
922 return checkParams(TT);
931 if (TTy->Name ==
"aarch64.svcount" &&
934 "target extension type aarch64.svcount should have no parameters");
937 if (TTy->Name ==
"riscv.vector.tuple" &&
940 "target extension type riscv.vector.tuple should have one "
941 "type parameter and one integer parameter");
944 if (TTy->Name ==
"amdgcn.named.barrier" &&
947 "should have no type parameters "
948 "and one integer parameter");
955struct TargetTypeInfo {
959 template <
typename... ArgTys>
960 TargetTypeInfo(
Type *LayoutType, ArgTys... Properties)
961 : LayoutType(LayoutType), Properties((0 | ... | Properties)) {}
968 if (
Name ==
"spirv.Image")
969 return TargetTypeInfo(PointerType::get(
C, 0), TargetExtType::CanBeGlobal,
970 TargetExtType::CanBeLocal);
971 if (
Name.starts_with(
"spirv."))
972 return TargetTypeInfo(PointerType::get(
C, 0), TargetExtType::HasZeroInit,
973 TargetExtType::CanBeGlobal,
974 TargetExtType::CanBeLocal);
977 if (
Name ==
"aarch64.svcount")
978 return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(
C), 16),
979 TargetExtType::HasZeroInit,
980 TargetExtType::CanBeLocal);
985 if (
Name ==
"riscv.vector.tuple") {
986 unsigned TotalNumElts =
988 ->getMinNumElements(),
989 RISCV::RVVBitsPerBlock / 8) *
991 return TargetTypeInfo(
992 ScalableVectorType::get(Type::getInt8Ty(
C), TotalNumElts),
993 TargetExtType::CanBeLocal, TargetExtType::HasZeroInit);
997 if (
Name.starts_with(
"dx."))
998 return TargetTypeInfo(PointerType::get(
C, 0), TargetExtType::CanBeGlobal,
999 TargetExtType::CanBeLocal);
1002 if (
Name ==
"amdgcn.named.barrier") {
1003 return TargetTypeInfo(FixedVectorType::get(Type::getInt32Ty(
C), 4),
1004 TargetExtType::CanBeGlobal);
1007 return TargetTypeInfo(Type::getVoidTy(
C));
1010Type *TargetExtType::getLayoutType()
const {
1014bool TargetExtType::hasProperty(Property Prop)
const {
1016 return (Properties & Prop) == Prop;
This file defines the StringMap class.
static const fltSemantics * getFltSemantics(unsigned Size)
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...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::optional< std::vector< StOtherPiece > > Other
static char getTypeID(Type *Ty)
const Type::TypeID FloatTyID
const Type::TypeID DoubleTyID
static StringRef getName(Value *V)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static unsigned getNumElements(Type *Ty)
static bool isValidElementType(Type *Ty)
Predicate for the element types that the SLP vectorizer supports.
static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty)
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_)
Class for arbitrary precision integers.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
This is the shared class of boolean and integer constants.
This is an important base class in LLVM.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
Class to represent fixed width SIMD vectors.
Class to represent integer types.
StructTypeSet AnonStructTypes
DenseMap< std::pair< Type *, uint64_t >, ArrayType * > ArrayTypes
DenseMap< unsigned, PointerType * > PointerTypes
PointerType * AS0PointerType
FunctionTypeSet FunctionTypes
This is an important class for using LLVM in a threaded context.
LLVMContextImpl *const pImpl
Class to represent scalable SIMD vectors.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
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",...
void remove(MapEntryTy *KeyValue)
remove - Remove the specified key/value pair from the map, but do not erase it.
StringRef - Represent a constant reference to a string, i.e.
Class to represent struct types.
Symbol info for RuntimeDyld.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
unsigned getNumIntParameters() const
Type * getTypeParameter(unsigned i) const
unsigned getNumTypeParameters() const
unsigned getIntParameter(unsigned i) const
StringRef getName() const
Return the name for this target extension type.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
bool containsNonLocalTargetExtType(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this type is or contains a target extension type that disallows being used as a local.
bool isLabelTy() const
Return true if this is 'label'.
bool isPointerTy() const
True if this is an instance of PointerType.
bool containsNonGlobalTargetExtType(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this type is or contains a target extension type that disallows being used as a global...
TypeID
Definitions of all of the base types for the Type system.
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
bool isScalableTy(SmallPtrSetImpl< const Type * > &Visited) const
Return true if this is a type whose size is a known multiple of vscale.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
void setSubclassData(unsigned val)
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
subtype_iterator subtype_begin() const
bool isX86_AMXTy() const
Return true if this is X86 AMX.
bool isFunctionTy() const
True if this is an instance of FunctionType.
bool isIntegerTy() const
True if this is an instance of IntegerType.
TypeID getTypeID() const
Return the type id for the type.
bool isTokenTy() const
Return true if this is 'token'.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
subtype_iterator subtype_end() const
bool isVoidTy() const
Return true if this is 'void'.
bool isMetadataTy() const
Return true if this is 'metadata'.
LLVM Value Representation.
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.
constexpr ScalarTy getFixedValue() const
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
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.
ElementType
The element type of an SRV or UAV resource.
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.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.