74#define DEBUG_TYPE "prologepilog"
78STATISTIC(NumLeafFuncWithSpills,
"Number of leaf functions with CSRs");
79STATISTIC(NumFuncSeen,
"Number of functions seen in PEI");
103 unsigned MinCSFrameIndex = std::numeric_limits<unsigned>::max();
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())
204 return Var == DV->getDebugVariable() &&
211 EntryDbgValues[&
MBB].push_back(&
MI);
216 for (
auto *
MI : EntryDbgValues[&
MBB])
217 MI->removeFromParent();
228 RS =
TRI->requiresRegisterScavenging(MF) ?
new RegScavenger() : nullptr;
229 FrameIndexVirtualScavenging =
TRI->requiresFrameIndexScavenging(MF);
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);
281 if (
TRI->requiresRegisterScavenging(MF) && FrameIndexVirtualScavenging)
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];
442 if (SavedRegs.
test(Reg)) {
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();
483 if (
RegInfo->hasReservedSpillSlot(
F, Reg, FrameIdx)) {
484 CS.setFrameIdx(FrameIdx);
491 while (FixedSlot != FixedSpillSlots + NumFixedSpillSlots &&
492 FixedSlot->
Reg != Reg)
496 if (FixedSlot == FixedSpillSlots + NumFixedSpillSlots) {
504 if ((
unsigned)FrameIdx < MinCSFrameIndex) MinCSFrameIndex = FrameIdx;
505 if ((
unsigned)FrameIdx > MaxCSFrameIndex) MaxCSFrameIndex = FrameIdx;
511 CS.setFrameIdx(FrameIdx);
550 while (!WorkList.
empty()) {
554 if (CurBB == Save && Save != Restore)
559 if (Visited.
insert(SuccBB).second)
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!");
656 MachineFunctionProperties::Property::NoVRegs));
661 MinCSFrameIndex = std::numeric_limits<unsigned>::max();
672 if (!
F.hasFnAttribute(Attribute::Naked)) {
678 NumLeafFuncWithSpills++;
694 bool StackGrowsDown, int64_t &
Offset,
704 MaxAlign = std::max(MaxAlign, Alignment);
709 if (StackGrowsDown) {
725 unsigned MinCSFrameIndex,
unsigned MaxCSFrameIndex,
726 int64_t FixedCSEnd,
BitVector &StackBytesFree) {
728 if (FixedCSEnd > std::numeric_limits<int>::max())
731 StackBytesFree.
resize(FixedCSEnd,
true);
740 if (MinCSFrameIndex <= MaxCSFrameIndex) {
741 for (
int i = MinCSFrameIndex; i <= (int)MaxCSFrameIndex; ++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);
833 for (
int i : UnassignedObjs) {
844 bool StackGrowsDown =
855 LocalAreaOffset = -LocalAreaOffset;
856 assert(LocalAreaOffset >= 0
857 &&
"Local area offset should be in direction of stack growth");
858 int64_t
Offset = LocalAreaOffset;
860#ifdef EXPENSIVE_CHECKS
865 "MaxAlignment is invalid");
878 if (StackGrowsDown) {
894 if (MaxCSFrameIndex >= MinCSFrameIndex) {
895 for (
unsigned i = 0; i <= MaxCSFrameIndex - MinCSFrameIndex; ++i) {
897 StackGrowsDown ? MinCSFrameIndex + i : MaxCSFrameIndex - i;
912 "MFI.getMaxAlign should already account for all callee-saved "
913 "registers without a fixed stack slot");
917 int64_t FixedCSEnd =
Offset;
924 if (RS && EarlyScavengingSlots) {
926 RS->getScavengingFrameIndices(SFIs);
946 int64_t FIOffset = (StackGrowsDown ? -
Offset :
Offset) + Entry.second;
947 LLVM_DEBUG(
dbgs() <<
"alloc FI(" << Entry.first <<
") at SP[" << FIOffset
954 MaxAlign = std::max(Alignment, MaxAlign);
958 int EHRegNodeFrameIndex = std::numeric_limits<int>::max();
960 EHRegNodeFrameIndex = FuncInfo->EHRegNodeFrameIndex;
979 "Offset of stack protector on non-default stack expected to be "
982 "Stack protector on non-default stack expected to not be "
983 "pre-allocated by LocalStackSlotPass.");
989 "Stack protector not pre-allocated by LocalStackSlotPass.");
996 if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
998 if (RS && RS->isScavengingFrameIndex((
int)i))
1002 if (StackProtectorFI == (
int)i || EHRegNodeFrameIndex == (
int)i)
1012 SmallArrayObjs.
insert(i);
1018 LargeArrayObjs.
insert(i);
1028 !(LargeArrayObjs.
empty() && SmallArrayObjs.
empty() &&
1029 AddrOfObjs.
empty()))
1031 "LocalStackSlotPass.");
1048 if (i >= MinCSFrameIndex && i <= MaxCSFrameIndex)
1050 if (RS && RS->isScavengingFrameIndex((
int)i))
1056 if (ProtectedObjs.
count(i))
1067 if (EHRegNodeFrameIndex != std::numeric_limits<int>::max())
1081 if (!ObjectsToAllocate.
empty() &&
1085 FixedCSEnd, StackBytesFree);
1088 for (
auto &
Object : ObjectsToAllocate)
1095 if (RS && !EarlyScavengingSlots) {
1097 RS->getScavengingFrameIndices(SFIs);
1098 for (
int SFI : SFIs)
1124 int64_t OffsetBeforeAlignment =
Offset;
1130 if (StackGrowsDown && OffsetBeforeAlignment !=
Offset && RS &&
1131 !EarlyScavengingSlots) {
1133 RS->getScavengingFrameIndices(SFIs);
1135 <<
"Adjusting emergency spill slots!\n";);
1136 int64_t Delta =
Offset - OffsetBeforeAlignment;
1137 for (
int SFI : SFIs) {
1139 <<
"Adjusting offset of emergency spill slot #" << SFI
1148 int64_t StackSize =
Offset - LocalAreaOffset;
1150 NumBytesStackSpace += StackSize;
1168 insertZeroCallUsedRegs(MF);
1196 if (!
F.hasFnAttribute(
"zero-call-used-regs"))
1199 using namespace ZeroCallUsedRegs;
1203 F.getFnAttribute(
"zero-call-used-regs").getValueAsString())
1204 .
Case(
"skip", ZeroCallUsedRegsKind::Skip)
1205 .
Case(
"used-gpr-arg", ZeroCallUsedRegsKind::UsedGPRArg)
1206 .
Case(
"used-gpr", ZeroCallUsedRegsKind::UsedGPR)
1207 .
Case(
"used-arg", ZeroCallUsedRegsKind::UsedArg)
1208 .
Case(
"used", ZeroCallUsedRegsKind::Used)
1209 .
Case(
"all-gpr-arg", ZeroCallUsedRegsKind::AllGPRArg)
1210 .
Case(
"all-gpr", ZeroCallUsedRegsKind::AllGPR)
1211 .
Case(
"all-arg", ZeroCallUsedRegsKind::AllArg)
1212 .
Case(
"all", ZeroCallUsedRegsKind::All);
1214 if (ZeroRegsKind == ZeroCallUsedRegsKind::Skip)
1217 const bool OnlyGPR =
static_cast<unsigned>(ZeroRegsKind) & ONLY_GPR;
1218 const bool OnlyUsed =
static_cast<unsigned>(ZeroRegsKind) & ONLY_USED;
1219 const bool OnlyArg =
static_cast<unsigned>(ZeroRegsKind) & ONLY_ARG;
1222 const BitVector AllocatableSet(
TRI.getAllocatableSet(MF));
1230 if (
MI.isDebugInstr())
1238 if (AllocatableSet[Reg] && !MO.isImplicit() &&
1239 (MO.isDef() || MO.isUse()))
1247 LiveIns.set(LI.PhysReg);
1250 for (
MCRegister Reg : AllocatableSet.set_bits()) {
1252 if (
TRI.isFixedRegister(MF, Reg))
1256 if (OnlyGPR && !
TRI.isGeneralPurposeRegister(MF, Reg))
1260 if (OnlyUsed && !UsedRegs[Reg])
1268 }
else if (!
TRI.isArgumentRegister(MF, Reg)) {
1273 RegsToZero.set(Reg);
1282 for (
const auto &MO :
MI.operands()) {
1290 RegsToZero.reset(*Unit);
1292 for (
MCPhysReg SReg :
TRI.sub_and_superregs_inclusive(Reg))
1293 RegsToZero.reset(SReg);
1311 TRI.sub_and_superregs_inclusive(MO.getReg()))
1312 RegsToZero.reset(Reg);
1318 for (
const MCPhysReg *CSRegs =
TRI.getCalleeSavedRegs(&MF);
1320 for (
MCRegister Reg :
TRI.sub_and_superregs_inclusive(CSReg))
1321 RegsToZero.reset(Reg);
1340 FrameIndexEliminationScavenging = (RS && !FrameIndexVirtualScavenging) ||
1341 TRI->requiresFrameIndexReplacementScavenging(MF);
1350 DFI != DFE; ++DFI) {
1353 if (DFI.getPathLength() >= 2) {
1356 "DFS stack predecessor is already visited.\n");
1357 SPAdj = SPState[StackPred->
getNumber()];
1360 replaceFrameIndices(BB, MF, SPAdj);
1365 for (
auto &BB : MF) {
1366 if (Reachable.
count(&BB))
1370 replaceFrameIndices(&BB, MF, SPAdj);
1375 unsigned OpIdx,
int SPAdj) {
1378 if (
MI.isDebugValue()) {
1382 "Frame indices can only appear as a debug operand in a DBG_VALUE*"
1383 " machine instruction");
1385 unsigned FrameIdx =
Op.getIndex();
1389 Op.ChangeToRegister(Reg,
false );
1399 if (
MI.isNonListDebugValue()) {
1401 if (!
MI.isIndirectDebugValue() && !DIExpr->
isComplex())
1408 if (
MI.isIndirectDebugValue() && DIExpr->
isImplicit()) {
1410 bool WithStackValue =
true;
1413 MI.getDebugOffset().ChangeToRegister(0,
false);
1415 DIExpr =
TRI.prependOffsetExpression(DIExpr, PrependFlags,
Offset);
1420 unsigned DebugOpIndex =
MI.getDebugOperandIndex(&Op);
1425 MI.getDebugExpressionOp().setMetadata(DIExpr);
1429 if (
MI.isDebugPHI()) {
1439 if (
MI.getOpcode() == TargetOpcode::STATEPOINT) {
1440 assert((!
MI.isDebugValue() || OpIdx == 0) &&
1441 "Frame indicies can only appear as the first operand of a "
1442 "DBG_VALUE machine instruction");
1446 MF,
MI.getOperand(OpIdx).getIndex(), Reg,
false);
1448 "Frame offsets with a scalable component are not supported");
1450 MI.getOperand(OpIdx).ChangeToRegister(Reg,
false );
1459 "getRegisterInfo() must be implemented!");
1463 RS->enterBasicBlockEnd(*BB);
1469 for (
unsigned i = 0; i !=
MI.getNumOperands(); ++i) {
1470 if (!
MI.getOperand(i).isFI())
1473 if (replaceFrameIndexDebugInstr(MF,
MI, i, SPAdj))
1504 bool Removed =
TRI.eliminateFrameIndex(
MI, SPAdj, i, RS);
1514 if (Step != BB->
begin())
1525 "getRegisterInfo() must be implemented!");
1530 if (RS &&
TRI.supportsBackwardScavenger())
1531 return replaceFrameIndicesBackward(BB, MF, SPAdj);
1533 if (RS && FrameIndexEliminationScavenging)
1534 RS->enterBasicBlock(*BB);
1536 bool InsideCallSequence =
false;
1539 if (
TII.isFrameInstr(*
I)) {
1540 InsideCallSequence =
TII.isFrameSetup(*
I);
1541 SPAdj +=
TII.getSPAdjust(*
I);
1548 bool DidFinishLoop =
true;
1549 for (
unsigned i = 0, e =
MI.getNumOperands(); i != e; ++i) {
1550 if (!
MI.getOperand(i).isFI())
1553 if (replaceFrameIndexDebugInstr(MF,
MI, i, SPAdj))
1563 bool AtBeginning = (
I == BB->
begin());
1564 if (!AtBeginning) --
I;
1569 TRI.eliminateFrameIndex(
MI, SPAdj, i,
1570 FrameIndexEliminationScavenging ? RS :
nullptr);
1578 DidFinishLoop =
false;
1589 if (DidFinishLoop && InsideCallSequence)
1590 SPAdj +=
TII.getSPAdjust(
MI);
1592 if (DoIncr &&
I != BB->
end()) ++
I;
1595 if (RS && FrameIndexEliminationScavenging && DidFinishLoop)
unsigned const MachineRegisterInfo * MRI
MachineBasicBlock MachineBasicBlock::iterator MBBI
This file contains the simple types necessary to represent the attributes associated with functions a...
This file implements the BitVector class.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
const HexagonInstrInfo * TII
unsigned const TargetRegisterInfo * TRI
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
static void insertCSRRestores(MachineBasicBlock &RestoreBlock, std::vector< CalleeSavedInfo > &CSI)
Insert restore code for the callee-saved registers used in the function.
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.
static void insertCSRSaves(MachineBasicBlock &SaveBlock, ArrayRef< CalleeSavedInfo > CSI)
Insert spill code for the callee-saved registers used in the function.
static void AssignProtectedObjSet(const StackObjSet &UnassignedObjs, SmallSet< int, 16 > &ProtectedObjs, MachineFrameInfo &MFI, bool StackGrowsDown, int64_t &Offset, Align &MaxAlign)
AssignProtectedObjSet - Helper function to assign large stack objects (i.e., those required to be clo...
static void AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx, bool StackGrowsDown, int64_t &Offset, Align &MaxAlign)
AdjustStackOffset - Helper function used to adjust the stack frame offset.
static void updateLiveness(MachineFunction &MF)
Helper function to update the liveness information for the callee-saved registers.
static void assignCalleeSavedSpillSlots(MachineFunction &F, const BitVector &SavedRegs, unsigned &MinCSFrameIndex, unsigned &MaxCSFrameIndex)
Prologue Epilogue Insertion &Frame Finalization
static void stashEntryDbgValues(MachineBasicBlock &MBB, SavedDbgValuesMap &EntryDbgValues)
Stash DBG_VALUEs that describe parameters and which are placed at the start of the block.
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...
This file declares the machine register scavenger class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
StringRef getValueAsString() const
Return the attribute's value as a string.
bool test(unsigned Idx) const
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
void clear()
clear - Removes all bits from the bitvector.
int find_next(unsigned Prev) const
find_next - Returns the index of the next set bit following the "Prev" bit.
bool none() const
none - Returns true if none of the bits are set.
size_type size() const
size - Returns the number of bits in this bitvector.
bool empty() const
empty - Tests whether there are no bits in this bitvector.
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
bool isImplicit() const
Return whether this is an implicit location description.
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.
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...
bool isComplex() const
Return whether the location is computed on the expression stack, meaning it cannot be a simple regist...
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.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
DISubprogram * getSubprogram() const
Get the attached subprogram.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
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.
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.
virtual bool usesPhysRegsForValues() const
True if the target uses physical regs (as nearly all targets do).
Wrapper class representing physical registers. Should be passed by value.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
void push_back(MachineInstr *MI)
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< iterator > terminators()
iterator_range< succ_iterator > successors()
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
SSPLayoutKind getObjectSSPLayout(int ObjectIdx) const
bool isObjectPreAllocated(int ObjectIdx) const
Return true if the object was pre-allocated into the local block.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
void setAdjustsStack(bool V)
void setRestorePoint(MachineBasicBlock *NewRestore)
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.
int64_t getLocalFrameObjectCount() const
Return the number of objects allocated into the local object block.
bool hasCalls() const
Return true if the current function has any function calls.
Align getMaxAlign() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
Align getLocalFrameMaxAlign() const
Return the required alignment of the local object blob.
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
@ SSPLK_SmallArray
Array or nested array < SSP-buffer-size.
@ SSPLK_LargeArray
Array or nested array >= SSP-buffer-size.
@ SSPLK_AddrOf
The address of this allocation is exposed and triggered protection.
@ SSPLK_None
Did not trigger a stack protector.
std::pair< int, int64_t > getLocalFrameObjectMap(int i) const
Get the local offset mapping for a for an object.
bool getUseLocalStackAllocationBlock() const
Get whether the local allocation blob should be allocated together or let PEI allocate the locals in ...
MachineBasicBlock * getRestorePoint() const
int getStackProtectorIndex() const
Return the index for the stack protector object.
void setCalleeSavedInfoValid(bool v)
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
bool isMaxCallFrameSizeComputed() const
int64_t getLocalFrameSize() const
Get the size of the local object blob.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
void setCalleeSavedInfo(std::vector< CalleeSavedInfo > CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
bool isVariableSizedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a variable sized object.
void setSavePoint(MachineBasicBlock *NewSave)
uint64_t getUnsafeStackSize() const
unsigned getMaxCallFrameSize() const
Return the maximum size of a call frame that must be allocated for an outgoing function call.
int getObjectIndexEnd() const
Return one past the maximum frame object index.
bool hasStackProtectorIndex() const
void setMaxCallFrameSize(unsigned S)
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.
void setStackSize(uint64_t Size)
Set the size of the stack.
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.
MachineBasicBlock * getSavePoint() const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
bool hasProperty(Property P) const
const WinEHFuncInfo * getWinEHFuncInfo() const
getWinEHFuncInfo - Return information about how the current function uses Windows exception handling.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
bool shouldSplitStack() const
Should we be emitting segmented stack stuff for the function.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineBasicBlock & front() const
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Wrapper class representing virtual and physical registers.
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StackOffset holds a fixed and a scalable offset in bytes.
static StackOffset getScalable(int64_t Scalable)
static StackOffset getFixed(int64_t Fixed)
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Information about stack frame layout on the target.
virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const =0
virtual const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
virtual bool hasReservedCallFrame(const MachineFunction &MF) const
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
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 bool allocateScavengingFrameIndexesNearIncomingSP(const MachineFunction &MF) const
Control the placement of special register scavenging spill slots when allocating a stack frame.
Align getTransientStackAlign() const
getTransientStackAlignment - This method returns the number of bytes to which the stack pointer must ...
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
virtual void inlineStackProbe(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const
Replace a StackProbe stub (if any) with the actual probe code inline.
virtual void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &objectsToAllocate) const
Order the symbols in the local stack frame.
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 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...
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
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.
virtual bool needsFrameIndexResolution(const MachineFunction &MF) const
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...
Align getStackAlign() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
virtual void processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF, RegScavenger *RS=nullptr) const
processFunctionBeforeFrameIndicesReplaced - This method is called immediately before MO_FrameIndex op...
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 ...
StackDirection getStackGrowthDirection() const
getStackGrowthDirection - Return the direction the stack grows
virtual void adjustForSegmentedStacks(MachineFunction &MF, MachineBasicBlock &PrologueMBB) const
Adjust the prologue to have the function use segmented stacks.
virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const
canSimplifyCallFramePseudos - When possible, it's best to simplify the call frame pseudo ops before d...
virtual void emitZeroCallUsedRegs(BitVector RegsToZero, MachineBasicBlock &MBB) const
emitZeroCallUsedRegs - Zeros out call used registers.
virtual bool targetHandlesStackFrameRounding() const
targetHandlesStackFrameRounding - Returns true if the target is responsible for rounding up the stack...
virtual void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const =0
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
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...
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...
TargetInstrInfo - Interface to description of machine instruction set.
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
unsigned StackSymbolOrdering
StackSymbolOrdering - When true, this will allow CodeGen to order the local stack symbols (for code s...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ HiPE
Used by the High-Performance Erlang Compiler (HiPE).
Reg
All possible values of the reg field in the ModR/M byte.
DiagnosticInfoOptimizationBase::Argument NV
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
testing::Matcher< const detail::ErrorHolder & > Failed()
void scavengeFrameVirtualRegs(MachineFunction &MF, RegScavenger &RS)
Replaces all frame index virtual registers with physical registers.
MachineFunctionPass * createPrologEpilogInserterPass()
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...
char & PrologEpilogCodeInserterID
PrologEpilogCodeInserter - This pass inserts prolog and epilog code, and eliminates abstract frame re...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
unsigned getKillRegState(bool B)
void initializePEIPass(PassRegistry &)
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Pair of physical register and lane mask.