42 bool Has64BitPointers;
47 void postMerge(
unsigned AggregateSize,
Class &
Lo,
Class &
Hi)
const;
50 bool IsNamedArg,
bool IsRegCall =
false)
const;
52 const Type *getIntegerTypeAtOffset(
const Type *IRType,
unsigned IROffset,
54 unsigned SourceOffset,
55 bool InMemory =
false)
const;
57 const Type *getSSETypeAtOffset(
const Type *ABIType,
unsigned ABIOffset,
59 unsigned SourceOffset)
const;
60 bool isIllegalVectorType(
const Type *Ty)
const;
61 bool containsMatrixField(
const RecordType *RT)
const;
64 ArgInfo getIndirectReturnResult(
const Type *Ty)
const;
65 const Type *getFPTypeAtOffset(
const Type *Ty,
unsigned Offset)
const;
67 const Type *getByteVectorType(
const Type *Ty)
const;
70 ArgInfo getIndirectResult(
const Type *Ty,
unsigned FreeIntRegs)
const;
72 ArgInfo classifyReturnType(
const Type *RetTy)
const;
74 ArgInfo classifyArgumentType(
const Type *Ty,
unsigned FreeIntRegs,
75 unsigned &NeededInt,
unsigned &NeededSse,
76 bool IsNamedArg,
bool IsRegCall =
false)
const;
78 bool shouldExtendReturnType(
const IntegerType *RetTy)
const;
84 Has64BitPointers(Has64BitPtrs), X86CompatInfo(Compat) {}
104 if (Fields.
empty()) {
108 const Type *StorageType =
nullptr;
110 for (
const auto &
Field : Fields) {
111 if (
Field.IsBitField &&
Field.IsUnnamedBitfield &&
112 Field.BitFieldWidth == 0) {
119 StorageType = FieldType;
134 (FieldType->getAlignment() == StorageType->
getAlignment() &&
137 StorageType = FieldType;
143bool X86_64TargetInfo::shouldExtendReturnType(
const IntegerType *RetTy)
const {
149 bool IsDarwin =
false;
156void X86_64TargetInfo::postMerge(
unsigned AggregateSize, Class &
Lo,
213 "Invalid accumulated classification during merge.");
234bool X86_64TargetInfo::containsMatrixField(
const RecordType *RT)
const {
235 for (
const auto &
Field : RT->getFields()) {
239 if (AT->isMatrixType())
245 if (containsMatrixField(NestedRT))
251void X86_64TargetInfo::classify(
const Type *
T,
uint64_t OffsetBase, Class &
Lo,
252 Class &
Hi,
bool IsNamedArg,
253 bool IsRegCall)
const {
255 Class &Current = OffsetBase < 64 ?
Lo :
Hi;
264 auto BitWidth =
IT->getSizeInBits().getFixedValue();
278 const auto *FltSem = FT->getSemantics();
296 if (
T->isPointer()) {
302 if (MPT->isFunctionPointer()) {
303 if (Has64BitPointers) {
306 uint64_t EbFuncPtr = OffsetBase / 64;
307 uint64_t EbThisAdj = (OffsetBase + 64 - 1) / 64;
308 if (EbFuncPtr != EbThisAdj) {
321 assert(VT->isFixedLength() &&
"x86-64 has no scalable vectors");
337 }
else if (
Size == 64) {
348 uint64_t ElemBits =
IT->getSizeInBits().getFixedValue();
360 if (OffsetBase && OffsetBase != 64)
362 }
else if (
Size == 128 ||
365 uint64_t ElemBits =
IT->getSizeInBits().getFixedValue();
368 ElemBits == 128 && !
IT->isBitInt())
399 else if (
Size <= 128)
402 const auto *FltSem = EFT->getSemantics();
421 uint64_t EbImag = (OffsetBase + ElementSize) / 64;
433 if (AT->isMatrixType())
443 if (!IsRegCall &&
Size > 512)
452 if (OffsetBase % ElemAlign)
459 uint64_t ArraySize = AT->getNumElements();
471 Class FieldLo, FieldHi;
472 classify(ElementType,
Offset, FieldLo, FieldHi, IsNamedArg);
473 Lo = merge(
Lo, FieldLo);
474 Hi = merge(
Hi, FieldHi);
486 if (containsMatrixField(RT)) {
503 if (RT->hasFlexibleArrayMember())
510 if (RT->isCXXRecord()) {
511 for (
const auto &
Base : RT->getBaseClasses()) {
518 Class FieldLo, FieldHi;
520 classify(
Base.FieldType,
Offset, FieldLo, FieldHi, IsNamedArg);
521 Lo = merge(
Lo, FieldLo);
522 Hi = merge(
Hi, FieldHi);
525 (
Size > 128 && (
Size !=
Base.FieldType->getABISizeInBits() ||
539 for (
const auto &
Field : RT->getFields()) {
547 ?
Field.BitFieldWidth == 0
548 :
Field.IsUnnamedBitfield))
559 bool IsInMemory =
Offset % (
Field.FieldType->getAlignment().value() * 8);
560 if (!BitField && IsInMemory) {
566 Class FieldLo, FieldHi;
574 assert(EbHi == EbLo &&
"Invalid classification, type > 16 bytes.");
582 classify(
Field.FieldType,
Offset, FieldLo, FieldHi, IsNamedArg);
585 Lo = merge(
Lo, FieldLo);
586 Hi = merge(
Hi, FieldHi);
599X86_64TargetInfo::classifyArgumentType(
const Type *Ty,
unsigned FreeIntRegs,
600 unsigned &NeededInt,
unsigned &NeededSSE,
601 bool IsNamedArg,
bool IsRegCall)
const {
606 classify(Ty, 0,
Lo,
Hi, IsNamedArg, IsRegCall);
614 const Type *ResType =
nullptr;
623 "Unknown missing lo part");
635 return getIndirectResult(Ty, FreeIntRegs);
648 ResType = getIntegerTypeAtOffset(Ty, 0, Ty, 0);
652 if (
Hi ==
NoClass && ResType->isInteger()) {
670 if (ResType->isInteger() && ResType->getSizeInBits() == 128) {
681 ResType = getSSETypeAtOffset(Ty, 0, Ty, 0);
686 const Type *HighPart =
nullptr;
702 HighPart = getIntegerTypeAtOffset(Ty, 8, Ty, 8);
713 HighPart = getSSETypeAtOffset(Ty, 8, Ty, 8);
723 assert(
Lo ==
Sse &&
"Unexpected SseUp classification");
724 ResType = getByteVectorType(Ty);
732 ResType = createPairType(ResType, HighPart);
737ArgInfo X86_64TargetInfo::classifyReturnType(
const Type *RetTy)
const {
742 classify(RetTy, 0,
Lo,
Hi,
true);
748 const Type *ResType =
nullptr;
756 "Unknown missing lo part");
765 return getIndirectReturnResult(RetTy);
770 ResType = getIntegerTypeAtOffset(RetTy, 0, RetTy, 0);
777 : ArgInfo::getDirect(RetTy);
779 if (ResType->isInteger() && ResType->getSizeInBits() == 128) {
780 assert(Hi == Integer);
781 return ArgInfo::getDirect(ResType);
788 ResType = getSSETypeAtOffset(RetTy, 0, RetTy, 0);
803 const Type *X87Type =
805 FieldInfo Fields[] = {FieldInfo(X87Type, 0), FieldInfo(X87Type, 80)};
812 const Type *HighPart =
nullptr;
825 HighPart = getIntegerTypeAtOffset(RetTy, 8, RetTy, 8);
831 HighPart = getSSETypeAtOffset(RetTy, 8, RetTy, 8);
842 assert(
Lo ==
Sse &&
"Unexpected SseUp classification.");
843 ResType = getByteVectorType(RetTy);
854 HighPart = getSSETypeAtOffset(RetTy, 8, RetTy, 8);
865 ResType = createPairType(ResType, HighPart);
875const Type *X86_64TargetInfo::createPairType(
const Type *
Lo,
882 llvm::Align HiAlign =
Hi->getAlignment();
883 unsigned HiStart =
alignTo(LoSize, HiAlign);
885 assert(HiStart != 0 && HiStart <= 8 &&
"Invalid x86-64 argument pair!");
891 const Type *AdjustedLo =
Lo;
906 else if (
Lo->isInteger() ||
Lo->isPointer())
907 AdjustedLo =
TB.getIntegerType(64,
Align(8),
false);
909 assert((
Lo->isInteger() ||
Lo->isPointer()) &&
910 "Invalid/unknown low type in pair");
911 unsigned AdjustedLoSize = AdjustedLo->getSizeInBits().getFixedValue() / 8;
912 HiStart =
alignTo(AdjustedLoSize, HiAlign);
916 FieldInfo Fields[] = {FieldInfo(AdjustedLo, 0), FieldInfo(
Hi, HiStart * 8)};
919 assert((8 * 8) == Fields[1].OffsetInBits &&
920 "High part must be at offset 8 bytes");
923 Fields[1].OffsetInBits +
Hi->getSizeInBits().getFixedValue();
931 unsigned TySize = Ty->getABISizeInBits();
932 if (TySize <= StartBit)
937 const Type *EltTy = AT->getElementType();
940 for (
unsigned I = 0;
I < AT->getNumElements(); ++
I) {
941 unsigned EltOffset =
I * EltSize;
942 if (EltOffset >= EndBit)
945 unsigned EltStart = (EltOffset < StartBit) ? StartBit - EltOffset : 0;
956 if (RT->isCXXRecord()) {
957 for (
unsigned I = 0;
I < RT->getNumBaseClasses(); ++
I) {
959 if (
Base.OffsetInBits >= EndBit)
963 (
Base.OffsetInBits < StartBit) ? StartBit -
Base.OffsetInBits : 0;
965 EndBit -
Base.OffsetInBits))
970 for (
unsigned I = 0;
I < RT->getNumFields(); ++
I) {
972 if (
Field.OffsetInBits >= EndBit)
975 unsigned FieldStart =
976 (
Field.OffsetInBits < StartBit) ? StartBit -
Field.OffsetInBits : 0;
978 EndBit -
Field.OffsetInBits))
988const Type *X86_64TargetInfo::getIntegerTypeAtOffset(
const Type *ABIType,
990 const Type *SourceTy,
991 unsigned SourceOffset,
992 bool InMemory)
const {
994 const Type *WorkingType = ABIType;
995 if (InMemory && ABIType->isInteger()) {
997 unsigned OriginalBitWidth =
IT->getSizeInBits().getFixedValue();
999 unsigned WidenedBitWidth = OriginalBitWidth;
1000 if (OriginalBitWidth <= 8) {
1001 WidenedBitWidth = 8;
1006 if (WidenedBitWidth != OriginalBitWidth) {
1007 WorkingType =
TB.getIntegerType(WidenedBitWidth,
ABIType->getAlignment(),
1013 if (InMemory &&
ABIType->isVector()) {
1016 if (
IT &&
IT->isBool())
1017 WorkingType =
TB.getIntegerType(
1018 std::max<uint64_t>(VT->getNumElements().getFixedValue(), 8),
1019 ABIType->getAlignment(),
false);
1023 if (ABIOffset == 0) {
1028 if ((WorkingType->isPointer() && Has64BitPointers) ||
1029 (WorkingType->isInteger() &&
1039 if ((WorkingType->isInteger() &&
1044 (WorkingType->isPointer() && !Has64BitPointers)) {
1046 unsigned BitWidth = WorkingType->isPointer()
1051 SourceOffset * 8 + 64))
1057 if (RTy->isUnion()) {
1060 if (ABIOffset * 8 < ReducedType->getABISizeInBits())
1061 return getIntegerTypeAtOffset(ReducedType, ABIOffset, SourceTy,
1062 SourceOffset,
true);
1067 SourceOffset * 8 + 64))
1068 return TB.getIntegerType(8,
Align(1),
false);
1069 unsigned RemainingBytes =
1071 return TB.getIntegerType(std::min(RemainingBytes, 8U) * 8,
Align(1),
1075 if (
const FieldInfo *Element =
1076 RTy->getElementContainingOffset(ABIOffset * 8)) {
1078 unsigned ElementOffsetBytes = Element->OffsetInBits / 8;
1079 return getIntegerTypeAtOffset(Element->FieldType,
1080 ABIOffset - ElementOffsetBytes, SourceTy,
1081 SourceOffset,
true);
1086 const Type *EltTy = ATy->getElementType();
1087 unsigned EltSize = EltTy->getABISizeInBits() / 8;
1089 unsigned EltOffset = (ABIOffset / EltSize) * EltSize;
1090 return getIntegerTypeAtOffset(EltTy, ABIOffset - EltOffset, SourceTy,
1091 SourceOffset,
true);
1102 unsigned TySizeInBytes =
llvm::divideCeil(SourceTy->getABISizeInBits(), 8);
1103 assert(TySizeInBytes != SourceOffset &&
"Empty field?");
1104 unsigned AvailableSize = TySizeInBytes - SourceOffset;
1105 return TB.getIntegerType(std::min(AvailableSize, 8U) * 8,
Align(1),
false);
1109const Type *X86_64TargetInfo::getFPTypeAtOffset(
const Type *Ty,
1112 if (
Offset == 0 && Ty->isFloat())
1117 unsigned ElementSize =
ElementType->getABISizeInBits() / 8;
1126 if (
const FieldInfo *Element = RT->getElementContainingOffset(
Offset * 8)) {
1127 unsigned ElementOffsetBytes = Element->OffsetInBits / 8;
1128 return getFPTypeAtOffset(Element->FieldType,
Offset - ElementOffsetBytes);
1134 const Type *EltTy = AT->getElementType();
1135 unsigned EltSize = EltTy->getABISizeInBits() / 8;
1138 unsigned EltIndex =
Offset / EltSize;
1140 return getFPTypeAtOffset(EltTy,
Offset - (EltIndex * EltSize));
1158const Type *X86_64TargetInfo::getSSETypeAtOffset(
const Type *ABIType,
1160 const Type *SourceTy,
1161 unsigned SourceOffset)
const {
1164 if (RTy->isUnion()) {
1167 return getSSETypeAtOffset(ReducedType, ABIOffset, SourceTy,
1173 auto Is16bitFpTy = [](
const Type *
T) {
1179 const Type *T0 = getFPTypeAtOffset(ABIType, ABIOffset);
1184 unsigned SourceSize = (SourceTy->getABISizeInBits() / 8) - SourceOffset;
1187 const Type *
T1 =
nullptr;
1188 unsigned T0Size = T0->getABISizeInBits() / 8;
1189 if (SourceSize > T0Size)
1190 T1 = getFPTypeAtOffset(ABIType, ABIOffset + T0Size);
1192 if (
T1 ==
nullptr) {
1193 if (Is16bitFpTy(T0) && SourceSize > 4)
1194 T1 = getFPTypeAtOffset(ABIType, ABIOffset + 4);
1204 if (Is16bitFpTy(T0) && Is16bitFpTy(
T1)) {
1205 const Type *T2 =
nullptr;
1207 T2 = getFPTypeAtOffset(ABIType, ABIOffset + 4);
1214 if (Is16bitFpTy(T0) || Is16bitFpTy(
T1))
1224const Type *X86_64TargetInfo::getByteVectorType(
const Type *Ty)
const {
1235 VT->getElementType()->isInteger() &&
1237 unsigned Size = VT->getABISizeInBits();
1238 return TB.getVectorType(
TB.getIntegerType(64,
Align(8),
false),
1250 unsigned Size = Ty->getABISizeInBits();
1257bool X86_64TargetInfo::isIllegalVectorType(
const Type *Ty)
const {
1267 const Type *EltTy = VecTy->getElementType();
1270 if (IntTy->getSizeInBits().getFixedValue() == 128 && !IntTy->isBitInt())
1277ArgInfo X86_64TargetInfo::getIndirectResult(
const Type *Ty,
1278 unsigned FreeIntRegs)
const {
1302 uint64_t AlignVal = std::max<uint64_t>(Ty->getAlignment().value(), 8u);
1325 if (FreeIntRegs == 0) {
1330 if (AlignVal == 8 &&
Size <= 64) {
1332 TB.getIntegerType(
Size, llvm::Align(8),
false);
1340ArgInfo X86_64TargetInfo::getIndirectReturnResult(
const Type *Ty)
const {
1344 if (IntTy->isBitInt())
1346 if (shouldExtendReturnType(IntTy))
1355void X86_64TargetInfo::computeInfo(
FunctionInfo &FI)
const {
1361 switch (CallingConv) {
1366 "calling convention not supported by the LLVMABI X86_64 classifier");
1369 unsigned FreeIntRegs = 6;
1370 unsigned FreeSSERegs = 8;
1371 unsigned NeededInt = 0, NeededSSE = 0;
1374 const Type *RetTy = FI.getReturnType();
1375 FI.getReturnInfo() = classifyReturnType(RetTy);
1378 if (FI.getReturnInfo().isIndirect())
1381 unsigned NumRequiredArgs = FI.getNumRequiredArgs();
1384 for (
auto IT = FI.arg_begin(), IE = FI.arg_end();
IT != IE; ++
IT, ++ArgNo) {
1385 bool IsNamedArg = ArgNo < NumRequiredArgs;
1386 const Type *ArgTy =
IT->ABIType;
1390 ArgInfo AI = classifyArgumentType(ArgTy, FreeIntRegs, NeededInt, NeededSSE,
1397 if (FreeIntRegs >= NeededInt && FreeSSERegs >= NeededSSE) {
1398 FreeIntRegs -= NeededInt;
1399 FreeSSERegs -= NeededSSE;
1400 AI.setNeededRegs(NeededInt, NeededSSE);
1405 IT->Info = getIndirectResult(ArgTy, FreeIntRegs);
1410std::unique_ptr<TargetInfo>
1413 return std::make_unique<X86_64TargetInfo>(TB, AVXLevel, Has64BitPointers,
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
static LoopDeletionResult merge(LoopDeletionResult A, LoopDeletionResult B)
OptimizedStructLayoutField Field
FunctionLoweringInfo::StatepointRelocationRecord RecordType
Target-specific ABI information and factory functions.
static const fltSemantics & IEEEsingle()
static const fltSemantics & BFloat()
static const fltSemantics & IEEEquad()
static const fltSemantics & IEEEdouble()
static const fltSemantics & x87DoubleExtended()
static const fltSemantics & IEEEhalf()
Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
Check if the array is empty.
static constexpr ElementCount getFixed(ScalarTy MinVal)
Class to represent integer types.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
The instances of the Type class are immutable: once they are created, they are never changed.
Helper class to encapsulate information about how a specific type should be passed to or returned fro...
static ArgInfo getConservativeExtend(const Type *T)
static ArgInfo getIgnore()
static ArgInfo getExtend(const Type *T)
static ArgInfo getIndirect(Align Align, bool ByVal, unsigned AddrSpace=0, bool Realign=false)
Realign: the caller couldn't guarantee sufficient alignment - the callee must copy the argument to a ...
static ArgInfo getDirect(const Type *T=nullptr, unsigned Offset=0, MaybeAlign Align=std::nullopt, bool CanBeFlattened=true)
const fltSemantics * getSemantics() const
ArrayRef< FieldInfo > getFields() const
bool isTransparentUnion() const
LLVM_ABI const Type * isSingleElementStruct(const Type *Ty) const
Returns the scalar a single-element struct reduces to, else null.
virtual unsigned getAllocaAddrSpace() const
Address space in which indirect arguments are allocated (the target's alloca/stack space).
LLVM_ABI bool isPromotableInteger(const IntegerType *IT) const
TargetInfo(TypeBuilder &Builder)
LLVM_ABI bool maybeCommonClassifyReturnType(FunctionInfo &FI) const
Apply rules for classifying return types that are common to all targets.
LLVM_ABI bool isAggregateTypeForABI(const Type *Ty) const
LLVM_ABI const Type * useFirstFieldIfTransparentUnion(const Type *Ty) const
If Ty is a transparent union, return its first field type; otherwise return Ty unchanged.
LLVM_ABI ArgInfo getNaturalAlignIndirect(const Type *Ty, unsigned AddrSpace, bool ByVal=true) const
LLVM_ABI RecordArgABI getRecordArgABI(const RecordType *RT) const
TypeBuilder manages the lifecycle of ABI types using bump pointer allocation.
Represents the ABI-specific view of a type in LLVM.
TypeSize getTypeAllocSize() const
TypeSize getSizeInBits() const
LLVM_ABI uint64_t getABISizeInBits() const
Returns the size in bits that the source language gives this type, including any padding.
Align getAlignment() const
X86_64TargetInfo(TypeBuilder &TypeBuilder, X86AVXABILevel AVXABILevel, bool Has64BitPtrs, const X86ABICompatInfo &Compat)
bool has64BitPointers() const
const X86ABICompatInfo & getX86ABICompatInfo() const
const ABICompatInfo & getABICompatInfo() const override
Return this target's ABI compatibility flags.
static constexpr bool isKnownGT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
This file defines the type system for the LLVMABI library, which mirrors ABI-relevant aspects of fron...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI std::unique_ptr< TargetInfo > createX86_64TargetInfo(TypeBuilder &TB, X86AVXABILevel AVXLevel, bool Has64BitPointers, const X86ABICompatInfo &Compat)
static unsigned getNativeVectorSizeForAVXABI(X86AVXABILevel AVXLevel)
X86AVXABILevel
The AVX ABI level for X86 targets.
static const Type * reduceUnionForX8664(const RecordType *UnionType, TypeBuilder &TB)
static bool bitsContainNoUserData(const Type *Ty, unsigned StartBit, unsigned EndBit)
static bool isFloatTypeWithSemantics(const Type *Ty, const fltSemantics &Semantics)
Helper to check if a floating point type matches specific semantics.
@ RAA_Indirect
Pass it as a pointer to temporary memory.
@ RAA_DirectInMemory
Pass it on the stack using its defined layout.
@ Both
Compat with both. Extend in caller, don't assume in callee.
@ Platform
Compat with platform ABI (high bits unspecified).
@ Clang23
Compat with old Clang ABI (high bits zero/sign-extended).
ElementType
The element type of an SRV or UAV resource.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
T bit_ceil(T Value)
Returns the smallest integral power of two no smaller than Value if Value is nonzero.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
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...
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Flags controlling ABI compatibility behaviour that applies to every target.
Flags controlling X86-specific ABI compatibility behaviour.