49 #include "llvm/Config/llvm-config.h" 65 #define DEBUG_TYPE "regalloc" 67 STATISTIC(NumSpilledRanges,
"Number of spilled live ranges");
68 STATISTIC(NumSnippets,
"Number of spilled snippets");
69 STATISTIC(NumSpills,
"Number of spills inserted");
70 STATISTIC(NumSpillsRemoved,
"Number of spills removed");
71 STATISTIC(NumReloads,
"Number of reloads inserted");
72 STATISTIC(NumReloadsRemoved,
"Number of reloads removed");
73 STATISTIC(NumFolded,
"Number of folded stack accesses");
74 STATISTIC(NumFoldedLoads,
"Number of folded loads");
75 STATISTIC(NumRemats,
"Number of rematerialized defs for spilling");
78 cl::desc(
"Disable inline spill hoisting"));
106 using MergeableSpillsMap =
108 MergeableSpillsMap MergeableSpills;
118 void rmRedundantSpills(
119 SmallPtrSet<MachineInstr *, 16> &Spills,
131 SmallPtrSet<MachineInstr *, 16> &Spills,
143 MRI(mf.getRegInfo()), TII(*mf.getSubtarget().getInstrInfo()),
144 TRI(*mf.getSubtarget().getRegisterInfo()),
146 IPA(LIS, mf.getNumBlockIDs()) {}
148 void addToMergeableSpills(
MachineInstr &Spill,
int StackSlot,
150 bool rmFromMergeableSpills(
MachineInstr &Spill,
int StackSlot);
151 void hoistAllSpills();
152 void LRE_DidCloneVirtReg(
unsigned,
unsigned)
override;
155 class InlineSpiller :
public Spiller {
188 HoistSpillHelper HSpiller;
190 ~InlineSpiller()
override =
default;
199 MRI(mf.getRegInfo()), TII(*mf.getSubtarget().getInstrInfo()),
200 TRI(*mf.getSubtarget().getRegisterInfo()),
202 HSpiller(pass, mf, vrm) {}
205 void postOptimization()
override;
209 void collectRegsToSpill();
211 bool isRegToSpill(
unsigned Reg) {
return is_contained(RegsToSpill, Reg); }
213 bool isSibling(
unsigned Reg);
219 void reMaterializeAll();
222 bool foldMemoryOperand(
ArrayRef<std::pair<MachineInstr *, unsigned>>,
227 void spillAroundUses(
unsigned Reg);
235 void Spiller::anchor() {}
240 return new InlineSpiller(pass, mf, vrm);
270 bool InlineSpiller::isSnippet(
const LiveInterval &SnipLI) {
271 unsigned Reg = Edit->getReg();
280 if (SnipLI.
getNumValNums() > 2 || !LIS.intervalIsInOneMBB(SnipLI))
287 RI =
MRI.reg_instr_nodbg_begin(SnipLI.
reg),
288 E =
MRI.reg_instr_nodbg_end(); RI !=
E; ) {
305 if (UseMI && &MI != UseMI)
314 void InlineSpiller::collectRegsToSpill() {
315 unsigned Reg = Edit->getReg();
318 RegsToSpill.assign(1, Reg);
319 SnippetCopies.clear();
327 RI =
MRI.reg_instr_begin(Reg),
E =
MRI.reg_instr_end(); RI !=
E; ) {
330 if (!isSibling(SnipReg))
333 if (!isSnippet(SnipLI))
335 SnippetCopies.insert(&MI);
336 if (isRegToSpill(SnipReg))
338 RegsToSpill.push_back(SnipReg);
344 bool InlineSpiller::isSibling(
unsigned Reg) {
346 VRM.getOriginal(Reg) == Original;
368 bool InlineSpiller::hoistSpillInsideBB(
LiveInterval &SpillLI,
370 SlotIndex Idx = LIS.getInstructionIndex(CopyMI);
387 assert(StackInt &&
"No stack slot assigned yet.");
390 StackInt->MergeValueInAsValue(OrigLI, OrigVNI, StackInt->getValNumInfo(0));
392 << *StackInt <<
'\n');
396 eliminateRedundantSpills(SrcLI, SrcVNI);
404 assert(DefMI &&
"Defining instruction disappeared");
410 MRI.getRegClass(SrcReg), &
TRI);
412 LIS.InsertMachineInstrInMaps(*MII);
415 HSpiller.addToMergeableSpills(*MII, StackSlot, Original);
423 assert(VNI &&
"Missing value");
425 WorkList.
push_back(std::make_pair(&SLI, VNI));
426 assert(StackInt &&
"No stack slot assigned yet.");
431 unsigned Reg = LI->
reg;
433 << VNI->
def <<
" in " << *LI <<
'\n');
436 if (isRegToSpill(Reg))
440 StackInt->MergeValueInAsValue(*LI, VNI, StackInt->getValNumInfo(0));
441 LLVM_DEBUG(
dbgs() <<
"Merged to stack int: " << *StackInt <<
'\n');
445 UI =
MRI.use_instr_nodbg_begin(Reg),
E =
MRI.use_instr_nodbg_end();
450 SlotIndex Idx = LIS.getInstructionIndex(MI);
456 if (isSibling(DstReg)) {
459 assert(DstVNI &&
"Missing defined value");
461 WorkList.
push_back(std::make_pair(&DstLI, DstVNI));
472 DeadDefs.push_back(&MI);
474 if (HSpiller.rmFromMergeableSpills(MI, StackSlot))
478 }
while (!WorkList.
empty());
489 WorkList.
push_back(std::make_pair(LI, VNI));
492 if (!UsedValues.insert(VNI).second)
500 WorkList.
push_back(std::make_pair(LI, PVNI));
507 if (!SnippetCopies.count(MI))
510 assert(isRegToSpill(SnipLI.
reg) &&
"Unexpected register in copy");
512 assert(SnipVNI &&
"Snippet undefined before copy");
513 WorkList.
push_back(std::make_pair(&SnipLI, SnipVNI));
514 }
while (!WorkList.
empty());
521 MIBundleOperands::VirtRegInfo RI =
541 if (SnippetCopies.count(&MI))
547 RM.
OrigMI = LIS.getInstructionFromIndex(OrigVNI->
def);
549 if (!Edit->canRematerializeAt(RM, OrigVNI, UseIdx,
false)) {
550 markValueUsed(&VirtReg, ParentVNI);
551 LLVM_DEBUG(
dbgs() <<
"\tcannot remat for " << UseIdx <<
'\t' << MI);
558 markValueUsed(&VirtReg, ParentVNI);
559 LLVM_DEBUG(
dbgs() <<
"\tcannot remat tied reg: " << UseIdx <<
'\t' << MI);
566 foldMemoryOperand(Ops, RM.
OrigMI)) {
573 unsigned NewVReg = Edit->createFrom(Original);
581 auto *NewMI = LIS.getInstructionFromIndex(DefIdx);
586 << *LIS.getInstructionFromIndex(DefIdx));
589 for (
const auto &OpPair : Ops) {
604 void InlineSpiller::reMaterializeAll() {
605 if (!Edit->anyRematerializable(AA))
611 bool anyRemat =
false;
612 for (
unsigned Reg : RegsToSpill) {
615 RegI =
MRI.reg_bundle_begin(Reg),
E =
MRI.reg_bundle_end();
624 "instruction that isn't a DBG_VALUE");
626 anyRemat |= reMaterializeFor(LI, MI);
633 for (
unsigned Reg : RegsToSpill) {
645 DeadDefs.push_back(MI);
651 if (DeadDefs.empty())
653 LLVM_DEBUG(
dbgs() <<
"Remat created " << DeadDefs.size() <<
" dead defs.\n");
654 Edit->eliminateDeadDefs(DeadDefs, RegsToSpill, AA);
662 unsigned ResultPos = 0;
663 for (
unsigned Reg : RegsToSpill) {
664 if (
MRI.reg_nodbg_empty(Reg)) {
665 Edit->eraseVirtReg(Reg);
669 assert(LIS.hasInterval(Reg) &&
670 (!LIS.getInterval(Reg).empty() || !
MRI.reg_nodbg_empty(Reg)) &&
671 "Empty and not used live-range?!");
673 RegsToSpill[ResultPos++] =
Reg;
675 RegsToSpill.erase(RegsToSpill.begin() + ResultPos, RegsToSpill.end());
677 <<
" registers to spill after remat.\n");
685 bool InlineSpiller::coalesceStackAccess(
MachineInstr *MI,
unsigned Reg) {
688 bool IsLoad = InstrReg;
693 if (InstrReg != Reg || FI != StackSlot)
697 HSpiller.rmFromMergeableSpills(*MI, StackSlot);
700 LIS.RemoveMachineInstrFromMaps(*MI);
714 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 720 const char *
const header,
722 char NextLine =
'\n';
723 char SlotIndent =
'\t';
725 if (std::next(B) == E) {
730 dbgs() <<
'\t' << header <<
": " << NextLine;
744 dbgs() << SlotIndent << Idx <<
'\t' << *
I;
756 foldMemoryOperand(
ArrayRef<std::pair<MachineInstr *, unsigned>> Ops,
762 if (Ops.back().first != MI || MI->
isBundled())
765 bool WasCopy = MI->
isCopy();
770 bool SpillSubRegs =
TII.isSubregFoldable() ||
771 MI->
getOpcode() == TargetOpcode::STATEPOINT ||
772 MI->
getOpcode() == TargetOpcode::PATCHPOINT ||
773 MI->
getOpcode() == TargetOpcode::STACKMAP;
778 for (
const auto &OpPair : Ops) {
779 unsigned Idx = OpPair.second;
780 assert(MI == OpPair.first &&
"Instruction conflict during operand folding");
790 if (LoadMI && MO.
isDef())
805 LoadMI ?
TII.foldMemoryOperand(*MI, FoldOps, *LoadMI, &LIS)
806 :
TII.foldMemoryOperand(*MI, FoldOps, StackSlot, &LIS);
814 unsigned Reg = MO->getReg();
816 MRI.isReserved(Reg)) {
822 MIBundleOperands::PhysRegInfo RI =
827 assert(MO->isDead() &&
"Cannot fold physreg def");
829 LIS.removePhysRegDefAt(Reg, Idx);
834 HSpiller.rmFromMergeableSpills(*MI, FI))
836 LIS.ReplaceMachineInstrInMaps(*MI, *FoldMI);
840 assert(!MIS.
empty() &&
"Unexpected empty span of instructions!");
843 LIS.InsertMachineInstrInMaps(MI);
852 if (MO.
getReg() == ImpReg)
861 else if (Ops.front().second == 0) {
863 HSpiller.addToMergeableSpills(*FoldMI, StackSlot, Original);
869 void InlineSpiller::insertReload(
unsigned NewVReg,
876 MRI.getRegClass(NewVReg), &
TRI);
878 LIS.InsertMachineInstrRangeInMaps(MIS.
begin(),
MI);
892 "Implicit def with more than one definition");
900 void InlineSpiller::insertSpill(
unsigned NewVReg,
bool isKill,
905 bool IsRealSpill =
true;
916 MRI.getRegClass(NewVReg), &
TRI);
918 LIS.InsertMachineInstrRangeInMaps(std::next(MI), MIS.
end());
924 HSpiller.addToMergeableSpills(*std::next(MI), StackSlot, Original);
928 void InlineSpiller::spillAroundUses(
unsigned Reg) {
934 RegI =
MRI.reg_bundle_begin(Reg),
E =
MRI.reg_bundle_end();
942 LLVM_DEBUG(
dbgs() <<
"Modifying debug info due to spill:\t" << *MI);
949 "instruction that isn't a DBG_VALUE");
952 if (SnippetCopies.count(MI))
956 if (coalesceStackAccess(MI, Reg))
961 MIBundleOperands::VirtRegInfo RI =
973 if (SibReg && isSibling(SibReg)) {
975 if (isRegToSpill(SibReg)) {
977 SnippetCopies.insert(MI);
981 if (hoistSpillInsideBB(OldLI, *MI)) {
984 DeadDefs.push_back(MI);
990 eliminateRedundantSpills(SibLI, SibLI.
getVNInfoAt(Idx));
996 if (foldMemoryOperand(Ops))
1001 unsigned NewVReg = Edit->createFrom(Reg);
1004 insertReload(NewVReg, Idx, MI);
1007 bool hasLiveDef =
false;
1008 for (
const auto &OpPair : Ops) {
1012 if (!OpPair.first->isRegTiedToDefOperand(OpPair.second))
1019 LLVM_DEBUG(
dbgs() <<
"\trewrite: " << Idx <<
'\t' << *MI <<
'\n');
1024 insertSpill(NewVReg,
true, MI);
1029 void InlineSpiller::spillAll() {
1032 StackSlot = VRM.assignVirt2StackSlot(Original);
1033 StackInt = &LSS.getOrCreateInterval(StackSlot,
MRI.getRegClass(Original));
1034 StackInt->getNextValue(
SlotIndex(), LSS.getVNInfoAllocator());
1036 StackInt = &LSS.getInterval(StackSlot);
1038 if (Original != Edit->getReg())
1039 VRM.assignVirt2StackSlot(Edit->getReg(), StackSlot);
1041 assert(StackInt->getNumValNums() == 1 &&
"Bad stack interval values");
1042 for (
unsigned Reg : RegsToSpill)
1043 StackInt->MergeSegmentsInAsValue(LIS.getInterval(Reg),
1044 StackInt->getValNumInfo(0));
1045 LLVM_DEBUG(
dbgs() <<
"Merged spilled regs: " << *StackInt <<
'\n');
1048 for (
unsigned Reg : RegsToSpill)
1049 spillAroundUses(Reg);
1052 if (!DeadDefs.empty()) {
1053 LLVM_DEBUG(
dbgs() <<
"Eliminating " << DeadDefs.size() <<
" dead defs\n");
1054 Edit->eliminateDeadDefs(DeadDefs, RegsToSpill, AA);
1058 for (
unsigned Reg : RegsToSpill) {
1060 RI =
MRI.reg_instr_begin(Reg),
E =
MRI.reg_instr_end();
1063 assert(SnippetCopies.count(&MI) &&
"Remaining use wasn't a snippet copy");
1065 LIS.RemoveMachineInstrFromMaps(MI);
1071 for (
unsigned Reg : RegsToSpill)
1072 Edit->eraseVirtReg(Reg);
1079 &&
"Trying to spill a stack slot.");
1081 Original = VRM.getOriginal(edit.
getReg());
1082 StackSlot = VRM.getStackSlot(Original);
1087 <<
':' << edit.
getParent() <<
"\nFrom original " 1090 "Attempting to spill already spilled value.");
1091 assert(DeadDefs.empty() &&
"Previous spill didn't remove dead defs");
1093 collectRegsToSpill();
1097 if (!RegsToSpill.empty())
1100 Edit->calculateRegClassAndHint(MF,
Loops, MBFI);
1104 void InlineSpiller::postOptimization() { HSpiller.hoistAllSpills(); }
1107 void HoistSpillHelper::addToMergeableSpills(
MachineInstr &Spill,
int StackSlot,
1108 unsigned Original) {
1113 if (StackSlotToOrigLI.find(StackSlot) == StackSlotToOrigLI.end()) {
1114 auto LI = llvm::make_unique<LiveInterval>(OrigLI.
reg, OrigLI.
weight);
1115 LI->
assign(OrigLI, Allocator);
1116 StackSlotToOrigLI[StackSlot] = std::move(LI);
1118 SlotIndex Idx = LIS.getInstructionIndex(Spill);
1119 VNInfo *OrigVNI = StackSlotToOrigLI[StackSlot]->getVNInfoAt(Idx.
getRegSlot());
1120 std::pair<int, VNInfo *> MIdx = std::make_pair(StackSlot, OrigVNI);
1121 MergeableSpills[MIdx].insert(&Spill);
1126 bool HoistSpillHelper::rmFromMergeableSpills(
MachineInstr &Spill,
1128 auto It = StackSlotToOrigLI.find(StackSlot);
1129 if (It == StackSlotToOrigLI.end())
1131 SlotIndex Idx = LIS.getInstructionIndex(Spill);
1133 std::pair<int, VNInfo *> MIdx = std::make_pair(StackSlot, OrigVNI);
1134 return MergeableSpills[MIdx].erase(&Spill);
1142 unsigned OrigReg = OrigLI.
reg;
1145 Idx = LIS.getInstructionIndex(*MI);
1151 for (
auto const SibReg : Siblings) {
1164 void HoistSpillHelper::rmRedundantSpills(
1171 for (
const auto CurrentSpill : Spills) {
1176 SlotIndex PIdx = LIS.getInstructionIndex(*PrevSpill);
1177 SlotIndex CIdx = LIS.getInstructionIndex(*CurrentSpill);
1178 MachineInstr *SpillToRm = (CIdx > PIdx) ? CurrentSpill : PrevSpill;
1179 MachineInstr *SpillToKeep = (CIdx > PIdx) ? PrevSpill : CurrentSpill;
1181 SpillBBToSpill[MDT.getBase().getNode(Block)] = SpillToKeep;
1183 SpillBBToSpill[MDT.getBase().getNode(Block)] = CurrentSpill;
1186 for (
const auto SpillToRm : SpillsToRm)
1187 Spills.
erase(SpillToRm);
1196 void HoistSpillHelper::getVisitOrders(
1220 for (
const auto Spill : Spills) {
1224 while (Node != RootIDomNode) {
1227 if (Node != MDT[Block] && SpillBBToSpill[Node]) {
1228 SpillToRm = SpillBBToSpill[MDT[Block]];
1233 }
else if (WorkSet.
count(Node)) {
1236 NodesOnPath.
insert(Node);
1238 Node = Node->getIDom();
1248 SpillsToKeep[MDT[Block]] = 0;
1251 NodesOnPath.
clear();
1257 Orders.
push_back(MDT.getBase().getNode(Root));
1260 const std::vector<MachineDomTreeNode *> &Children = Node->
getChildren();
1261 unsigned NumChildren = Children.size();
1262 for (
unsigned i = 0; i != NumChildren; ++i) {
1264 if (WorkSet.
count(Child))
1267 }
while (idx != Orders.
size());
1269 "Orders have different size with WorkSet");
1274 for (; RIt != Orders.
rend(); RIt++)
1275 LLVM_DEBUG(
dbgs() <<
"BB" << (*RIt)->getBlock()->getNumber() <<
",");
1283 void HoistSpillHelper::runHoistSpills(
1299 rmRedundantSpills(Spills, SpillsToRm, SpillBBToSpill);
1302 getVisitOrders(Root, Spills, Orders, SpillsToRm, SpillsToKeep,
1309 using NodesCostPair =
1310 std::pair<SmallPtrSet<MachineDomTreeNode *, 16>,
BlockFrequency>;
1318 for (; RIt != Orders.
rend(); RIt++) {
1322 if (SpillsToKeep.
find(*RIt) != SpillsToKeep.
end() && !SpillsToKeep[*RIt]) {
1323 SpillsInSubTreeMap[*RIt].first.
insert(*RIt);
1325 SpillsInSubTreeMap[*RIt].second = MBFI.getBlockFreq(Block);
1331 const std::vector<MachineDomTreeNode *> &Children = (*RIt)->getChildren();
1332 unsigned NumChildren = Children.
size();
1333 for (
unsigned i = 0; i != NumChildren; ++i) {
1335 if (SpillsInSubTreeMap.
find(Child) == SpillsInSubTreeMap.
end())
1343 SpillsInSubTreeMap[*RIt].first;
1344 BlockFrequency &SubTreeCost = SpillsInSubTreeMap[*RIt].second;
1345 SubTreeCost += SpillsInSubTreeMap[Child].second;
1346 auto BI = SpillsInSubTreeMap[Child].first.
begin();
1347 auto EI = SpillsInSubTreeMap[Child].first.
end();
1348 SpillsInSubTree.
insert(BI, EI);
1349 SpillsInSubTreeMap.
erase(Child);
1353 SpillsInSubTreeMap[*RIt].first;
1354 BlockFrequency &SubTreeCost = SpillsInSubTreeMap[*RIt].second;
1356 if (SpillsInSubTree.
empty())
1360 unsigned LiveReg = 0;
1361 if (!isSpillCandBB(OrigLI, OrigVNI, *Block, LiveReg))
1369 if (SubTreeCost > MBFI.getBlockFreq(Block) * MarginProb) {
1371 for (
const auto SpillBB : SpillsInSubTree) {
1374 if (SpillsToKeep.
find(SpillBB) != SpillsToKeep.
end() &&
1375 !SpillsToKeep[SpillBB]) {
1380 SpillsToKeep.
erase(SpillBB);
1384 SpillsToKeep[*RIt] = LiveReg;
1386 dbgs() <<
"spills in BB: ";
1387 for (
const auto Rspill : SpillsInSubTree)
1388 dbgs() << Rspill->getBlock()->getNumber() <<
" ";
1389 dbgs() <<
"were promoted to BB" << (*RIt)->getBlock()->getNumber()
1392 SpillsInSubTree.clear();
1393 SpillsInSubTree.insert(*RIt);
1394 SubTreeCost = MBFI.getBlockFreq(Block);
1399 for (
const auto Ent : SpillsToKeep) {
1401 SpillsToIns[Ent.first->getBlock()] = Ent.second;
1421 void HoistSpillHelper::hoistAllSpills() {
1425 for (
unsigned i = 0, e =
MRI.getNumVirtRegs(); i != e; ++i) {
1427 unsigned Original = VRM.getPreSplitReg(Reg);
1428 if (!
MRI.def_empty(Reg))
1429 Virt2SiblingsMap[Original].insert(Reg);
1433 for (
auto &Ent : MergeableSpills) {
1434 int Slot = Ent.first.first;
1436 VNInfo *OrigVNI = Ent.first.second;
1438 if (Ent.second.empty())
1442 dbgs() <<
"\nFor Slot" << Slot <<
" and VN" << OrigVNI->
id <<
":\n" 1443 <<
"Equal spills in BB: ";
1444 for (
const auto spill : EqValSpills)
1445 dbgs() << spill->getParent()->getNumber() <<
" ";
1454 runHoistSpills(OrigLI, *OrigVNI, EqValSpills, SpillsToRm, SpillsToIns);
1457 dbgs() <<
"Finally inserted spills in BB: ";
1458 for (
const auto Ispill : SpillsToIns)
1459 dbgs() << Ispill.first->getNumber() <<
" ";
1460 dbgs() <<
"\nFinally removed spills in BB: ";
1461 for (
const auto Rspill : SpillsToRm)
1462 dbgs() << Rspill->getParent()->getNumber() <<
" ";
1468 if (!SpillsToIns.
empty() || !SpillsToRm.empty())
1470 StackIntvl.getValNumInfo(0));
1473 for (
auto const Insert : SpillsToIns) {
1475 unsigned LiveReg = Insert.second;
1478 MRI.getRegClass(LiveReg), &
TRI);
1479 LIS.InsertMachineInstrRangeInMaps(std::prev(MI), MI);
1484 NumSpills -= SpillsToRm.size();
1485 for (
auto const RMEnt : SpillsToRm) {
1487 for (
unsigned i = RMEnt->getNumOperands(); i; --i) {
1490 RMEnt->RemoveOperand(i - 1);
1499 void HoistSpillHelper::LRE_DidCloneVirtReg(
unsigned New,
unsigned Old) {
1500 if (VRM.hasPhys(Old))
1501 VRM.assignVirt2Phys(New, VRM.getPhys(Old));
1503 VRM.assignVirt2StackSlot(New, VRM.getStackSlot(Old));
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
Safe Stack instrumentation pass
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
SlotIndex def
The index of the defining instruction.
This class represents lattice values for constants.
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
void MergeValueInAsValue(const LiveRange &RHS, const VNInfo *RHSValNo, VNInfo *LHSValNo)
MergeValueInAsValue - Merge all of the segments of a specific val# in RHS into this live range as the...
bool addRegisterDead(unsigned Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
Store the specified register of the given register class to the specified stack frame index...
VNInfoList::iterator vni_iterator
void push_back(const T &Elt)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LiveInterval - This class represents the liveness of a register, or stack slot.
MIBundleOperands - Iterate over all operands in a bundle of machine instructions. ...
unsigned getReg() const
getReg - Returns the register number.
void setIsUndef(bool Val=true)
void eliminateDeadDefs(SmallVectorImpl< MachineInstr *> &Dead, ArrayRef< unsigned > RegsBeingSpilled=None, AliasAnalysis *AA=nullptr)
eliminateDeadDefs - Try to delete machine instructions that are now dead (allDefsAreDead returns true...
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
unsigned getSubReg() const
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
This class implements a map that also provides access to all stored values in a deterministic order...
STATISTIC(NumFunctions, "Total number of functions")
unsigned const TargetRegisterInfo * TRI
void setIsDead(bool Val=true)
VNInfo - Value Number Information.
Determines the latest safe point in a block in which we can insert a split, spill or other instructio...
Callback methods for LiveRangeEdit owners.
VirtRegInfo analyzeVirtReg(unsigned Reg, SmallVectorImpl< std::pair< MachineInstr *, unsigned > > *Ops=nullptr)
analyzeVirtReg - Analyze how the current instruction or bundle uses a virtual register.
bool isUnused() const
Returns true if this value is unused.
MachineInstrSpan provides an interface to get an iteration range containing the instruction it was in...
bool isEarlyClobber() const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
Load the specified register of the given register class from the specified stack frame index...
MachineInstr * buildDbgValueForSpill(MachineBasicBlock &BB, MachineBasicBlock::iterator I, const MachineInstr &Orig, int FrameIndex)
Clone a DBG_VALUE whose value has been spilled to FrameIndex.
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
unsigned getNumOperands() const
Retuns the total number of operands.
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Result of a LiveRange query.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
PhysRegInfo analyzePhysReg(unsigned Reg, const TargetRegisterInfo *TRI)
analyzePhysReg - Analyze how the current instruction or bundle uses a physical register.
MachineBasicBlock::iterator end()
defusechain_iterator - This class provides iterator support for machine operands in the function that...
bool isValid() const
isValid - Returns true until all the operands have been visited.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
Base class for the actual dominator tree node.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
const std::vector< DomTreeNodeBase * > & getChildren() const
bool isKill() const
Return true if the live-in value is killed by this instruction.
bool allDefsAreDead() const
Return true if all the defs of this instruction are dead.
unsigned getKillRegState(bool B)
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
TargetInstrInfo - Interface to description of machine instruction set.
iterator find(const_arg_type_t< KeyT > Val)
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
static LLVM_DUMP_METHOD void dumpMachineInstrRangeWithSlotIndex(MachineBasicBlock::iterator B, MachineBasicBlock::iterator E, LiveIntervals const &LIS, const char *const header, unsigned VReg=0)
bool erase(const KeyT &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
Allocate memory in an ever growing pool, as if by bump-pointer.
bool isBundled() const
Return true if this instruction part of a bundle.
MachineInstrBuilder & UseMI
DomTreeNodeBase * getIDom() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_NODISCARD bool empty() const
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx=nullptr) const
Return true if the use operand of the specified index is tied to a def operand.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
iterator_range< pred_iterator > predecessors()
bool isImplicitDef() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool isDebugInstr() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setIsKill(bool Val=true)
static bool isStackSlot(unsigned Reg)
isStackSlot - Sometimes it is useful the be able to store a non-negative frame index in a variable th...
unsigned id
The ID number of this value.
LiveInterval & getParent() const
A SetVector that performs no allocations if smaller than a certain size.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
static bool isFullUndefDef(const MachineInstr &Def)
Check if Def fully defines a VReg with an undefined value.
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
bool isDebugValue() const
MachineOperand class - Representation of each machine instruction operand.
MachineInstrBuilder MachineInstrBuilder & DefMI
static cl::opt< bool > DisableHoisting("disable-spill-hoist", cl::Hidden, cl::desc("Disable inline spill hoisting"))
unsigned isStoreToStackSlot(const MachineInstr &MI, int &FrameIndex) const override
If the specified machine instruction is a direct store to a stack slot, return the virtual or physica...
LLVM_NODISCARD T pop_back_val()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarilly including Idx...
unsigned isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
TargetInstrInfo overrides.
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Spiller * createInlineSpiller(MachineFunctionPass &pass, MachineFunction &mf, VirtRegMap &vrm)
Create and return a spiller that will insert spill code directly instead of deferring though VirtRegM...
unsigned getNumValNums() const
Representation of each machine instruction.
void assign(const LiveRange &Other, BumpPtrAllocator &Allocator)
Copies values numbers and live segments from Other into this range.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
LLVM_NODISCARD bool empty() const
bool canFoldAsLoad(QueryType Type=IgnoreBundle) const
Return true for instructions that can be folded as memory operands in other instructions.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
static unsigned isFullCopyOf(const MachineInstr &MI, unsigned Reg)
isFullCopyOf - If MI is a COPY to or from Reg, return the other register, otherwise return 0...
LLVM_NODISCARD bool empty() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Remat - Information needed to rematerialize at a specific location.
reverse_iterator rbegin()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isSpillable() const
isSpillable - Can this interval be spilled?
iterator SkipPHIsLabelsAndDebug(iterator I)
Return the first instruction in MBB after I that is not a PHI, label or debug.
void RemoveOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
const MachineOperand & getOperand(unsigned i) const
SlotIndex - An opaque wrapper around machine indexes.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineBasicBlock::iterator begin()
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.