Go to the documentation of this file.
74 #define DEBUG_TYPE "prologepilog"
78 STATISTIC(NumLeafFuncWithSpills,
"Number of leaf functions with CSRs");
79 STATISTIC(NumFuncSeen,
"Number of functions seen in PEI");
104 unsigned MaxCSFrameIndex = 0;
114 bool FrameIndexVirtualScavenging;
118 bool FrameIndexEliminationScavenging;
135 unsigned OpIdx,
int SPAdj = 0);
166 "Number of bytes used for stack in all functions");
189 for (
auto &
MI :
MBB) {
190 if (!
MI.isDebugInstr())
192 if (!
MI.isDebugValue() || !
MI.getDebugVariable()->isParameter())
198 FrameIndexValues.push_back(&
MI);
204 return Var == DV->getDebugVariable() &&
211 EntryDbgValues[&
MBB].push_back(&
MI);
216 for (
auto *
MI : EntryDbgValues[&
MBB])
217 MI->removeFromParent();
230 ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
235 calculateCallFrameInfo(MF);
239 calculateSaveRestoreBlocks(MF);
248 spillCalleeSavedRegs(MF);
255 calculateFrameObjectOffsets(MF);
262 if (!
F.hasFnAttribute(Attribute::Naked))
263 insertPrologEpilogCode(MF);
266 for (
auto &
I : EntryDbgValues)
267 I.first->insert(
I.first->begin(),
I.second.begin(),
I.second.end());
276 replaceFrameIndices(MF);
288 unsigned Threshold = UINT_MAX;
295 assert(!
Failed &&
"Invalid warn-stack-size fn attr value");
300 StackSize += UnsafeStackSize;
302 if (StackSize > Threshold) {
304 F.getContext().diagnose(DiagStackSize);
305 int64_t SpillSize = 0;
313 static_cast<float>(SpillSize) /
static_cast<float>(StackSize);
314 float VarPct = 1.0f - SpillPct;
315 int64_t VariableSize = StackSize - SpillSize;
316 dbgs() <<
formatv(
"{0}/{1} ({3:P}) spills, {2}/{1} ({4:P}) variables",
317 SpillSize, StackSize, VariableSize, SpillPct, VarPct);
318 if (UnsafeStackSize != 0) {
320 static_cast<float>(UnsafeStackSize) /
static_cast<float>(StackSize);
321 dbgs() <<
formatv(
", {0}/{2} ({1:P}) unsafe stack", UnsafeStackSize,
322 UnsafePct, StackSize);
331 <<
ore::NV(
"NumStackBytes", StackSize) <<
" stack bytes in function";
336 RestoreBlocks.clear();
350 unsigned MaxCallFrameSize = 0;
354 unsigned FrameSetupOpcode =
TII.getCallFrameSetupOpcode();
355 unsigned FrameDestroyOpcode =
TII.getCallFrameDestroyOpcode();
359 if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
362 std::vector<MachineBasicBlock::iterator> FrameSDOps;
365 if (
TII.isFrameInstr(*
I)) {
366 unsigned Size =
TII.getFrameSize(*
I);
367 if (Size > MaxCallFrameSize) MaxCallFrameSize =
Size;
369 FrameSDOps.push_back(
I);
370 }
else if (
I->isInlineAsm()) {
416 SaveBlocks.push_back(&MF.
front());
419 SaveBlocks.push_back(&
MBB);
421 RestoreBlocks.push_back(&
MBB);
427 unsigned &MinCSFrameIndex,
428 unsigned &MaxCSFrameIndex) {
429 if (SavedRegs.
empty())
433 const MCPhysReg *CSRegs =
F.getRegInfo().getCalleeSavedRegs();
436 for (
unsigned i = 0; CSRegs[
i]; ++
i)
437 CSMask.
set(CSRegs[
i]);
439 std::vector<CalleeSavedInfo> CSI;
440 for (
unsigned i = 0; CSRegs[
i]; ++
i) {
441 unsigned Reg = CSRegs[
i];
443 bool SavedSuper =
false;
447 if (SavedRegs.
test(SuperReg) && CSMask.
test(SuperReg)) {
467 unsigned NumFixedSpillSlots;
473 for (
auto &CS : CSI) {
476 if (CS.isSpilledToReg())
479 unsigned Reg = CS.getReg();
484 CS.setFrameIdx(FrameIdx);
491 while (FixedSlot != FixedSpillSlots + NumFixedSpillSlots &&
496 if (FixedSlot == FixedSpillSlots + NumFixedSpillSlots) {
504 if ((
unsigned)FrameIdx < MinCSFrameIndex) MinCSFrameIndex = FrameIdx;
505 if ((
unsigned)FrameIdx > MaxCSFrameIndex) MaxCSFrameIndex = FrameIdx;
511 CS.setFrameIdx(FrameIdx);
538 WorkList.push_back(Entry);
548 WorkList.push_back(Restore);
550 while (!WorkList.empty()) {
554 if (CurBB == Save && Save != Restore)
559 if (Visited.
insert(SuccBB).second)
560 WorkList.push_back(SuccBB);
579 if (
I.isSpilledToReg()) {
581 if (Visited.count(&
MBB))
603 unsigned Reg = CS.getReg();
605 if (CS.isSpilledToReg()) {
607 TII.get(TargetOpcode::COPY), CS.getDstReg())
620 std::vector<CalleeSavedInfo> &CSI) {
632 unsigned Reg = CI.getReg();
633 if (CI.isSpilledToReg()) {
641 "loadRegFromStackSlot didn't insert any code!");
672 if (!
F.hasFnAttribute(Attribute::Naked)) {
678 NumLeafFuncWithSpills++;
694 bool StackGrowsDown, int64_t &
Offset,
695 Align &MaxAlign,
unsigned Skew) {
704 MaxAlign =
std::max(MaxAlign, Alignment);
709 if (StackGrowsDown) {
725 unsigned MinCSFrameIndex,
unsigned MaxCSFrameIndex,
726 int64_t FixedCSEnd,
BitVector &StackBytesFree) {
731 StackBytesFree.
resize(FixedCSEnd,
true);
738 AllocatedFrameSlots.push_back(
i);
740 if (MinCSFrameIndex <= MaxCSFrameIndex) {
741 for (
int i = MinCSFrameIndex;
i <= (
int)MaxCSFrameIndex; ++
i)
743 AllocatedFrameSlots.push_back(
i);
746 for (
int i : AllocatedFrameSlots) {
751 int ObjStart, ObjEnd;
752 if (StackGrowsDown) {
754 ObjStart = -ObjOffset - ObjSize;
757 ObjStart = ObjOffset;
758 ObjEnd = ObjOffset + ObjSize;
762 StackBytesFree.
reset(ObjStart, ObjEnd);
769 bool StackGrowsDown,
Align MaxAlign,
774 if (StackBytesFree.
none()) {
777 StackBytesFree.
clear();
782 if (ObjAlign > MaxAlign)
787 for (FreeStart = StackBytesFree.
find_first(); FreeStart != -1;
788 FreeStart = StackBytesFree.
find_next(FreeStart)) {
791 unsigned ObjStart = StackGrowsDown ? FreeStart + ObjSize : FreeStart;
792 if (
alignTo(ObjStart, ObjAlign) != ObjStart)
795 if (FreeStart + ObjSize > StackBytesFree.
size())
798 bool AllBytesFree =
true;
799 for (
unsigned Byte = 0; Byte < ObjSize; ++Byte)
800 if (!StackBytesFree.
test(FreeStart + Byte)) {
801 AllBytesFree =
false;
811 if (StackGrowsDown) {
812 int ObjStart = -(FreeStart + ObjSize);
813 LLVM_DEBUG(
dbgs() <<
"alloc FI(" << FrameIdx <<
") scavenged at SP["
814 << ObjStart <<
"]\n");
817 LLVM_DEBUG(
dbgs() <<
"alloc FI(" << FrameIdx <<
") scavenged at SP["
818 << FreeStart <<
"]\n");
822 StackBytesFree.
reset(FreeStart, FreeStart + ObjSize);
834 for (
int i : UnassignedObjs) {
845 bool StackGrowsDown =
856 LocalAreaOffset = -LocalAreaOffset;
857 assert(LocalAreaOffset >= 0
858 &&
"Local area offset should be in direction of stack growth");
859 int64_t
Offset = LocalAreaOffset;
864 #ifdef EXPENSIVE_CHECKS
869 "MaxAlignment is invalid");
882 if (StackGrowsDown) {
898 if (MaxCSFrameIndex >= MinCSFrameIndex) {
899 for (
unsigned i = 0;
i <= MaxCSFrameIndex - MinCSFrameIndex; ++
i) {
901 StackGrowsDown ? MinCSFrameIndex +
i : MaxCSFrameIndex -
i;
917 "MFI.getMaxAlign should already account for all callee-saved "
918 "registers without a fixed stack slot");
922 int64_t FixedCSEnd =
Offset;
929 if (RS && EarlyScavengingSlots) {
931 RS->getScavengingFrameIndices(SFIs);
951 int64_t FIOffset = (StackGrowsDown ? -
Offset :
Offset) + Entry.second;
952 LLVM_DEBUG(
dbgs() <<
"alloc FI(" << Entry.first <<
") at SP[" << FIOffset
959 MaxAlign =
std::max(Alignment, MaxAlign);
965 EHRegNodeFrameIndex = FuncInfo->EHRegNodeFrameIndex;
984 "Offset of stack protector on non-default stack expected to be "
987 "Stack protector on non-default stack expected to not be "
988 "pre-allocated by LocalStackSlotPass.");
994 "Stack protector not pre-allocated by LocalStackSlotPass.");
1001 if (
i >= MinCSFrameIndex &&
i <= MaxCSFrameIndex)
1003 if (RS && RS->isScavengingFrameIndex((
int)
i))
1007 if (StackProtectorFI == (
int)
i || EHRegNodeFrameIndex == (
int)
i)
1033 !(LargeArrayObjs.
empty() && SmallArrayObjs.
empty() &&
1034 AddrOfObjs.
empty()))
1036 "LocalStackSlotPass.");
1053 if (
i >= MinCSFrameIndex &&
i <= MaxCSFrameIndex)
1055 if (RS && RS->isScavengingFrameIndex((
int)
i))
1061 if (ProtectedObjs.
count(
i))
1068 ObjectsToAllocate.push_back(
i);
1086 if (!ObjectsToAllocate.empty() &&
1090 FixedCSEnd, StackBytesFree);
1093 for (
auto &Object : ObjectsToAllocate)
1100 if (RS && !EarlyScavengingSlots) {
1102 RS->getScavengingFrameIndices(SFIs);
1103 for (
int SFI : SFIs)
1129 int64_t OffsetBeforeAlignment =
Offset;
1135 if (StackGrowsDown && OffsetBeforeAlignment !=
Offset && RS &&
1136 !EarlyScavengingSlots) {
1138 RS->getScavengingFrameIndices(SFIs);
1140 <<
"Adjusting emergency spill slots!\n";);
1141 int64_t Delta =
Offset - OffsetBeforeAlignment;
1142 for (
int SFI : SFIs) {
1144 <<
"Adjusting offset of emergency spill slot #" << SFI
1153 int64_t StackSize =
Offset - LocalAreaOffset;
1155 NumBytesStackSpace += StackSize;
1173 insertZeroCallUsedRegs(MF);
1201 if (!
F.hasFnAttribute(
"zero-call-used-regs"))
1204 using namespace ZeroCallUsedRegs;
1208 F.getFnAttribute(
"zero-call-used-regs").getValueAsString())
1222 const bool OnlyGPR =
static_cast<unsigned>(ZeroRegsKind) &
ONLY_GPR;
1223 const bool OnlyUsed =
static_cast<unsigned>(ZeroRegsKind) &
ONLY_USED;
1224 const bool OnlyArg =
static_cast<unsigned>(ZeroRegsKind) &
ONLY_ARG;
1235 if (
MI.isDebugInstr())
1243 if (AllocatableSet[
Reg] && !MO.isImplicit() &&
1244 (MO.isDef() || MO.isUse()))
1252 LiveIns.set(LI.PhysReg);
1265 if (OnlyUsed && !UsedRegs[
Reg])
1278 RegsToZero.set(
Reg);
1287 for (
const auto &MO :
MI.operands()) {
1295 RegsToZero.reset(*Unit);
1298 RegsToZero.reset(SReg);
1317 RegsToZero.reset(
Reg);
1326 RegsToZero.reset(
Reg);
1345 FrameIndexEliminationScavenging = (RS && !FrameIndexVirtualScavenging) ||
1355 DFI != DFE; ++DFI) {
1358 if (DFI.getPathLength() >= 2) {
1361 "DFS stack predecessor is already visited.\n");
1362 SPAdj = SPState[StackPred->
getNumber()];
1365 replaceFrameIndices(
BB, MF, SPAdj);
1366 SPState[
BB->getNumber()] = SPAdj;
1370 for (
auto &
BB : MF) {
1375 replaceFrameIndices(&
BB, MF, SPAdj);
1380 unsigned OpIdx,
int SPAdj) {
1383 if (
MI.isDebugValue()) {
1387 "Frame indices can only appear as a debug operand in a DBG_VALUE*"
1388 " machine instruction");
1390 unsigned FrameIdx =
Op.getIndex();
1394 Op.ChangeToRegister(
Reg,
false );
1404 if (
MI.isNonListDebugValue()) {
1406 if (!
MI.isIndirectDebugValue() && !DIExpr->
isComplex())
1413 if (
MI.isIndirectDebugValue() && DIExpr->
isImplicit()) {
1415 bool WithStackValue =
true;
1418 MI.getDebugOffset().ChangeToRegister(0,
false);
1425 unsigned DebugOpIndex =
MI.getDebugOperandIndex(&
Op);
1430 MI.getDebugExpressionOp().setMetadata(DIExpr);
1434 if (
MI.isDebugPHI()) {
1444 if (
MI.getOpcode() == TargetOpcode::STATEPOINT) {
1445 assert((!
MI.isDebugValue() || OpIdx == 0) &&
1446 "Frame indicies can only appear as the first operand of a "
1447 "DBG_VALUE machine instruction");
1451 MF,
MI.getOperand(OpIdx).getIndex(),
Reg,
false);
1453 "Frame offsets with a scalable component are not supported");
1455 MI.getOperand(OpIdx).ChangeToRegister(
Reg,
false );
1464 "getRegisterInfo() must be implemented!");
1468 RS->enterBasicBlockEnd(*
BB);
1474 for (
unsigned i = 0;
i !=
MI.getNumOperands(); ++
i) {
1475 if (!
MI.getOperand(
i).isFI())
1478 if (replaceFrameIndexDebugInstr(MF,
MI,
i, SPAdj))
1519 if (Step !=
BB->begin())
1530 "getRegisterInfo() must be implemented!");
1536 return replaceFrameIndicesBackward(
BB, MF, SPAdj);
1538 if (RS && FrameIndexEliminationScavenging)
1539 RS->enterBasicBlock(*
BB);
1541 bool InsideCallSequence =
false;
1544 if (
TII.isFrameInstr(*
I)) {
1545 InsideCallSequence =
TII.isFrameSetup(*
I);
1546 SPAdj +=
TII.getSPAdjust(*
I);
1553 bool DidFinishLoop =
true;
1554 for (
unsigned i = 0,
e =
MI.getNumOperands();
i !=
e; ++
i) {
1555 if (!
MI.getOperand(
i).isFI())
1558 if (replaceFrameIndexDebugInstr(MF,
MI,
i, SPAdj))
1568 bool AtBeginning = (
I ==
BB->begin());
1569 if (!AtBeginning) --
I;
1575 FrameIndexEliminationScavenging ? RS :
nullptr);
1583 DidFinishLoop =
false;
1594 if (DidFinishLoop && InsideCallSequence)
1595 SPAdj +=
TII.getSPAdjust(
MI);
1597 if (DoIncr &&
I !=
BB->end()) ++
I;
1600 if (RS && FrameIndexEliminationScavenging && DidFinishLoop)
StringSwitch & Case(StringLiteral S, T Value)
virtual void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &objectsToAllocate) const
Order the symbols in the local stack frame.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
bool isMaxCallFrameSizeComputed() const
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
bool hasProperty(Property P) const
This is an optimization pass for GlobalISel generic memory operations.
virtual bool isFixedRegister(const MachineFunction &MF, MCRegister PhysReg) const
Returns true if PhysReg is a fixed register.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
virtual bool needsFrameIndexResolution(const MachineFunction &MF) const
Information about stack frame layout on the target.
virtual bool isGeneralPurposeRegister(const MachineFunction &MF, MCRegister PhysReg) const
Returns true if PhysReg is a general purpose register.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
virtual bool isArgumentRegister(const MachineFunction &MF, MCRegister PhysReg) const
Returns true if PhysReg can be used as an argument to a function.
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...
virtual bool usesPhysRegsForValues() const
True if the target uses physical regs (as nearly all targets do).
virtual const TargetInstrInfo * getInstrInfo() const
void clear()
clear - Removes all bits from the bitvector.
bool none() const
none - Returns true if none of the bits are set.
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
DISubprogram * getSubprogram() const
Get the attached subprogram.
bool getUseLocalStackAllocationBlock() const
Get whether the local allocation blob should be allocated together or let PEI allocate the locals in ...
static void stashEntryDbgValues(MachineBasicBlock &MBB, SavedDbgValuesMap &EntryDbgValues)
Stash DBG_VALUEs that describe parameters and which are placed at the start of the block.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
Reg
All possible values of the reg field in the ModR/M byte.
BitVector getAllocatableSet(const MachineFunction &MF, const TargetRegisterClass *RC=nullptr) const
Returns a bitset indexed by register number indicating if a register is allocatable or not.
virtual void getOffsetOpcodes(const StackOffset &Offset, SmallVectorImpl< uint64_t > &Ops) const
Gets the DWARF expression opcodes for Offset.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
@ HiPE
Used by the High-Performance Erlang Compiler (HiPE).
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MachineFunctionPass * createPrologEpilogInserterPass()
detail::concat_range< const MCPhysReg, iterator_range< mc_subreg_iterator >, iterator_range< mc_superreg_iterator > > sub_and_superregs_inclusive(MCRegister Reg) const
Return an iterator range over all sub- and super-registers of Reg, including Reg.
void setStackSize(uint64_t Size)
Set the size of the stack.
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
bool isObjectPreAllocated(int ObjectIdx) const
Return true if the object was pre-allocated into the local block.
virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const
Returns true if the target requires post PEI scavenging of registers for materializing frame index co...
@ SSPLK_LargeArray
Array or nested array >= SSP-buffer-size.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
void setMaxCallFrameSize(unsigned S)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
DiagnosticInfoOptimizationBase::Argument NV
void setAdjustsStack(bool V)
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
virtual void processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF, RegScavenger *RS=nullptr) const
processFunctionBeforeFrameIndicesReplaced - This method is called immediately before MO_FrameIndex op...
int getObjectIndexEnd() const
Return one past the maximum frame object index.
iterator_range< iterator > terminators()
unsigned const TargetRegisterInfo * TRI
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Align getTransientStackAlign() const
getTransientStackAlignment - This method returns the number of bytes to which the stack pointer must ...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
virtual const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const =0
Return a null-terminated list of all of the callee-saved registers on this target.
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
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...
void push_back(MachineInstr *MI)
virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
const MachineBasicBlock & front() const
static DIExpression * appendOpsToArg(const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_a...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
TargetInstrInfo - Interface to description of machine instruction set.
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
testing::Matcher< const detail::ErrorHolder & > Failed()
char & PrologEpilogCodeInserterID
PrologEpilogCodeInserter - This pass inserts prolog and epilog code, and eliminates abstract frame re...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
void setCalleeSavedInfoValid(bool v)
virtual bool hasReservedCallFrame(const MachineFunction &MF) const
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
bool isReserved(MCRegister PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
virtual void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const
Replace a StackProbe stub (if any) with the actual probe code inline.
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
size_type size() const
size - Returns the number of bits in this bitvector.
static void updateLiveness(MachineFunction &MF)
Helper function to update the liveness information for the callee-saved registers.
Represent the analysis usage information of a pass.
virtual bool supportsBackwardScavenger() const
Process frame indices in reverse block order.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const HexagonInstrInfo * TII
MachineOperand class - Representation of each machine instruction operand.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Pair of physical register and lane mask.
INITIALIZE_PASS_BEGIN(PEI, DEBUG_TYPE, "Prologue/Epilogue Insertion", false, false) INITIALIZE_PASS_END(PEI
static StackOffset getFixed(int64_t Fixed)
static bool scavengeStackSlot(MachineFrameInfo &MFI, int FrameIdx, bool StackGrowsDown, Align MaxAlign, BitVector &StackBytesFree)
Assign frame object to an unused portion of the stack in the fixed stack object range.
virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
MachineBasicBlock * getRestorePoint() const
STATISTIC(NumFunctions, "Total number of functions")
uint8_t getStackID(int ObjectIdx) const
bool shouldSplitStack() const
Should we be emitting segmented stack stuff for the function.
@ SSPLK_None
Did not trigger a stack protector.
Align getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
This struct is a compact representation of a valid (non-zero power of two) alignment.
int getObjectIndexBegin() const
Return the minimum frame object index.
bool empty() const
Determine if the SetVector is empty or not.
StringRef getValueAsString() const
Return the attribute's value as a string.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
virtual bool 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...
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
bool empty() const
empty - Tests whether there are no bits in this bitvector.
bool isImplicit() const
Return whether this is an implicit location description.
Align getSpillAlign(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
std::pair< int, int64_t > getLocalFrameObjectMap(int i) const
Get the local offset mapping for a for an object.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
void setCalleeSavedInfo(std::vector< CalleeSavedInfo > CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
static void AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx, bool StackGrowsDown, int64_t &Offset, Align &MaxAlign, unsigned Skew)
AdjustStackOffset - Helper function used to adjust the stack frame offset.
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
int64_t getLocalFrameSize() const
Get the size of the local object blob.
Representation of each machine instruction.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
virtual const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool hasStackProtectorIndex() const
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
virtual void adjustForSegmentedStacks(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const
Adjust the prologue to have the function use segmented stacks.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
void scavengeFrameVirtualRegs(MachineFunction &MF, RegScavenger &RS)
Replaces all frame index virtual registers with physical registers.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
void setRestorePoint(MachineBasicBlock *NewRestore)
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...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
virtual bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI, unsigned &MinCSFrameIndex, unsigned &MaxCSFrameIndex) const
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
void setSavePoint(MachineBasicBlock *NewSave)
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
bool insert(const value_type &X)
Insert a new element into the SetVector.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
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.
iterator_range< succ_iterator > successors()
void setPreservesCFG()
This function should be called by the pass, iff they do not:
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...
MachineBasicBlock MachineBasicBlock::iterator MBBI
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
virtual void emitZeroCallUsedRegs(BitVector RegsToZero, MachineBasicBlock &MBB) const
emitZeroCallUsedRegs - Zeros out call used registers.
static void AssignProtectedObjSet(const StackObjSet &UnassignedObjs, SmallSet< int, 16 > &ProtectedObjs, MachineFrameInfo &MFI, bool StackGrowsDown, int64_t &Offset, Align &MaxAlign, unsigned Skew)
AssignProtectedObjSet - Helper function to assign large stack objects (i.e., those required to be clo...
StackOffset holds a fixed and a scalable offset in bytes.
Prologue Epilogue Insertion &Frame Finalization
uint64_t getUnsafeStackSize() const
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
static StackOffset getScalable(int64_t Scalable)
int64_t getLocalFrameObjectCount() const
Return the number of objects allocated into the local object block.
unsigned const MachineRegisterInfo * MRI
Align getMaxAlign() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
Wrapper class representing virtual and physical registers.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
bool hasCalls() const
Return true if the current function has any function calls.
MachineBasicBlock * getSavePoint() const
bool test(unsigned Idx) const
static DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false, bool EntryValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
SSPLayoutKind getObjectSSPLayout(int ObjectIdx) const
Function & getFunction()
Return the LLVM function that this machine code represents.
virtual const TargetFrameLowering * getFrameLowering() const
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
virtual bool allocateScavengingFrameIndexesNearIncomingSP(const MachineFunction &MF) const
Control the placement of special register scavenging spill slots when allocating a stack frame.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.
virtual StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
void initializePEIPass(PassRegistry &)
static void assignCalleeSavedSpillSlots(MachineFunction &F, const BitVector &SavedRegs, unsigned &MinCSFrameIndex, unsigned &MaxCSFrameIndex)
virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const
canSimplifyCallFramePseudos - When possible, it's best to simplify the call frame pseudo ops before d...
virtual bool targetHandlesStackFrameRounding() const
targetHandlesStackFrameRounding - Returns true if the target is responsible for rounding up the stack...
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
int find_next(unsigned Prev) const
find_next - Returns the index of the next set bit following the "Prev" bit.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
bool hasStackRealignment(const MachineFunction &MF) const
True if stack realignment is required and still possible.
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const override
Load the specified register of the given register class from the specified stack frame index.
iterator_range< mc_superreg_iterator > superregs(MCRegister Reg) const
Return an iterator range over all super-registers of Reg, excluding Reg.
unsigned getKillRegState(bool B)
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
static void insertCSRRestores(MachineBasicBlock &RestoreBlock, std::vector< CalleeSavedInfo > &CSI)
Insert restore code for the callee-saved registers used in the function.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const
Returns true if the target requires (and can make use of) the register scavenger.
static void insertCSRSaves(MachineBasicBlock &SaveBlock, ArrayRef< CalleeSavedInfo > CSI)
Insert spill code for the callee-saved registers used in the function.
@ SSPLK_AddrOf
The address of this allocation is exposed and triggered protection.
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
@ SSPLK_SmallArray
Array or nested array < SSP-buffer-size.
unsigned StackSymbolOrdering
StackSymbolOrdering - When true, this will allow CodeGen to order the local stack symbols (for code s...
auto reverse(ContainerTy &&C)
A switch()-like statement whose cases are string literals.
A SetVector that performs no allocations if smaller than a certain size.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
int getStackProtectorIndex() const
Return the index for the stack protector object.
virtual void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const =0
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
AnalysisUsage & addRequired()
virtual StackOffset getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI, Register &FrameReg, bool IgnoreSPUpdates) const
Same as getFrameIndexReference, except that the stack pointer (as opposed to the frame pointer) will ...
bool adjustsStack() const
Return true if this function adjusts the stack – e.g., when calling another function.
const TargetRegisterClass * getMinimalPhysRegClass(MCRegister Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const =0
virtual bool hasReservedSpillSlot(const MachineFunction &MF, Register Reg, int &FrameIdx) const
Return true if target has reserved a spill slot in the stack frame of the given function for the spec...
DIExpression * prependOffsetExpression(const DIExpression *Expr, unsigned PrependFlags, const StackOffset &Offset) const
Prepends a DWARF expression for Offset to DIExpression Expr.
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, Register SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI, Register VReg) const override
Store the specified register of the given register class to the specified stack frame index.
virtual unsigned getStackAlignmentSkew(const MachineFunction &MF) const
Return the skew that has to be applied to stack alignment under certain conditions (e....
Wrapper class representing physical registers. Should be passed by value.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
virtual bool requiresFrameIndexReplacementScavenging(const MachineFunction &MF) const
Returns true if the target requires using the RegScavenger directly for frame elimination despite usi...
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.