/// 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
/// realignment.
bool StackRealignable;
+ /// Whether the function has the \c alignstack attribute.
+ bool ForcedRealign;
+
/// The list of stack objects allocated.
std::vector<StackObject> Objects;
/// 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;
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;
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());
/// 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;
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;
/// 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);
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;
// 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));
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,