29 #define DEBUG_TYPE "nvptx-prolog-epilog"
45 return new NVPTXPrologEpilogPass();
54 bool Modified =
false;
56 calculateFrameObjectOffsets(MF);
60 for (
unsigned i = 0, e =
MI.getNumOperands();
i != e; ++
i) {
61 if (!
MI.getOperand(
i).isFI())
74 if (
I->isReturnBlock())
84 bool StackGrowsDown, int64_t &
Offset,
94 MaxAlign = std::max(MaxAlign, Align);
97 Offset = (Offset + Align - 1) / Align * Align;
100 DEBUG(
dbgs() <<
"alloc FI(" << FrameIdx <<
") at SP[" << -Offset <<
"]\n");
103 DEBUG(
dbgs() <<
"alloc FI(" << FrameIdx <<
") at SP[" << Offset <<
"]\n");
110 NVPTXPrologEpilogPass::calculateFrameObjectOffsets(
MachineFunction &Fn) {
114 bool StackGrowsDown =
125 LocalAreaOffset = -LocalAreaOffset;
126 assert(LocalAreaOffset >= 0
127 &&
"Local area offset should be in direction of stack growth");
128 int64_t
Offset = LocalAreaOffset;
137 if (StackGrowsDown) {
147 if (FixedOff > Offset) Offset = FixedOff;
164 Offset = (Offset + Align - 1) / Align * Align;
166 DEBUG(
dbgs() <<
"Local frame base offset: " << Offset <<
"\n");
171 int64_t FIOffset = (StackGrowsDown ? -Offset :
Offset) + Entry.second;
172 DEBUG(
dbgs() <<
"alloc FI(" << Entry.first <<
") at SP[" <<
179 MaxAlign = std::max(Align, MaxAlign);
219 StackAlign = std::max(StackAlign, MaxAlign);
220 unsigned AlignMask = StackAlign - 1;
221 Offset = (Offset + AlignMask) & ~uint64_t(AlignMask);
225 int64_t StackSize = Offset - LocalAreaOffset;
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
MachineFunctionPass * createNVPTXPrologEpilogPass()
bool isObjectPreAllocated(int ObjectIdx) const
Return true if the object was pre-allocated into the local block.
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
virtual bool targetHandlesStackFrameRounding() const
targetHandlesStackFrameRounding - Returns true if the target is responsible for rounding up the stack...
int64_t getLocalFrameSize() const
Get the size of the local object blob.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
int getObjectIndexBegin() const
Return the minimum frame object index.
static void AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx, bool StackGrowsDown, int64_t &Offset, unsigned &MaxAlign)
AdjustStackOffset - Helper function used to adjust the stack frame offset.
unsigned getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
virtual void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const =0
This method must be overriden to eliminate abstract frame indices from instructions which may use the...
unsigned getTransientStackAlignment() const
getTransientStackAlignment - This method returns the number of bytes to which the stack pointer must ...
int64_t getLocalFrameObjectCount() const
Return the number of objects allocated into the local object block.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
std::pair< int, int64_t > getLocalFrameObjectMap(int i) const
Get the local offset mapping for a for an object.
virtual void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const =0
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
bool getUseLocalStackAllocationBlock() const
Get whether the local allocation blob should be allocated together or let PEI allocate the locals in ...
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
void setStackSize(uint64_t Size)
Set the size of the stack.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
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.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
virtual const TargetFrameLowering * getFrameLowering() const
Iterator for intrusive lists based on ilist_node.
virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const =0
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
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.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
TargetSubtargetInfo - Generic base class for all target subtargets.
Representation of each machine instruction.
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return 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...
int getObjectIndexEnd() const
Return one past the maximum frame object index.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.