48 #include "llvm/Config/llvm-config.h" 64 #define DEBUG_TYPE "regalloc" 66 STATISTIC(NumSpilledRanges,
"Number of spilled live ranges");
67 STATISTIC(NumSnippets,
"Number of spilled snippets");
68 STATISTIC(NumSpills,
"Number of spills inserted");
69 STATISTIC(NumSpillsRemoved,
"Number of spills removed");
70 STATISTIC(NumReloads,
"Number of reloads inserted");
71 STATISTIC(NumReloadsRemoved,
"Number of reloads removed");
72 STATISTIC(NumFolded,
"Number of folded stack accesses");
73 STATISTIC(NumFoldedLoads,
"Number of folded loads");
74 STATISTIC(NumRemats,
"Number of rematerialized defs for spilling");
77 cl::desc(
"Disable inline spill hoisting"));
81 cl::desc(
"Restrict remat for statepoint operands"));
109 using MergeableSpillsMap =
111 MergeableSpillsMap MergeableSpills;
121 void rmRedundantSpills(
122 SmallPtrSet<MachineInstr *, 16> &Spills,
134 SmallPtrSet<MachineInstr *, 16> &Spills,
146 MRI(mf.getRegInfo()), TII(*mf.getSubtarget().getInstrInfo()),
147 TRI(*mf.getSubtarget().getRegisterInfo()),
149 IPA(LIS, mf.getNumBlockIDs()) {}
151 void addToMergeableSpills(
MachineInstr &Spill,
int StackSlot,
153 bool rmFromMergeableSpills(
MachineInstr &Spill,
int StackSlot);
154 void hoistAllSpills();
155 void LRE_DidCloneVirtReg(
unsigned,
unsigned)
override;
158 class InlineSpiller :
public Spiller {
191 HoistSpillHelper HSpiller;
193 ~InlineSpiller()
override =
default;
202 MRI(mf.getRegInfo()), TII(*mf.getSubtarget().getInstrInfo()),
203 TRI(*mf.getSubtarget().getRegisterInfo()),
205 HSpiller(pass, mf, vrm) {}
208 void postOptimization()
override;
212 void collectRegsToSpill();
214 bool isRegToSpill(
unsigned Reg) {
return is_contained(RegsToSpill, Reg); }
216 bool isSibling(
unsigned Reg);
221 bool canGuaranteeAssignmentAfterRemat(
unsigned VReg,
MachineInstr &
MI);
223 void reMaterializeAll();
226 bool foldMemoryOperand(
ArrayRef<std::pair<MachineInstr *, unsigned>>,
231 void spillAroundUses(
unsigned Reg);
239 void Spiller::anchor() {}
244 return new InlineSpiller(pass, mf, vrm);
274 bool InlineSpiller::isSnippet(
const LiveInterval &SnipLI) {
275 unsigned Reg = Edit->getReg();
284 if (SnipLI.
getNumValNums() > 2 || !LIS.intervalIsInOneMBB(SnipLI))
291 RI =
MRI.reg_instr_nodbg_begin(SnipLI.
reg),
292 E =
MRI.reg_instr_nodbg_end(); RI !=
E; ) {
309 if (UseMI && &MI != UseMI)
318 void InlineSpiller::collectRegsToSpill() {
319 unsigned Reg = Edit->getReg();
322 RegsToSpill.assign(1, Reg);
323 SnippetCopies.clear();
331 RI =
MRI.reg_instr_begin(Reg),
E =
MRI.reg_instr_end(); RI !=
E; ) {
334 if (!isSibling(SnipReg))
337 if (!isSnippet(SnipLI))
339 SnippetCopies.insert(&MI);
340 if (isRegToSpill(SnipReg))
342 RegsToSpill.push_back(SnipReg);
348 bool InlineSpiller::isSibling(
unsigned Reg) {
371 bool InlineSpiller::hoistSpillInsideBB(
LiveInterval &SpillLI,
373 SlotIndex Idx = LIS.getInstructionIndex(CopyMI);
390 assert(StackInt &&
"No stack slot assigned yet.");
393 StackInt->MergeValueInAsValue(OrigLI, OrigVNI, StackInt->getValNumInfo(0));
395 << *StackInt <<
'\n');
399 eliminateRedundantSpills(SrcLI, SrcVNI);
407 assert(DefMI &&
"Defining instruction disappeared");
413 MRI.getRegClass(SrcReg), &
TRI);
415 LIS.InsertMachineInstrInMaps(*MII);
418 HSpiller.addToMergeableSpills(*MII, StackSlot, Original);
426 assert(VNI &&
"Missing value");
428 WorkList.
push_back(std::make_pair(&SLI, VNI));
429 assert(StackInt &&
"No stack slot assigned yet.");
434 unsigned Reg = LI->
reg;
436 << VNI->
def <<
" in " << *LI <<
'\n');
439 if (isRegToSpill(Reg))
443 StackInt->MergeValueInAsValue(*LI, VNI, StackInt->getValNumInfo(0));
444 LLVM_DEBUG(
dbgs() <<
"Merged to stack int: " << *StackInt <<
'\n');
448 UI =
MRI.use_instr_nodbg_begin(Reg),
E =
MRI.use_instr_nodbg_end();
453 SlotIndex Idx = LIS.getInstructionIndex(MI);
459 if (isSibling(DstReg)) {
462 assert(DstVNI &&
"Missing defined value");
464 WorkList.
push_back(std::make_pair(&DstLI, DstVNI));
475 DeadDefs.push_back(&MI);
477 if (HSpiller.rmFromMergeableSpills(MI, StackSlot))
481 }
while (!WorkList.
empty());
492 WorkList.
push_back(std::make_pair(LI, VNI));
495 if (!UsedValues.insert(VNI).second)
503 WorkList.
push_back(std::make_pair(LI, PVNI));
510 if (!SnippetCopies.count(MI))
513 assert(isRegToSpill(SnipLI.
reg) &&
"Unexpected register in copy");
515 assert(SnipVNI &&
"Snippet undefined before copy");
516 WorkList.
push_back(std::make_pair(&SnipLI, SnipVNI));
517 }
while (!WorkList.
empty());
520 bool InlineSpiller::canGuaranteeAssignmentAfterRemat(
unsigned VReg,
539 return (MI.
getOpcode() != TargetOpcode::STATEPOINT);
565 if (SnippetCopies.count(&MI))
571 RM.
OrigMI = LIS.getInstructionFromIndex(OrigVNI->
def);
573 if (!Edit->canRematerializeAt(RM, OrigVNI, UseIdx,
false)) {
574 markValueUsed(&VirtReg, ParentVNI);
575 LLVM_DEBUG(
dbgs() <<
"\tcannot remat for " << UseIdx <<
'\t' << MI);
582 markValueUsed(&VirtReg, ParentVNI);
583 LLVM_DEBUG(
dbgs() <<
"\tcannot remat tied reg: " << UseIdx <<
'\t' << MI);
590 foldMemoryOperand(Ops, RM.
OrigMI)) {
598 if (!canGuaranteeAssignmentAfterRemat(VirtReg.
reg, MI)) {
599 markValueUsed(&VirtReg, ParentVNI);
600 LLVM_DEBUG(
dbgs() <<
"\tcannot remat for " << UseIdx <<
'\t' << MI);
605 unsigned NewVReg = Edit->createFrom(Original);
613 auto *NewMI = LIS.getInstructionFromIndex(DefIdx);
618 << *LIS.getInstructionFromIndex(DefIdx));
621 for (
const auto &OpPair : Ops) {
636 void InlineSpiller::reMaterializeAll() {
637 if (!Edit->anyRematerializable(AA))
643 bool anyRemat =
false;
644 for (
unsigned Reg : RegsToSpill) {
647 RegI =
MRI.reg_bundle_begin(Reg),
E =
MRI.reg_bundle_end();
656 "instruction that isn't a DBG_VALUE");
658 anyRemat |= reMaterializeFor(LI, MI);
665 for (
unsigned Reg : RegsToSpill) {
677 DeadDefs.push_back(MI);
683 if (DeadDefs.empty())
685 LLVM_DEBUG(
dbgs() <<
"Remat created " << DeadDefs.size() <<
" dead defs.\n");
686 Edit->eliminateDeadDefs(DeadDefs, RegsToSpill, AA);
694 unsigned ResultPos = 0;
695 for (
unsigned Reg : RegsToSpill) {
696 if (
MRI.reg_nodbg_empty(Reg)) {
697 Edit->eraseVirtReg(Reg);
701 assert(LIS.hasInterval(Reg) &&
702 (!LIS.getInterval(Reg).empty() || !
MRI.reg_nodbg_empty(Reg)) &&
703 "Empty and not used live-range?!");
705 RegsToSpill[ResultPos++] =
Reg;
707 RegsToSpill.erase(RegsToSpill.begin() + ResultPos, RegsToSpill.end());
709 <<
" registers to spill after remat.\n");
717 bool InlineSpiller::coalesceStackAccess(
MachineInstr *MI,
unsigned Reg) {
720 bool IsLoad = InstrReg;
725 if (InstrReg != Reg || FI != StackSlot)
729 HSpiller.rmFromMergeableSpills(*MI, StackSlot);
732 LIS.RemoveMachineInstrFromMaps(*MI);
746 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 752 const char *
const header,
754 char NextLine =
'\n';
755 char SlotIndent =
'\t';
757 if (std::next(B) == E) {
762 dbgs() <<
'\t' << header <<
": " << NextLine;
776 dbgs() << SlotIndent << Idx <<
'\t' << *
I;
788 foldMemoryOperand(
ArrayRef<std::pair<MachineInstr *, unsigned>> Ops,
794 if (Ops.back().first != MI || MI->
isBundled())
797 bool WasCopy = MI->
isCopy();
802 bool SpillSubRegs =
TII.isSubregFoldable() ||
803 MI->
getOpcode() == TargetOpcode::STATEPOINT ||
804 MI->
getOpcode() == TargetOpcode::PATCHPOINT ||
805 MI->
getOpcode() == TargetOpcode::STACKMAP;
810 for (
const auto &OpPair : Ops) {
811 unsigned Idx = OpPair.second;
812 assert(MI == OpPair.first &&
"Instruction conflict during operand folding");
822 if (LoadMI && MO.
isDef())
837 LoadMI ?
TII.foldMemoryOperand(*MI, FoldOps, *LoadMI, &LIS)
838 :
TII.foldMemoryOperand(*MI, FoldOps, StackSlot, &LIS, &VRM);
857 assert(MO->isDead() &&
"Cannot fold physreg def");
859 LIS.removePhysRegDefAt(Reg, Idx);
864 HSpiller.rmFromMergeableSpills(*MI, FI))
866 LIS.ReplaceMachineInstrInMaps(*MI, *FoldMI);
872 assert(!MIS.empty() &&
"Unexpected empty span of instructions!");
875 LIS.InsertMachineInstrInMaps(MI);
880 for (
unsigned i = FoldMI->getNumOperands(); i; --i) {
884 if (MO.
getReg() == ImpReg)
885 FoldMI->RemoveOperand(i - 1);
893 else if (Ops.front().second == 0) {
895 HSpiller.addToMergeableSpills(*FoldMI, StackSlot, Original);
901 void InlineSpiller::insertReload(
unsigned NewVReg,
908 MRI.getRegClass(NewVReg), &
TRI);
910 LIS.InsertMachineInstrRangeInMaps(MIS.
begin(),
MI);
924 "Implicit def with more than one definition");
932 void InlineSpiller::insertSpill(
unsigned NewVReg,
bool isKill,
937 bool IsRealSpill =
true;
948 MRI.getRegClass(NewVReg), &
TRI);
950 LIS.InsertMachineInstrRangeInMaps(std::next(MI), MIS.
end());
956 HSpiller.addToMergeableSpills(*std::next(MI), StackSlot, Original);
960 void InlineSpiller::spillAroundUses(
unsigned Reg) {
966 RegI =
MRI.reg_bundle_begin(Reg),
E =
MRI.reg_bundle_end();
974 LLVM_DEBUG(
dbgs() <<
"Modifying debug info due to spill:\t" << *MI);
981 "instruction that isn't a DBG_VALUE");
984 if (SnippetCopies.count(MI))
988 if (coalesceStackAccess(MI, Reg))
1004 if (SibReg && isSibling(SibReg)) {
1006 if (isRegToSpill(SibReg)) {
1008 SnippetCopies.insert(MI);
1012 if (hoistSpillInsideBB(OldLI, *MI)) {
1015 DeadDefs.push_back(MI);
1021 eliminateRedundantSpills(SibLI, SibLI.
getVNInfoAt(Idx));
1027 if (foldMemoryOperand(Ops))
1032 unsigned NewVReg = Edit->createFrom(Reg);
1035 insertReload(NewVReg, Idx, MI);
1038 bool hasLiveDef =
false;
1039 for (
const auto &OpPair : Ops) {
1043 if (!OpPair.first->isRegTiedToDefOperand(OpPair.second))
1050 LLVM_DEBUG(
dbgs() <<
"\trewrite: " << Idx <<
'\t' << *MI <<
'\n');
1055 insertSpill(NewVReg,
true, MI);
1060 void InlineSpiller::spillAll() {
1063 StackSlot = VRM.assignVirt2StackSlot(Original);
1064 StackInt = &LSS.getOrCreateInterval(StackSlot,
MRI.getRegClass(Original));
1065 StackInt->getNextValue(
SlotIndex(), LSS.getVNInfoAllocator());
1067 StackInt = &LSS.getInterval(StackSlot);
1069 if (Original != Edit->getReg())
1070 VRM.assignVirt2StackSlot(Edit->getReg(), StackSlot);
1072 assert(StackInt->getNumValNums() == 1 &&
"Bad stack interval values");
1073 for (
unsigned Reg : RegsToSpill)
1074 StackInt->MergeSegmentsInAsValue(LIS.getInterval(Reg),
1075 StackInt->getValNumInfo(0));
1076 LLVM_DEBUG(
dbgs() <<
"Merged spilled regs: " << *StackInt <<
'\n');
1079 for (
unsigned Reg : RegsToSpill)
1080 spillAroundUses(Reg);
1083 if (!DeadDefs.empty()) {
1084 LLVM_DEBUG(
dbgs() <<
"Eliminating " << DeadDefs.size() <<
" dead defs\n");
1085 Edit->eliminateDeadDefs(DeadDefs, RegsToSpill, AA);
1089 for (
unsigned Reg : RegsToSpill) {
1091 RI =
MRI.reg_instr_begin(Reg),
E =
MRI.reg_instr_end();
1094 assert(SnippetCopies.count(&MI) &&
"Remaining use wasn't a snippet copy");
1096 LIS.RemoveMachineInstrFromMaps(MI);
1102 for (
unsigned Reg : RegsToSpill)
1103 Edit->eraseVirtReg(Reg);
1110 "Trying to spill a stack slot.");
1112 Original = VRM.getOriginal(edit.
getReg());
1113 StackSlot = VRM.getStackSlot(Original);
1118 <<
':' << edit.
getParent() <<
"\nFrom original " 1121 "Attempting to spill already spilled value.");
1122 assert(DeadDefs.empty() &&
"Previous spill didn't remove dead defs");
1124 collectRegsToSpill();
1128 if (!RegsToSpill.empty())
1131 Edit->calculateRegClassAndHint(MF,
Loops, MBFI);
1135 void InlineSpiller::postOptimization() { HSpiller.hoistAllSpills(); }
1138 void HoistSpillHelper::addToMergeableSpills(
MachineInstr &Spill,
int StackSlot,
1139 unsigned Original) {
1144 if (StackSlotToOrigLI.find(StackSlot) == StackSlotToOrigLI.end()) {
1145 auto LI = std::make_unique<LiveInterval>(OrigLI.
reg, OrigLI.
weight);
1146 LI->
assign(OrigLI, Allocator);
1147 StackSlotToOrigLI[StackSlot] = std::move(LI);
1149 SlotIndex Idx = LIS.getInstructionIndex(Spill);
1150 VNInfo *OrigVNI = StackSlotToOrigLI[StackSlot]->getVNInfoAt(Idx.
getRegSlot());
1151 std::pair<int, VNInfo *> MIdx = std::make_pair(StackSlot, OrigVNI);
1152 MergeableSpills[MIdx].insert(&Spill);
1157 bool HoistSpillHelper::rmFromMergeableSpills(
MachineInstr &Spill,
1159 auto It = StackSlotToOrigLI.find(StackSlot);
1160 if (It == StackSlotToOrigLI.end())
1162 SlotIndex Idx = LIS.getInstructionIndex(Spill);
1164 std::pair<int, VNInfo *> MIdx = std::make_pair(StackSlot, OrigVNI);
1165 return MergeableSpills[MIdx].erase(&Spill);
1173 unsigned OrigReg = OrigLI.
reg;
1176 Idx = LIS.getInstructionIndex(*MI);
1182 for (
auto const SibReg : Siblings) {
1195 void HoistSpillHelper::rmRedundantSpills(
1202 for (
const auto CurrentSpill : Spills) {
1207 SlotIndex PIdx = LIS.getInstructionIndex(*PrevSpill);
1208 SlotIndex CIdx = LIS.getInstructionIndex(*CurrentSpill);
1209 MachineInstr *SpillToRm = (CIdx > PIdx) ? CurrentSpill : PrevSpill;
1210 MachineInstr *SpillToKeep = (CIdx > PIdx) ? PrevSpill : CurrentSpill;
1212 SpillBBToSpill[MDT.getBase().getNode(Block)] = SpillToKeep;
1214 SpillBBToSpill[MDT.getBase().getNode(Block)] = CurrentSpill;
1217 for (
const auto SpillToRm : SpillsToRm)
1218 Spills.
erase(SpillToRm);
1227 void HoistSpillHelper::getVisitOrders(
1251 for (
const auto Spill : Spills) {
1255 while (Node != RootIDomNode) {
1258 if (Node != MDT[Block] && SpillBBToSpill[Node]) {
1259 SpillToRm = SpillBBToSpill[MDT[Block]];
1264 }
else if (WorkSet.
count(Node)) {
1267 NodesOnPath.
insert(Node);
1269 Node = Node->getIDom();
1279 SpillsToKeep[MDT[Block]] = 0;
1282 NodesOnPath.
clear();
1288 Orders.
push_back(MDT.getBase().getNode(Root));
1291 const std::vector<MachineDomTreeNode *> &Children = Node->
getChildren();
1292 unsigned NumChildren = Children.size();
1293 for (
unsigned i = 0; i != NumChildren; ++i) {
1295 if (WorkSet.
count(Child))
1298 }
while (idx != Orders.
size());
1300 "Orders have different size with WorkSet");
1305 for (; RIt != Orders.
rend(); RIt++)
1306 LLVM_DEBUG(
dbgs() <<
"BB" << (*RIt)->getBlock()->getNumber() <<
",");
1314 void HoistSpillHelper::runHoistSpills(
1330 rmRedundantSpills(Spills, SpillsToRm, SpillBBToSpill);
1333 getVisitOrders(Root, Spills, Orders, SpillsToRm, SpillsToKeep,
1340 using NodesCostPair =
1341 std::pair<SmallPtrSet<MachineDomTreeNode *, 16>,
BlockFrequency>;
1349 for (; RIt != Orders.
rend(); RIt++) {
1353 if (SpillsToKeep.
find(*RIt) != SpillsToKeep.
end() && !SpillsToKeep[*RIt]) {
1354 SpillsInSubTreeMap[*RIt].first.
insert(*RIt);
1356 SpillsInSubTreeMap[*RIt].second = MBFI.getBlockFreq(Block);
1362 const std::vector<MachineDomTreeNode *> &Children = (*RIt)->getChildren();
1363 unsigned NumChildren = Children.
size();
1364 for (
unsigned i = 0; i != NumChildren; ++i) {
1366 if (SpillsInSubTreeMap.
find(Child) == SpillsInSubTreeMap.
end())
1374 SpillsInSubTreeMap[*RIt].first;
1375 BlockFrequency &SubTreeCost = SpillsInSubTreeMap[*RIt].second;
1376 SubTreeCost += SpillsInSubTreeMap[Child].second;
1377 auto BI = SpillsInSubTreeMap[Child].first.
begin();
1378 auto EI = SpillsInSubTreeMap[Child].first.
end();
1379 SpillsInSubTree.
insert(BI, EI);
1380 SpillsInSubTreeMap.
erase(Child);
1384 SpillsInSubTreeMap[*RIt].first;
1385 BlockFrequency &SubTreeCost = SpillsInSubTreeMap[*RIt].second;
1387 if (SpillsInSubTree.
empty())
1391 unsigned LiveReg = 0;
1392 if (!isSpillCandBB(OrigLI, OrigVNI, *Block, LiveReg))
1400 if (SubTreeCost > MBFI.getBlockFreq(Block) * MarginProb) {
1402 for (
const auto SpillBB : SpillsInSubTree) {
1405 if (SpillsToKeep.
find(SpillBB) != SpillsToKeep.
end() &&
1406 !SpillsToKeep[SpillBB]) {
1411 SpillsToKeep.
erase(SpillBB);
1415 SpillsToKeep[*RIt] = LiveReg;
1417 dbgs() <<
"spills in BB: ";
1418 for (
const auto Rspill : SpillsInSubTree)
1419 dbgs() << Rspill->getBlock()->getNumber() <<
" ";
1420 dbgs() <<
"were promoted to BB" << (*RIt)->getBlock()->getNumber()
1423 SpillsInSubTree.clear();
1424 SpillsInSubTree.insert(*RIt);
1425 SubTreeCost = MBFI.getBlockFreq(Block);
1430 for (
const auto &Ent : SpillsToKeep) {
1432 SpillsToIns[Ent.first->getBlock()] = Ent.second;
1452 void HoistSpillHelper::hoistAllSpills() {
1456 for (
unsigned i = 0,
e =
MRI.getNumVirtRegs(); i !=
e; ++i) {
1458 unsigned Original = VRM.getPreSplitReg(Reg);
1459 if (!
MRI.def_empty(Reg))
1460 Virt2SiblingsMap[Original].insert(Reg);
1464 for (
auto &Ent : MergeableSpills) {
1465 int Slot = Ent.first.first;
1467 VNInfo *OrigVNI = Ent.first.second;
1469 if (Ent.second.empty())
1473 dbgs() <<
"\nFor Slot" << Slot <<
" and VN" << OrigVNI->
id <<
":\n" 1474 <<
"Equal spills in BB: ";
1475 for (
const auto spill : EqValSpills)
1476 dbgs() << spill->getParent()->getNumber() <<
" ";
1485 runHoistSpills(OrigLI, *OrigVNI, EqValSpills, SpillsToRm, SpillsToIns);
1488 dbgs() <<
"Finally inserted spills in BB: ";
1489 for (
const auto &Ispill : SpillsToIns)
1490 dbgs() << Ispill.first->getNumber() <<
" ";
1491 dbgs() <<
"\nFinally removed spills in BB: ";
1492 for (
const auto Rspill : SpillsToRm)
1493 dbgs() << Rspill->getParent()->getNumber() <<
" ";
1499 if (!SpillsToIns.
empty() || !SpillsToRm.empty())
1501 StackIntvl.getValNumInfo(0));
1504 for (
auto const &Insert : SpillsToIns) {
1506 unsigned LiveReg = Insert.second;
1509 MRI.getRegClass(LiveReg), &
TRI);
1510 LIS.InsertMachineInstrRangeInMaps(std::prev(MI), MI);
1515 NumSpills -= SpillsToRm.size();
1516 for (
auto const RMEnt : SpillsToRm) {
1518 for (
unsigned i = RMEnt->getNumOperands(); i; --i) {
1521 RMEnt->RemoveOperand(i - 1);
1530 void HoistSpillHelper::LRE_DidCloneVirtReg(
unsigned New,
unsigned Old) {
1531 if (VRM.hasPhys(Old))
1532 VRM.assignVirt2Phys(New, VRM.getPhys(Old));
1534 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...
bool isCall(QueryType Type=AnyInBundle) const
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
SlotIndex def
The index of the defining instruction.
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
This class represents lattice values for constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
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...
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. ...
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 isStackSlot(unsigned Reg)
isStackSlot - Sometimes it is useful the be able to store a non-negative frame index in a variable th...
bool addRegisterDead(Register Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
unsigned getSubReg() const
bool isValid() const
isValid - Returns true until all the operands have been visited.
VirtRegInfo AnalyzeVirtRegInBundle(MachineInstr &MI, unsigned Reg, SmallVectorImpl< std::pair< MachineInstr *, unsigned >> *Ops=nullptr)
AnalyzeVirtRegInBundle - Analyze how the current instruction or bundle uses a virtual register...
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
PhysRegInfo AnalyzePhysRegInBundle(const MachineInstr &MI, unsigned Reg, const TargetRegisterInfo *TRI)
AnalyzePhysRegInBundle - Analyze how the current instruction or bundle uses a physical register...
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)
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
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.
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.
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.
MachineBasicBlock::iterator end()
defusechain_iterator - This class provides iterator support for machine operands in the function that...
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
bool Reads
Reads - One of the operands read the virtual register.
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
void setReg(Register Reg)
Change the register this operand corresponds to.
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)
initializer< Ty > init(const Ty &Val)
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 FullyDefined
Reg or a super-register is defined.
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)
unsigned id
The ID number of this value.
LiveInterval & getParent() const
A SetVector that performs no allocations if smaller than a certain size.
Information about how a physical register Reg is used by a set of operands.
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"))
modulo schedule Modulo Schedule test pass
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()
bool Tied
Tied - Uses and defs must use the same register.
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.
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())
VirtRegInfo - Information about a virtual register used by a set of operands.
bool isSpillable() const
isSpillable - Can this interval be spilled?
void moveCallSiteInfo(const MachineInstr *Old, const MachineInstr *New)
Following functions update call site info.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
iterator SkipPHIsLabelsAndDebug(iterator I)
Return the first instruction in MBB after I that is not a PHI, label or debug.
bool Writes
Writes - One of the operands writes the virtual register.
Register getReg() const
getReg - Returns the register number.
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.
static cl::opt< bool > RestrictStatepointRemat("restrict-statepoint-remat", cl::init(false), cl::Hidden, cl::desc("Restrict remat for statepoint operands"))
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Wrapper class representing virtual and physical registers.
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.