48 #define DEBUG_TYPE "pei"
52 unsigned &MinCSFrameIndex,
53 unsigned &MaxCXFrameIndex,
66 if (
TM && (!
TM->usesPhysRegsForPEI())) {
68 unsigned &,
unsigned &,
const MBBVector &,
69 const MBBVector &) {};
74 UsesCalleeSaves =
true;
94 unsigned &MinCSFrameIndex,
unsigned &MaxCSFrameIndex,
97 SpillCalleeSavedRegisters;
98 std::function<void(MachineFunction &MF, RegScavenger *RS)>
99 ScavengeFrameVirtualRegs;
101 bool UsesCalleeSaves =
false;
107 unsigned MinCSFrameIndex = std::numeric_limits<unsigned>::max();
108 unsigned MaxCSFrameIndex = 0;
118 bool FrameIndexVirtualScavenging;
122 bool FrameIndexEliminationScavenging;
140 cl::desc(
"Warn for stack size bigger than the given"
157 STATISTIC(NumScavengedRegs,
"Number of frame index regs scavenged");
159 "Number of bytes used for stack in all functions");
183 FrameIndexEliminationScavenging = (RS && !FrameIndexVirtualScavenging) ||
189 calculateCallFrameInfo(Fn);
193 calculateSaveRestoreBlocks(Fn);
196 SpillCalleeSavedRegisters(Fn, RS, MinCSFrameIndex, MaxCSFrameIndex,
197 SaveBlocks, RestoreBlocks);
204 calculateFrameObjectOffsets(Fn);
212 insertPrologEpilogCode(Fn);
217 replaceFrameIndices(Fn);
223 ScavengeFrameVirtualRegs(Fn, RS);
239 RestoreBlocks.clear();
253 unsigned MaxCallFrameSize = 0;
262 if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
265 std::vector<MachineBasicBlock::iterator> FrameSDOps;
268 if (
I->getOpcode() == FrameSetupOpcode ||
269 I->getOpcode() == FrameDestroyOpcode) {
270 assert(
I->getNumOperands() >= 1 &&
"Call Frame Setup/Destroy Pseudo"
271 " instructions should have a single immediate argument!");
272 unsigned Size =
I->getOperand(0).getImm();
273 if (Size > MaxCallFrameSize) MaxCallFrameSize = Size;
275 FrameSDOps.push_back(
I);
276 }
else if (
I->isInlineAsm()) {
286 for (std::vector<MachineBasicBlock::iterator>::iterator
287 i = FrameSDOps.begin(), e = FrameSDOps.end();
i != e; ++
i) {
316 if (!RestoreBlock->succ_empty() || RestoreBlock->isReturnBlock())
322 SaveBlocks.push_back(&Fn.
front());
325 SaveBlocks.push_back(&
MBB);
327 RestoreBlocks.push_back(&
MBB);
333 unsigned &MinCSFrameIndex,
334 unsigned &MaxCSFrameIndex) {
335 if (SavedRegs.
empty())
341 std::vector<CalleeSavedInfo> CSI;
342 for (
unsigned i = 0; CSRegs[
i]; ++
i) {
343 unsigned Reg = CSRegs[
i];
344 if (SavedRegs.
test(Reg))
356 unsigned NumFixedSpillSlots;
362 for (
auto &CS : CSI) {
363 unsigned Reg = CS.getReg();
368 CS.setFrameIdx(FrameIdx);
375 while (FixedSlot != FixedSpillSlots + NumFixedSpillSlots &&
376 FixedSlot->
Reg != Reg)
379 if (FixedSlot == FixedSpillSlots + NumFixedSpillSlots) {
387 Align =
std::min(Align, StackAlign);
389 if ((
unsigned)FrameIdx < MinCSFrameIndex) MinCSFrameIndex = FrameIdx;
390 if ((
unsigned)FrameIdx > MaxCSFrameIndex) MaxCSFrameIndex = FrameIdx;
397 CS.setFrameIdx(FrameIdx);
436 while (!WorkList.
empty()) {
440 if (CurBB == Save && Save != Restore)
445 if (Visited.
insert(SuccBB).second)
451 for (
unsigned i = 0, e = CSI.size();
i != e; ++
i) {
485 I = SaveBlock->begin();
487 for (
unsigned i = 0, e = CSI.size();
i != e; ++
i) {
489 unsigned Reg = CSI[
i].getReg();
506 while (I2 !=
MBB->
begin() && (--I2)->isTerminator())
517 for (
unsigned i = 0, e = CSI.size();
i != e; ++
i) {
518 unsigned Reg = CSI[
i].getReg();
522 "loadRegFromStackSlot didn't insert any code!");
537 unsigned &MinCSFrameIndex,
538 unsigned &MaxCSFrameIndex,
543 MinCSFrameIndex = std::numeric_limits<unsigned>::max();
561 bool StackGrowsDown, int64_t &
Offset,
562 unsigned &MaxAlign,
unsigned Skew) {
571 MaxAlign = std::max(MaxAlign, Align);
574 Offset =
alignTo(Offset, Align, Skew);
576 if (StackGrowsDown) {
577 DEBUG(
dbgs() <<
"alloc FI(" << FrameIdx <<
") at SP[" << -Offset <<
"]\n");
580 DEBUG(
dbgs() <<
"alloc FI(" << FrameIdx <<
") at SP[" << Offset <<
"]\n");
591 unsigned MinCSFrameIndex,
unsigned MaxCSFrameIndex,
592 int64_t FixedCSEnd,
BitVector &StackBytesFree) {
594 if (FixedCSEnd > std::numeric_limits<int>::max())
597 StackBytesFree.
resize(FixedCSEnd,
true);
604 for (
int i = MinCSFrameIndex;
i <= (int)MaxCSFrameIndex; ++
i)
607 for (
int i : AllocatedFrameSlots) {
612 int ObjStart, ObjEnd;
613 if (StackGrowsDown) {
615 ObjStart = -ObjOffset - ObjSize;
618 ObjStart = ObjOffset;
619 ObjEnd = ObjOffset + ObjSize;
623 StackBytesFree.
reset(ObjStart, ObjEnd);
631 bool StackGrowsDown,
unsigned MaxAlign,
636 if (StackBytesFree.
none()) {
639 StackBytesFree.
clear();
644 if (ObjAlign > MaxAlign)
649 for (FreeStart = StackBytesFree.
find_first(); FreeStart != -1;
650 FreeStart = StackBytesFree.
find_next(FreeStart)) {
653 unsigned ObjStart = StackGrowsDown ? FreeStart + ObjSize : FreeStart;
654 if (
alignTo(ObjStart, ObjAlign) != ObjStart)
657 if (FreeStart + ObjSize > StackBytesFree.
size())
660 bool AllBytesFree =
true;
661 for (
unsigned Byte = 0; Byte < ObjSize; ++Byte)
662 if (!StackBytesFree.
test(FreeStart + Byte)) {
663 AllBytesFree =
false;
673 if (StackGrowsDown) {
674 int ObjStart = -(FreeStart + ObjSize);
675 DEBUG(
dbgs() <<
"alloc FI(" << FrameIdx <<
") scavenged at SP[" << ObjStart
679 DEBUG(
dbgs() <<
"alloc FI(" << FrameIdx <<
") scavenged at SP[" << FreeStart
684 StackBytesFree.
reset(FreeStart, FreeStart + ObjSize);
694 int64_t &
Offset,
unsigned &MaxAlign,
unsigned Skew) {
697 E = UnassignedObjs.
end();
I !=
E; ++
I) {
711 bool StackGrowsDown =
722 LocalAreaOffset = -LocalAreaOffset;
723 assert(LocalAreaOffset >= 0
724 &&
"Local area offset should be in direction of stack growth");
725 int64_t
Offset = LocalAreaOffset;
736 if (StackGrowsDown) {
746 if (FixedOff > Offset) Offset = FixedOff;
751 if (StackGrowsDown) {
752 for (
unsigned i = MinCSFrameIndex;
i <= MaxCSFrameIndex; ++
i) {
759 Offset =
alignTo(Offset, Align, Skew);
761 DEBUG(
dbgs() <<
"alloc FI(" <<
i <<
") at SP[" << -Offset <<
"]\n");
764 }
else if (MaxCSFrameIndex >= MinCSFrameIndex) {
766 for (
unsigned i = MaxCSFrameIndex;
i != MinCSFrameIndex - 1; --
i) {
769 Offset =
alignTo(Offset, Align, Skew);
771 DEBUG(
dbgs() <<
"alloc FI(" <<
i <<
") at SP[" << Offset <<
"]\n");
779 int64_t FixedCSEnd =
Offset;
786 bool EarlyScavengingSlots = (TFI.
hasFP(Fn) &&
790 if (RS && EarlyScavengingSlots) {
792 RS->getScavengingFrameIndices(SFIs);
806 Offset =
alignTo(Offset, Align, Skew);
808 DEBUG(
dbgs() <<
"Local frame base offset: " << Offset <<
"\n");
813 int64_t FIOffset = (StackGrowsDown ? -Offset :
Offset) + Entry.second;
814 DEBUG(
dbgs() <<
"alloc FI(" << Entry.first <<
") at SP[" <<
821 MaxAlign = std::max(Align, MaxAlign);
825 int EHRegNodeFrameIndex = INT_MAX;
827 EHRegNodeFrameIndex = FuncInfo->EHRegNodeFrameIndex;
845 if (
i >= MinCSFrameIndex &&
i <= MaxCSFrameIndex)
847 if (RS && RS->isScavengingFrameIndex((
int)
i))
852 EHRegNodeFrameIndex == (
int)
i)
872 Offset, MaxAlign, Skew);
874 Offset, MaxAlign, Skew);
876 Offset, MaxAlign, Skew);
886 if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
888 if (RS && RS->isScavengingFrameIndex((
int)i))
893 EHRegNodeFrameIndex == (
int)
i)
895 if (ProtectedObjs.count(i))
903 if (EHRegNodeFrameIndex != INT_MAX)
917 if (!ObjectsToAllocate.
empty() &&
921 FixedCSEnd, StackBytesFree);
924 for (
auto &Object : ObjectsToAllocate)
931 if (RS && !EarlyScavengingSlots) {
933 RS->getScavengingFrameIndices(SFIs);
960 StackAlign = std::max(StackAlign, MaxAlign);
961 Offset =
alignTo(Offset, StackAlign, Skew);
965 int64_t StackSize = Offset - LocalAreaOffset;
967 NumBytesStackSpace += StackSize;
1021 DFI != DFE; ++DFI) {
1024 if (DFI.getPathLength() >= 2) {
1027 "DFS stack predecessor is already visited.\n");
1028 SPAdj = SPState[StackPred->
getNumber()];
1031 replaceFrameIndices(BB, Fn, SPAdj);
1036 for (
auto &BB : Fn) {
1037 if (Reachable.
count(&BB))
1041 replaceFrameIndices(&BB, Fn, SPAdj);
1048 "getRegisterInfo() must be implemented!");
1052 unsigned FrameSetupOpcode = TII.getCallFrameSetupOpcode();
1053 unsigned FrameDestroyOpcode = TII.getCallFrameDestroyOpcode();
1055 if (RS && FrameIndexEliminationScavenging)
1056 RS->enterBasicBlock(*BB);
1058 bool InsideCallSequence =
false;
1062 if (
I->getOpcode() == FrameSetupOpcode ||
1063 I->getOpcode() == FrameDestroyOpcode) {
1064 InsideCallSequence = (
I->getOpcode() == FrameSetupOpcode);
1065 SPAdj += TII.getSPAdjust(*
I);
1073 bool DidFinishLoop =
true;
1082 assert(i == 0 &&
"Frame indices can only appear as the first "
1083 "operand of a DBG_VALUE machine instruction");
1098 if (MI.
getOpcode() == TargetOpcode::STATEPOINT) {
1100 "Frame indicies can only appear as the first operand of a "
1101 "DBG_VALUE machine instruction");
1118 bool AtBeginning = (
I == BB->
begin());
1119 if (!AtBeginning) --
I;
1125 FrameIndexEliminationScavenging ? RS :
nullptr);
1133 DidFinishLoop =
false;
1144 if (DidFinishLoop && InsideCallSequence)
1145 SPAdj += TII.getSPAdjust(MI);
1147 if (DoIncr &&
I != BB->
end()) ++
I;
1150 if (RS && FrameIndexEliminationScavenging && DidFinishLoop)
1195 unsigned Reg = MO.getReg();
1201 assert(MO.isDef() &&
"frame index virtual missing def!");
1210 assert(ScratchReg &&
"Missing scratch register!");
1223 if (
I != std::prev(J)) {
1233 "The register scavenger has an unexpected position");
unsigned StackSymbolOrdering
StackSymbolOrdering - When true, this will allow CodeGen to order the local stack symbols (for code s...
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
void push_back(const T &Elt)
virtual void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &objectsToAllocate) const
Order the symbols in the local stack frame.
virtual bool hasReservedSpillSlot(const MachineFunction &MF, unsigned Reg, int &FrameIdx) const
Return true if target has reserved a spill slot in the stack frame of the given function for the spec...
void setSavePoint(MachineBasicBlock *NewSave)
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
void setRestorePoint(MachineBasicBlock *NewRestore)
size_type size() const
size - Returns the number of bits in this bitvector.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static void AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx, bool StackGrowsDown, int64_t &Offset, unsigned &MaxAlign, unsigned Skew)
AdjustStackOffset - Helper function used to adjust the stack frame offset.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
void setCalleeSavedInfoValid(bool v)
STATISTIC(NumFunctions,"Total number of functions")
bool none() const
none - Returns true if none of the bits are set.
static void computeFreeStackSlots(MachineFrameInfo &MFI, bool StackGrowsDown, unsigned MinCSFrameIndex, unsigned MaxCSFrameIndex, int64_t FixedCSEnd, BitVector &StackBytesFree)
Compute which bytes of fixed and callee-save stack area are unused and keep track of them in StackByt...
void ChangeToRegister(unsigned Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isDebug=false)
ChangeToRegister - Replace this operand with a new register operand of the specified value...
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
static void updateLiveness(MachineFunction &MF)
Helper function to update the liveness information for the callee-saved registers.
MachineBasicBlock * getRestorePoint() const
int find_next(unsigned Prev) const
find_next - Returns the index of the next set bit following the "Prev" bit.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
INITIALIZE_TM_PASS_BEGIN(PEI,"prologepilog","Prologue/Epilogue Insertion", false, false) INITIALIZE_TM_PASS_END(PEI
virtual void adjustForHiPEPrologue(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const
Adjust the prologue to add Erlang Run-Time System (ERTS) specific code in the assembly prologue to ex...
virtual unsigned getStackAlignmentSkew(const MachineFunction &MF) const
Return the skew that has to be applied to stack alignment under certain conditions (e...
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
MachineInstrBundleIterator< MachineInstr > iterator
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
SmallVector< MachineBasicBlock *, 4 > MBBVector
virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const
Returns true if the target requires post PEI scavenging of registers for materializing frame index co...
virtual const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
vector_type::const_iterator const_iterator
iterator_range< mop_iterator > operands()
iterator end()
Get an iterator to the end of the SetVector.
bool isObjectPreAllocated(int ObjectIdx) const
Return true if the object was pre-allocated into the local block.
void clearVirtRegs()
clearVirtRegs - Remove all virtual registers (after physreg assignment).
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
iterator_range< succ_iterator > successors()
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
Prologue Epilogue Insertion &Frame false
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
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.
unsigned getSize() const
Return the size of the register in bytes, which is also the size of a stack slot allocated to hold a ...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
virtual void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const
Replace a StackProbe stub (if any) with the actual probe code inline.
unsigned getCallFrameDestroyOpcode() const
Did not trigger a stack protector.
void clear()
clear - Clear all bits.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
virtual bool hasFP(const MachineFunction &MF) const =0
hasFP - Return true if the specified function should have a dedicated frame pointer register...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
The address of this allocation is exposed and triggered protection.
virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool Immutable=false)
Create a spill slot at a fixed location on the stack.
LLVM_NODISCARD bool empty() const
unsigned getNumOperands() const
Access to explicit operands of the instruction.
MachineBasicBlock::iterator getCurrentPosition() const
void forward()
Move the internal MBB iterator and update register states.
const MachineBasicBlock & front() const
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
int getObjectIndexBegin() const
Return the minimum frame object index.
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
unsigned getCallFrameSetupOpcode() const
These methods return the opcode of the frame setup/destroy instructions if they exist (-1 otherwise)...
virtual bool needsFrameIndexResolution(const MachineFunction &MF) const
virtual int getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI, unsigned &FrameReg, bool IgnoreSPUpdates) const
Same as getFrameIndexReference, except that the stack pointer (as opposed to the frame pointer) will ...
unsigned getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
iterator begin()
Get an iterator to the beginning of the SetVector.
virtual bool enableStackSlotScavenging(const MachineFunction &MF) const
Returns true if the stack slot holes in the fixed and callee-save stack area should be used when allo...
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...
virtual bool useFPForScavengingIndex(const MachineFunction &MF) const
Returns true if the target wants to use frame pointer based accesses to spill to the scavenger emerge...
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
static cl::opt< unsigned > WarnStackSize("warn-stack-size", cl::Hidden, cl::init((unsigned)-1), cl::desc("Warn for stack size bigger than the given"" number"))
virtual MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
virtual const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const =0
Return a null-terminated list of all of the callee-saved registers on this target.
virtual int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
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.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const
Returns true if the target requires (and can make use of) the register scavenger. ...
TargetInstrInfo - Interface to description of machine instruction set.
std::pair< int, int64_t > getLocalFrameObjectMap(int i) const
Get the local offset mapping for a for an object.
bool isDebugValue() const
virtual void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const =0
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
initializer< Ty > init(const Ty &Val)
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
This file declares the machine register scavenger class.
bool getUseLocalStackAllocationBlock() const
Get whether the local allocation blob should be allocated together or let PEI allocate the locals in ...
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
unsigned const MachineRegisterInfo * MRI
void initializePEIPass(PassRegistry &)
virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
unsigned getAlignment() const
Return the minimum required alignment for a register of this class.
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
void setStackSize(uint64_t Size)
Set the size of the stack.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
const MachineOperand & getOperand(unsigned i) const
void unprocess()
Invert the behavior of forward() on the current instruction (undo the changes to the available regist...
bool empty() const
empty - Tests whether there are no bits in this bitvector.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
#define INITIALIZE_TM_PASS_END(passName, arg, name, cfg, analysis)
Target machine pass initializer for passes with dependencies.
virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const
Load the specified register of the given register class from the specified stack frame index...
SmallSetVector< int, 8 > StackObjSet
StackObjSet - A set of stack object indexes.
Represent the analysis usage information of a pass.
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
static void doScavengeFrameVirtualRegs(MachineFunction &MF, RegScavenger *RS)
doScavengeFrameVirtualRegs - Replace all frame index virtual registers with physical registers...
bool shouldSplitStack() const
Should we be emitting segmented stack stuff for the function.
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
void setImm(int64_t immVal)
static bool scavengeStackSlot(MachineFrameInfo &MFI, int FrameIdx, bool StackGrowsDown, unsigned MaxAlign, BitVector &StackBytesFree)
Assign frame object to an unused portion of the stack in the fixed stack object range.
SSPLayoutKind getSSPLayout(const AllocaInst *AI) const
static void assignCalleeSavedSpillSlots(MachineFunction &F, const BitVector &SavedRegs, unsigned &MinCSFrameIndex, unsigned &MaxCSFrameIndex)
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
static void insertCSRSpillsAndRestores(MachineFunction &Fn, const MBBVector &SaveBlocks, const MBBVector &RestoreBlocks)
insertCSRSpillsAndRestores - Insert spill and restore code for callee saved registers used in the fun...
virtual void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const
Store the specified register of the given register class to the specified stack frame index...
MachineFunctionPass * createPrologEpilogInserterPass(const TargetMachine *TM)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction. ...
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 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
virtual const TargetFrameLowering * getFrameLowering() const
A SetVector that performs no allocations if smaller than a certain size.
static void doSpillCalleeSavedRegs(MachineFunction &MF, RegScavenger *RS, unsigned &MinCSFrameIndex, unsigned &MaxCXFrameIndex, const MBBVector &SaveBlocks, const MBBVector &RestoreBlocks)
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
virtual bool requiresFrameIndexReplacementScavenging(const MachineFunction &MF) const
Returns true if the target requires using the RegScavenger directly for frame elimination despite usi...
virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const =0
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
bool test(unsigned Idx) const
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
Prologue Epilogue Insertion &Frame Finalization
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.
LLVM_NODISCARD T pop_back_val()
virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const
canSimplifyCallFramePseudos - When possible, it's best to simplify the call frame pseudo ops before d...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
void setAdjustsStack(bool V)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
const TargetRegisterClass * getMinimalPhysRegClass(unsigned Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
int getStackProtectorIndex() const
Return the index for the stack protector object.
char & PrologEpilogCodeInserterID
PrologEpilogCodeInserter - This pass inserts prolog and epilog code, and eliminates abstract frame re...
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
MachineBasicBlock * getSavePoint() const
Representation of each machine instruction.
void setCalleeSavedInfo(const std::vector< CalleeSavedInfo > &CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
void enterBasicBlock(MachineBasicBlock &MBB)
Start tracking liveness from the begin of basic block MBB.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void push_back(MachineInstr *MI)
virtual void adjustForSegmentedStacks(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const
Adjust the prologue to have the function use segmented stacks.
void setMaxCallFrameSize(unsigned S)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling...
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca=nullptr)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
virtual bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void setRegUsed(unsigned Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Tell the scavenger a register is used.
virtual const TargetInstrInfo * getInstrInfo() const
Primary interface to the complete machine description for the target machine.
print Print MemDeps of function
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.
const AllocaInst * getObjectAllocation(int ObjectIdx) const
Return the underlying Alloca of the specified stack object if it exists.
static void AssignProtectedObjSet(const StackObjSet &UnassignedObjs, SmallSet< int, 16 > &ProtectedObjs, MachineFrameInfo &MFI, bool StackGrowsDown, int64_t &Offset, unsigned &MaxAlign, unsigned Skew)
AssignProtectedObjSet - Helper function to assign large stack objects (i.e., those required to be clo...
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
Array or nested array >= SSP-buffer-size.
Properties which a MachineFunction may have at a given point in time.
Array or nested array < SSP-buffer-size.
virtual bool isFPCloseToIncomingSP() const
isFPCloseToIncomingSP - Return true if the frame pointer is close to the incoming stack pointer...
unsigned scavengeRegister(const TargetRegisterClass *RegClass, MachineBasicBlock::iterator I, int SPAdj)
Make a register of the specific register class available and do the appropriate bookkeeping.