diff options
author | Charles Davis <cdavis5x@gmail.com> | 2016-04-09 23:34:42 +0000 |
---|---|---|
committer | Charles Davis <cdavis5x@gmail.com> | 2016-04-09 23:34:42 +0000 |
commit | 2f65f35c271f39454b3490238b0eb69e57cb5f65 (patch) | |
tree | 286130f9c0a4875346e96ef511f3d6caff1ad719 /llvm/lib | |
parent | eeae124faf3be90af5248b18f734072d071aa776 (diff) | |
download | bcm5719-llvm-2f65f35c271f39454b3490238b0eb69e57cb5f65.tar.gz bcm5719-llvm-2f65f35c271f39454b3490238b0eb69e57cb5f65.zip |
[CodeGen] Don't assume that fixed stack objects are aligned in a stack-realigned function.
Summary:
After we make the adjustment, we can assume that for local allocas, but
not for stack parameters, the return address, or any other fixed stack
object (which has a negative offset and therefore lies prior to the
adjusted SP).
Fixes PR26662.
Reviewers: hfinkel, qcolombet, rnk
Subscribers: rnk, llvm-commits
Differential Revision: http://reviews.llvm.org/D18471
llvm-svn: 265886
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/MachineFunction.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index 52f9a1d27a6..5a2b3b4c859 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -84,6 +84,13 @@ void ilist_traits<MachineBasicBlock>::deleteNode(MachineBasicBlock *MBB) { MBB->getParent()->DeleteMachineBasicBlock(MBB); } +static inline unsigned getFnStackAlignment(const TargetSubtargetInfo *STI, + const Function *Fn) { + if (Fn->hasFnAttribute(Attribute::StackAlignment)) + return Fn->getFnStackAlignment(); + return STI->getFrameLowering()->getStackAlignment(); +} + MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM, unsigned FunctionNum, MachineModuleInfo &mmi) : Fn(F), Target(TM), STI(TM.getSubtargetImpl(*F)), Ctx(mmi.getContext()), @@ -97,9 +104,11 @@ MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM, MFInfo = nullptr; FrameInfo = new (Allocator) - MachineFrameInfo(STI->getFrameLowering()->getStackAlignment(), + MachineFrameInfo(getFnStackAlignment(STI, Fn), STI->getFrameLowering()->isStackRealignable(), - !F->hasFnAttribute("no-realign-stack")); + !F->hasFnAttribute("no-realign-stack"), + !F->hasFnAttribute("no-realign-stack") && + F->hasFnAttribute(Attribute::StackAlignment)); if (Fn->hasFnAttribute(Attribute::StackAlignment)) FrameInfo->ensureMaxAlignment(Fn->getFnStackAlignment()); @@ -613,8 +622,10 @@ int MachineFrameInfo::CreateFixedObject(uint64_t Size, int64_t SPOffset, // The alignment of the frame index can be determined from its offset from // the incoming frame position. If the frame object is at offset 32 and // the stack is guaranteed to be 16-byte aligned, then we know that the - // object is 16-byte aligned. - unsigned Align = MinAlign(SPOffset, StackAlignment); + // object is 16-byte aligned. Note that unlike the non-fixed case, if the + // stack needs realignment, we can't assume that the stack will in fact be + // aligned. + unsigned Align = MinAlign(SPOffset, ForcedRealign ? 1 : StackAlignment); Align = clampStackAlignment(!StackRealignable || !RealignOption, Align, StackAlignment); Objects.insert(Objects.begin(), StackObject(Size, Align, SPOffset, Immutable, @@ -627,7 +638,7 @@ int MachineFrameInfo::CreateFixedObject(uint64_t Size, int64_t SPOffset, /// Returns an index with a negative value. int MachineFrameInfo::CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset) { - unsigned Align = MinAlign(SPOffset, StackAlignment); + unsigned Align = MinAlign(SPOffset, ForcedRealign ? 1 : StackAlignment); Align = clampStackAlignment(!StackRealignable || !RealignOption, Align, StackAlignment); Objects.insert(Objects.begin(), StackObject(Size, Align, SPOffset, |