diff options
-rw-r--r-- | llvm/include/llvm/CodeGen/MachineFrameInfo.h | 28 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineFunction.cpp | 31 |
2 files changed, 27 insertions, 32 deletions
diff --git a/llvm/include/llvm/CodeGen/MachineFrameInfo.h b/llvm/include/llvm/CodeGen/MachineFrameInfo.h index 1d14d03a32f..46a4026f0fe 100644 --- a/llvm/include/llvm/CodeGen/MachineFrameInfo.h +++ b/llvm/include/llvm/CodeGen/MachineFrameInfo.h @@ -138,11 +138,12 @@ class MachineFrameInfo { /// The alignment of the stack. unsigned StackAlignment; - /// Can the stack be realigned. - /// Targets that set this to false don't have the ability to overalign - /// their stack frame, and thus, overaligned allocas are all treated - /// as dynamic allocations and the target must handle them as part - /// of DYNAMIC_STACKALLOC lowering. + /// Can the stack be realigned. This can be false if the target does not + /// support stack realignment, or if the user asks us not to realign the + /// stack. In this situation, overaligned allocas are all treated as dynamic + /// allocations and the target must handle them as part of DYNAMIC_STACKALLOC + /// lowering. All non-alloca stack objects have their alignment clamped to the + /// base ABI stack alignment. /// FIXME: There is room for improvement in this case, in terms of /// grouping overaligned allocas into a "secondary stack frame" and /// then only use a single alloca to allocate this frame and only a @@ -151,6 +152,9 @@ class MachineFrameInfo { /// realignment. bool StackRealignable; + /// Whether the function has the \c alignstack attribute. + bool ForcedRealign; + /// The list of stack objects allocated. std::vector<StackObject> Objects; @@ -250,12 +254,6 @@ class MachineFrameInfo { /// just allocate them normally. bool UseLocalStackAllocationBlock; - /// Whether the "realign-stack" option is on. - bool RealignOption; - - /// Whether the function has the \c alignstack attribute. - bool ForcedRealign; - /// True if the function dynamically adjusts the stack pointer through some /// opaque mechanism like inline assembly or Win32 EH. bool HasOpaqueSPAdjustment; @@ -281,10 +279,10 @@ class MachineFrameInfo { MachineBasicBlock *Restore; public: - explicit MachineFrameInfo(unsigned StackAlign, bool isStackRealign, - bool RealignOpt, bool ForceRealign) - : StackAlignment(StackAlign), StackRealignable(isStackRealign), - RealignOption(RealignOpt), ForcedRealign(ForceRealign) { + explicit MachineFrameInfo(unsigned StackAlignment, bool StackRealignable, + bool ForcedRealign) + : StackAlignment(StackAlignment), StackRealignable(StackRealignable), + ForcedRealign(ForcedRealign) { StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0; HasVarSizedObjects = false; FrameAddressTaken = false; diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp index 5a2b3b4c859..8c987ba216a 100644 --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -103,12 +103,14 @@ MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM, RegInfo = nullptr; MFInfo = nullptr; - FrameInfo = new (Allocator) - MachineFrameInfo(getFnStackAlignment(STI, Fn), - STI->getFrameLowering()->isStackRealignable(), - !F->hasFnAttribute("no-realign-stack"), - !F->hasFnAttribute("no-realign-stack") && - F->hasFnAttribute(Attribute::StackAlignment)); + // We can realign the stack if the target supports it and the user hasn't + // explicitly asked us not to. + bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() && + !F->hasFnAttribute("no-realign-stack"); + FrameInfo = new (Allocator) MachineFrameInfo( + getFnStackAlignment(STI, Fn), /*StackRealignable=*/CanRealignSP, + /*ForceRealign=*/CanRealignSP && + F->hasFnAttribute(Attribute::StackAlignment)); if (Fn->hasFnAttribute(Attribute::StackAlignment)) FrameInfo->ensureMaxAlignment(Fn->getFnStackAlignment()); @@ -555,7 +557,7 @@ MCSymbol *MachineFunction::getPICBaseSymbol() const { /// Make sure the function is at least Align bytes aligned. void MachineFrameInfo::ensureMaxAlignment(unsigned Align) { - if (!StackRealignable || !RealignOption) + if (!StackRealignable) assert(Align <= StackAlignment && "For targets without stack realignment, Align is out of limit!"); if (MaxAlignment < Align) MaxAlignment = Align; @@ -577,8 +579,7 @@ static inline unsigned clampStackAlignment(bool ShouldClamp, unsigned Align, int MachineFrameInfo::CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca) { assert(Size != 0 && "Cannot allocate zero size stack objects!"); - Alignment = clampStackAlignment(!StackRealignable || !RealignOption, - Alignment, StackAlignment); + Alignment = clampStackAlignment(!StackRealignable, Alignment, StackAlignment); Objects.push_back(StackObject(Size, Alignment, 0, false, isSS, Alloca, !isSS)); int Index = (int)Objects.size() - NumFixedObjects - 1; @@ -591,8 +592,7 @@ int MachineFrameInfo::CreateStackObject(uint64_t Size, unsigned Alignment, /// returning a nonnegative identifier to represent it. int MachineFrameInfo::CreateSpillStackObject(uint64_t Size, unsigned Alignment) { - Alignment = clampStackAlignment(!StackRealignable || !RealignOption, - Alignment, StackAlignment); + Alignment = clampStackAlignment(!StackRealignable, Alignment, StackAlignment); CreateStackObject(Size, Alignment, true); int Index = (int)Objects.size() - NumFixedObjects - 1; ensureMaxAlignment(Alignment); @@ -605,8 +605,7 @@ int MachineFrameInfo::CreateSpillStackObject(uint64_t Size, int MachineFrameInfo::CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca) { HasVarSizedObjects = true; - Alignment = clampStackAlignment(!StackRealignable || !RealignOption, - Alignment, StackAlignment); + Alignment = clampStackAlignment(!StackRealignable, Alignment, StackAlignment); Objects.push_back(StackObject(0, Alignment, 0, false, false, Alloca, true)); ensureMaxAlignment(Alignment); return (int)Objects.size()-NumFixedObjects-1; @@ -626,8 +625,7 @@ int MachineFrameInfo::CreateFixedObject(uint64_t Size, int64_t SPOffset, // 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); + Align = clampStackAlignment(!StackRealignable, Align, StackAlignment); Objects.insert(Objects.begin(), StackObject(Size, Align, SPOffset, Immutable, /*isSS*/ false, /*Alloca*/ nullptr, isAliased)); @@ -639,8 +637,7 @@ int MachineFrameInfo::CreateFixedObject(uint64_t Size, int64_t SPOffset, int MachineFrameInfo::CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset) { unsigned Align = MinAlign(SPOffset, ForcedRealign ? 1 : StackAlignment); - Align = clampStackAlignment(!StackRealignable || !RealignOption, Align, - StackAlignment); + Align = clampStackAlignment(!StackRealignable, Align, StackAlignment); Objects.insert(Objects.begin(), StackObject(Size, Align, SPOffset, /*Immutable*/ true, /*isSS*/ true, |