diff --git a/llvm/include/llvm/CodeGen/MachineFrameInfo.h b/llvm/include/llvm/CodeGen/MachineFrameInfo.h --- a/llvm/include/llvm/CodeGen/MachineFrameInfo.h +++ b/llvm/include/llvm/CodeGen/MachineFrameInfo.h @@ -584,6 +584,9 @@ /// Return the alignment in bytes that this function must be aligned to, /// which is greater than the default stack alignment provided by the target. unsigned getMaxAlignment() const { return MaxAlignment.value(); } + /// Return the alignment in bytes that this function must be aligned to, + /// which is greater than the default stack alignment provided by the target. + Align getMaxAlign() const { return MaxAlignment; } /// Make sure the function is at least Align bytes aligned. void ensureMaxAlignment(Align Alignment); diff --git a/llvm/include/llvm/CodeGen/TargetFrameLowering.h b/llvm/include/llvm/CodeGen/TargetFrameLowering.h --- a/llvm/include/llvm/CodeGen/TargetFrameLowering.h +++ b/llvm/include/llvm/CodeGen/TargetFrameLowering.h @@ -93,6 +93,11 @@ /// is the largest alignment for any data object in the target. /// unsigned getStackAlignment() const { return StackAlignment.value(); } + /// getStackAlignment - This method returns the number of bytes to which the + /// stack pointer must be aligned on entry to a function. Typically, this + /// is the largest alignment for any data object in the target. + /// + Align getStackAlign() const { return StackAlignment; } /// alignSPAdjust - This method aligns the stack adjustment to the correct /// alignment. @@ -110,9 +115,15 @@ /// which the stack pointer must be aligned at all times, even between /// calls. /// - unsigned getTransientStackAlignment() const { + LLVM_ATTRIBUTE_DEPRECATED(unsigned getTransientStackAlignment() const, + "Use getTransientStackAlign instead") { return TransientStackAlignment.value(); } + /// getTransientStackAlignment - This method returns the number of bytes to + /// which the stack pointer must be aligned at all times, even between + /// calls. + /// + Align getTransientStackAlign() const { return TransientStackAlignment; } /// isStackRealignable - This method returns whether the stack can be /// realigned. diff --git a/llvm/lib/CodeGen/MachineFrameInfo.cpp b/llvm/lib/CodeGen/MachineFrameInfo.cpp --- a/llvm/lib/CodeGen/MachineFrameInfo.cpp +++ b/llvm/lib/CodeGen/MachineFrameInfo.cpp @@ -136,7 +136,7 @@ uint64_t MachineFrameInfo::estimateStackSize(const MachineFunction &MF) const { const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering(); const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo(); - unsigned MaxAlign = getMaxAlignment(); + Align MaxAlign = getMaxAlign(); int64_t Offset = 0; // This code is very, very similar to PEI::calculateFrameObjectOffsets(). @@ -155,11 +155,11 @@ if (isDeadObjectIndex(i) || getStackID(i) != TargetStackID::Default) continue; Offset += getObjectSize(i); - unsigned Align = getObjectAlignment(i); + Align Alignment = getObjectAlign(i); // Adjust to alignment boundary - Offset = (Offset+Align-1)/Align*Align; + Offset = alignTo(Offset, Alignment); - MaxAlign = std::max(Align, MaxAlign); + MaxAlign = std::max(Alignment, MaxAlign); } if (adjustsStack() && TFI->hasReservedCallFrame(MF)) @@ -170,20 +170,17 @@ // ensure that the callee's frame or the alloca data is suitably aligned; // otherwise, for leaf functions, align to the TransientStackAlignment // value. - unsigned StackAlign; + Align StackAlign; if (adjustsStack() || hasVarSizedObjects() || (RegInfo->needsStackRealignment(MF) && getObjectIndexEnd() != 0)) - StackAlign = TFI->getStackAlignment(); + StackAlign = TFI->getStackAlign(); else - StackAlign = TFI->getTransientStackAlignment(); + StackAlign = TFI->getTransientStackAlign(); // If the frame pointer is eliminated, all frame offsets will be relative to // SP not FP. Align to MaxAlign so this works. StackAlign = std::max(StackAlign, MaxAlign); - unsigned AlignMask = StackAlign - 1; - Offset = (Offset + AlignMask) & ~uint64_t(AlignMask); - - return (uint64_t)Offset; + return alignTo(Offset, StackAlign); } void MachineFrameInfo::computeMaxCallFrameSize(const MachineFunction &MF) { diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -635,22 +635,21 @@ } /// AdjustStackOffset - Helper function used to adjust the stack frame offset. -static inline void -AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx, - bool StackGrowsDown, int64_t &Offset, - unsigned &MaxAlign, unsigned Skew) { +static inline void AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx, + bool StackGrowsDown, int64_t &Offset, + Align &MaxAlign, unsigned Skew) { // If the stack grows down, add the object size to find the lowest address. if (StackGrowsDown) Offset += MFI.getObjectSize(FrameIdx); - unsigned Align = MFI.getObjectAlignment(FrameIdx); + Align Alignment = MFI.getObjectAlign(FrameIdx); // If the alignment of this object is greater than that of the stack, then // increase the stack alignment to match. - MaxAlign = std::max(MaxAlign, Align); + MaxAlign = std::max(MaxAlign, Alignment); // Adjust to alignment boundary. - Offset = alignTo(Offset, Align, Skew); + Offset = alignTo(Offset, Alignment, Skew); if (StackGrowsDown) { LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << -Offset @@ -710,7 +709,7 @@ /// Assign frame object to an unused portion of the stack in the fixed stack /// object range. Return true if the allocation was successful. static inline bool scavengeStackSlot(MachineFrameInfo &MFI, int FrameIdx, - bool StackGrowsDown, unsigned MaxAlign, + bool StackGrowsDown, Align MaxAlign, BitVector &StackBytesFree) { if (MFI.isVariableSizedObjectIndex(FrameIdx)) return false; @@ -722,7 +721,7 @@ return false; } - unsigned ObjAlign = MFI.getObjectAlignment(FrameIdx); + Align ObjAlign = MFI.getObjectAlign(FrameIdx); if (ObjAlign > MaxAlign) return false; @@ -769,11 +768,11 @@ /// AssignProtectedObjSet - Helper function to assign large stack objects (i.e., /// those required to be close to the Stack Protector) to stack offsets. -static void -AssignProtectedObjSet(const StackObjSet &UnassignedObjs, - SmallSet &ProtectedObjs, - MachineFrameInfo &MFI, bool StackGrowsDown, - int64_t &Offset, unsigned &MaxAlign, unsigned Skew) { +static void AssignProtectedObjSet(const StackObjSet &UnassignedObjs, + SmallSet &ProtectedObjs, + MachineFrameInfo &MFI, bool StackGrowsDown, + int64_t &Offset, Align &MaxAlign, + unsigned Skew) { for (StackObjSet::const_iterator I = UnassignedObjs.begin(), E = UnassignedObjs.end(); I != E; ++I) { @@ -850,9 +849,8 @@ // address of the object. Offset += MFI.getObjectSize(i); - unsigned Align = MFI.getObjectAlignment(i); // Adjust to alignment boundary - Offset = alignTo(Offset, Align, Skew); + Offset = alignTo(Offset, MFI.getObjectAlign(i), Skew); LLVM_DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << -Offset << "]\n"); MFI.setObjectOffset(i, -Offset); // Set the computed offset @@ -867,9 +865,8 @@ if (MFI.isDeadObjectIndex(i)) continue; - unsigned Align = MFI.getObjectAlignment(i); // Adjust to alignment boundary - Offset = alignTo(Offset, Align, Skew); + Offset = alignTo(Offset, MFI.getObjectAlign(i), Skew); LLVM_DEBUG(dbgs() << "alloc FI(" << i << ") at SP[" << Offset << "]\n"); MFI.setObjectOffset(i, Offset); @@ -880,7 +877,7 @@ // FixedCSEnd is the stack offset to the end of the fixed and callee-save // stack area. int64_t FixedCSEnd = Offset; - unsigned MaxAlign = MFI.getMaxAlignment(); + Align MaxAlign = MFI.getMaxAlign(); // Make sure the special register scavenging spill slot is closest to the // incoming stack pointer if a frame pointer is required and is closer @@ -903,10 +900,10 @@ // frame index registers. Functions which don't want/need this optimization // will continue to use the existing code path. if (MFI.getUseLocalStackAllocationBlock()) { - unsigned Align = MFI.getLocalFrameMaxAlign().value(); + Align Alignment = MFI.getLocalFrameMaxAlign(); // Adjust to alignment boundary. - Offset = alignTo(Offset, Align, Skew); + Offset = alignTo(Offset, Alignment, Skew); LLVM_DEBUG(dbgs() << "Local frame base offset: " << Offset << "\n"); @@ -921,7 +918,7 @@ // Allocate the local block Offset += MFI.getLocalFrameSize(); - MaxAlign = std::max(Align, MaxAlign); + MaxAlign = std::max(Alignment, MaxAlign); } // Retrieve the Exception Handler registration node. @@ -1072,12 +1069,12 @@ // ensure that the callee's frame or the alloca data is suitably aligned; // otherwise, for leaf functions, align to the TransientStackAlignment // value. - unsigned StackAlign; + Align StackAlign; if (MFI.adjustsStack() || MFI.hasVarSizedObjects() || (RegInfo->needsStackRealignment(MF) && MFI.getObjectIndexEnd() != 0)) - StackAlign = TFI.getStackAlignment(); + StackAlign = TFI.getStackAlign(); else - StackAlign = TFI.getTransientStackAlignment(); + StackAlign = TFI.getTransientStackAlign(); // If the frame pointer is eliminated, all frame offsets will be relative to // SP not FP. Align to MaxAlign so this works. diff --git a/llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp b/llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp --- a/llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp +++ b/llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp @@ -991,7 +991,7 @@ // Stack pointer alignment is out of the programmers control so we can trust // SP-relative loads/stores. if (getLoadStoreBaseOp(MI).getReg() == ARM::SP && - STI.getFrameLowering()->getTransientStackAlignment() >= 4) + STI.getFrameLowering()->getTransientStackAlign() >= Align(4)) return true; return false; } diff --git a/llvm/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp b/llvm/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp --- a/llvm/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp @@ -97,22 +97,21 @@ } /// AdjustStackOffset - Helper function used to adjust the stack frame offset. -static inline void -AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx, - bool StackGrowsDown, int64_t &Offset, - unsigned &MaxAlign) { +static inline void AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx, + bool StackGrowsDown, int64_t &Offset, + Align &MaxAlign) { // If the stack grows down, add the object size to find the lowest address. if (StackGrowsDown) Offset += MFI.getObjectSize(FrameIdx); - unsigned Align = MFI.getObjectAlignment(FrameIdx); + Align Alignment = MFI.getObjectAlign(FrameIdx); // If the alignment of this object is greater than that of the stack, then // increase the stack alignment to match. - MaxAlign = std::max(MaxAlign, Align); + MaxAlign = std::max(MaxAlign, Alignment); // Adjust to alignment boundary. - Offset = (Offset + Align - 1) / Align * Align; + Offset = alignTo(Offset, Alignment); if (StackGrowsDown) { LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << -Offset @@ -169,7 +168,7 @@ // NOTE: We do not have a call stack - unsigned MaxAlign = MFI.getMaxAlignment(); + Align MaxAlign = MFI.getMaxAlign(); // No scavenger @@ -178,10 +177,10 @@ // frame index registers. Functions which don't want/need this optimization // will continue to use the existing code path. if (MFI.getUseLocalStackAllocationBlock()) { - unsigned Align = MFI.getLocalFrameMaxAlign().value(); + Align Alignment = MFI.getLocalFrameMaxAlign(); // Adjust to alignment boundary. - Offset = (Offset + Align - 1) / Align * Align; + Offset = alignTo(Offset, Alignment); LLVM_DEBUG(dbgs() << "Local frame base offset: " << Offset << "\n"); @@ -196,7 +195,7 @@ // Allocate the local block Offset += MFI.getLocalFrameSize(); - MaxAlign = std::max(Align, MaxAlign); + MaxAlign = std::max(Alignment, MaxAlign); } // No stack protector @@ -227,18 +226,16 @@ // ensure that the callee's frame or the alloca data is suitably aligned; // otherwise, for leaf functions, align to the TransientStackAlignment // value. - unsigned StackAlign; + Align StackAlign; if (MFI.adjustsStack() || MFI.hasVarSizedObjects() || (RegInfo->needsStackRealignment(Fn) && MFI.getObjectIndexEnd() != 0)) - StackAlign = TFI.getStackAlignment(); + StackAlign = TFI.getStackAlign(); else - StackAlign = TFI.getTransientStackAlignment(); + StackAlign = TFI.getTransientStackAlign(); // If the frame pointer is eliminated, all frame offsets will be relative to // SP not FP. Align to MaxAlign so this works. - StackAlign = std::max(StackAlign, MaxAlign); - unsigned AlignMask = StackAlign - 1; - Offset = (Offset + AlignMask) & ~uint64_t(AlignMask); + Offset = alignTo(Offset, std::max(StackAlign, MaxAlign)); } // Update frame info to pretend that this is part of the stack... diff --git a/llvm/lib/Target/XCore/XCoreFrameLowering.cpp b/llvm/lib/Target/XCore/XCoreFrameLowering.cpp --- a/llvm/lib/Target/XCore/XCoreFrameLowering.cpp +++ b/llvm/lib/Target/XCore/XCoreFrameLowering.cpp @@ -233,9 +233,9 @@ // to determine the end of the prologue. DebugLoc dl; - if (MFI.getMaxAlignment() > getStackAlignment()) - report_fatal_error("emitPrologue unsupported alignment: " - + Twine(MFI.getMaxAlignment())); + if (MFI.getMaxAlign() > getStackAlign()) + report_fatal_error("emitPrologue unsupported alignment: " + + Twine(MFI.getMaxAlign().value())); const AttributeList &PAL = MF.getFunction().getAttributes(); if (PAL.hasAttrSomewhere(Attribute::Nest)) @@ -490,8 +490,7 @@ // We need to keep the stack aligned properly. To do this, we round the // amount of space needed for the outgoing arguments up to the next // alignment boundary. - unsigned Align = getStackAlignment(); - Amount = (Amount+Align-1)/Align*Align; + Amount = alignTo(Amount, getStackAlign()); assert(Amount%4 == 0); Amount /= 4;