namespace llvm {
class raw_ostream;
-class TargetData;
+class DataLayout;
class TargetRegisterClass;
class Type;
class MachineFunction;
class MachineBasicBlock;
class TargetFrameLowering;
class BitVector;
+class Value;
+class AllocaInst;
/// The CalleeSavedInfo class tracks the information need to locate where a
/// callee saved register is in the current frame.
// protector.
bool MayNeedSP;
+ /// Alloca - If this stack object is originated from an Alloca instruction
+ /// this value saves the original IR allocation. Can be NULL.
+ const AllocaInst *Alloca;
+
// PreAllocated - If true, the object was mapped into the local frame
// block and doesn't need additional handling for allocation beyond that.
bool PreAllocated;
StackObject(uint64_t Sz, unsigned Al, int64_t SP, bool IM,
- bool isSS, bool NSP)
+ bool isSS, bool NSP, const AllocaInst *Val)
: SPOffset(SP), Size(Sz), Alignment(Al), isImmutable(IM),
- isSpillSlot(isSS), MayNeedSP(NSP), PreAllocated(false) {}
+ isSpillSlot(isSS), MayNeedSP(NSP), Alloca(Val), PreAllocated(false) {}
};
/// Objects - The list of stack objects allocated...
/// just allocate them normally.
bool UseLocalStackAllocationBlock;
- /// After the stack pointer has been restore from the base pointer we
- /// use a cached adjusment. Currently only used for x86.
- int64_t BPAdj;
-
+ /// Whether the "realign-stack" option is on.
+ bool RealignOption;
public:
- explicit MachineFrameInfo(const TargetFrameLowering &tfi) : TFI(tfi) {
+ explicit MachineFrameInfo(const TargetFrameLowering &tfi, bool RealignOpt)
+ : TFI(tfi), RealignOption(RealignOpt) {
StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0;
HasVarSizedObjects = false;
FrameAddressTaken = false;
LocalFrameSize = 0;
LocalFrameMaxAlign = 0;
UseLocalStackAllocationBlock = false;
- BPAdj = 0;
}
/// hasStackObjects - Return true if there are any stack objects in this
ensureMaxAlignment(Align);
}
+ /// getObjectAllocation - Return the underlying Alloca of the specified
+ /// stack object if it exists. Returns 0 if none exists.
+ const AllocaInst* getObjectAllocation(int ObjectIdx) const {
+ assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() &&
+ "Invalid Object Idx!");
+ return Objects[ObjectIdx+NumFixedObjects].Alloca;
+ }
+
/// NeedsStackProtector - Returns true if the object may need stack
/// protectors.
bool MayNeedStackProtector(int ObjectIdx) const {
/// ensureMaxAlignment - Make sure the function is at least Align bytes
/// aligned.
- void ensureMaxAlignment(unsigned Align) {
- if (MaxAlignment < Align) MaxAlignment = Align;
- }
+ void ensureMaxAlignment(unsigned Align);
/// AdjustsStack - Return true if this function adjusts the stack -- e.g.,
/// when calling another function. This is only valid during and after
return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
}
+ /// 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 CreateStackObjectWithMinAlign(uint64_t Size, unsigned PrefAlignment,
+ unsigned MinAlignment, bool isSS,
+ bool MayNeedSP = false, const AllocaInst *Alloca = 0);
+
/// CreateStackObject - Create a new statically sized stack object, returning
- /// a nonnegative identifier to represent it.
+ /// a nonnegative identifier to represent it. Will not emit an error when
+ /// Alignment can't be satisfied.
///
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS,
- bool MayNeedSP = false) {
- assert(Size != 0 && "Cannot allocate zero size stack objects!");
- Objects.push_back(StackObject(Size, Alignment, 0, false, isSS, MayNeedSP));
- int Index = (int)Objects.size() - NumFixedObjects - 1;
- assert(Index >= 0 && "Bad frame index!");
- ensureMaxAlignment(Alignment);
- return Index;
+ bool MayNeedSP = false, const AllocaInst *Alloca = 0) {
+ return CreateStackObjectWithMinAlign(Size, Alignment, 0, isSS,
+ MayNeedSP, Alloca);
}
/// CreateSpillStackObject - Create a new statically sized stack object that
/// represents a spill slot, returning a nonnegative identifier to represent
/// it.
///
- int CreateSpillStackObject(uint64_t Size, unsigned Alignment) {
- CreateStackObject(Size, Alignment, true, false);
- int Index = (int)Objects.size() - NumFixedObjects - 1;
- ensureMaxAlignment(Alignment);
- return Index;
- }
+ int CreateSpillStackObject(uint64_t Size, unsigned Alignment);
/// RemoveStackObject - Remove or mark dead a statically sized stack object.
///
/// variable sized object is created, whether or not the index returned is
/// actually used.
///
- int CreateVariableSizedObject(unsigned Alignment) {
- HasVarSizedObjects = true;
- Objects.push_back(StackObject(0, Alignment, 0, false, false, true));
- ensureMaxAlignment(Alignment);
- return (int)Objects.size()-NumFixedObjects-1;
- }
+ int CreateVariableSizedObject(unsigned PrefAlignment, unsigned MinAlignment,
+ const AllocaInst *Alloca = 0);
/// getCalleeSavedInfo - Returns a reference to call saved info vector for the
/// current function.
void setCalleeSavedInfoValid(bool v) { CSIValid = v; }
- /// setBasePtrStackAdjustment - If we're restoring the stack pointer from the
- /// base pointer, due to dynamic stack realignment + VLAs, we cache the
- /// number of bytes initially allocated for the stack frame. In obscure
- /// cases (e.g., tail calls with byval argument and no stack protector), the
- /// stack gets adjusted outside of the prolog, but these shouldn't be
- /// considered when restoring from the base pointer. Currently, this is only
- /// needed for x86.
- void setBasePtrStackAdjustment(int64_t adj) { BPAdj = adj; }
- int64_t getBasePtrStackAdjustment() const { return BPAdj; }
-
/// getPristineRegs - Return a set of physical registers that are pristine on
/// entry to the MBB.
///