diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-09-16 20:41:56 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-09-16 20:41:56 +0000 |
commit | fb67d6c3814524fdd43bd2fb159f7c594eae581c (patch) | |
tree | 14d6798f9817f7a0c6d1120e2cca437e78599267 /lib/CodeGen/TargetInfo.cpp | |
parent | a02d183357424b007eb93170acf9577a4f1a34e1 (diff) |
IRgen/x86_32/Linux: Linux seems to align all stack objects to 4 bytes, unlike
Darwin. Checked vs the handiest Linux llvm-gcc I had around, someone on Linux is
welcome to investigate more.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114112 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/TargetInfo.cpp')
-rw-r--r-- | lib/CodeGen/TargetInfo.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 4d221d4e65..2ae88f3a4c 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -336,6 +336,8 @@ ABIArgInfo DefaultABIInfo::classifyArgumentType(QualType Ty) const { /// X86_32ABIInfo - The X86-32 ABI information. class X86_32ABIInfo : public ABIInfo { + static const unsigned MinABIStackAlignInBytes = 4; + bool IsDarwinVectorABI; bool IsSmallStructInRegABI; @@ -349,6 +351,9 @@ class X86_32ABIInfo : public ABIInfo { /// such that the argument will be passed in memory. ABIArgInfo getIndirectResult(QualType Ty, bool ByVal = true) const; + /// \brief Return the alignment to use for the given type on the stack. + unsigned getTypeStackAlignInBytes(QualType Ty) const; + public: ABIArgInfo classifyReturnType(QualType RetTy) const; @@ -547,15 +552,30 @@ ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy) const { ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); } +unsigned X86_32ABIInfo::getTypeStackAlignInBytes(QualType Ty) const { + // On non-Darwin, the stack type alignment is always 4. + if (!IsDarwinVectorABI) + return MinABIStackAlignInBytes; + + // Otherwise, if the alignment is less than or equal to 4, use the minimum ABI + // alignment. + unsigned Align = getContext().getTypeAlign(Ty) / 8; + if (Align <= MinABIStackAlignInBytes) + return MinABIStackAlignInBytes; + + // Otherwise, if the type contains SSE or MMX vector types, then the alignment + // matches that of the struct. + return Align; +} + ABIArgInfo X86_32ABIInfo::getIndirectResult(QualType Ty, bool ByVal) const { if (!ByVal) return ABIArgInfo::getIndirect(0, false); // Compute the byval alignment. We trust the back-end to honor the // minimum ABI alignment for byval, to make cleaner IR. - const unsigned MinABIAlign = 4; - unsigned Align = getContext().getTypeAlign(Ty) / 8; - if (Align > MinABIAlign) + unsigned Align = getTypeStackAlignInBytes(Ty); + if (Align > MinABIStackAlignInBytes) return ABIArgInfo::getIndirect(Align); return ABIArgInfo::getIndirect(0); } |