22 #include "llvm/Config/llvm-config.h" 27 #define DEBUG_TYPE "codegen" 32 if (!StackRealignable)
33 assert(Alignment <= StackAlignment &&
34 "For targets without stack realignment, Alignment is out of limit!");
35 if (MaxAlignment < Alignment)
36 MaxAlignment = Alignment;
41 Align StackAlignment) {
42 if (!ShouldClamp || Alignment <= StackAlignment)
45 <<
" exceeds the stack alignment " << StackAlignment.
value()
46 <<
" when stack realignment is off" <<
'\n');
47 return StackAlignment;
54 assert(Size != 0 &&
"Cannot allocate zero size stack objects!");
56 Objects.push_back(StackObject(Size, Alignment, 0,
false, IsSpillSlot, Alloca,
57 !IsSpillSlot, StackID));
58 int Index = (int)Objects.size() - NumFixedObjects - 1;
59 assert(Index >= 0 &&
"Bad frame index!");
68 int Index = (int)Objects.size() - NumFixedObjects - 1;
75 HasVarSizedObjects =
true;
77 Objects.push_back(StackObject(0, Alignment, 0,
false,
false, Alloca,
true));
79 return (
int)Objects.size()-NumFixedObjects-1;
83 bool IsImmutable,
bool IsAliased) {
84 assert(Size != 0 &&
"Cannot allocate zero size fixed stack objects!");
94 Objects.insert(Objects.begin(),
95 StackObject(Size, Alignment, SPOffset, IsImmutable,
98 return -++NumFixedObjects;
107 Objects.insert(Objects.begin(),
108 StackObject(Size, Alignment, SPOffset, IsImmutable,
111 return -++NumFixedObjects;
151 if (FixedOff > Offset) Offset = FixedOff;
160 Offset = (Offset+Align-1)/Align*Align;
162 MaxAlign =
std::max(Align, MaxAlign);
182 StackAlign =
std::max(StackAlign, MaxAlign);
183 unsigned AlignMask = StackAlign - 1;
184 Offset = (Offset + AlignMask) & ~uint64_t(AlignMask);
193 assert(FrameSetupOpcode != ~0u && FrameDestroyOpcode != ~0u &&
194 "Can only compute MaxCallFrameSize if Setup/Destroy opcode are known");
196 MaxCallFrameSize = 0;
199 unsigned Opcode =
MI.getOpcode();
200 if (Opcode == FrameSetupOpcode || Opcode == FrameDestroyOpcode) {
202 MaxCallFrameSize =
std::max(MaxCallFrameSize, Size);
204 }
else if (
MI.isInlineAsm()) {
215 if (Objects.empty())
return;
220 OS <<
"Frame Objects:\n";
222 for (
unsigned i = 0,
e = Objects.size(); i !=
e; ++i) {
223 const StackObject &SO = Objects[i];
224 OS <<
" fi#" << (int)(i-NumFixedObjects) <<
": ";
227 OS <<
"id=" <<
static_cast<unsigned>(SO.StackID) <<
' ';
229 if (SO.Size == ~0ULL) {
234 OS <<
"variable sized";
236 OS <<
"size=" << SO.Size;
237 OS <<
", align=" << SO.Alignment.value();
239 if (i < NumFixedObjects)
241 if (i < NumFixedObjects || SO.SPOffset != -1) {
242 int64_t Off = SO.SPOffset - ValOffset;
243 OS <<
", at location [SP";
254 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
This class represents lattice values for constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
void dump(const MachineFunction &MF) const
dump - Print the function to stderr.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
void ensureMaxAlignment(Align Alignment)
Make sure the function is at least Align bytes aligned.
unsigned const TargetRegisterInfo * TRI
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
unsigned getCallFrameDestroyOpcode() const
static Align clampStackAlignment(bool ShouldClamp, Align Alignment, Align StackAlignment)
Clamp the alignment if requested and emit a warning.
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
const HexagonInstrInfo * TII
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created. ...
Align commonAlignment(Align A, Align B)
Returns the alignment that satisfies both alignments.
int getObjectIndexBegin() const
Return the minimum frame object index.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
virtual const TargetInstrInfo * getInstrInfo() const
int CreateSpillStackObject(uint64_t Size, Align Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
uint64_t value() const
This is a hole in the type system and should not be abused.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
TargetInstrInfo - Interface to description of machine instruction set.
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
unsigned const MachineRegisterInfo * MRI
void print(const MachineFunction &MF, raw_ostream &OS) const
Used by the MachineFunction printer to print information about stack objects.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
unsigned getCallFrameSetupOpcode() const
These methods return the opcode of the frame setup/destroy instructions if they exist (-1 otherwise)...
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
void computeMaxCallFrameSize(const MachineFunction &MF)
Computes the maximum size of a callframe and the AdjustsStack property.
static constexpr const Align None()
Returns a default constructed Align which corresponds to no alignment.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MCSubRegIterator enumerates all sub-registers of Reg.
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
virtual bool hasReservedCallFrame(const MachineFunction &MF) const
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required, we reserve argument space for call sites in the function immediately on entry to the current function.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Align max(MaybeAlign Lhs, Align Rhs)
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call...
Information about stack frame layout on the target.
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
int64_t getFrameSize(const MachineInstr &I) const
Returns size of the frame associated with the given frame instruction.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getTransientStackAlignment() const
getTransientStackAlignment - This method returns the number of bytes to which the stack pointer must ...
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
uint64_t estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
virtual const TargetFrameLowering * getFrameLowering() const
uint8_t getStackID(int ObjectIdx) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
bool needsStackRealignment(const MachineFunction &MF) const
True if storage within the function requires the stack pointer to be aligned more than the normal cal...
const MCPhysReg * getCalleeSavedRegs() const
Returns list of callee saved registers.
This class implements an extremely fast bulk output stream that can only output to a stream...
BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
an instruction to allocate memory on the stack