@@ -1676,7 +1676,6 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
16761676 bool IsVectorCall = State.CC == llvm::CallingConv::X86_VectorCall;
16771677
16781678 Ty = useFirstFieldIfTransparentUnion (Ty);
1679- TypeInfo TI = getContext ().getTypeInfo (Ty);
16801679
16811680 // Check with the C++ ABI first.
16821681 const RecordType *RT = Ty->getAs <RecordType>();
@@ -1726,7 +1725,7 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
17261725 bool NeedsPadding = false ;
17271726 bool InReg;
17281727 if (shouldAggregateUseDirect (Ty, State, InReg, NeedsPadding)) {
1729- unsigned SizeInRegs = (TI. Width + 31 ) / 32 ;
1728+ unsigned SizeInRegs = (getContext (). getTypeSize (Ty) + 31 ) / 32 ;
17301729 SmallVector<llvm::Type*, 3 > Elements (SizeInRegs, Int32);
17311730 llvm::Type *Result = llvm::StructType::get (LLVMContext, Elements);
17321731 if (InReg)
@@ -1736,44 +1735,29 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
17361735 }
17371736 llvm::IntegerType *PaddingType = NeedsPadding ? Int32 : nullptr ;
17381737
1739- // Pass over-aligned aggregates on Windows indirectly. This behavior was
1740- // added in MSVC 2015.
1741- if (IsWin32StructABI && TI.AlignIsRequired && TI.Align > 32 )
1742- return getIndirectResult (Ty, /* ByVal=*/ false , State);
1743-
17441738 // Expand small (<= 128-bit) record types when we know that the stack layout
17451739 // of those arguments will match the struct. This is important because the
17461740 // LLVM backend isn't smart enough to remove byval, which inhibits many
17471741 // optimizations.
17481742 // Don't do this for the MCU if there are still free integer registers
17491743 // (see X86_64 ABI for full explanation).
1750- if (TI. Width <= 4 * 32 && (!IsMCUABI || State. FreeRegs == 0 ) &&
1751- canExpandIndirectArgument (Ty))
1744+ if (getContext (). getTypeSize (Ty) <= 4 * 32 &&
1745+ (!IsMCUABI || State. FreeRegs == 0 ) && canExpandIndirectArgument (Ty))
17521746 return ABIArgInfo::getExpandWithPadding (
17531747 IsFastCall || IsVectorCall || IsRegCall, PaddingType);
17541748
17551749 return getIndirectResult (Ty, true , State);
17561750 }
17571751
17581752 if (const VectorType *VT = Ty->getAs <VectorType>()) {
1759- // On Windows, vectors are passed directly if registers are available, or
1760- // indirectly if not. This avoids the need to align argument memory. Pass
1761- // user-defined vector types larger than 512 bits indirectly for simplicity.
1762- if (IsWin32StructABI) {
1763- if (TI.Width <= 512 && State.FreeSSERegs > 0 ) {
1764- --State.FreeSSERegs ;
1765- return ABIArgInfo::getDirectInReg ();
1766- }
1767- return getIndirectResult (Ty, /* ByVal=*/ false , State);
1768- }
1769-
17701753 // On Darwin, some vectors are passed in memory, we handle this by passing
17711754 // it as an i8/i16/i32/i64.
17721755 if (IsDarwinVectorABI) {
1773- if ((TI.Width == 8 || TI.Width == 16 || TI.Width == 32 ) ||
1774- (TI.Width == 64 && VT->getNumElements () == 1 ))
1775- return ABIArgInfo::getDirect (
1776- llvm::IntegerType::get (getVMContext (), TI.Width ));
1756+ uint64_t Size = getContext ().getTypeSize (Ty);
1757+ if ((Size == 8 || Size == 16 || Size == 32 ) ||
1758+ (Size == 64 && VT->getNumElements () == 1 ))
1759+ return ABIArgInfo::getDirect (llvm::IntegerType::get (getVMContext (),
1760+ Size));
17771761 }
17781762
17791763 if (IsX86_MMXType (CGT.ConvertType (Ty)))
@@ -1803,22 +1787,16 @@ void X86_32ABIInfo::computeInfo(CGFunctionInfo &FI) const {
18031787 CCState State (FI);
18041788 if (IsMCUABI)
18051789 State.FreeRegs = 3 ;
1806- else if (State.CC == llvm::CallingConv::X86_FastCall) {
1790+ else if (State.CC == llvm::CallingConv::X86_FastCall)
18071791 State.FreeRegs = 2 ;
1808- State.FreeSSERegs = 3 ;
1809- } else if (State.CC == llvm::CallingConv::X86_VectorCall) {
1792+ else if (State.CC == llvm::CallingConv::X86_VectorCall) {
18101793 State.FreeRegs = 2 ;
18111794 State.FreeSSERegs = 6 ;
18121795 } else if (FI.getHasRegParm ())
18131796 State.FreeRegs = FI.getRegParm ();
18141797 else if (State.CC == llvm::CallingConv::X86_RegCall) {
18151798 State.FreeRegs = 5 ;
18161799 State.FreeSSERegs = 8 ;
1817- } else if (IsWin32StructABI) {
1818- // Since MSVC 2015, the first three SSE vectors have been passed in
1819- // registers. The rest are passed indirectly.
1820- State.FreeRegs = DefaultNumRegisterParameters;
1821- State.FreeSSERegs = 3 ;
18221800 } else
18231801 State.FreeRegs = DefaultNumRegisterParameters;
18241802
@@ -1865,25 +1843,16 @@ X86_32ABIInfo::addFieldToArgStruct(SmallVector<llvm::Type *, 6> &FrameFields,
18651843 CharUnits &StackOffset, ABIArgInfo &Info,
18661844 QualType Type) const {
18671845 // Arguments are always 4-byte-aligned.
1868- CharUnits WordSize = CharUnits::fromQuantity (4 );
1869- assert (StackOffset.isMultipleOf (WordSize) && " unaligned inalloca struct" );
1846+ CharUnits FieldAlign = CharUnits::fromQuantity (4 );
18701847
1871- // sret pointers and indirect things will require an extra pointer
1872- // indirection, unless they are byval. Most things are byval, and will not
1873- // require this indirection.
1874- bool IsIndirect = false ;
1875- if (Info.isIndirect () && !Info.getIndirectByVal ())
1876- IsIndirect = true ;
1877- Info = ABIArgInfo::getInAlloca (FrameFields.size (), IsIndirect);
1878- llvm::Type *LLTy = CGT.ConvertTypeForMem (Type);
1879- if (IsIndirect)
1880- LLTy = LLTy->getPointerTo (0 );
1881- FrameFields.push_back (LLTy);
1882- StackOffset += IsIndirect ? WordSize : getContext ().getTypeSizeInChars (Type);
1848+ assert (StackOffset.isMultipleOf (FieldAlign) && " unaligned inalloca struct" );
1849+ Info = ABIArgInfo::getInAlloca (FrameFields.size ());
1850+ FrameFields.push_back (CGT.ConvertTypeForMem (Type));
1851+ StackOffset += getContext ().getTypeSizeInChars (Type);
18831852
18841853 // Insert padding bytes to respect alignment.
18851854 CharUnits FieldEnd = StackOffset;
1886- StackOffset = FieldEnd.alignTo (WordSize );
1855+ StackOffset = FieldEnd.alignTo (FieldAlign );
18871856 if (StackOffset != FieldEnd) {
18881857 CharUnits NumBytes = StackOffset - FieldEnd;
18891858 llvm::Type *Ty = llvm::Type::getInt8Ty (getVMContext ());
@@ -1897,12 +1866,16 @@ static bool isArgInAlloca(const ABIArgInfo &Info) {
18971866 switch (Info.getKind ()) {
18981867 case ABIArgInfo::InAlloca:
18991868 return true ;
1869+ case ABIArgInfo::Indirect:
1870+ assert (Info.getIndirectByVal ());
1871+ return true ;
19001872 case ABIArgInfo::Ignore:
19011873 return false ;
1902- case ABIArgInfo::Indirect:
19031874 case ABIArgInfo::Direct:
19041875 case ABIArgInfo::Extend:
1905- return !Info.getInReg ();
1876+ if (Info.getInReg ())
1877+ return false ;
1878+ return true ;
19061879 case ABIArgInfo::Expand:
19071880 case ABIArgInfo::CoerceAndExpand:
19081881 // These are aggregate types which are never passed in registers when
@@ -1936,7 +1909,8 @@ void X86_32ABIInfo::rewriteWithInAlloca(CGFunctionInfo &FI) const {
19361909
19371910 // Put the sret parameter into the inalloca struct if it's in memory.
19381911 if (Ret.isIndirect () && !Ret.getInReg ()) {
1939- addFieldToArgStruct (FrameFields, StackOffset, Ret, FI.getReturnType ());
1912+ CanQualType PtrTy = getContext ().getPointerType (FI.getReturnType ());
1913+ addFieldToArgStruct (FrameFields, StackOffset, Ret, PtrTy);
19401914 // On Windows, the hidden sret parameter is always returned in eax.
19411915 Ret.setInAllocaSRet (IsWin32StructABI);
19421916 }
0 commit comments