43 #define DEBUG_TYPE "regalloc"
45 STATISTIC(NumSpilledRanges,
"Number of spilled live ranges");
46 STATISTIC(NumSnippets,
"Number of spilled snippets");
47 STATISTIC(NumSpills,
"Number of spills inserted");
48 STATISTIC(NumSpillsRemoved,
"Number of spills removed");
49 STATISTIC(NumReloads,
"Number of reloads inserted");
50 STATISTIC(NumReloadsRemoved,
"Number of reloads removed");
51 STATISTIC(NumFolded,
"Number of folded stack accesses");
52 STATISTIC(NumFoldedLoads,
"Number of folded loads");
53 STATISTIC(NumRemats,
"Number of rematerialized defs for spilling");
56 cl::desc(
"Disable inline spill hoisting"));
82 MergeableSpillsMap MergeableSpills;
92 void rmRedundantSpills(
104 void runHoistSpills(
unsigned OrigReg,
VNInfo &OrigVNI,
117 MFI(mf.getFrameInfo()),
MRI(mf.getRegInfo()),
118 TII(*mf.getSubtarget().getInstrInfo()),
119 TRI(*mf.getSubtarget().getRegisterInfo()),
121 IPA(LIS, mf.getNumBlockIDs()) {}
126 void hoistAllSpills();
127 void LRE_DidCloneVirtReg(
unsigned,
unsigned)
override;
130 class InlineSpiller :
public Spiller {
164 HoistSpillHelper HSpiller;
166 ~InlineSpiller()
override {}
175 MFI(mf.getFrameInfo()),
MRI(mf.getRegInfo()),
176 TII(*mf.getSubtarget().getInstrInfo()),
177 TRI(*mf.getSubtarget().getRegisterInfo()),
179 HSpiller(pass, mf, vrm) {}
182 void postOptimization()
override;
186 void collectRegsToSpill();
188 bool isRegToSpill(
unsigned Reg) {
return is_contained(RegsToSpill, Reg); }
190 bool isSibling(
unsigned Reg);
196 void reMaterializeAll();
199 bool foldMemoryOperand(
ArrayRef<std::pair<MachineInstr*, unsigned> >,
204 void spillAroundUses(
unsigned Reg);
212 void Spiller::anchor() { }
217 return new InlineSpiller(pass, mf, vrm);
249 bool InlineSpiller::isSnippet(
const LiveInterval &SnipLI) {
250 unsigned Reg = Edit->getReg();
259 if (SnipLI.
getNumValNums() > 2 || !LIS.intervalIsInOneMBB(SnipLI))
266 RI =
MRI.reg_instr_nodbg_begin(SnipLI.
reg),
267 E =
MRI.reg_instr_nodbg_end(); RI !=
E; ) {
284 if (UseMI && &MI != UseMI)
293 void InlineSpiller::collectRegsToSpill() {
294 unsigned Reg = Edit->getReg();
297 RegsToSpill.assign(1, Reg);
298 SnippetCopies.clear();
306 RI =
MRI.reg_instr_begin(Reg),
E =
MRI.reg_instr_end(); RI !=
E; ) {
309 if (!isSibling(SnipReg))
312 if (!isSnippet(SnipLI))
314 SnippetCopies.insert(&MI);
315 if (isRegToSpill(SnipReg))
317 RegsToSpill.push_back(SnipReg);
318 DEBUG(
dbgs() <<
"\talso spill snippet " << SnipLI <<
'\n');
323 bool InlineSpiller::isSibling(
unsigned Reg) {
324 return TargetRegisterInfo::isVirtualRegister(Reg) &&
325 VRM.getOriginal(Reg) == Original;
347 bool InlineSpiller::hoistSpillInsideBB(
LiveInterval &SpillLI,
349 SlotIndex Idx = LIS.getInstructionIndex(CopyMI);
366 assert(StackInt &&
"No stack slot assigned yet.");
369 StackInt->MergeValueInAsValue(OrigLI, OrigVNI, StackInt->getValNumInfo(0));
370 DEBUG(
dbgs() <<
"\tmerged orig valno " << OrigVNI->
id <<
": "
371 << *StackInt <<
'\n');
375 eliminateRedundantSpills(SrcLI, SrcVNI);
383 assert(DefMI &&
"Defining instruction disappeared");
389 MRI.getRegClass(SrcReg), &TRI);
391 LIS.InsertMachineInstrInMaps(*MII);
392 DEBUG(
dbgs() <<
"\thoisted: " << SrcVNI->
def <<
'\t' << *MII);
394 HSpiller.addToMergeableSpills(*MII, StackSlot, Original);
402 assert(VNI &&
"Missing value");
404 WorkList.
push_back(std::make_pair(&SLI, VNI));
405 assert(StackInt &&
"No stack slot assigned yet.");
410 unsigned Reg = LI->
reg;
411 DEBUG(
dbgs() <<
"Checking redundant spills for "
412 << VNI->
id <<
'@' << VNI->
def <<
" in " << *LI <<
'\n');
415 if (isRegToSpill(Reg))
419 StackInt->MergeValueInAsValue(*LI, VNI, StackInt->getValNumInfo(0));
420 DEBUG(
dbgs() <<
"Merged to stack int: " << *StackInt <<
'\n');
424 UI =
MRI.use_instr_nodbg_begin(Reg),
E =
MRI.use_instr_nodbg_end();
429 SlotIndex Idx = LIS.getInstructionIndex(MI);
435 if (isSibling(DstReg)) {
438 assert(DstVNI &&
"Missing defined value");
440 WorkList.
push_back(std::make_pair(&DstLI, DstVNI));
448 DEBUG(
dbgs() <<
"Redundant spill " << Idx <<
'\t' << MI);
451 DeadDefs.push_back(&MI);
453 if (HSpiller.rmFromMergeableSpills(MI, StackSlot))
457 }
while (!WorkList.
empty());
469 WorkList.
push_back(std::make_pair(LI, VNI));
472 if (!UsedValues.insert(VNI).second)
480 WorkList.
push_back(std::make_pair(LI, PVNI));
487 if (!SnippetCopies.count(MI))
490 assert(isRegToSpill(SnipLI.
reg) &&
"Unexpected register in copy");
492 assert(SnipVNI &&
"Snippet undefined before copy");
493 WorkList.
push_back(std::make_pair(&SnipLI, SnipVNI));
494 }
while (!WorkList.
empty());
502 MIBundleOperands::VirtRegInfo RI =
512 DEBUG(
dbgs() <<
"\tadding <undef> flags: ");
522 if (SnippetCopies.count(&MI))
528 RM.OrigMI = LIS.getInstructionFromIndex(OrigVNI->
def);
530 if (!Edit->canRematerializeAt(
RM, OrigVNI, UseIdx,
false)) {
531 markValueUsed(&VirtReg, ParentVNI);
532 DEBUG(
dbgs() <<
"\tcannot remat for " << UseIdx <<
'\t' << MI);
539 markValueUsed(&VirtReg, ParentVNI);
540 DEBUG(
dbgs() <<
"\tcannot remat tied reg: " << UseIdx <<
'\t' << MI);
546 if (
RM.OrigMI->canFoldAsLoad() &&
547 foldMemoryOperand(Ops,
RM.OrigMI)) {
548 Edit->markRematerialized(
RM.ParentVNI);
554 unsigned NewVReg = Edit->createFrom(Original);
558 Edit->rematerializeAt(*MI.
getParent(),
MI, NewVReg,
RM, TRI);
562 auto *NewMI = LIS.getInstructionFromIndex(DefIdx);
566 DEBUG(
dbgs() <<
"\tremat: " << DefIdx <<
'\t'
567 << *LIS.getInstructionFromIndex(DefIdx));
570 for (
const auto &OpPair : Ops) {
577 DEBUG(
dbgs() <<
"\t " << UseIdx <<
'\t' << MI <<
'\n');
585 void InlineSpiller::reMaterializeAll() {
586 if (!Edit->anyRematerializable(AA))
592 bool anyRemat =
false;
593 for (
unsigned Reg : RegsToSpill) {
596 RegI =
MRI.reg_bundle_begin(Reg),
E =
MRI.reg_bundle_end();
604 anyRemat |= reMaterializeFor(LI, MI);
611 for (
unsigned Reg : RegsToSpill) {
622 DEBUG(
dbgs() <<
"All defs dead: " << *MI);
623 DeadDefs.push_back(MI);
629 if (DeadDefs.empty())
631 DEBUG(
dbgs() <<
"Remat created " << DeadDefs.size() <<
" dead defs.\n");
632 Edit->eliminateDeadDefs(DeadDefs, RegsToSpill, AA);
640 unsigned ResultPos = 0;
641 for (
unsigned Reg : RegsToSpill) {
642 if (
MRI.reg_nodbg_empty(Reg)) {
643 Edit->eraseVirtReg(Reg);
647 assert(LIS.hasInterval(Reg) &&
648 (!LIS.getInterval(Reg).empty() || !
MRI.reg_nodbg_empty(Reg)) &&
649 "Empty and not used live-range?!");
651 RegsToSpill[ResultPos++] =
Reg;
653 RegsToSpill.erase(RegsToSpill.begin() + ResultPos, RegsToSpill.end());
654 DEBUG(
dbgs() << RegsToSpill.size() <<
" registers to spill after remat.\n");
663 bool InlineSpiller::coalesceStackAccess(
MachineInstr *MI,
unsigned Reg) {
666 bool IsLoad = InstrReg;
671 if (InstrReg != Reg || FI != StackSlot)
675 HSpiller.rmFromMergeableSpills(*MI, StackSlot);
677 DEBUG(
dbgs() <<
"Coalescing stack access: " << *MI);
678 LIS.RemoveMachineInstrFromMaps(*MI);
692 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
698 const char *
const header,
700 char NextLine =
'\n';
701 char SlotIndent =
'\t';
703 if (std::next(B) == E) {
708 dbgs() <<
'\t' << header <<
": " << NextLine;
722 dbgs() << SlotIndent << Idx <<
'\t' << *
I;
734 foldMemoryOperand(
ArrayRef<std::pair<MachineInstr*, unsigned> > Ops,
740 if (Ops.back().first != MI || MI->
isBundled())
743 bool WasCopy = MI->
isCopy();
748 bool SpillSubRegs =
TII.isSubregFoldable() ||
749 MI->
getOpcode() == TargetOpcode::STATEPOINT ||
750 MI->
getOpcode() == TargetOpcode::PATCHPOINT ||
751 MI->
getOpcode() == TargetOpcode::STACKMAP;
756 for (
const auto &OpPair : Ops) {
757 unsigned Idx = OpPair.second;
758 assert(MI == OpPair.first &&
"Instruction conflict during operand folding");
768 if (LoadMI && MO.
isDef())
783 LoadMI ?
TII.foldMemoryOperand(*MI, FoldOps, *LoadMI, &LIS)
784 :
TII.foldMemoryOperand(*MI, FoldOps, StackSlot, &LIS);
792 unsigned Reg = MO->
getReg();
793 if (!Reg || TargetRegisterInfo::isVirtualRegister(Reg) ||
794 MRI.isReserved(Reg)) {
800 MIBundleOperands::PhysRegInfo RI =
806 SlotIndex Idx = LIS.getInstructionIndex(*MI).getRegSlot();
807 LIS.removePhysRegDefAt(Reg, Idx);
812 HSpiller.rmFromMergeableSpills(*MI, FI))
814 LIS.ReplaceMachineInstrInMaps(*MI, *FoldMI);
818 assert(!MIS.empty() &&
"Unexpected empty span of instructions!");
821 LIS.InsertMachineInstrInMaps(MI);
830 if (MO.
getReg() == ImpReg)
839 else if (Ops.front().second == 0) {
841 HSpiller.addToMergeableSpills(*FoldMI, StackSlot, Original);
847 void InlineSpiller::insertReload(
unsigned NewVReg,
854 MRI.getRegClass(NewVReg), &TRI);
856 LIS.InsertMachineInstrRangeInMaps(MIS.begin(),
MI);
870 "Implicit def with more than one definition");
878 void InlineSpiller::insertSpill(
unsigned NewVReg,
bool isKill,
883 bool IsRealSpill =
true;
894 MRI.getRegClass(NewVReg), &TRI);
896 LIS.InsertMachineInstrRangeInMaps(std::next(MI), MIS.end());
902 HSpiller.addToMergeableSpills(*std::next(MI), StackSlot, Original);
906 void InlineSpiller::spillAroundUses(
unsigned Reg) {
912 RegI =
MRI.reg_bundle_begin(Reg),
E =
MRI.reg_bundle_end();
920 DEBUG(
dbgs() <<
"Modifying debug info due to spill:\t" << *MI);
927 if (SnippetCopies.count(MI))
931 if (coalesceStackAccess(MI, Reg))
936 MIBundleOperands::VirtRegInfo RI =
943 if (SlotIndex::isSameInstr(Idx, VNI->
def))
948 if (SibReg && isSibling(SibReg)) {
950 if (isRegToSpill(SibReg)) {
951 DEBUG(
dbgs() <<
"Found new snippet copy: " << *MI);
952 SnippetCopies.insert(MI);
956 if (hoistSpillInsideBB(OldLI, *MI)) {
959 DeadDefs.push_back(MI);
965 eliminateRedundantSpills(SibLI, SibLI.
getVNInfoAt(Idx));
971 if (foldMemoryOperand(Ops))
976 unsigned NewVReg = Edit->createFrom(Reg);
979 insertReload(NewVReg, Idx, MI);
982 bool hasLiveDef =
false;
983 for (
const auto &OpPair : Ops) {
987 if (!OpPair.first->isRegTiedToDefOperand(OpPair.second))
994 DEBUG(
dbgs() <<
"\trewrite: " << Idx <<
'\t' << *MI <<
'\n');
999 insertSpill(NewVReg,
true, MI);
1004 void InlineSpiller::spillAll() {
1006 if (StackSlot == VirtRegMap::NO_STACK_SLOT) {
1007 StackSlot = VRM.assignVirt2StackSlot(Original);
1008 StackInt = &LSS.getOrCreateInterval(StackSlot,
MRI.getRegClass(Original));
1009 StackInt->getNextValue(
SlotIndex(), LSS.getVNInfoAllocator());
1011 StackInt = &LSS.getInterval(StackSlot);
1013 if (Original != Edit->getReg())
1014 VRM.assignVirt2StackSlot(Edit->getReg(), StackSlot);
1016 assert(StackInt->getNumValNums() == 1 &&
"Bad stack interval values");
1017 for (
unsigned Reg : RegsToSpill)
1018 StackInt->MergeSegmentsInAsValue(LIS.getInterval(Reg),
1019 StackInt->getValNumInfo(0));
1020 DEBUG(
dbgs() <<
"Merged spilled regs: " << *StackInt <<
'\n');
1023 for (
unsigned Reg : RegsToSpill)
1024 spillAroundUses(Reg);
1027 if (!DeadDefs.empty()) {
1028 DEBUG(
dbgs() <<
"Eliminating " << DeadDefs.size() <<
" dead defs\n");
1029 Edit->eliminateDeadDefs(DeadDefs, RegsToSpill, AA);
1033 for (
unsigned Reg : RegsToSpill) {
1035 RI =
MRI.reg_instr_begin(Reg),
E =
MRI.reg_instr_end();
1038 assert(SnippetCopies.count(&MI) &&
"Remaining use wasn't a snippet copy");
1040 LIS.RemoveMachineInstrFromMaps(MI);
1046 for (
unsigned Reg : RegsToSpill)
1047 Edit->eraseVirtReg(Reg);
1054 &&
"Trying to spill a stack slot.");
1056 Original = VRM.getOriginal(edit.
getReg());
1057 StackSlot = VRM.getStackSlot(Original);
1061 << TRI.getRegClassName(
MRI.getRegClass(edit.
getReg()))
1063 <<
"\nFrom original " <<
PrintReg(Original) <<
'\n');
1065 "Attempting to spill already spilled value.");
1066 assert(DeadDefs.empty() &&
"Previous spill didn't remove dead defs");
1068 collectRegsToSpill();
1072 if (!RegsToSpill.empty())
1075 Edit->calculateRegClassAndHint(MF,
Loops, MBFI);
1080 void InlineSpiller::postOptimization() { HSpiller.hoistAllSpills(); }
1085 unsigned Original) {
1086 StackSlotToReg[StackSlot] = Original;
1087 SlotIndex Idx = LIS.getInstructionIndex(Spill);
1089 std::pair<int, VNInfo *> MIdx = std::make_pair(StackSlot, OrigVNI);
1090 MergeableSpills[MIdx].insert(&Spill);
1096 bool HoistSpillHelper::rmFromMergeableSpills(
MachineInstr &Spill,
1098 int Original = StackSlotToReg[StackSlot];
1101 SlotIndex Idx = LIS.getInstructionIndex(Spill);
1103 std::pair<int, VNInfo *> MIdx = std::make_pair(StackSlot, OrigVNI);
1104 return MergeableSpills[MIdx].erase(&Spill);
1110 bool HoistSpillHelper::isSpillCandBB(
unsigned OrigReg,
VNInfo &OrigVNI,
1116 Idx = LIS.getInstructionIndex(*MI);
1120 assert((LIS.getInterval(OrigReg)).getVNInfoAt(Idx) == &OrigVNI &&
1123 for (
auto const SibReg : Siblings) {
1137 void HoistSpillHelper::rmRedundantSpills(
1144 for (
const auto CurrentSpill : Spills) {
1149 SlotIndex PIdx = LIS.getInstructionIndex(*PrevSpill);
1150 SlotIndex CIdx = LIS.getInstructionIndex(*CurrentSpill);
1151 MachineInstr *SpillToRm = (CIdx > PIdx) ? CurrentSpill : PrevSpill;
1152 MachineInstr *SpillToKeep = (CIdx > PIdx) ? PrevSpill : CurrentSpill;
1154 SpillBBToSpill[MDT.getBase().getNode(Block)] = SpillToKeep;
1156 SpillBBToSpill[MDT.getBase().getNode(Block)] = CurrentSpill;
1159 for (
const auto SpillToRm : SpillsToRm)
1160 Spills.
erase(SpillToRm);
1170 void HoistSpillHelper::getVisitOrders(
1194 for (
const auto Spill : Spills) {
1198 while (Node != RootIDomNode) {
1201 if (Node != MDT[Block] && SpillBBToSpill[Node]) {
1202 SpillToRm = SpillBBToSpill[MDT[Block]];
1207 }
else if (WorkSet.
count(Node)) {
1210 NodesOnPath.
insert(Node);
1212 Node = Node->getIDom();
1222 SpillsToKeep[MDT[Block]] = 0;
1225 NodesOnPath.
clear();
1231 Orders.
push_back(MDT.getBase().getNode(Root));
1234 const std::vector<MachineDomTreeNode *> &Children = Node->
getChildren();
1235 unsigned NumChildren = Children.size();
1236 for (
unsigned i = 0; i != NumChildren; ++i) {
1238 if (WorkSet.
count(Child))
1241 }
while (idx != Orders.
size());
1243 "Orders have different size with WorkSet");
1246 DEBUG(
dbgs() <<
"Orders size is " << Orders.
size() <<
"\n");
1248 for (; RIt != Orders.
rend(); RIt++)
1249 DEBUG(
dbgs() <<
"BB" << (*RIt)->getBlock()->getNumber() <<
",");
1258 void HoistSpillHelper::runHoistSpills(
1273 rmRedundantSpills(Spills, SpillsToRm, SpillBBToSpill);
1276 getVisitOrders(Root, Spills, Orders, SpillsToRm, SpillsToKeep,
1283 typedef std::pair<SmallPtrSet<MachineDomTreeNode *, 16>,
BlockFrequency>
1291 for (; RIt != Orders.
rend(); RIt++) {
1295 if (SpillsToKeep.
find(*RIt) != SpillsToKeep.
end() && !SpillsToKeep[*RIt]) {
1296 SpillsInSubTreeMap[*RIt].first.
insert(*RIt);
1298 SpillsInSubTreeMap[*RIt].second = MBFI.getBlockFreq(Block);
1304 const std::vector<MachineDomTreeNode *> &Children = (*RIt)->getChildren();
1305 unsigned NumChildren = Children.size();
1306 for (
unsigned i = 0; i != NumChildren; ++i) {
1308 if (SpillsInSubTreeMap.
find(Child) == SpillsInSubTreeMap.
end())
1316 SpillsInSubTreeMap[*RIt].first;
1318 SubTreeCost += SpillsInSubTreeMap[Child].second;
1319 auto BI = SpillsInSubTreeMap[Child].first.
begin();
1320 auto EI = SpillsInSubTreeMap[Child].first.
end();
1321 SpillsInSubTree.
insert(BI, EI);
1322 SpillsInSubTreeMap.
erase(Child);
1326 SpillsInSubTreeMap[*RIt].first;
1329 if (SpillsInSubTree.
empty())
1333 unsigned LiveReg = 0;
1334 if (!isSpillCandBB(OrigReg, OrigVNI, *Block, LiveReg))
1342 if (SubTreeCost > MBFI.getBlockFreq(Block) * MarginProb) {
1344 for (
const auto SpillBB : SpillsInSubTree) {
1347 if (SpillsToKeep.
find(SpillBB) != SpillsToKeep.
end() &&
1348 !SpillsToKeep[SpillBB]) {
1353 SpillsToKeep.
erase(SpillBB);
1357 SpillsToKeep[*RIt] = LiveReg;
1359 dbgs() <<
"spills in BB: ";
1360 for (
const auto Rspill : SpillsInSubTree)
1361 dbgs() << Rspill->getBlock()->getNumber() <<
" ";
1362 dbgs() <<
"were promoted to BB" << (*RIt)->getBlock()->getNumber()
1365 SpillsInSubTree.clear();
1366 SpillsInSubTree.insert(*RIt);
1367 SubTreeCost = MBFI.getBlockFreq(Block);
1372 for (
const auto Ent : SpillsToKeep) {
1374 SpillsToIns[Ent.first->getBlock()] = Ent.second;
1395 void HoistSpillHelper::hoistAllSpills() {
1401 for (
unsigned i = 0, e =
MRI.getNumVirtRegs(); i != e; ++i) {
1402 unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
1403 int Slot = VRM.getStackSlot(Reg);
1404 if (Slot != VirtRegMap::NO_STACK_SLOT)
1405 SlotToOrigReg[Slot] = VRM.getOriginal(Reg);
1406 unsigned Original = VRM.getPreSplitReg(Reg);
1407 if (!
MRI.def_empty(Reg))
1408 Virt2SiblingsMap[Original].insert(Reg);
1412 for (
auto &Ent : MergeableSpills) {
1413 int Slot = Ent.first.first;
1414 unsigned OrigReg = SlotToOrigReg[Slot];
1416 VNInfo *OrigVNI = Ent.first.second;
1418 if (Ent.second.empty())
1422 dbgs() <<
"\nFor Slot" << Slot <<
" and VN" << OrigVNI->
id <<
":\n"
1423 <<
"Equal spills in BB: ";
1424 for (
const auto spill : EqValSpills)
1425 dbgs() << spill->getParent()->getNumber() <<
" ";
1434 runHoistSpills(OrigReg, *OrigVNI, EqValSpills, SpillsToRm, SpillsToIns);
1437 dbgs() <<
"Finally inserted spills in BB: ";
1438 for (
const auto Ispill : SpillsToIns)
1439 dbgs() << Ispill.first->getNumber() <<
" ";
1440 dbgs() <<
"\nFinally removed spills in BB: ";
1441 for (
const auto Rspill : SpillsToRm)
1442 dbgs() << Rspill->getParent()->getNumber() <<
" ";
1448 if (!SpillsToIns.empty() || !SpillsToRm.empty())
1450 StackIntvl.getValNumInfo(0));
1453 for (
auto const Insert : SpillsToIns) {
1455 unsigned LiveReg = Insert.second;
1458 MRI.getRegClass(LiveReg), &TRI);
1459 LIS.InsertMachineInstrRangeInMaps(std::prev(MI), MI);
1464 NumSpills -= SpillsToRm.size();
1465 for (
auto const RMEnt : SpillsToRm) {
1467 for (
unsigned i = RMEnt->getNumOperands(); i; --i) {
1470 RMEnt->RemoveOperand(i - 1);
1473 Edit.eliminateDeadDefs(SpillsToRm,
None, AA);
1479 void HoistSpillHelper::LRE_DidCloneVirtReg(
unsigned New,
unsigned Old) {
1480 if (VRM.hasPhys(Old))
1481 VRM.assignVirt2Phys(New, VRM.getPhys(Old));
1482 else if (VRM.getStackSlot(Old) != VirtRegMap::NO_STACK_SLOT)
1483 VRM.assignVirt2StackSlot(New, VRM.getStackSlot(Old));
void push_back(const T &Elt)
Safe Stack instrumentation pass
SlotIndex def
The index of the defining instruction.
STATISTIC(NumFunctions,"Total number of functions")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
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...
LiveInterval - This class represents the liveness of a register, or stack slot.
MIBundleOperands - Iterate over all operands in a bundle of machine instructions. ...
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
bool isSpillable() const
isSpillable - Can this interval be spilled?
void setIsUndef(bool Val=true)
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
bool isKill() const
Return true if the live-in value is killed by this instruction.
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
This class implements a map that also provides access to all stored values in a deterministic order...
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...
unsigned getNumValNums() const
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
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 allDefsAreDead() const
Return true if all the defs of this instruction are dead.
MachineInstrSpan provides an interface to get an iteration range containing the instruction it was in...
const std::vector< DomTreeNodeBase * > & getChildren() 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
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Result of a LiveRange query.
Reg
All possible values of the reg field in the ModR/M byte.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
PhysRegInfo analyzePhysReg(unsigned Reg, const TargetRegisterInfo *TRI)
analyzePhysReg - Analyze how the current instruction or bundle uses a physical register.
LLVM_NODISCARD bool empty() const
unsigned getNumOperands() const
Access to explicit operands of the instruction.
bool isUnused() const
Returns true if this value is unused.
defusechain_iterator - This class provides iterator support for machine operands in the function that...
void RemoveOperand(unsigned i)
Erase an operand from an instruction, leaving it with one fewer operand than it started with...
DomTreeNodeBase * getIDom() const
bool isBundled() const
Return true if this instruction part of a bundle.
Base class for the actual dominator tree node.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Printable PrintReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubRegIdx=0)
Prints virtual and physical registers with or without a TRI instance.
unsigned getKillRegState(bool B)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
const MachineBasicBlock * getParent() const
TargetInstrInfo - Interface to description of machine instruction set.
iterator find(const_arg_type_t< KeyT > Val)
bool isDebugValue() const
bool isImplicitDef() const
bool isEarlyClobber() const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
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)
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
const MachineOperand & getOperand(unsigned i) const
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
LiveInterval & getParent() const
iterator_range< pred_iterator > predecessors()
LLVM_NODISCARD bool empty() const
unsigned getSubReg() const
Information about a live register.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
void setIsKill(bool Val=true)
unsigned id
The ID number of this value.
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.
MachineOperand class - Representation of each machine instruction operand.
static cl::opt< bool > DisableHoisting("disable-spill-hoist", cl::Hidden, cl::desc("Disable inline spill hoisting"))
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
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.
unsigned isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const override
TargetInstrInfo overrides.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
llvm_unreachable("Unknown RegBank!")
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...
Representation of each machine instruction.
void setReg(unsigned Reg)
Change the register this operand corresponds to.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
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...
Remat - Information needed to rematerialize at a specific location.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
unsigned getReg() const
getReg - Returns the register number.
reverse_iterator rbegin()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx=nullptr) const
Return true if the use operand of the specified index is tied to a def operand.
iterator SkipPHIsLabelsAndDebug(iterator I)
Return the first instruction in MBB after I that is not a PHI, label or debug.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
SlotIndex - An opaque wrapper around machine indexes.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarilly including Idx...
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.