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 "
47 <<
" when stack realignment is off" <<
'\n');
48 return StackAlignment;
55 assert(
Size != 0 &&
"Cannot allocate zero size stack objects!");
57 Objects.push_back(StackObject(
Size, Alignment, 0,
false, IsSpillSlot, Alloca,
58 !IsSpillSlot, StackID));
59 int Index = (int)Objects.size() - NumFixedObjects - 1;
60 assert(Index >= 0 &&
"Bad frame index!");
69 int Index = (int)Objects.size() - NumFixedObjects - 1;
76 HasVarSizedObjects =
true;
78 Objects.push_back(StackObject(0, Alignment, 0,
false,
false, Alloca,
true));
80 return (
int)Objects.size()-NumFixedObjects-1;
84 bool IsImmutable,
bool IsAliased) {
85 assert(
Size != 0 &&
"Cannot allocate zero size fixed stack objects!");
95 Objects.insert(Objects.begin(),
96 StackObject(
Size, Alignment, SPOffset, IsImmutable,
99 return -++NumFixedObjects;
108 Objects.insert(Objects.begin(),
109 StackObject(
Size, Alignment, SPOffset, IsImmutable,
112 return -++NumFixedObjects;
125 for (
const MCPhysReg *CSR =
MRI.getCalleeSavedRegs(); CSR && *CSR;
163 MaxAlign = std::max(Alignment, MaxAlign);
183 StackAlign = std::max(StackAlign, MaxAlign);
188 MachineFunction &MF, std::vector<MachineBasicBlock::iterator> *FrameSDOps) {
190 unsigned FrameSetupOpcode =
TII.getCallFrameSetupOpcode();
191 unsigned FrameDestroyOpcode =
TII.getCallFrameDestroyOpcode();
192 assert(FrameSetupOpcode != ~0u && FrameDestroyOpcode != ~0u &&
193 "Can only compute MaxCallFrameSize if Setup/Destroy opcode are known");
195 MaxCallFrameSize = 0;
198 unsigned Opcode =
MI.getOpcode();
199 if (Opcode == FrameSetupOpcode || Opcode == FrameDestroyOpcode) {
201 MaxCallFrameSize = std::max(MaxCallFrameSize,
Size);
202 if (FrameSDOps !=
nullptr)
203 FrameSDOps->push_back(&
MI);
210 if (Objects.empty())
return;
215 OS <<
"Frame Objects:\n";
217 for (
unsigned i = 0, e = Objects.size(); i != e; ++i) {
218 const StackObject &SO = Objects[i];
219 OS <<
" fi#" << (int)(i-NumFixedObjects) <<
": ";
222 OS <<
"id=" <<
static_cast<unsigned>(SO.StackID) <<
' ';
224 if (SO.Size == ~0ULL) {
229 OS <<
"variable sized";
231 OS <<
"size=" << SO.Size;
232 OS <<
", align=" << SO.Alignment.value();
234 if (i < NumFixedObjects)
236 if (i < NumFixedObjects || SO.SPOffset != -1) {
237 int64_t Off = SO.SPOffset - ValOffset;
238 OS <<
", at location [SP";
249#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
unsigned const MachineRegisterInfo * MRI
This file implements the BitVector class.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
const HexagonInstrInfo * TII
static Align clampStackAlignment(bool ShouldClamp, Align Alignment, Align StackAlignment)
Clamp the alignment if requested and emit a warning.
unsigned const TargetRegisterInfo * TRI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
an instruction to allocate memory 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.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
void computeMaxCallFrameSize(MachineFunction &MF, std::vector< MachineBasicBlock::iterator > *FrameSDOps=nullptr)
Computes the maximum size of a callframe.
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
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.
void ensureMaxAlignment(Align Alignment)
Make sure the function is at least Align bytes aligned.
Align getMaxAlign() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
bool contributesToMaxAlignment(uint8_t StackID)
Should this stack ID be considered in MaxAlignment.
uint64_t getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
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 estimateStackSize(const MachineFunction &MF) const
Estimate and return the size of the stack frame.
bool isCalleeSavedInfoValid() const
Has the callee saved info been calculated yet?
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
BitVector getPristineRegs(const MachineFunction &MF) const
Return a set of physical registers that are pristine.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
void print(const MachineFunction &MF, raw_ostream &OS) const
Used by the MachineFunction printer to print information about stack objects.
int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created.
void dump(const MachineFunction &MF) const
dump - Print the function to stderr.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
uint8_t getStackID(int ObjectIdx) const
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
int getObjectIndexBegin() const
Return the minimum frame object index.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Information about stack frame layout on the target.
virtual bool hasReservedCallFrame(const MachineFunction &MF) const
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
Align getTransientStackAlign() const
getTransientStackAlignment - This method returns the number of bytes to which the stack pointer must ...
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool hasStackRealignment(const MachineFunction &MF) const
True if stack realignment is required and still possible.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
This struct is a compact representation of a valid (non-zero power of two) alignment.