@@ -1676,7 +1676,6 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
1676
1676
bool IsVectorCall = State.CC == llvm::CallingConv::X86_VectorCall;
1677
1677
1678
1678
Ty = useFirstFieldIfTransparentUnion (Ty);
1679
- TypeInfo TI = getContext ().getTypeInfo (Ty);
1680
1679
1681
1680
// Check with the C++ ABI first.
1682
1681
const RecordType *RT = Ty->getAs <RecordType>();
@@ -1726,7 +1725,7 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
1726
1725
bool NeedsPadding = false ;
1727
1726
bool InReg;
1728
1727
if (shouldAggregateUseDirect (Ty, State, InReg, NeedsPadding)) {
1729
- unsigned SizeInRegs = (TI. Width + 31 ) / 32 ;
1728
+ unsigned SizeInRegs = (getContext (). getTypeSize (Ty) + 31 ) / 32 ;
1730
1729
SmallVector<llvm::Type*, 3 > Elements (SizeInRegs, Int32);
1731
1730
llvm::Type *Result = llvm::StructType::get (LLVMContext, Elements);
1732
1731
if (InReg)
@@ -1736,44 +1735,29 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
1736
1735
}
1737
1736
llvm::IntegerType *PaddingType = NeedsPadding ? Int32 : nullptr ;
1738
1737
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
-
1744
1738
// Expand small (<= 128-bit) record types when we know that the stack layout
1745
1739
// of those arguments will match the struct. This is important because the
1746
1740
// LLVM backend isn't smart enough to remove byval, which inhibits many
1747
1741
// optimizations.
1748
1742
// Don't do this for the MCU if there are still free integer registers
1749
1743
// (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))
1752
1746
return ABIArgInfo::getExpandWithPadding (
1753
1747
IsFastCall || IsVectorCall || IsRegCall, PaddingType);
1754
1748
1755
1749
return getIndirectResult (Ty, true , State);
1756
1750
}
1757
1751
1758
1752
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
-
1770
1753
// On Darwin, some vectors are passed in memory, we handle this by passing
1771
1754
// it as an i8/i16/i32/i64.
1772
1755
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));
1777
1761
}
1778
1762
1779
1763
if (IsX86_MMXType (CGT.ConvertType (Ty)))
@@ -1803,22 +1787,16 @@ void X86_32ABIInfo::computeInfo(CGFunctionInfo &FI) const {
1803
1787
CCState State (FI);
1804
1788
if (IsMCUABI)
1805
1789
State.FreeRegs = 3 ;
1806
- else if (State.CC == llvm::CallingConv::X86_FastCall) {
1790
+ else if (State.CC == llvm::CallingConv::X86_FastCall)
1807
1791
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) {
1810
1793
State.FreeRegs = 2 ;
1811
1794
State.FreeSSERegs = 6 ;
1812
1795
} else if (FI.getHasRegParm ())
1813
1796
State.FreeRegs = FI.getRegParm ();
1814
1797
else if (State.CC == llvm::CallingConv::X86_RegCall) {
1815
1798
State.FreeRegs = 5 ;
1816
1799
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 ;
1822
1800
} else
1823
1801
State.FreeRegs = DefaultNumRegisterParameters;
1824
1802
@@ -1865,25 +1843,16 @@ X86_32ABIInfo::addFieldToArgStruct(SmallVector<llvm::Type *, 6> &FrameFields,
1865
1843
CharUnits &StackOffset, ABIArgInfo &Info,
1866
1844
QualType Type) const {
1867
1845
// 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 );
1870
1847
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);
1883
1852
1884
1853
// Insert padding bytes to respect alignment.
1885
1854
CharUnits FieldEnd = StackOffset;
1886
- StackOffset = FieldEnd.alignTo (WordSize );
1855
+ StackOffset = FieldEnd.alignTo (FieldAlign );
1887
1856
if (StackOffset != FieldEnd) {
1888
1857
CharUnits NumBytes = StackOffset - FieldEnd;
1889
1858
llvm::Type *Ty = llvm::Type::getInt8Ty (getVMContext ());
@@ -1897,12 +1866,16 @@ static bool isArgInAlloca(const ABIArgInfo &Info) {
1897
1866
switch (Info.getKind ()) {
1898
1867
case ABIArgInfo::InAlloca:
1899
1868
return true ;
1869
+ case ABIArgInfo::Indirect:
1870
+ assert (Info.getIndirectByVal ());
1871
+ return true ;
1900
1872
case ABIArgInfo::Ignore:
1901
1873
return false ;
1902
- case ABIArgInfo::Indirect:
1903
1874
case ABIArgInfo::Direct:
1904
1875
case ABIArgInfo::Extend:
1905
- return !Info.getInReg ();
1876
+ if (Info.getInReg ())
1877
+ return false ;
1878
+ return true ;
1906
1879
case ABIArgInfo::Expand:
1907
1880
case ABIArgInfo::CoerceAndExpand:
1908
1881
// These are aggregate types which are never passed in registers when
@@ -1936,7 +1909,8 @@ void X86_32ABIInfo::rewriteWithInAlloca(CGFunctionInfo &FI) const {
1936
1909
1937
1910
// Put the sret parameter into the inalloca struct if it's in memory.
1938
1911
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);
1940
1914
// On Windows, the hidden sret parameter is always returned in eax.
1941
1915
Ret.setInAllocaSRet (IsWin32StructABI);
1942
1916
}
0 commit comments