diff options
author | Manman Ren <mren@apple.com> | 2013-01-10 01:10:10 +0000 |
---|---|---|
committer | Manman Ren <mren@apple.com> | 2013-01-10 01:10:10 +0000 |
commit | 86441169da23959c81d8648c3dfdc7a0bb8d2225 (patch) | |
tree | 83dec40a840a61665f75b6052878d06e66bb8709 /lib/CodeGen/MachineFunction.cpp | |
parent | 7932c41884f182ae44a3feacc8a6a462e9097ca1 (diff) |
Stack Alignment: throw error if we can't satisfy the minimal alignment
requirement when creating stack objects in MachineFrameInfo.
Add CreateStackObjectWithMinAlign to throw error when the minimal alignment
can't be achieved and to clamp the alignment when the preferred alignment
can't be achieved. Same is true for CreateVariableSizedObject.
Will not emit error in CreateSpillStackObject or CreateStackObject.
As long as callers of CreateStackObject do not assume the object will be
aligned at the requested alignment, we should not have miscompile since
later optimizations which look at the object's alignment will have the correct
information.
rdar://12713765
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172027 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/MachineFunction.cpp')
-rw-r--r-- | lib/CodeGen/MachineFunction.cpp | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 9647e83e24..3d7d20d416 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -473,24 +473,32 @@ void MachineFrameInfo::ensureMaxAlignment(unsigned Align) { } /// clampStackAlignment - Clamp the alignment if requested and emit a warning. -static inline unsigned clampStackAlignment(bool ShouldClamp, unsigned Align, - unsigned StackAlign) { - if (!ShouldClamp || Align <= StackAlign) - return Align; - DEBUG(dbgs() << "Warning: requested alignment " << Align - << " exceeds the stack alignment " << StackAlign - << " when stack realignment is off" << '\n'); +static inline unsigned clampStackAlignment(bool ShouldClamp, unsigned PrefAlign, + unsigned MinAlign, unsigned StackAlign, + const AllocaInst *Alloca = 0) { + if (!ShouldClamp || PrefAlign <= StackAlign) + return PrefAlign; + if (Alloca && MinAlign > StackAlign) + Alloca->getParent()->getContext().emitError(Alloca, + "Requested Minimal Alignment exceeds the Stack Alignment!"); + else + assert(MinAlign <= StackAlign && + "Requested Minimal Alignment exceeds the Stack Alignment!"); return StackAlign; } -/// CreateStackObject - Create a new statically sized stack object, returning -/// a nonnegative identifier to represent it. +/// CreateStackObjectWithMinAlign - Create a new statically sized stack +/// object, returning a nonnegative identifier to represent it. This function +/// takes a preferred alignment and a minimal alignment. /// -int MachineFrameInfo::CreateStackObject(uint64_t Size, unsigned Alignment, - bool isSS, bool MayNeedSP, const AllocaInst *Alloca) { +int MachineFrameInfo::CreateStackObjectWithMinAlign(uint64_t Size, + unsigned PrefAlignment, unsigned MinAlignment, + bool isSS, bool MayNeedSP, const AllocaInst *Alloca) { assert(Size != 0 && "Cannot allocate zero size stack objects!"); - Alignment = clampStackAlignment(!TFI.isStackRealignable() || !RealignOption, - Alignment, TFI.getStackAlignment()); + unsigned Alignment = clampStackAlignment( + !TFI.isStackRealignable() || !RealignOption, + PrefAlignment, MinAlignment, + TFI.getStackAlignment(), Alloca); Objects.push_back(StackObject(Size, Alignment, 0, false, isSS, MayNeedSP, Alloca)); int Index = (int)Objects.size() - NumFixedObjects - 1; @@ -506,7 +514,8 @@ int MachineFrameInfo::CreateStackObject(uint64_t Size, unsigned Alignment, int MachineFrameInfo::CreateSpillStackObject(uint64_t Size, unsigned Alignment) { Alignment = clampStackAlignment(!TFI.isStackRealignable() || !RealignOption, - Alignment, TFI.getStackAlignment()); + Alignment, 0, + TFI.getStackAlignment()); CreateStackObject(Size, Alignment, true, false); int Index = (int)Objects.size() - NumFixedObjects - 1; ensureMaxAlignment(Alignment); @@ -518,10 +527,13 @@ int MachineFrameInfo::CreateSpillStackObject(uint64_t Size, /// variable sized object is created, whether or not the index returned is /// actually used. /// -int MachineFrameInfo::CreateVariableSizedObject(unsigned Alignment) { +int MachineFrameInfo::CreateVariableSizedObject(unsigned PrefAlignment, + unsigned MinAlignment, const AllocaInst *Alloca) { HasVarSizedObjects = true; - Alignment = clampStackAlignment(!TFI.isStackRealignable() || !RealignOption, - Alignment, TFI.getStackAlignment()); + unsigned Alignment = clampStackAlignment( + !TFI.isStackRealignable() || !RealignOption, + PrefAlignment, MinAlignment, + TFI.getStackAlignment(), Alloca); Objects.push_back(StackObject(0, Alignment, 0, false, false, true, 0)); ensureMaxAlignment(Alignment); return (int)Objects.size()-NumFixedObjects-1; @@ -542,7 +554,7 @@ int MachineFrameInfo::CreateFixedObject(uint64_t Size, int64_t SPOffset, unsigned StackAlign = TFI.getStackAlignment(); unsigned Align = MinAlign(SPOffset, StackAlign); Align = clampStackAlignment(!TFI.isStackRealignable() || !RealignOption, - Align, TFI.getStackAlignment()); + Align, 0, TFI.getStackAlignment()); Objects.insert(Objects.begin(), StackObject(Size, Align, SPOffset, Immutable, /*isSS*/ false, /*NeedSP*/ false, |