10#include "TargetInfo.h"
13#include "llvm/ADT/SmallBitVector.h"
21bool IsX86_MMXType(llvm::Type *IRType) {
23 return IRType->isVectorTy() && IRType->getPrimitiveSizeInBits() == 64 &&
25 IRType->getScalarSizeInBits() != 64;
31 bool IsMMXCons = llvm::StringSwitch<bool>(Constraint)
32 .Cases({
"y",
"&y",
"^Ym"},
true)
34 if (IsMMXCons && Ty->isVectorTy() &&
39 if (Constraint ==
"k") {
41 return llvm::FixedVectorType::get(Int1Ty, Ty->getScalarSizeInBits());
52 if (BT->isFloatingPoint() && BT->getKind() != BuiltinType::Half) {
53 if (BT->getKind() == BuiltinType::LongDouble) {
54 if (&Context.getTargetInfo().getLongDoubleFormat() ==
55 &llvm::APFloat::x87DoubleExtended())
63 unsigned VecSize = Context.getTypeSize(VT);
64 if (VecSize == 128 || VecSize == 256 || VecSize == 512)
72static bool isX86VectorCallAggregateSmallEnough(
uint64_t NumMembers) {
73 return NumMembers <= 4;
77static ABIArgInfo getDirectX86Hva(llvm::Type*
T =
nullptr) {
80 AI.setCanBeFlattened(
false);
90 CCState(CGFunctionInfo &FI)
91 : IsPreassigned(FI.arg_size()), CC(FI.getCallingConvention()),
92 Required(FI.getRequiredArgs()), IsDelegateCall(FI.isDelegateCall()) {}
94 llvm::SmallBitVector IsPreassigned;
95 unsigned CC = CallingConv::CC_C;
96 unsigned FreeRegs = 0;
97 unsigned FreeSSERegs = 0;
98 RequiredArgs Required;
99 bool IsDelegateCall =
false;
103class X86_32ABIInfo :
public ABIInfo {
104 enum Class { Integer, Float, AlwaysStack };
106 static const unsigned MinABIStackAlignInBytes = 4;
108 bool IsDarwinVectorABI;
109 bool IsRetSmallStructInRegABI;
110 bool IsWin32StructABI;
114 unsigned DefaultNumRegisterParameters;
116 static bool isRegisterSize(
unsigned Size) {
117 return (Size == 8 || Size == 16 || Size == 32 || Size == 64);
120 bool isHomogeneousAggregateBaseType(QualType Ty)
const override {
122 return isX86VectorTypeForVectorCall(getContext(), Ty);
125 bool isHomogeneousAggregateSmallEnough(
const Type *Ty,
126 uint64_t NumMembers)
const override {
128 return isX86VectorCallAggregateSmallEnough(NumMembers);
131 bool shouldReturnTypeInRegister(QualType Ty, ASTContext &Context)
const;
135 ABIArgInfo getIndirectResult(QualType Ty,
bool ByVal, CCState &State)
const;
137 ABIArgInfo getIndirectReturnResult(QualType Ty, CCState &State)
const;
140 unsigned getTypeStackAlignInBytes(QualType Ty,
unsigned Align)
const;
142 Class classify(QualType Ty)
const;
145 unsigned ArgIndex)
const;
149 bool updateFreeRegs(QualType Ty, CCState &State)
const;
151 bool shouldAggregateUseDirect(QualType Ty, CCState &State,
bool &InReg,
152 bool &NeedsPadding)
const;
153 bool shouldPrimitiveUseInReg(QualType Ty, CCState &State)
const;
155 bool canExpandIndirectArgument(QualType Ty)
const;
159 void rewriteWithInAlloca(CGFunctionInfo &FI)
const;
161 void addFieldToArgStruct(SmallVector<llvm::Type *, 6> &FrameFields,
162 CharUnits &StackOffset, ABIArgInfo &Info,
163 QualType
Type)
const;
164 void runVectorCallFirstPass(CGFunctionInfo &FI, CCState &State)
const;
168 void computeInfo(CGFunctionInfo &FI)
const override;
169 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
170 AggValueSlot Slot)
const override;
172 X86_32ABIInfo(CodeGen::CodeGenTypes &CGT,
bool DarwinVectorABI,
173 bool RetSmallStructInRegABI,
bool Win32StructABI,
174 unsigned NumRegisterParameters,
bool SoftFloatABI)
175 : ABIInfo(CGT), IsDarwinVectorABI(DarwinVectorABI),
176 IsRetSmallStructInRegABI(RetSmallStructInRegABI),
177 IsWin32StructABI(Win32StructABI), IsSoftFloatABI(SoftFloatABI),
178 IsMCUABI(CGT.getTarget().
getTriple().isOSIAMCU()),
179 IsLinuxABI(CGT.getTarget().
getTriple().isOSLinux() ||
180 CGT.getTarget().
getTriple().isOSCygMing()),
181 DefaultNumRegisterParameters(NumRegisterParameters) {}
186 explicit X86_32SwiftABIInfo(CodeGenTypes &CGT)
187 : SwiftABIInfo(CGT,
false) {}
190 bool AsReturnValue)
const override {
195 return occupiesMoreThan(ComponentTys, 3);
201 X86_32TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
bool DarwinVectorABI,
202 bool RetSmallStructInRegABI,
bool Win32StructABI,
203 unsigned NumRegisterParameters,
bool SoftFloatABI)
204 : TargetCodeGenInfo(std::make_unique<X86_32ABIInfo>(
205 CGT, DarwinVectorABI, RetSmallStructInRegABI, Win32StructABI,
206 NumRegisterParameters, SoftFloatABI)) {
207 SwiftInfo = std::make_unique<X86_32SwiftABIInfo>(CGT);
210 static bool isStructReturnInRegABI(
211 const llvm::Triple &Triple,
const CodeGenOptions &Opts);
213 void setTargetAttributes(
const Decl *D, llvm::GlobalValue *GV,
214 CodeGen::CodeGenModule &CGM)
const override;
216 int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM)
const override {
222 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
223 llvm::Value *Address)
const override;
225 llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
226 StringRef Constraint,
227 llvm::Type* Ty)
const override {
228 return X86AdjustInlineAsmType(CGF, Constraint, Ty);
231 void addReturnRegisterOutputs(CodeGenFunction &CGF, LValue ReturnValue,
232 std::string &Constraints,
233 std::vector<llvm::Type *> &ResultRegTypes,
234 std::vector<llvm::Type *> &ResultTruncRegTypes,
235 std::vector<LValue> &ResultRegDests,
236 std::string &AsmString,
237 unsigned NumOutputs)
const override;
239 StringRef getARCRetainAutoreleasedReturnValueMarker()
const override {
240 return "movl\t%ebp, %ebp"
241 "\t\t// marker for objc_retainAutoreleaseReturnValue";
257 std::string &AsmString) {
259 llvm::raw_string_ostream OS(Buf);
261 while (Pos < AsmString.size()) {
262 size_t DollarStart = AsmString.find(
'$', Pos);
263 if (DollarStart == std::string::npos)
264 DollarStart = AsmString.size();
265 size_t DollarEnd = AsmString.find_first_not_of(
'$', DollarStart);
266 if (DollarEnd == std::string::npos)
267 DollarEnd = AsmString.size();
268 OS << StringRef(&AsmString[Pos], DollarEnd - Pos);
270 size_t NumDollars = DollarEnd - DollarStart;
271 if (NumDollars % 2 != 0 && Pos < AsmString.size()) {
273 size_t DigitStart = Pos;
274 if (AsmString[DigitStart] ==
'{') {
278 size_t DigitEnd = AsmString.find_first_not_of(
"0123456789", DigitStart);
279 if (DigitEnd == std::string::npos)
280 DigitEnd = AsmString.size();
281 StringRef OperandStr(&AsmString[DigitStart], DigitEnd - DigitStart);
282 unsigned OperandIndex;
283 if (!OperandStr.getAsInteger(10, OperandIndex)) {
284 if (OperandIndex >= FirstIn)
285 OperandIndex += NumNewOuts;
293 AsmString = std::move(Buf);
297void X86_32TargetCodeGenInfo::addReturnRegisterOutputs(
299 std::vector<llvm::Type *> &ResultRegTypes,
300 std::vector<llvm::Type *> &ResultTruncRegTypes,
301 std::vector<LValue> &ResultRegDests, std::string &AsmString,
302 unsigned NumOutputs)
const {
307 if (!Constraints.empty())
309 if (RetWidth <= 32) {
310 Constraints +=
"={eax}";
311 ResultRegTypes.push_back(CGF.
Int32Ty);
315 ResultRegTypes.push_back(CGF.
Int64Ty);
319 llvm::Type *CoerceTy = llvm::IntegerType::get(CGF.
getLLVMContext(), RetWidth);
320 ResultTruncRegTypes.push_back(CoerceTy);
323 ReturnSlot.setAddress(ReturnSlot.getAddress().withElementType(CoerceTy));
324 ResultRegDests.push_back(ReturnSlot);
331bool X86_32ABIInfo::shouldReturnTypeInRegister(QualType Ty,
332 ASTContext &Context)
const {
337 if ((IsMCUABI && Size > 64) || (!IsMCUABI && !isRegisterSize(Size)))
343 if (Size == 64 || Size == 128)
358 return shouldReturnTypeInRegister(AT->getElementType(), Context);
369 for (
const auto *FD : RD->fields()) {
375 if (!shouldReturnTypeInRegister(FD->getType(), Context))
384 Ty = CTy->getElementType();
393 uint64_t Size = Context.getTypeSize(Ty);
394 return Size == 32 || Size == 64;
399 for (
const auto *FD : RD->
fields()) {
409 if (FD->isBitField())
412 Size += Context.getTypeSize(FD->getType());
434bool X86_32ABIInfo::canExpandIndirectArgument(QualType Ty)
const {
440 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
441 if (!IsWin32StructABI) {
444 if (!CXXRD->isCLike())
448 if (CXXRD->isDynamicClass())
459 return Size == getContext().getTypeSize(Ty);
476 const llvm::Triple &
T) {
477 if (
T.isOSDarwin() ||
T.isPS())
479 return Opts.getSmallIntABICompat();
482ABIArgInfo X86_32ABIInfo::getIndirectReturnResult(QualType RetTy, CCState &State)
const {
485 if (State.CC != llvm::CallingConv::X86_FastCall &&
486 State.CC != llvm::CallingConv::X86_VectorCall && State.FreeRegs) {
489 return getNaturalAlignIndirectInReg(RetTy);
491 return getNaturalAlignIndirect(
492 RetTy, getDataLayout().getAllocaAddrSpace(),
496ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy,
497 CCState &State)
const {
503 if ((State.CC == llvm::CallingConv::X86_VectorCall ||
504 State.CC == llvm::CallingConv::X86_RegCall) &&
505 isHomogeneousAggregate(RetTy, Base, NumElts)) {
510 if (
const VectorType *VT = RetTy->
getAs<VectorType>()) {
512 if (IsDarwinVectorABI) {
520 llvm::Type::getInt64Ty(getVMContext()), 2));
524 if ((Size == 8 || Size == 16 || Size == 32) ||
525 (Size == 64 && VT->getNumElements() == 1))
529 return getIndirectReturnResult(RetTy, State);
539 return getIndirectReturnResult(RetTy, State);
543 return getIndirectReturnResult(RetTy, State);
550 if (
const ComplexType *CT = RetTy->
getAs<ComplexType>()) {
551 QualType ET = getContext().getCanonicalType(CT->getElementType());
554 llvm::Type::getHalfTy(getVMContext()), 2));
559 if (shouldReturnTypeInRegister(RetTy, getContext())) {
568 if ((!IsWin32StructABI && SeltTy->isRealFloatingType())
569 || SeltTy->hasPointerRepresentation())
577 return getIndirectReturnResult(RetTy, State);
582 RetTy = ED->getIntegerType();
584 if (
const auto *EIT = RetTy->
getAs<BitIntType>())
585 if (EIT->getNumBits() > 64)
586 return getIndirectReturnResult(RetTy, State);
589 : ABIArgInfo::getDirect();
592unsigned X86_32ABIInfo::getTypeStackAlignInBytes(QualType Ty,
593 unsigned Align)
const {
596 if (Align <= MinABIStackAlignInBytes)
607 if (Ty->
isVectorType() && (Align == 16 || Align == 32 || Align == 64))
611 if (!IsDarwinVectorABI) {
613 return MinABIStackAlignInBytes;
621 return MinABIStackAlignInBytes;
624ABIArgInfo X86_32ABIInfo::getIndirectResult(QualType Ty,
bool ByVal,
625 CCState &State)
const {
627 if (State.FreeRegs) {
630 return getNaturalAlignIndirectInReg(Ty);
632 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
637 unsigned TypeAlign = getContext().getTypeAlign(Ty) / 8;
638 unsigned StackAlign = getTypeStackAlignInBytes(Ty, TypeAlign);
642 getDataLayout().getAllocaAddrSpace(),
647 bool Realign = TypeAlign > StackAlign;
650 getDataLayout().getAllocaAddrSpace(),
true,
657 const auto *RD =
T->getAsRecordDecl();
667 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
668 for (
const auto &I : CXXRD->bases()) {
677 Found = I.getType().getTypePtr();
682 for (
const auto *FD : RD->
fields()) {
696 if (AT->getZExtSize() != 1)
698 FT = AT->getElementType();
706 if (
Found && Context.getTypeSize(
Found) != Context.getTypeSize(
T))
712X86_32ABIInfo::Class X86_32ABIInfo::classify(QualType Ty)
const {
713 if (getContext().getLangOpts().isCompatibleWith(
714 LangOptions::ClangABI::Ver23)) {
719 if (
const BuiltinType *BT =
T->
getAs<BuiltinType>()) {
721 if (K == BuiltinType::Float || K == BuiltinType::Double)
738 Ty = QualType(FT, 0);
746 if (
const BuiltinType *BT = Ty->
getAs<BuiltinType>())
747 if (BT->isFloatingPoint())
753bool X86_32ABIInfo::updateFreeRegs(QualType Ty, CCState &State)
const {
755 if (
C == AlwaysStack && !IsMCUABI)
757 if (
C ==
Float && !IsSoftFloatABI)
760 unsigned Size = getContext().getTypeSize(Ty);
761 unsigned SizeInRegs = (
Size + 31) / 32;
767 if (SizeInRegs > State.FreeRegs) {
776 if (SizeInRegs > State.FreeRegs || SizeInRegs > 2)
780 State.FreeRegs -= SizeInRegs;
784bool X86_32ABIInfo::shouldAggregateUseDirect(QualType Ty, CCState &State,
786 bool &NeedsPadding)
const {
793 NeedsPadding =
false;
796 if (!updateFreeRegs(Ty, State))
802 if (State.CC == llvm::CallingConv::X86_FastCall ||
803 State.CC == llvm::CallingConv::X86_VectorCall ||
804 State.CC == llvm::CallingConv::X86_RegCall) {
805 if (getContext().getTypeSize(Ty) <= 32 && State.FreeRegs)
814bool X86_32ABIInfo::shouldPrimitiveUseInReg(QualType Ty, CCState &State)
const {
815 bool IsPtrOrInt = (getContext().getTypeSize(Ty) <= 32) &&
819 if (!IsPtrOrInt && (State.CC == llvm::CallingConv::X86_FastCall ||
820 State.CC == llvm::CallingConv::X86_VectorCall))
823 if (!updateFreeRegs(Ty, State))
826 if (!IsPtrOrInt && State.CC == llvm::CallingConv::X86_RegCall)
833void X86_32ABIInfo::runVectorCallFirstPass(CGFunctionInfo &FI, CCState &State)
const {
843 MutableArrayRef<CGFunctionInfoArgInfo> Args = FI.
arguments();
844 for (
int I = 0, E = Args.size(); I < E; ++I) {
847 const QualType &Ty = Args[I].type;
849 isHomogeneousAggregate(Ty, Base, NumElts)) {
850 if (State.FreeSSERegs >= NumElts) {
851 State.FreeSSERegs -= NumElts;
853 State.IsPreassigned.set(I);
859ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, CCState &State,
860 unsigned ArgIndex)
const {
862 bool IsFastCall = State.CC == llvm::CallingConv::X86_FastCall;
863 bool IsRegCall = State.CC == llvm::CallingConv::X86_RegCall;
864 bool IsVectorCall = State.CC == llvm::CallingConv::X86_VectorCall;
867 TypeInfo TI = getContext().getTypeInfo(Ty);
874 return getIndirectResult(Ty,
false, State);
875 }
else if (State.IsDelegateCall) {
878 ABIArgInfo Res = getIndirectResult(Ty,
false, State);
891 if ((IsRegCall || IsVectorCall) &&
892 isHomogeneousAggregate(Ty, Base, NumElts)) {
893 if (State.FreeSSERegs >= NumElts) {
894 State.FreeSSERegs -= NumElts;
899 return getDirectX86Hva();
907 return getIndirectResult(Ty,
false, State);
913 if (RT && RT->getDecl()->getDefinitionOrSelf()->hasFlexibleArrayMember())
914 return getIndirectResult(Ty,
true, State);
917 if (!IsWin32StructABI &&
isEmptyRecord(getContext(), Ty,
true))
924 llvm::LLVMContext &LLVMContext = getVMContext();
925 llvm::IntegerType *
Int32 = llvm::Type::getInt32Ty(LLVMContext);
926 bool NeedsPadding =
false;
928 if (shouldAggregateUseDirect(Ty, State, InReg, NeedsPadding)) {
929 unsigned SizeInRegs = (TI.
Width + 31) / 32;
930 SmallVector<llvm::Type*, 3> Elements(SizeInRegs, Int32);
931 llvm::Type *
Result = llvm::StructType::get(LLVMContext, Elements);
937 llvm::IntegerType *PaddingType = NeedsPadding ?
Int32 :
nullptr;
944 if (IsWin32StructABI && State.Required.
isRequiredArg(ArgIndex)) {
945 unsigned AlignInBits = 0;
947 const ASTRecordLayout &Layout =
948 getContext().getASTRecordLayout(RT->getDecl());
951 AlignInBits = TI.
Align;
953 if (AlignInBits > 32)
954 return getIndirectResult(Ty,
false, State);
963 if (TI.
Width <= 4 * 32 && (!IsMCUABI || State.FreeRegs == 0) &&
964 canExpandIndirectArgument(Ty))
966 IsFastCall || IsVectorCall || IsRegCall, PaddingType);
968 return getIndirectResult(Ty,
true, State);
971 if (
const VectorType *VT = Ty->
getAs<VectorType>()) {
975 if (IsWin32StructABI) {
976 if (TI.
Width <= 512 && State.FreeSSERegs > 0) {
980 return getIndirectResult(Ty,
false, State);
985 if (IsDarwinVectorABI) {
987 (TI.
Width == 64 && VT->getNumElements() == 1))
989 llvm::IntegerType::get(getVMContext(), TI.
Width));
992 if (IsX86_MMXType(CGT.ConvertType(Ty)))
999 Ty = ED->getIntegerType();
1001 bool InReg = shouldPrimitiveUseInReg(Ty, State);
1003 if (isPromotableIntegerTypeForABI(Ty)) {
1006 case CodeGenOptions::SmallIntABICompatKind::Platform:
1012 CGT.ConvertType(Ty))
1013 : ABIArgInfo::getConservativeExtend(Ty, CGT.ConvertType(Ty));
1016 case CodeGenOptions::SmallIntABICompatKind::Clang23:
1018 : ABIArgInfo::getExtend(Ty, CGT.ConvertType(Ty));
1019 case CodeGenOptions::SmallIntABICompatKind::Both:
1021 CGT.ConvertType(Ty))
1022 : ABIArgInfo::getConservativeExtend(Ty, CGT.ConvertType(Ty));
1026 if (
const auto *EIT = Ty->
getAs<BitIntType>()) {
1027 if (EIT->getNumBits() <= 64) {
1032 return getIndirectResult(Ty,
false, State);
1040void X86_32ABIInfo::computeInfo(CGFunctionInfo &FI)
const {
1044 else if (State.CC == llvm::CallingConv::X86_FastCall) {
1046 State.FreeSSERegs = 3;
1047 }
else if (State.CC == llvm::CallingConv::X86_VectorCall) {
1049 State.FreeSSERegs = 6;
1052 else if (State.CC == llvm::CallingConv::X86_RegCall) {
1054 State.FreeSSERegs = 8;
1055 }
else if (IsWin32StructABI) {
1058 State.FreeRegs = DefaultNumRegisterParameters;
1059 State.FreeSSERegs = 3;
1061 State.FreeRegs = DefaultNumRegisterParameters;
1068 if (State.FreeRegs) {
1081 if (State.CC == llvm::CallingConv::X86_VectorCall)
1082 runVectorCallFirstPass(FI, State);
1084 bool UsedInAlloca =
false;
1085 MutableArrayRef<CGFunctionInfoArgInfo> Args = FI.
arguments();
1086 for (
unsigned I = 0, E = Args.size(); I < E; ++I) {
1088 if (State.IsPreassigned.test(I))
1099 rewriteWithInAlloca(FI);
1103X86_32ABIInfo::addFieldToArgStruct(SmallVector<llvm::Type *, 6> &FrameFields,
1104 CharUnits &StackOffset, ABIArgInfo &Info,
1105 QualType
Type)
const {
1108 assert(StackOffset.
isMultipleOf(WordSize) &&
"unaligned inalloca struct");
1113 bool IsIndirect =
false;
1117 llvm::Type *LLTy = CGT.ConvertTypeForMem(
Type);
1119 LLTy = llvm::PointerType::getUnqual(getVMContext());
1120 FrameFields.push_back(LLTy);
1121 StackOffset += IsIndirect ? WordSize : getContext().getTypeSizeInChars(
Type);
1124 CharUnits FieldEnd = StackOffset;
1125 StackOffset = FieldEnd.
alignTo(WordSize);
1126 if (StackOffset != FieldEnd) {
1127 CharUnits NumBytes = StackOffset - FieldEnd;
1128 llvm::Type *Ty = llvm::Type::getInt8Ty(getVMContext());
1129 Ty = llvm::ArrayType::get(Ty, NumBytes.
getQuantity());
1130 FrameFields.push_back(Ty);
1153 llvm_unreachable(
"invalid enum");
1156void X86_32ABIInfo::rewriteWithInAlloca(CGFunctionInfo &FI)
const {
1157 assert(IsWin32StructABI &&
"inalloca only supported on win32");
1160 SmallVector<llvm::Type *, 6> FrameFields;
1165 CharUnits StackOffset;
1172 if (
Ret.isIndirect() &&
Ret.isSRetAfterThis() && !IsThisCall &&
1174 addFieldToArgStruct(FrameFields, StackOffset, I->
info, I->
type);
1179 if (
Ret.isIndirect() && !
Ret.getInReg()) {
1180 addFieldToArgStruct(FrameFields, StackOffset, Ret, FI.
getReturnType());
1182 Ret.setInAllocaSRet(IsWin32StructABI);
1190 for (; I != E; ++I) {
1192 addFieldToArgStruct(FrameFields, StackOffset, I->
info, I->
type);
1195 FI.
setArgStruct(llvm::StructType::get(getVMContext(), FrameFields,
1200RValue X86_32ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
1201 QualType Ty, AggValueSlot Slot)
const {
1203 auto TypeInfo = getContext().getTypeInfoInChars(Ty);
1205 CCState State(*
const_cast<CGFunctionInfo *
>(CGF.
CurFnInfo));
1216 getTypeStackAlignInBytes(Ty, TypeInfo.Align.getQuantity()));
1223bool X86_32TargetCodeGenInfo::isStructReturnInRegABI(
1224 const llvm::Triple &Triple,
const CodeGenOptions &Opts) {
1225 assert(Triple.getArch() == llvm::Triple::x86);
1227 switch (Opts.getStructReturnConvention()) {
1236 if (Triple.isOSDarwin() || Triple.isOSIAMCU())
1239 switch (Triple.getOS()) {
1240 case llvm::Triple::DragonFly:
1241 case llvm::Triple::FreeBSD:
1242 case llvm::Triple::OpenBSD:
1243 case llvm::Triple::Win32:
1252 if (!FD->
hasAttr<AnyX86InterruptAttr>())
1256 Fn->setCallingConv(llvm::CallingConv::X86_INTR);
1262 llvm::Attribute NewAttr = llvm::Attribute::getWithByValType(
1263 Fn->getContext(), ByValTy);
1264 Fn->addParamAttr(0, NewAttr);
1267void X86_32TargetCodeGenInfo::setTargetAttributes(
1268 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM)
const {
1269 if (GV->isDeclaration())
1271 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
1272 if (FD->hasAttr<X86ForceAlignArgPointerAttr>()) {
1274 Fn->addFnAttr(
"stackrealign");
1281bool X86_32TargetCodeGenInfo::initDwarfEHRegSizeTable(
1282 CodeGen::CodeGenFunction &CGF,
1283 llvm::Value *Address)
const {
1284 CodeGen::CGBuilderTy &Builder = CGF.
Builder;
1286 llvm::Value *Four8 = llvm::ConstantInt::get(CGF.
Int8Ty, 4);
1297 llvm::Value *Sixteen8 = llvm::ConstantInt::get(CGF.
Int8Ty, 16);
1303 Builder.CreateAlignedStore(
1304 Four8, Builder.CreateConstInBoundsGEP1_32(CGF.
Int8Ty, Address, 9),
1310 llvm::Value *Twelve8 = llvm::ConstantInt::get(CGF.
Int8Ty, 12);
1325static unsigned getNativeVectorSizeForAVXABI(
X86AVXABILevel AVXLevel) {
1327 case X86AVXABILevel::AVX512:
1329 case X86AVXABILevel::AVX:
1331 case X86AVXABILevel::None:
1334 llvm_unreachable(
"Unknown AVXLevel");
1338class X86_64ABIInfo :
public ABIInfo {
1375 void postMerge(
unsigned AggregateSize,
Class &Lo,
Class &Hi)
const;
1404 bool isNamedArg,
bool IsRegCall =
false)
const;
1406 llvm::Type *GetByteVectorType(QualType Ty)
const;
1407 llvm::Type *GetSSETypeAtOffset(llvm::Type *IRType,
1408 unsigned IROffset, QualType SourceTy,
1409 unsigned SourceOffset)
const;
1410 llvm::Type *GetINTEGERTypeAtOffset(llvm::Type *IRType,
1411 unsigned IROffset, QualType SourceTy,
1412 unsigned SourceOffset)
const;
1416 ABIArgInfo getIndirectReturnResult(QualType Ty)
const;
1423 ABIArgInfo getIndirectResult(QualType Ty,
unsigned freeIntRegs)
const;
1428 unsigned &neededInt,
unsigned &neededSSE,
1430 bool IsRegCall =
false)
const;
1432 ABIArgInfo classifyRegCallStructType(QualType Ty,
unsigned &NeededInt,
1433 unsigned &NeededSSE,
1434 unsigned &MaxVectorWidth)
const;
1436 bool passRegCallStructTypeDirectly(QualType Ty,
1437 SmallVectorImpl<llvm::Type *> &CoerceElts,
1438 unsigned &NeededInt,
unsigned &NeededSSE,
1439 unsigned &MaxVectorWidth)
const;
1441 bool IsIllegalVectorType(QualType Ty)
const;
1448 bool honorsRevision0_98()
const {
1449 return !getTarget().getTriple().isOSDarwin();
1454 bool classifyIntegerMMXAsSSE()
const {
1456 if (getContext().getLangOpts().isCompatibleWith(
1457 LangOptions::ClangABI::Ver3_8))
1460 const llvm::Triple &Triple = getTarget().getTriple();
1461 if (Triple.isOSDarwin() || Triple.isPS() || Triple.isOSFreeBSD())
1467 bool passInt128VectorsInMem()
const {
1469 if (getContext().getLangOpts().isCompatibleWith(
1470 LangOptions::ClangABI::Ver9))
1473 const llvm::Triple &
T = getTarget().getTriple();
1474 return T.isOSLinux() ||
T.isOSNetBSD();
1477 bool returnCXXRecordGreaterThan128InMem()
const {
1479 if (getContext().getLangOpts().isCompatibleWith(
1480 LangOptions::ClangABI::Ver20) ||
1490 bool Has64BitPointers;
1493 X86_64ABIInfo(CodeGen::CodeGenTypes &CGT,
X86AVXABILevel AVXLevel)
1494 : ABIInfo(CGT), AVXLevel(AVXLevel),
1495 Has64BitPointers(CGT.getDataLayout().getPointerSize(0) == 8) {}
1497 bool isPassedUsingAVXType(QualType
type)
const {
1498 unsigned neededInt, neededSSE;
1502 if (
info.isDirect()) {
1503 llvm::Type *ty =
info.getCoerceToType();
1504 if (llvm::VectorType *vectorTy = dyn_cast_or_null<llvm::VectorType>(ty))
1505 return vectorTy->getPrimitiveSizeInBits().getFixedValue() > 128;
1510 void computeInfo(CGFunctionInfo &FI)
const override;
1511 unsigned getX86ABIAVXLevel(
const FunctionDecl *FD,
1512 const FunctionType::ExtInfo &Info)
const override;
1514 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
1515 AggValueSlot Slot)
const override;
1516 RValue EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
1517 AggValueSlot Slot)
const override;
1519 bool has64BitPointers()
const {
1520 return Has64BitPointers;
1525class WinX86_64ABIInfo :
public ABIInfo {
1527 WinX86_64ABIInfo(CodeGen::CodeGenTypes &CGT,
X86AVXABILevel AVXLevel)
1528 : ABIInfo(CGT), AVXLevel(AVXLevel),
1529 IsMingw64(getTarget().
getTriple().isWindowsGNUEnvironment()) {}
1531 void computeInfo(CGFunctionInfo &FI)
const override;
1532 unsigned getX86ABIAVXLevel(
const FunctionDecl *FD,
1533 const FunctionType::ExtInfo &Info)
const override;
1535 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
1536 AggValueSlot Slot)
const override;
1538 bool isHomogeneousAggregateBaseType(QualType Ty)
const override {
1540 return isX86VectorTypeForVectorCall(getContext(), Ty);
1543 bool isHomogeneousAggregateSmallEnough(
const Type *Ty,
1544 uint64_t NumMembers)
const override {
1546 return isX86VectorCallAggregateSmallEnough(NumMembers);
1549 ABIArgInfo classifyArgForArm64ECVarArg(QualType Ty,
1550 bool IsNamedArg)
const override {
1551 unsigned FreeSSERegs = 0;
1553 IsNamedArg ? ClassifyKind::FixedArgument : ClassifyKind::VarArg;
1554 return classify(Ty, FreeSSERegs, Kind, llvm::CallingConv::C);
1558 enum class ClassifyKind { Return, FixedArgument, VarArg };
1560 ABIArgInfo classify(QualType Ty,
unsigned &FreeSSERegs, ClassifyKind Kind,
1562 ABIArgInfo reclassifyHvaArgForVectorCall(QualType Ty,
unsigned &FreeSSERegs,
1563 const ABIArgInfo ¤t)
const;
1570class X86_64TargetCodeGenInfo :
public TargetCodeGenInfo {
1572 X86_64TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
X86AVXABILevel AVXLevel)
1573 : TargetCodeGenInfo(std::make_unique<X86_64ABIInfo>(CGT, AVXLevel)) {
1575 std::make_unique<SwiftABIInfo>(CGT,
true);
1580 bool markARCOptimizedReturnCallsAsNoTail()
const override {
return true; }
1582 int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM)
const override {
1586 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
1587 llvm::Value *Address)
const override {
1588 llvm::Value *Eight8 = llvm::ConstantInt::get(CGF.
Int8Ty, 8);
1596 llvm::Type* adjustInlineAsmType(CodeGen::CodeGenFunction &CGF,
1597 StringRef Constraint,
1598 llvm::Type* Ty)
const override {
1599 return X86AdjustInlineAsmType(CGF, Constraint, Ty);
1602 bool isNoProtoCallVariadic(
const CallArgList &args,
1603 const FunctionNoProtoType *fnType)
const override {
1611 bool HasAVXType =
false;
1612 for (
const CallArg &arg : args) {
1613 if (getABIInfo<X86_64ABIInfo>().isPassedUsingAVXType(
arg.Ty)) {
1626 void setTargetAttributes(
const Decl *D, llvm::GlobalValue *GV,
1627 CodeGen::CodeGenModule &CGM)
const override {
1628 if (GV->isDeclaration())
1630 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
1631 if (FD->hasAttr<X86ForceAlignArgPointerAttr>()) {
1633 Fn->addFnAttr(
"stackrealign");
1640 void checkFunctionCallABI(CodeGenModule &CGM, SourceLocation CallLoc,
1641 const FunctionDecl *Caller,
1642 const FunctionDecl *Callee,
const CallArgList &Args,
1643 QualType ReturnType)
const override;
1645 void checkFunctionABI(CodeGenModule &CGM,
1646 const FunctionDecl *FD)
const override;
1651 llvm::StringMap<bool> &CallerMap,
1653 llvm::StringMap<bool> &CalleeMap,
1655 if (CalleeMap.empty() && CallerMap.empty()) {
1667 const llvm::StringMap<bool> &CallerMap,
1668 const llvm::StringMap<bool> &CalleeMap,
1671 bool CallerHasFeat = CallerMap.lookup(
Feature);
1672 bool CalleeHasFeat = CalleeMap.lookup(
Feature);
1674 if (!CallerHasFeat && !CalleeHasFeat &&
1675 (!Callee.isExternallyVisible() || Callee.hasAttr<AlwaysInlineAttr>()))
1678 if (!CallerHasFeat && !CalleeHasFeat)
1679 return Diag.Report(CallLoc, diag::warn_avx_calling_convention)
1680 << IsArgument << Ty <<
Feature;
1683 if (!CallerHasFeat || !CalleeHasFeat)
1684 return Diag.Report(CallLoc, diag::err_avx_calling_convention)
1685 << IsArgument << Ty <<
Feature;
1694 const llvm::StringMap<bool> &CallerMap,
1695 const llvm::StringMap<bool> &CalleeMap,
QualType Ty,
1700 "avx512f", IsArgument);
1709void X86_64TargetCodeGenInfo::checkFunctionABI(CodeGenModule &CGM,
1710 const FunctionDecl *FD)
const {
1711 auto GetReturnTypeLoc = [](
const FunctionDecl *FD) {
1713 TypeLoc TL = TSI->getTypeLoc();
1716 SourceLocation Loc = FTL.getReturnLoc().getBeginLoc();
1729 auto Check = [&](QualType Ty, SourceLocation Loc,
bool IsReturn) {
1738 llvm::StringMap<bool> FeatureMap;
1740 if (!FeatureMap.lookup(
Feature)) {
1742 << !IsReturn << Ty <<
Feature;
1759 for (
const ParmVarDecl *P : FD->
parameters()) {
1760 SourceLocation Loc = P->getLocation();
1762 Loc = P->getBeginLoc();
1763 if (Check(P->getType(), Loc,
false))
1768void X86_64TargetCodeGenInfo::checkFunctionCallABI(CodeGenModule &CGM,
1769 SourceLocation CallLoc,
1770 const FunctionDecl *Caller,
1771 const FunctionDecl *Callee,
1772 const CallArgList &Args,
1773 QualType ReturnType)
const {
1777 llvm::StringMap<bool> CallerMap;
1778 llvm::StringMap<bool> CalleeMap;
1779 unsigned ArgIndex = 0;
1783 for (
const CallArg &Arg : Args) {
1791 if (Arg.getType()->isVectorType() &&
1794 QualType Ty = Arg.getType();
1797 if (ArgIndex < Callee->getNumParams())
1798 Ty =
Callee->getParamDecl(ArgIndex)->getType();
1801 CallerMap, CalleeMap, Ty,
true))
1809 if (
Callee->getReturnType()->isVectorType() &&
1813 CalleeMap,
Callee->getReturnType(),
1822 bool Quote = Lib.contains(
' ');
1823 std::string ArgStr = Quote ?
"\"" :
"";
1825 if (!Lib.ends_with_insensitive(
".lib") && !Lib.ends_with_insensitive(
".a"))
1827 ArgStr += Quote ?
"\"" :
"";
1832class WinX86_32TargetCodeGenInfo :
public X86_32TargetCodeGenInfo {
1835 bool DarwinVectorABI,
bool RetSmallStructInRegABI,
bool Win32StructABI,
1836 unsigned NumRegisterParameters)
1837 : X86_32TargetCodeGenInfo(CGT, DarwinVectorABI, RetSmallStructInRegABI,
1838 Win32StructABI, NumRegisterParameters,
false) {}
1840 void setTargetAttributes(
const Decl *D, llvm::GlobalValue *GV,
1843 void getDependentLibraryOption(llvm::StringRef Lib,
1845 Opt =
"/DEFAULTLIB:";
1846 Opt += qualifyWindowsLibrary(Lib);
1849 void getDetectMismatchOption(llvm::StringRef Name,
1850 llvm::StringRef
Value,
1852 Opt =
"/FAILIFMISMATCH:\"" + Name.str() +
"=" +
Value.str() +
"\"";
1857void WinX86_32TargetCodeGenInfo::setTargetAttributes(
1858 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM)
const {
1859 X86_32TargetCodeGenInfo::setTargetAttributes(D, GV, CGM);
1860 if (GV->isDeclaration())
1862 addStackProbeTargetAttributes(D, GV, CGM);
1866class WinX86_64TargetCodeGenInfo :
public TargetCodeGenInfo {
1868 WinX86_64TargetCodeGenInfo(CodeGen::CodeGenTypes &CGT,
1870 : TargetCodeGenInfo(std::make_unique<WinX86_64ABIInfo>(CGT, AVXLevel)) {
1872 std::make_unique<SwiftABIInfo>(CGT,
true);
1875 void setTargetAttributes(
const Decl *D, llvm::GlobalValue *GV,
1876 CodeGen::CodeGenModule &CGM)
const override;
1878 int getDwarfEHStackPointer(CodeGen::CodeGenModule &CGM)
const override {
1882 bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
1883 llvm::Value *Address)
const override {
1884 llvm::Value *Eight8 = llvm::ConstantInt::get(CGF.
Int8Ty, 8);
1892 void getDependentLibraryOption(llvm::StringRef Lib,
1893 llvm::SmallString<24> &Opt)
const override {
1894 Opt =
"/DEFAULTLIB:";
1895 Opt += qualifyWindowsLibrary(Lib);
1898 void getDetectMismatchOption(llvm::StringRef Name,
1899 llvm::StringRef
Value,
1900 llvm::SmallString<32> &Opt)
const override {
1901 Opt =
"/FAILIFMISMATCH:\"" + Name.str() +
"=" +
Value.str() +
"\"";
1906void WinX86_64TargetCodeGenInfo::setTargetAttributes(
1907 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM)
const {
1909 if (GV->isDeclaration())
1911 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
1912 if (FD->
hasAttr<X86ForceAlignArgPointerAttr>()) {
1914 Fn->addFnAttr(
"stackrealign");
1920 addStackProbeTargetAttributes(D, GV, CGM);
1923void X86_64ABIInfo::postMerge(
unsigned AggregateSize,
Class &Lo,
1948 if (Hi == X87Up && Lo != X87 && honorsRevision0_98())
1950 if (AggregateSize > 128 && (Lo != SSE || Hi != SSEUp))
1952 if (Hi == SSEUp && Lo != SSE)
1962 LangOptions::ClangABI::Ver23) {
1963 return GlobalAVXLevel;
1970 if (!FD || !FD->
hasAttr<TargetAttr>())
1973 llvm::StringMap<bool> FeatureMap;
1975 if (FeatureMap.lookup(
"avx512f"))
1977 if (FeatureMap.lookup(
"avx"))
1982X86_64ABIInfo::Class X86_64ABIInfo::merge(
Class Accum,
Class Field) {
2006 assert((Accum !=
Memory && Accum != ComplexX87) &&
2007 "Invalid accumulated classification during merge.");
2008 if (Accum == Field || Field == NoClass)
2012 if (Accum == NoClass)
2016 if (Field == X87 || Field == X87Up || Field == ComplexX87 ||
2017 Accum == X87 || Accum == X87Up)
2022void X86_64ABIInfo::classify(QualType Ty,
uint64_t OffsetBase,
Class &Lo,
2023 Class &Hi,
bool isNamedArg,
bool IsRegCall)
const {
2034 Class &Current = OffsetBase < 64 ? Lo : Hi;
2037 if (
const BuiltinType *BT = Ty->
getAs<BuiltinType>()) {
2040 if (k == BuiltinType::Void) {
2042 }
else if (k == BuiltinType::Int128 || k == BuiltinType::UInt128) {
2045 }
else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
2047 }
else if (k == BuiltinType::Float || k == BuiltinType::Double ||
2048 k == BuiltinType::Float16 || k == BuiltinType::BFloat16) {
2050 }
else if (k == BuiltinType::Float128) {
2053 }
else if (k == BuiltinType::LongDouble) {
2054 const llvm::fltSemantics *LDF = &getTarget().getLongDoubleFormat();
2055 if (LDF == &llvm::APFloat::IEEEquad()) {
2058 }
else if (LDF == &llvm::APFloat::x87DoubleExtended()) {
2061 }
else if (LDF == &llvm::APFloat::IEEEdouble()) {
2064 llvm_unreachable(
"unexpected long double representation!");
2073 classify(ED->getIntegerType(), OffsetBase, Lo, Hi, isNamedArg);
2084 if (Has64BitPointers) {
2091 uint64_t EB_FuncPtr = (OffsetBase) / 64;
2092 uint64_t EB_ThisAdj = (OffsetBase + 64 - 1) / 64;
2093 if (EB_FuncPtr != EB_ThisAdj) {
2105 if (
const VectorType *VT = Ty->
getAs<VectorType>()) {
2107 if (Size == 1 || Size == 8 || Size == 16 || Size == 32) {
2116 uint64_t EB_Lo = (OffsetBase) / 64;
2120 }
else if (Size == 64) {
2121 QualType ElementType = VT->getElementType();
2124 if (ElementType->isSpecificBuiltinType(BuiltinType::Double))
2130 if (!classifyIntegerMMXAsSSE() &&
2131 (ElementType->isSpecificBuiltinType(BuiltinType::LongLong) ||
2132 ElementType->isSpecificBuiltinType(BuiltinType::ULongLong) ||
2133 ElementType->isSpecificBuiltinType(BuiltinType::Long) ||
2134 ElementType->isSpecificBuiltinType(BuiltinType::ULong)))
2141 if (OffsetBase && OffsetBase != 64)
2143 }
else if (Size == 128 ||
2144 (isNamedArg && Size <= getNativeVectorSizeForAVXABI(AVXLevel))) {
2145 QualType ElementType = VT->getElementType();
2148 if (passInt128VectorsInMem() && Size != 128 &&
2149 (ElementType->isSpecificBuiltinType(BuiltinType::Int128) ||
2150 ElementType->isSpecificBuiltinType(BuiltinType::UInt128)))
2173 if (
const ComplexType *CT = Ty->
getAs<ComplexType>()) {
2180 else if (Size <= 128)
2182 }
else if (ET->
isFloat16Type() || ET == getContext().FloatTy ||
2185 }
else if (ET == getContext().DoubleTy) {
2187 }
else if (ET == getContext().LongDoubleTy) {
2188 const llvm::fltSemantics *LDF = &getTarget().getLongDoubleFormat();
2189 if (LDF == &llvm::APFloat::IEEEquad())
2191 else if (LDF == &llvm::APFloat::x87DoubleExtended())
2192 Current = ComplexX87;
2193 else if (LDF == &llvm::APFloat::IEEEdouble())
2196 llvm_unreachable(
"unexpected long double representation!");
2201 uint64_t EB_Real = (OffsetBase) / 64;
2202 uint64_t EB_Imag = (OffsetBase + getContext().getTypeSize(ET)) / 64;
2203 if (Hi == NoClass && EB_Real != EB_Imag)
2209 if (
const auto *EITy = Ty->
getAs<BitIntType>()) {
2210 if (EITy->getNumBits() <= 64)
2212 else if (EITy->getNumBits() <= 128)
2218 if (
const ConstantArrayType *AT = getContext().getAsConstantArrayType(Ty)) {
2227 if (!IsRegCall && Size > 512)
2234 if (OffsetBase % getContext().getTypeAlign(AT->getElementType()))
2240 uint64_t EltSize = getContext().getTypeSize(AT->getElementType());
2241 uint64_t ArraySize = AT->getZExtSize();
2248 (Size != EltSize || Size > getNativeVectorSizeForAVXABI(AVXLevel)))
2251 for (
uint64_t i=0, Offset=OffsetBase; i<ArraySize; ++i, Offset += EltSize) {
2252 Class FieldLo, FieldHi;
2253 classify(AT->getElementType(), Offset, FieldLo, FieldHi, isNamedArg);
2254 Lo =
merge(Lo, FieldLo);
2255 Hi =
merge(Hi, FieldHi);
2260 postMerge(Size, Lo, Hi);
2261 assert((Hi != SSEUp || Lo == SSE) &&
"Invalid SSEUp array classification.");
2285 const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
2291 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
2292 for (
const auto &I : CXXRD->bases()) {
2293 assert(!I.isVirtual() && !I.getType()->isDependentType() &&
2294 "Unexpected base class!");
2295 const auto *
Base = I.getType()->castAsCXXRecordDecl();
2301 Class FieldLo, FieldHi;
2304 classify(I.getType(), Offset, FieldLo, FieldHi, isNamedArg);
2305 Lo =
merge(Lo, FieldLo);
2306 Hi =
merge(Hi, FieldHi);
2307 if (returnCXXRecordGreaterThan128InMem() &&
2309 (Size > 128 && (Size != getContext().getTypeSize(I.getType()) ||
2310 Size > getNativeVectorSizeForAVXABI(AVXLevel)))) {
2316 postMerge(Size, Lo, Hi);
2324 bool UseClang11Compat = getContext().getLangOpts().isCompatibleWith(
2325 LangOptions::ClangABI::Ver11) ||
2326 getContext().getTargetInfo().getTriple().isPS();
2327 bool ClassifyUnnamedBitFields =
2328 getContext().getLangOpts().getClangABICompat() >
2329 LangOptions::ClangABI::Ver23 &&
2330 !getContext().getTargetInfo().getTriple().isPS();
2331 bool IsUnion = RT->isUnionType() && !UseClang11Compat;
2334 i != e; ++i, ++idx) {
2336 bool BitField = i->isBitField();
2343 if (BitField && (ClassifyUnnamedBitFields ? i->isZeroLengthBitField()
2344 : i->isUnnamedBitField()))
2357 ((!IsUnion && Size != getContext().getTypeSize(i->getType())) ||
2358 Size > getNativeVectorSizeForAVXABI(AVXLevel))) {
2360 postMerge(Size, Lo, Hi);
2365 Offset % getContext().getTypeAlign(i->getType().getCanonicalType());
2367 if (!BitField && IsInMemory) {
2369 postMerge(Size, Lo, Hi);
2379 Class FieldLo, FieldHi;
2385 assert(ClassifyUnnamedBitFields ? !i->isZeroLengthBitField()
2386 : !i->isUnnamedBitField());
2394 assert(EB_Hi == EB_Lo &&
"Invalid classification, type > 16 bytes.");
2399 FieldHi = EB_Hi ?
Integer : NoClass;
2402 classify(i->getType(), Offset, FieldLo, FieldHi, isNamedArg);
2403 Lo =
merge(Lo, FieldLo);
2404 Hi =
merge(Hi, FieldHi);
2409 postMerge(Size, Lo, Hi);
2413ABIArgInfo X86_64ABIInfo::getIndirectReturnResult(QualType Ty)
const {
2419 Ty = ED->getIntegerType();
2422 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace());
2424 llvm::Type *IRTy = CGT.ConvertType(Ty);
2426 : ABIArgInfo::getDirect(IRTy);
2429 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace());
2432bool X86_64ABIInfo::IsIllegalVectorType(QualType Ty)
const {
2433 if (
const VectorType *VecTy = Ty->
getAs<VectorType>()) {
2435 unsigned LargestVector = getNativeVectorSizeForAVXABI(AVXLevel);
2436 if (Size <= 64 || Size > LargestVector)
2438 QualType EltTy = VecTy->getElementType();
2439 if (passInt128VectorsInMem() &&
2448ABIArgInfo X86_64ABIInfo::getIndirectResult(QualType Ty,
2449 unsigned freeIntRegs)
const {
2462 Ty = ED->getIntegerType();
2464 llvm::Type *IRTy = CGT.ConvertType(Ty);
2470 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
2475 unsigned Align = std::max(getContext().getTypeAlign(Ty) / 8, 8U);
2498 if (freeIntRegs == 0) {
2503 if (Align == 8 && Size <= 64)
2509 getDataLayout().getAllocaAddrSpace());
2514llvm::Type *X86_64ABIInfo::GetByteVectorType(QualType Ty)
const {
2518 Ty = QualType(InnerTy, 0);
2520 llvm::Type *IRType = CGT.ConvertType(Ty);
2524 if (passInt128VectorsInMem() &&
2528 return llvm::FixedVectorType::get(llvm::Type::getInt64Ty(getVMContext()),
2535 if (IRType->getTypeID() == llvm::Type::FP128TyID)
2540 assert((Size == 128 || Size == 256 || Size == 512) &&
"Invalid type found!");
2544 return llvm::FixedVectorType::get(llvm::Type::getDoubleTy(getVMContext()),
2560 unsigned TySize = (
unsigned)Context.getTypeSize(Ty);
2561 if (TySize <= StartBit)
2565 unsigned EltSize = (
unsigned)Context.getTypeSize(AT->getElementType());
2566 unsigned NumElts = (
unsigned)AT->getZExtSize();
2569 for (
unsigned i = 0; i != NumElts; ++i) {
2571 unsigned EltOffset = i*EltSize;
2572 if (EltOffset >= EndBit)
break;
2574 unsigned EltStart = EltOffset < StartBit ? StartBit-EltOffset :0;
2576 EndBit-EltOffset, Context))
2587 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
2588 for (
const auto &I : CXXRD->bases()) {
2589 assert(!I.isVirtual() && !I.getType()->isDependentType() &&
2590 "Unexpected base class!");
2591 const auto *
Base = I.getType()->castAsCXXRecordDecl();
2595 if (BaseOffset >= EndBit)
continue;
2597 unsigned BaseStart = BaseOffset < StartBit ? StartBit-BaseOffset :0;
2599 EndBit-BaseOffset, Context))
2610 i != e; ++i, ++idx) {
2614 if (FieldOffset >= EndBit)
break;
2616 unsigned FieldStart = FieldOffset < StartBit ? StartBit-FieldOffset :0;
2632 const llvm::DataLayout &TD) {
2633 if (IROffset == 0 && IRType->isFloatingPointTy())
2637 if (llvm::StructType *STy = dyn_cast<llvm::StructType>(IRType)) {
2638 if (!STy->getNumContainedTypes())
2641 const llvm::StructLayout *SL = TD.getStructLayout(STy);
2642 unsigned Elt = SL->getElementContainingOffset(IROffset);
2643 IROffset -= SL->getElementOffset(Elt);
2648 if (llvm::ArrayType *ATy = dyn_cast<llvm::ArrayType>(IRType)) {
2649 llvm::Type *EltTy = ATy->getElementType();
2650 unsigned EltSize = TD.getTypeAllocSize(EltTy);
2653 IROffset -= IROffset / EltSize * EltSize;
2662llvm::Type *X86_64ABIInfo::
2663GetSSETypeAtOffset(llvm::Type *IRType,
unsigned IROffset,
2664 QualType SourceTy,
unsigned SourceOffset)
const {
2665 const llvm::DataLayout &TD = getDataLayout();
2666 unsigned SourceSize =
2667 (
unsigned)getContext().getTypeSize(SourceTy) / 8 - SourceOffset;
2669 if (!T0 || T0->isDoubleTy())
2670 return llvm::Type::getDoubleTy(getVMContext());
2673 llvm::Type *T1 =
nullptr;
2674 unsigned T0Size = TD.getTypeAllocSize(T0);
2675 if (SourceSize > T0Size)
2677 if (T1 ==
nullptr) {
2680 if (T0->is16bitFPTy() && SourceSize > 4)
2689 if (T0->isFloatTy() && T1->isFloatTy())
2690 return llvm::FixedVectorType::get(T0, 2);
2692 if (T0->is16bitFPTy() && T1->is16bitFPTy()) {
2693 llvm::Type *T2 =
nullptr;
2697 return llvm::FixedVectorType::get(T0, 2);
2698 return llvm::FixedVectorType::get(T0, 4);
2701 if (T0->is16bitFPTy() || T1->is16bitFPTy())
2702 return llvm::FixedVectorType::get(llvm::Type::getHalfTy(getVMContext()), 4);
2704 return llvm::Type::getDoubleTy(getVMContext());
2721llvm::Type *X86_64ABIInfo::
2722GetINTEGERTypeAtOffset(llvm::Type *IRType,
unsigned IROffset,
2723 QualType SourceTy,
unsigned SourceOffset)
const {
2726 if (IROffset == 0) {
2729 IRType->isIntegerTy(64))
2738 if (IRType->isIntegerTy(8) || IRType->isIntegerTy(16) ||
2739 IRType->isIntegerTy(32) ||
2745 SourceOffset*8+64, getContext()))
2750 if (llvm::StructType *STy = dyn_cast<llvm::StructType>(IRType)) {
2752 const llvm::StructLayout *SL = getDataLayout().getStructLayout(STy);
2753 if (IROffset < SL->getSizeInBytes()) {
2754 unsigned FieldIdx = SL->getElementContainingOffset(IROffset);
2755 IROffset -= SL->getElementOffset(FieldIdx);
2757 return GetINTEGERTypeAtOffset(STy->getElementType(FieldIdx), IROffset,
2758 SourceTy, SourceOffset);
2762 if (llvm::ArrayType *ATy = dyn_cast<llvm::ArrayType>(IRType)) {
2763 llvm::Type *EltTy = ATy->getElementType();
2764 unsigned EltSize = getDataLayout().getTypeAllocSize(EltTy);
2765 unsigned EltOffset = IROffset/EltSize*EltSize;
2766 return GetINTEGERTypeAtOffset(EltTy, IROffset-EltOffset, SourceTy,
2772 if (IRType->isIntegerTy(128)) {
2773 assert(IROffset == 0);
2779 unsigned TySizeInBytes =
2780 (
unsigned)getContext().getTypeSizeInChars(SourceTy).getQuantity();
2782 assert(TySizeInBytes != SourceOffset &&
"Empty field?");
2786 return llvm::IntegerType::get(getVMContext(),
2787 std::min(TySizeInBytes-SourceOffset, 8U)*8);
2798 const llvm::DataLayout &TD) {
2803 unsigned LoSize = (
unsigned)TD.getTypeAllocSize(Lo);
2804 llvm::Align HiAlign = TD.getABITypeAlign(Hi);
2805 unsigned HiStart = llvm::alignTo(LoSize, HiAlign);
2806 assert(HiStart != 0 && HiStart <= 8 &&
"Invalid x86-64 argument pair!");
2817 if (Lo->isHalfTy() || Lo->isFloatTy())
2818 Lo = llvm::Type::getDoubleTy(Lo->getContext());
2820 assert((Lo->isIntegerTy() || Lo->isPointerTy())
2821 &&
"Invalid/unknown lo type");
2822 Lo = llvm::Type::getInt64Ty(Lo->getContext());
2826 llvm::StructType *
Result = llvm::StructType::get(Lo, Hi);
2829 assert(TD.getStructLayout(
Result)->getElementOffset(1) == 8 &&
2830 "Invalid x86-64 argument pair!");
2834ABIArgInfo X86_64ABIInfo::classifyReturnType(QualType RetTy)
const {
2837 X86_64ABIInfo::Class Lo, Hi;
2838 classify(RetTy, 0, Lo, Hi,
true);
2841 assert((Hi !=
Memory || Lo ==
Memory) &&
"Invalid memory classification.");
2842 assert((Hi != SSEUp || Lo == SSE) &&
"Invalid SSEUp classification.");
2844 llvm::Type *ResType =
nullptr;
2851 assert((Hi == SSE || Hi ==
Integer || Hi == X87Up) &&
2852 "Unknown missing lo part");
2857 llvm_unreachable(
"Invalid classification for lo word.");
2862 return getIndirectReturnResult(RetTy);
2867 ResType = GetINTEGERTypeAtOffset(CGT.ConvertType(RetTy), 0, RetTy, 0);
2871 RetTy = ED->getIntegerType();
2878 : ABIArgInfo::getDirect();
2880 if (ResType->isIntegerTy(128)) {
2882 assert(Hi == Integer);
2883 return ABIArgInfo::getDirect(ResType);
2890 ResType = GetSSETypeAtOffset(CGT.ConvertType(RetTy), 0, RetTy, 0);
2896 ResType = llvm::Type::getX86_FP80Ty(getVMContext());
2903 assert(Hi == ComplexX87 &&
"Unexpected ComplexX87 classification.");
2904 ResType = llvm::StructType::get(llvm::Type::getX86_FP80Ty(getVMContext()),
2905 llvm::Type::getX86_FP80Ty(getVMContext()));
2909 llvm::Type *HighPart =
nullptr;
2915 llvm_unreachable(
"Invalid classification for hi word.");
2922 HighPart = GetINTEGERTypeAtOffset(CGT.ConvertType(RetTy), 8, RetTy, 8);
2927 HighPart = GetSSETypeAtOffset(CGT.ConvertType(RetTy), 8, RetTy, 8);
2938 assert(Lo == SSE &&
"Unexpected SSEUp classification.");
2939 ResType = GetByteVectorType(RetTy);
2950 HighPart = GetSSETypeAtOffset(CGT.ConvertType(RetTy), 8, RetTy, 8);
2967X86_64ABIInfo::classifyArgumentType(QualType Ty,
unsigned freeIntRegs,
2968 unsigned &neededInt,
unsigned &neededSSE,
2969 bool isNamedArg,
bool IsRegCall)
const {
2972 X86_64ABIInfo::Class Lo, Hi;
2973 classify(Ty, 0, Lo, Hi, isNamedArg, IsRegCall);
2977 assert((Hi !=
Memory || Lo ==
Memory) &&
"Invalid memory classification.");
2978 assert((Hi != SSEUp || Lo == SSE) &&
"Invalid SSEUp classification.");
2982 llvm::Type *ResType =
nullptr;
2989 assert((Hi == SSE || Hi ==
Integer || Hi == X87Up) &&
2990 "Unknown missing lo part");
3003 return getIndirectResult(Ty, freeIntRegs);
3007 llvm_unreachable(
"Invalid classification for lo word.");
3016 ResType = GetINTEGERTypeAtOffset(CGT.ConvertType(Ty), 0, Ty, 0);
3023 Ty = ED->getIntegerType();
3025 isPromotableIntegerTypeForABI(Ty)) {
3028 case CodeGenOptions::SmallIntABICompatKind::Platform:
3035 case CodeGenOptions::SmallIntABICompatKind::Clang23:
3037 case CodeGenOptions::SmallIntABICompatKind::Both:
3043 if (ResType->isIntegerTy(128)) {
3054 llvm::Type *IRType = CGT.ConvertType(Ty);
3055 ResType = GetSSETypeAtOffset(IRType, 0, Ty, 0);
3061 llvm::Type *HighPart =
nullptr;
3069 llvm_unreachable(
"Invalid classification for hi word.");
3071 case NoClass:
break;
3076 HighPart = GetINTEGERTypeAtOffset(CGT.ConvertType(Ty), 8, Ty, 8);
3087 HighPart = GetSSETypeAtOffset(CGT.ConvertType(Ty), 8, Ty, 8);
3097 assert(Lo == SSE &&
"Unexpected SSEUp classification");
3098 ResType = GetByteVectorType(Ty);
3115bool X86_64ABIInfo::passRegCallStructTypeDirectly(
3116 QualType Ty, SmallVectorImpl<llvm::Type *> &CoerceElts,
unsigned &NeededInt,
3117 unsigned &NeededSSE,
unsigned &MaxVectorWidth)
const {
3125 if (
auto CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
3126 if (CXXRD->isDynamicClass())
3129 for (
const auto &I : CXXRD->bases()) {
3130 QualType BaseTy = I.getType();
3133 if (!passRegCallStructTypeDirectly(BaseTy, CoerceElts, NeededInt,
3134 NeededSSE, MaxVectorWidth))
3140 for (
const auto *FD : RD->
fields()) {
3145 if (!passRegCallStructTypeDirectly(MTy, CoerceElts, NeededInt, NeededSSE,
3151 const auto *AT = getContext().getAsConstantArrayType(MTy);
3153 MTy = AT->getElementType();
3155 unsigned LocalNeededInt, LocalNeededSSE;
3157 LocalNeededSSE,
true,
true);
3164 assert(CoerceTy &&
"ABI info for struct member has no coerce type");
3166 uint64_t NumElts = AT->getZExtSize();
3167 LocalNeededInt *= NumElts;
3168 LocalNeededSSE *= NumElts;
3169 CoerceElts.push_back(llvm::ArrayType::get(CoerceTy, NumElts));
3171 CoerceElts.push_back(CoerceTy);
3174 if (
const auto *VT = MTy->
getAs<VectorType>())
3175 if (getContext().getTypeSize(VT) > MaxVectorWidth)
3176 MaxVectorWidth = getContext().getTypeSize(VT);
3178 NeededInt += LocalNeededInt;
3179 NeededSSE += LocalNeededSSE;
3186X86_64ABIInfo::classifyRegCallStructType(QualType Ty,
unsigned &NeededInt,
3187 unsigned &NeededSSE,
3188 unsigned &MaxVectorWidth)
const {
3196 SmallVector<llvm::Type *, 16> CoerceElts;
3197 if (!passRegCallStructTypeDirectly(Ty, CoerceElts, NeededInt, NeededSSE,
3199 NeededInt = NeededSSE = 0;
3200 return getIndirectReturnResult(Ty);
3203 assert(!CoerceElts.empty() &&
"Non-empty struct produced no element types");
3205 llvm::StructType::get(getVMContext(), CoerceElts));
3209X86_64ABIInfo::getX86ABIAVXLevel(
const FunctionDecl *FD,
3210 const FunctionType::ExtInfo &Info)
const {
3214void X86_64ABIInfo::computeInfo(CGFunctionInfo &FI)
const {
3220 WinX86_64ABIInfo Win64ABIInfo(CGT, AVXLevel);
3221 Win64ABIInfo.computeInfo(FI);
3226 static_cast<unsigned>(X86AVXABILevel::AVX512) &&
3227 "Unexpected X86 AVX ABI level");
3230 if (EffectiveAVXLevel != AVXLevel) {
3231 X86_64ABIInfo EffectiveABIInfo(CGT, EffectiveAVXLevel);
3232 EffectiveABIInfo.computeInfo(FI);
3236 bool IsRegCall =
CallingConv == llvm::CallingConv::X86_RegCall;
3239 unsigned FreeIntRegs = IsRegCall ? 11 : 6;
3240 unsigned FreeSSERegs = IsRegCall ? 16 : 8;
3241 unsigned NeededInt = 0, NeededSSE = 0, MaxVectorWidth = 0;
3248 if (FreeIntRegs >= NeededInt && FreeSSERegs >= NeededSSE) {
3249 FreeIntRegs -= NeededInt;
3250 FreeSSERegs -= NeededSSE;
3256 ->
getAs<ComplexType>()
3257 ->getElementType()) ==
3258 getContext().LongDoubleTy)
3270 else if (NeededSSE && MaxVectorWidth > 0)
3286 it != ie; ++it, ++ArgNo) {
3287 bool IsNamedArg = ArgNo < NumRequiredArgs;
3289 if (IsRegCall && it->type->isStructureOrClassType())
3290 it->info = classifyRegCallStructType(it->type, NeededInt, NeededSSE,
3294 NeededSSE, IsNamedArg);
3300 if (FreeIntRegs >= NeededInt && FreeSSERegs >= NeededSSE) {
3301 FreeIntRegs -= NeededInt;
3302 FreeSSERegs -= NeededSSE;
3306 it->info = getIndirectResult(it->type, FreeIntRegs);
3315 llvm::Value *overflow_arg_area =
3330 llvm::Value *Res = overflow_arg_area;
3338 llvm::Value *Offset =
3339 llvm::ConstantInt::get(CGF.
Int32Ty, (SizeInBytes + 7) & ~7);
3341 Offset,
"overflow_arg_area.next");
3345 return Address(Res, LTy, Align);
3348RValue X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
3349 QualType Ty, AggValueSlot Slot)
const {
3357 unsigned neededInt, neededSSE;
3369 if (!neededInt && !neededSSE)
3385 llvm::Value *InRegs =
nullptr;
3387 llvm::Value *gp_offset =
nullptr, *fp_offset =
nullptr;
3391 InRegs = llvm::ConstantInt::get(CGF.
Int32Ty, 48 - neededInt * 8);
3392 InRegs = CGF.
Builder.CreateICmpULE(gp_offset, InRegs,
"fits_in_gp");
3398 llvm::Value *FitsInFP =
3399 llvm::ConstantInt::get(CGF.
Int32Ty, 176 - neededSSE * 16);
3400 FitsInFP = CGF.
Builder.CreateICmpULE(fp_offset, FitsInFP,
"fits_in_fp");
3401 InRegs = InRegs ? CGF.
Builder.CreateAnd(InRegs, FitsInFP) : FitsInFP;
3407 CGF.
Builder.CreateCondBr(InRegs, InRegBlock, InMemBlock);
3428 if (neededInt && neededSSE) {
3430 assert(AI.
isDirect() &&
"Unexpected ABI info for mixed regs");
3434 assert(ST->getNumElements() == 2 &&
"Unexpected ABI info for mixed regs");
3435 llvm::Type *TyLo = ST->getElementType(0);
3436 llvm::Type *TyHi = ST->getElementType(1);
3437 assert((TyLo->isFPOrFPVectorTy() ^ TyHi->isFPOrFPVectorTy()) &&
3438 "Unexpected ABI info for mixed regs");
3439 llvm::Value *GPAddr =
3441 llvm::Value *FPAddr =
3443 llvm::Value *RegLoAddr = TyLo->isFPOrFPVectorTy() ? FPAddr : GPAddr;
3444 llvm::Value *RegHiAddr = TyLo->isFPOrFPVectorTy() ? GPAddr : FPAddr;
3460 }
else if (neededInt || neededSSE == 1) {
3462 auto TInfo = getContext().getTypeInfoInChars(Ty);
3463 uint64_t TySize = TInfo.Width.getQuantity();
3464 CharUnits TyAlign = TInfo.Align;
3465 llvm::Type *CoTy =
nullptr;
3469 llvm::Value *GpOrFpOffset = neededInt ? gp_offset : fp_offset;
3470 uint64_t Alignment = neededInt ? 8 : 16;
3471 uint64_t RegSize = neededInt ? neededInt * 8 : 16;
3496 llvm::Value *PtrOffset =
3518 assert(neededSSE == 2 &&
"Invalid number of needed registers!");
3551 llvm::Value *Offset = llvm::ConstantInt::get(CGF.
Int32Ty, neededInt * 8);
3556 llvm::Value *Offset = llvm::ConstantInt::get(CGF.
Int32Ty, neededSSE * 16);
3575RValue X86_64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
3576 QualType Ty, AggValueSlot Slot)
const {
3579 uint64_t Width = getContext().getTypeSize(Ty);
3580 bool IsIndirect = Width > 64 || !llvm::isPowerOf2_64(Width);
3588ABIArgInfo WinX86_64ABIInfo::reclassifyHvaArgForVectorCall(
3589 QualType Ty,
unsigned &FreeSSERegs,
const ABIArgInfo ¤t)
const {
3594 isHomogeneousAggregate(Ty, Base, NumElts) && FreeSSERegs >= NumElts) {
3595 FreeSSERegs -= NumElts;
3596 return getDirectX86Hva();
3601ABIArgInfo WinX86_64ABIInfo::classify(QualType Ty,
unsigned &FreeSSERegs,
3602 ClassifyKind Kind,
unsigned CC)
const {
3603 bool IsVectorCall = CC == llvm::CallingConv::X86_VectorCall;
3604 bool IsRegCall = CC == llvm::CallingConv::X86_RegCall;
3609 bool PromoteScopedEnum =
false;
3611 Ty = ED->getIntegerType();
3612 PromoteScopedEnum =
Kind == ClassifyKind::VarArg && ED->isScoped() &&
3613 getContext().isPromotableIntegerType(Ty);
3620 if (PromoteScopedEnum)
3623 TypeInfo Info = getContext().getTypeInfo(Ty);
3625 CharUnits Align = getContext().toCharUnitsFromBits(Info.
Align);
3629 if (Kind != ClassifyKind::Return) {
3631 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
3635 if (RT->getDecl()->getDefinitionOrSelf()->hasFlexibleArrayMember())
3636 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
3644 if ((IsVectorCall || IsRegCall) &&
3645 isHomogeneousAggregate(Ty, Base, NumElts)) {
3647 if (FreeSSERegs >= NumElts) {
3648 FreeSSERegs -= NumElts;
3655 Align, getDataLayout().getAllocaAddrSpace(),
3657 }
else if (IsVectorCall) {
3658 if (FreeSSERegs >= NumElts &&
3661 FreeSSERegs -= NumElts;
3663 }
else if (Kind == ClassifyKind::Return) {
3668 Align, getDataLayout().getAllocaAddrSpace(),
3677 llvm::Type *LLTy = CGT.ConvertType(Ty);
3678 if (LLTy->isPointerTy() || LLTy->isIntegerTy())
3685 if (Width > 64 || !llvm::isPowerOf2_64(Width))
3686 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
3693 if (
const BuiltinType *BT = Ty->
getAs<BuiltinType>()) {
3694 switch (BT->getKind()) {
3695 case BuiltinType::Bool:
3700 case BuiltinType::LongDouble:
3704 const llvm::fltSemantics *LDF = &getTarget().getLongDoubleFormat();
3705 if (LDF == &llvm::APFloat::x87DoubleExtended())
3707 Align, getDataLayout().getAllocaAddrSpace(),
3712 case BuiltinType::Int128:
3713 case BuiltinType::UInt128:
3714 case BuiltinType::Float128:
3718 if (Kind != ClassifyKind::Return)
3720 Align, getDataLayout().getAllocaAddrSpace(),
3725 if (BT->getKind() == BuiltinType::Int128 ||
3726 BT->getKind() == BuiltinType::UInt128)
3728 llvm::Type::getInt64Ty(getVMContext()), 2));
3732 if (BT->getKind() == BuiltinType::Float128) {
3733 auto IsWin64F128StackCC = [
this](
unsigned CC) ->
bool {
3735 case llvm::CallingConv::Win64:
3737 case llvm::CallingConv::C:
3738 return getTarget().getTriple().isOSWindowsOrUEFI();
3744 if (IsWin64F128StackCC(CC))
3745 return getNaturalAlignIndirect(
3746 Ty, getDataLayout().getAllocaAddrSpace(),
false);
3764 Align, getDataLayout().getAllocaAddrSpace(),
3772WinX86_64ABIInfo::getX86ABIAVXLevel(
const FunctionDecl *FD,
3773 const FunctionType::ExtInfo &Info)
const {
3778 return static_cast<unsigned>(AVXLevel);
3781void WinX86_64ABIInfo::computeInfo(CGFunctionInfo &FI)
const {
3783 bool IsVectorCall = CC == llvm::CallingConv::X86_VectorCall;
3784 bool IsRegCall = CC == llvm::CallingConv::X86_RegCall;
3788 if (CC == llvm::CallingConv::X86_64_SysV) {
3789 X86_64ABIInfo SysVABIInfo(CGT, AVXLevel);
3790 SysVABIInfo.computeInfo(FI);
3794 unsigned FreeSSERegs = 0;
3798 }
else if (IsRegCall) {
3805 classify(FI.
getReturnType(), FreeSSERegs, ClassifyKind::Return, CC);
3810 }
else if (IsRegCall) {
3815 unsigned ArgNum = 0;
3816 unsigned ZeroSSERegs = 0;
3821 unsigned *MaybeFreeSSERegs =
3822 (IsVectorCall && ArgNum >= 6) ? &ZeroSSERegs : &FreeSSERegs;
3824 ? ClassifyKind::VarArg
3825 : ClassifyKind::FixedArgument;
3826 I.
info = classify(I.
type, *MaybeFreeSSERegs, Kind, CC);
3834 I.
info = reclassifyHvaArgForVectorCall(I.
type, FreeSSERegs, I.
info);
3838RValue WinX86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
3839 QualType Ty, AggValueSlot Slot)
const {
3842 uint64_t Width = getContext().getTypeSize(Ty);
3843 bool IsIndirect = Width > 64 || !llvm::isPowerOf2_64(Width);
3852 CodeGenModule &CGM,
bool DarwinVectorABI,
bool Win32StructABI,
3853 unsigned NumRegisterParameters,
bool SoftFloatABI) {
3854 bool RetSmallStructInRegABI = X86_32TargetCodeGenInfo::isStructReturnInRegABI(
3856 return std::make_unique<X86_32TargetCodeGenInfo>(
3857 CGM.
getTypes(), DarwinVectorABI, RetSmallStructInRegABI, Win32StructABI,
3858 NumRegisterParameters, SoftFloatABI);
3862 CodeGenModule &CGM,
bool DarwinVectorABI,
bool Win32StructABI,
3863 unsigned NumRegisterParameters) {
3864 bool RetSmallStructInRegABI = X86_32TargetCodeGenInfo::isStructReturnInRegABI(
3866 return std::make_unique<WinX86_32TargetCodeGenInfo>(
3867 CGM.
getTypes(), DarwinVectorABI, RetSmallStructInRegABI, Win32StructABI,
3868 NumRegisterParameters);
3871std::unique_ptr<TargetCodeGenInfo>
3874 return std::make_unique<X86_64TargetCodeGenInfo>(CGM.
getTypes(), AVXLevel);
3877std::unique_ptr<TargetCodeGenInfo>
3880 return std::make_unique<WinX86_64TargetCodeGenInfo>(CGM.
getTypes(), AVXLevel);
static bool is32Or64BitBasicType(QualType Ty, ASTContext &Context)
static bool checkAVXParamFeature(DiagnosticsEngine &Diag, SourceLocation CallLoc, const FunctionDecl &Callee, const llvm::StringMap< bool > &CallerMap, const llvm::StringMap< bool > &CalleeMap, QualType Ty, StringRef Feature, bool IsArgument)
static void rewriteInputConstraintReferences(unsigned FirstIn, unsigned NumNewOuts, std::string &AsmString)
Rewrite input constraint references after adding some output constraints.
static const Type * getSingleFieldType(QualType T, ASTContext &Context)
Like isSingleElementRecord, but only looks through one level of records.
static void initFeatureMaps(const ASTContext &Ctx, llvm::StringMap< bool > &CallerMap, const FunctionDecl *Caller, llvm::StringMap< bool > &CalleeMap, const FunctionDecl *Callee)
static CodeGenOptions::SmallIntABICompatKind getEffectiveSmallIntABICompat(const CodeGenOptions &Opts, const llvm::Triple &T)
static llvm::Type * GetX86_64ByValArgumentPair(llvm::Type *Lo, llvm::Type *Hi, const llvm::DataLayout &TD)
GetX86_64ByValArgumentPair - Given a high and low type that can ideally be used as elements of a two ...
static X86AVXABILevel getEffectiveX86AVXABILevel(CodeGenTypes &CGT, X86AVXABILevel GlobalAVXLevel, const FunctionDecl *FD)
static bool checkAVXParam(DiagnosticsEngine &Diag, ASTContext &Ctx, SourceLocation CallLoc, const FunctionDecl &Callee, const llvm::StringMap< bool > &CallerMap, const llvm::StringMap< bool > &CalleeMap, QualType Ty, bool IsArgument)
static bool addBaseAndFieldSizes(ASTContext &Context, const CXXRecordDecl *RD, uint64_t &Size)
static llvm::Type * getFPTypeAtOffset(llvm::Type *IRType, unsigned IROffset, const llvm::DataLayout &TD)
getFPTypeAtOffset - Return a floating point type at the specified offset.
static bool addFieldSizes(ASTContext &Context, const RecordDecl *RD, uint64_t &Size)
static bool shouldExtendReturnType(const ABIInfo &Info, QualType RetTy)
static bool BitsContainNoUserData(QualType Ty, unsigned StartBit, unsigned EndBit, ASTContext &Context)
BitsContainNoUserData - Return true if the specified [start,end) bit range is known to either be off ...
static Address EmitX86_64VAArgFromMemory(CodeGenFunction &CGF, Address VAListAddr, QualType Ty)
static void addX86InterruptAttrs(const FunctionDecl *FD, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM)
static bool isArgInAlloca(const ABIArgInfo &Info)
Result
Implement __builtin_bit_cast and related operations.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
static StringRef getTriple(const Command &Job)
Defines the clang::SourceLocation class and associated facilities.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const ConstantArrayType * getAsConstantArrayType(QualType T) const
const llvm::StringMap< bool > & getFunctionFeatureMap(const FunctionDecl *FD) const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
const LangOptions & getLangOpts() const
TypeInfoChars getTypeInfoInChars(const Type *T) const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CharUnits getRequiredAlignment() const
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
This class is used for builtin types like 'int'.
Represents a base class of a C++ class.
Represents a C++ struct/union/class.
CanProxy< U > getAs() const
Retrieve a canonical type pointer with a different static type, upcasting or downcasting as needed.
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
This is an opaque type for sizes expressed in character units.
CharUnits alignTo(CharUnits Align) const
Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is a multiple...
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits One()
Construct a CharUnits quantity of one.
bool isMultipleOf(CharUnits N) const
Test whether this is a multiple of the other value.
static CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
bool getIndirectByVal() const
static ABIArgInfo getInAlloca(unsigned FieldIndex, bool Indirect=false)
static ABIArgInfo getIgnore()
static ABIArgInfo getExpand()
static ABIArgInfo getConservativeExtendInReg(QualType Ty, llvm::Type *T=nullptr)
unsigned getDirectOffset() const
void setIndirectAlign(CharUnits IA)
static ABIArgInfo getExtendInReg(QualType Ty, llvm::Type *T=nullptr)
static ABIArgInfo getExpandWithPadding(bool PaddingInReg, llvm::Type *Padding)
static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
@ Extend
Extend - Valid only for integer argument types.
@ Ignore
Ignore - Ignore the argument (treat as void).
@ IndirectAliased
IndirectAliased - Similar to Indirect, but the pointer may be to an object that is otherwise referenc...
@ Expand
Expand - Only valid for aggregate argument types.
@ TargetSpecific
TargetSpecific - Some argument types are passed as target specific types such as RISC-V's tuple type,...
@ InAlloca
InAlloca - Pass the argument directly using the LLVM inalloca attribute.
@ Indirect
Indirect - Pass the argument indirectly via a hidden pointer with the specified alignment (0 indicate...
@ CoerceAndExpand
CoerceAndExpand - Only valid for aggregate argument types.
@ Direct
Direct - Pass the argument directly using the normal converted LLVM type, or by coercing to another s...
static ABIArgInfo getExtend(QualType Ty, llvm::Type *T=nullptr, llvm::Type *Padding=nullptr)
static ABIArgInfo getIndirect(CharUnits Alignment, unsigned AddrSpace, bool ByVal=true, bool Realign=false, llvm::Type *Padding=nullptr)
static ABIArgInfo getConservativeExtend(QualType Ty, llvm::Type *T=nullptr)
llvm::Type * getCoerceToType() const
bool canHaveCoerceToType() const
static ABIArgInfo getDirectInReg(llvm::Type *T=nullptr)
ABIInfo - Target specific hooks for defining how a type should be passed or returned from functions.
bool isPromotableIntegerTypeForABI(QualType Ty) const
const TargetInfo & getTarget() const
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * getBasePointer() const
Address withElementType(llvm::Type *ElemTy) const
Return address with different element type, but same pointer and alignment.
llvm::StoreInst * CreateStore(llvm::Value *Val, Address Addr, bool IsVolatile=false)
Address CreateConstInBoundsByteGEP(Address Addr, CharUnits Offset, const llvm::Twine &Name="")
Given a pointer to i8, adjust it by a given constant offset.
Address CreateGEP(CodeGenFunction &CGF, Address Addr, llvm::Value *Index, const llvm::Twine &Name="")
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
llvm::LoadInst * CreateLoad(Address Addr, const llvm::Twine &Name="")
llvm::CallInst * CreateMemCpy(Address Dest, Address Src, llvm::Value *Size, bool IsVolatile=false)
llvm::LoadInst * CreateAlignedLoad(llvm::Type *Ty, llvm::Value *Addr, CharUnits Align, const llvm::Twine &Name="")
RecordArgABI
Specify how one should pass an argument of a record type.
@ RAA_Indirect
Pass it as a pointer to temporary memory.
@ RAA_DirectInMemory
Pass it on the stack using its defined layout.
ABIArgInfo & getReturnInfo()
unsigned getCallingConvention() const
getCallingConvention - Return the user specified calling convention, which has been translated into a...
const_arg_iterator arg_begin() const
unsigned getRegParm() const
CanQualType getReturnType() const
bool getHasRegParm() const
MutableArrayRef< ArgInfo > arguments()
const_arg_iterator arg_end() const
unsigned getX86ABIAVXLevel() const
void setArgStruct(llvm::StructType *Ty, CharUnits Align)
unsigned getMaxVectorWidth() const
Return the maximum vector width in the arguments.
unsigned getNumRequiredArgs() const
void setMaxVectorWidth(unsigned Width)
Set the maximum vector width in the arguments.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
RValue EmitLoadOfAnyValue(LValue V, AggValueSlot Slot=AggValueSlot::ignored(), SourceLocation Loc={})
Like EmitLoadOfLValue but also handles complex and aggregate types.
RawAddress CreateMemTempWithoutCast(QualType T, const Twine &Name="tmp")
CreateMemTemp - Create a temporary memory object of the given type, with appropriate alignmen without...
ASTContext & getContext() const
llvm::Type * ConvertTypeForMem(QualType T)
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
const CGFunctionInfo * CurFnInfo
llvm::LLVMContext & getLLVMContext()
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
This class organizes the cross-function state that is used while generating LLVM code.
DiagnosticsEngine & getDiags() const
CodeGenTypes & getTypes()
const TargetInfo & getTarget() const
const llvm::Triple & getTriple() const
ASTContext & getContext() const
const CodeGenOptions & getCodeGenOpts() const
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
ASTContext & getContext() const
const TargetInfo & getTarget() const
CodeGenModule & getCGM() const
bool isRequiredArg(unsigned argIdx) const
Return true if the argument at a given index is required.
Target specific hooks for defining how a type should be passed or returned from functions with one of...
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const
setTargetAttributes - Provides a convenient hook to handle extra target-specific attributes for the g...
static std::string qualifyWindowsLibrary(StringRef Lib)
virtual bool isNoProtoCallVariadic(const CodeGen::CallArgList &args, const FunctionNoProtoType *fnType) const
Determine whether a call to an unprototyped functions under the given calling convention should use t...
Complex values, per C99 6.2.5p11.
Represents the canonical version of C arrays with a specified constant size.
Decl - This represents one declaration (or definition), e.g.
SourceLocation getLocation() const
SourceLocation getBeginLoc() const LLVM_READONLY
TypeSourceInfo * getTypeSourceInfo() const
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
CallingConv getCC() const
CallingConv getCallConv() const
bool isExternallyVisible() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
QualType getCanonicalType() const
Represents a struct/union/class.
bool hasFlexibleArrayMember() const
field_iterator field_end() const
field_range fields() const
specific_decl_iterator< FieldDecl > field_iterator
RecordDecl * getDefinitionOrSelf() const
field_iterator field_begin() const
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
TypeLoc IgnoreParens() const
The base class of the type hierarchy.
bool isBlockPointerType() const
bool isBooleanType() const
bool isFloat16Type() const
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isPointerType() const
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isEnumeralType() const
bool isFloat128Type() const
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
bool isBitIntType() const
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
bool isBuiltinType() const
Helper methods to distinguish type categories.
bool isAnyComplexType() const
bool isMemberPointerType() const
EnumDecl * getAsEnumDecl() const
Retrieves the EnumDecl this type refers to.
bool isBFloat16Type() const
bool isMemberFunctionPointerType() const
bool isVectorType() const
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
bool hasPointerRepresentation() const
Whether this type is represented natively as a pointer.
Represents a GCC generic vector type.
bool shouldPassIndirectly(CodeGenModule &CGM, ArrayRef< llvm::Type * > types, bool asReturnValue)
Should an aggregate which expands to the given type sequence be passed/returned indirectly under swif...
ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type)
Classify the rules for how to pass a particular type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI)
std::unique_ptr< TargetCodeGenInfo > createX86_64TargetCodeGenInfo(CodeGenModule &CGM, X86AVXABILevel AVXLevel)
bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI, const ABIInfo &Info)
std::unique_ptr< TargetCodeGenInfo > createWinX86_32TargetCodeGenInfo(CodeGenModule &CGM, bool DarwinVectorABI, bool Win32StructABI, unsigned NumRegisterParameters)
bool isRecordWithSIMDVectorType(ASTContext &Context, QualType Ty)
RValue emitVoidPtrVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType ValueTy, bool IsIndirect, TypeInfoChars ValueInfo, CharUnits SlotSizeAndAlign, bool AllowHigherAlign, AggValueSlot Slot, bool ForceRightAdjust=false)
Emit va_arg for a platform using the common void* representation, where arguments are simply emitted ...
Address emitMergePHI(CodeGenFunction &CGF, Address Addr1, llvm::BasicBlock *Block1, Address Addr2, llvm::BasicBlock *Block2, const llvm::Twine &Name="")
X86AVXABILevel
The AVX ABI level for X86 targets.
const Type * isSingleElementRecord(QualType T, ASTContext &Context)
isSingleElementRecord - Determine if a record is a "singleelement record", i.e.
bool isEmptyField(ASTContext &Context, const FieldDecl *FD, bool AllowArrays, bool AsIfNoUniqueAddr=false)
isEmptyField - Return true iff a the field is "empty", that is it is an unnamed bit-field or an (arra...
llvm::Value * emitRoundPointerUpToAlignment(CodeGenFunction &CGF, llvm::Value *Ptr, CharUnits Align)
bool isAggregateTypeForABI(QualType T)
void AssignToArrayRange(CodeGen::CGBuilderTy &Builder, llvm::Value *Array, llvm::Value *Value, unsigned FirstIndex, unsigned LastIndex)
QualType useFirstFieldIfTransparentUnion(QualType Ty)
Pass transparent unions as if they were the type of the first element.
std::unique_ptr< TargetCodeGenInfo > createX86_32TargetCodeGenInfo(CodeGenModule &CGM, bool DarwinVectorABI, bool Win32StructABI, unsigned NumRegisterParameters, bool SoftFloatABI)
bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays, bool AsIfNoUniqueAddr=false)
isEmptyRecord - Return true iff a structure contains only empty fields.
std::unique_ptr< TargetCodeGenInfo > createWinX86_64TargetCodeGenInfo(CodeGenModule &CGM, X86AVXABILevel AVXLevel)
bool isSIMDVectorType(ASTContext &Context, QualType Ty)
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
PRESERVE_NONE bool Ret(InterpState &S)
@ Address
A pointer to a ValueDecl.
void info(bool Verbose, unsigned Level, const char *Fmt, Ts &&...Args)
Prints an indented note to stderr when Verbose is set.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
@ Default
Set to the current date and time.
const FunctionProtoType * T
CallingConv
CallingConv - Specifies the calling convention that a function uses.
U cast(CodeGen::Address addr)
@ Class
The "class" keyword introduces the elaborated-type-specifier.
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 unsigned
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
llvm::IntegerType * Int64Ty
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
llvm::IntegerType * Int32Ty