42 #include "llvm/Config/llvm-config.h" 60 #define DEBUG_TYPE "regalloc" 62 STATISTIC(NumFinished,
"Number of splits finished");
63 STATISTIC(NumSimple,
"Number of splits that were simple");
64 STATISTIC(NumCopies,
"Number of copies inserted for splitting");
65 STATISTIC(NumRemats,
"Number of rematerialized defs for splitting");
66 STATISTIC(NumRepairs,
"Number of invalid live ranges repaired");
74 : LIS(lis), LastInsertPoint(BBNum) {}
77 InsertPointAnalysis::computeLastInsertPoint(
const LiveInterval &CurLI,
80 std::pair<SlotIndex, SlotIndex> &LIP = LastInsertPoint[Num];
90 if (!LIP.first.isValid()) {
92 if (FirstTerm == MBB.
end())
98 if (EHPadSuccessors.
empty())
101 LIP.second = LIP.first;
154 : MF(vrm.getMachineFunction()), VRM(vrm), LIS(lis),
Loops(mli),
155 TII(*MF.getSubtarget().getInstrInfo()), IPA(lis, MF.getNumBlockIDs()) {}
160 ThroughBlocks.
clear();
162 DidRepairRange =
false;
166 void SplitAnalysis::analyzeUses() {
167 assert(UseSlots.empty() &&
"Call clear first");
173 UseSlots.push_back(VNI->
def);
185 UseSlots.erase(std::unique(UseSlots.begin(), UseSlots.end(),
190 if (!calcLiveBlockInfo()) {
193 DidRepairRange =
true;
195 LLVM_DEBUG(
dbgs() <<
"*** Fixing inconsistent live interval! ***\n");
197 .shrinkToUses(const_cast<LiveInterval*>(CurLI));
199 ThroughBlocks.
clear();
200 bool fixed = calcLiveBlockInfo();
202 assert(fixed &&
"Couldn't fix broken live interval");
205 LLVM_DEBUG(
dbgs() <<
"Analyze counted " << UseSlots.size() <<
" instrs in " 206 << UseBlocks.size() <<
" blocks, through " 207 << NumThroughBlocks <<
" blocks.\n");
212 bool SplitAnalysis::calcLiveBlockInfo() {
214 NumThroughBlocks = NumGapBlocks = 0;
222 UseI = UseSlots.begin();
223 UseE = UseSlots.end();
237 if (UseI == UseE || *UseI >= Stop) {
249 while (UseI != UseE && *UseI < Stop);
254 BI.
LiveIn = LVI->start <= Start;
258 assert(LVI->start == LVI->valno->def &&
"Dangling Segment start");
265 while (LVI->end < Stop) {
267 if (++LVI == LVE || LVI->start >= Stop) {
273 if (LastStop < LVI->start) {
280 UseBlocks.push_back(BI);
281 UseBlocks.back().LastInstr = LastStop;
290 assert(LVI->start == LVI->valno->def &&
"Dangling Segment start");
295 UseBlocks.push_back(BI);
303 if (LVI->end == Stop && ++LVI == LVE)
307 if (LVI->start < Stop)
337 }
while (Stop <= LVI->start);
344 assert(!Orig.
empty() &&
"Splitting empty interval?");
348 if (I != Orig.
end() && I->start <= Idx)
349 return I->start == Idx;
352 return I != Orig.
begin() && (--
I)->
end == Idx;
370 : SA(sa), AA(aa),
LIS(lis),
VRM(vrm),
371 MRI(vrm.getMachineFunction().getRegInfo()), MDT(mdt),
372 TII(*vrm.getMachineFunction().getSubtarget().getInstrInfo()),
373 TRI(*vrm.getMachineFunction().getSubtarget().getRegisterInfo()),
395 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 397 if (RegAssign.
empty()) {
398 dbgs() <<
" empty\n";
403 dbgs() <<
" [" <<
I.start() <<
';' <<
I.stop() <<
"):" <<
I.value();
411 if (S.LaneMask == LM)
428 auto &PS = getSubRangeForMask(S.LaneMask, Edit->
getParent());
429 VNInfo *PV = PS.getVNInfoAt(Def);
430 if (PV !=
nullptr && PV->def == Def)
441 unsigned R = DefOp.getReg();
444 if (
unsigned SR = DefOp.getSubReg())
452 if ((S.LaneMask & LM).any())
457 VNInfo *SplitEditor::defValue(
unsigned RegIdx,
461 assert(ParentVNI &&
"Mapping NULL value");
469 bool Force = LI->hasSubRanges();
472 std::pair<ValueMap::iterator, bool> InsP =
473 Values.
insert(std::make_pair(std::make_pair(RegIdx, ParentVNI->
id), FP));
477 if (!Force && InsP.second)
481 if (
VNInfo *OldVNI = InsP.first->second.getPointer()) {
482 addDeadDef(*LI, OldVNI, Original);
490 addDeadDef(*LI, VNI, Original);
494 void SplitEditor::forceRecompute(
unsigned RegIdx,
const VNInfo &ParentVNI) {
513 SlotIndex SplitEditor::buildSingleSubRegCopy(
unsigned FromReg,
unsigned ToReg,
517 bool FirstCopy = !Def.
isValid();
521 .
addReg(FromReg, 0, SubIdx);
538 SlotIndex SplitEditor::buildCopy(
unsigned FromReg,
unsigned ToReg,
558 unsigned BestIdx = 0;
559 unsigned BestCover = 0;
568 if (SubRegMask == LaneMask) {
574 if ((SubRegMask & ~LaneMask).any())
579 if (PopCount > BestCover) {
580 BestCover = PopCount;
589 SlotIndex Def = buildSingleSubRegCopy(FromReg, ToReg, MBB, InsertBefore,
595 while (LanesLeft.
any()) {
596 unsigned BestIdx = 0;
597 int BestCover = std::numeric_limits<int>::min();
598 for (
unsigned Idx : PossibleIndexes) {
601 if (SubRegMask == LanesLeft) {
608 int Cover = (SubRegMask & LanesLeft).getNumLanes()
609 - (SubRegMask & ~LanesLeft).getNumLanes();
610 if (Cover > BestCover) {
619 buildSingleSubRegCopy(FromReg, ToReg, MBB, InsertBefore, BestIdx,
627 VNInfo *SplitEditor::defFromParent(
unsigned RegIdx,
637 bool Late = RegIdx != 0;
645 bool DidRemat =
false;
660 LaneMask |= S.LaneMask;
666 Def = buildCopy(Edit->
getReg(),
Reg, LaneMask, MBB,
I, Late, RegIdx);
670 return defValue(RegIdx, ParentVNI, Def,
false);
680 OpenIdx = Edit->
size();
686 assert(Idx != 0 &&
"Cannot select the complement interval");
687 assert(Idx < Edit->
size() &&
"Can only select previously opened interval");
688 LLVM_DEBUG(
dbgs() <<
" selectIntv " << OpenIdx <<
" -> " << Idx <<
'\n');
693 assert(OpenIdx &&
"openIntv not called before enterIntvBefore");
703 assert(MI &&
"enterIntvBefore called with invalid index");
710 assert(OpenIdx &&
"openIntv not called before enterIntvAfter");
720 assert(MI &&
"enterIntvAfter called with invalid index");
728 assert(OpenIdx &&
"openIntv not called before enterIntvAtEnd");
739 VNInfo *VNI = defFromParent(OpenIdx, ParentVNI, Last, MBB,
741 RegAssign.
insert(VNI->
def, End, OpenIdx);
752 assert(OpenIdx &&
"openIntv not called before useIntv");
753 LLVM_DEBUG(
dbgs() <<
" useIntv [" << Start <<
';' << End <<
"):");
754 RegAssign.
insert(Start, End, OpenIdx);
759 assert(OpenIdx &&
"openIntv not called before leaveIntvAfter");
771 assert(MI &&
"No instruction at index");
779 forceRecompute(0, *ParentVNI);
780 defFromParent(0, ParentVNI, Idx, *MI->
getParent(),
MI);
790 assert(OpenIdx &&
"openIntv not called before leaveIntvBefore");
803 assert(MI &&
"No instruction at index");
809 assert(OpenIdx &&
"openIntv not called before leaveIntvAtTop");
820 VNInfo *VNI = defFromParent(0, ParentVNI, Start, MBB,
822 RegAssign.
insert(Start, VNI->
def, OpenIdx);
828 assert(OpenIdx &&
"openIntv not called before overlapIntv");
831 "Parent changes value in extended range");
833 "Range cannot span basic blocks");
837 forceRecompute(0, *ParentVNI);
838 LLVM_DEBUG(
dbgs() <<
" overlapIntv [" << Start <<
';' << End <<
"):");
839 RegAssign.
insert(Start, End, OpenIdx);
851 AssignI.setMap(RegAssign);
853 for (
unsigned i = 0, e = Copies.
size(); i != e; ++i) {
856 assert(MI &&
"No instruction for back-copy");
861 do AtBegin = MBBI == MBB->
begin();
862 while (!AtBegin && (--MBBI)->isDebugInstr());
872 if (!AssignI.valid() || AssignI.start() >=
Def)
875 if (AssignI.stop() !=
Def)
877 unsigned RegIdx = AssignI.value();
878 if (AtBegin || !MBBI->readsVirtualRegister(Edit->
getReg())) {
879 LLVM_DEBUG(
dbgs() <<
" cannot find simple kill of RegIdx " << RegIdx
885 AssignI.setStop(Kill);
895 assert(MDT.
dominates(DefMBB, MBB) &&
"MBB must be dominated by the def.");
898 const MachineLoop *DefLoop = Loops.getLoopFor(DefMBB);
918 if (Loop == DefLoop) {
921 <<
" in the same loop\n");
927 if (Depth < BestDepth) {
932 <<
" at depth " << Depth <<
'\n');
940 if (!IDom || !MDT.
dominates(DefDomNode, IDom))
947 void SplitEditor::computeRedundantBackCopies(
959 EqualVNs[ParentVNI->
id].insert(VNI);
964 for (
unsigned i = 0, e = Parent->
getNumValNums(); i != e; ++i) {
966 if (!NotToHoistSet.
count(ParentVNI->
id))
970 for (; It1 != EqualVNs[ParentVNI->
id].end(); ++It1) {
972 for (++It2; It2 != EqualVNs[ParentVNI->
id].end(); ++It2) {
973 if (DominatedVNIs.count(*It1) || DominatedVNIs.count(*It2))
979 DominatedVNIs.
insert((*It1)->def < (*It2)->def ? (*It2) : (*It1));
981 DominatedVNIs.
insert(*It2);
983 DominatedVNIs.
insert(*It1);
987 if (!DominatedVNIs.
empty()) {
988 forceRecompute(0, *ParentVNI);
989 for (
auto VNI : DominatedVNIs) {
992 DominatedVNIs.clear();
1002 void SplitEditor::hoistCopies() {
1009 using DomPair = std::pair<MachineBasicBlock *, SlotIndex>;
1023 assert(ParentVNI &&
"Parent not live at complement def");
1032 DomPair &Dom = NearestDom[ParentVNI->
id];
1037 if (VNI->
def == ParentVNI->
def) {
1039 Dom = DomPair(ValMBB, VNI->
def);
1051 Dom = DomPair(ValMBB, VNI->
def);
1052 }
else if (Dom.first == ValMBB) {
1054 if (!Dom.second.isValid() || VNI->
def < Dom.second)
1055 Dom.second = VNI->
def;
1062 Dom = DomPair(ValMBB, VNI->
def);
1063 else if (Near != Dom.first)
1070 << VNI->
def <<
" for parent " << ParentVNI->
id <<
'@' 1071 << ParentVNI->
def <<
" hoist to " 1077 for (
unsigned i = 0, e = Parent->
getNumValNums(); i != e; ++i) {
1078 DomPair &Dom = NearestDom[i];
1079 if (!Dom.first || Dom.second.isValid())
1085 Dom.first = findShallowDominator(Dom.first, DefMBB);
1088 NotToHoistSet.
insert(ParentVNI->
id);
1093 defFromParent(0, ParentVNI, Last, *Dom.first,
1104 const DomPair &Dom = NearestDom[ParentVNI->
id];
1105 if (!Dom.first || Dom.second == VNI->
def ||
1106 NotToHoistSet.count(ParentVNI->
id))
1108 BackCopies.push_back(VNI);
1109 forceRecompute(0, *ParentVNI);
1115 computeRedundantBackCopies(NotToHoistSet, BackCopies);
1117 removeBackCopies(BackCopies);
1122 bool SplitEditor::transferValues() {
1123 bool Skipped =
false;
1127 VNInfo *ParentVNI = S.valno;
1130 AssignI.advanceTo(Start);
1134 if (!AssignI.valid()) {
1136 }
else if (AssignI.start() <= Start) {
1137 RegIdx = AssignI.value();
1138 if (AssignI.stop() < End) {
1139 End = AssignI.stop();
1144 End = std::min(End, AssignI.start());
1148 LLVM_DEBUG(
dbgs() <<
" [" << Start <<
';' << End <<
")=" << RegIdx <<
'(' 1179 if (Start != BlockStart) {
1181 assert(VNI &&
"Missing def for complex mapped value");
1184 if (BlockEnd <= End)
1189 BlockStart = BlockEnd;
1193 assert(Start <= BlockStart &&
"Expected live-in block");
1194 while (BlockStart < End) {
1197 if (BlockStart == ParentVNI->
def) {
1199 assert(ParentVNI->
isPHIDef() &&
"Non-phi defined at block start?");
1201 assert(VNI &&
"Missing def for complex mapped parent PHI");
1202 if (End >= BlockEnd)
1215 BlockStart = BlockEnd;
1219 }
while (Start != S.end);
1252 LiveRange &PSR = !LM.
all() ? getSubRangeForMask(LM, PLI)
1255 LRC.
extend(LR, End, 0, Undefs);
1259 void SplitEditor::extendPHIKillRanges() {
1271 unsigned RegIdx = RegAssign.
lookup(V->
def);
1283 for (
const VNInfo *V : PS.valnos) {
1286 unsigned RegIdx = RegAssign.
lookup(V->
def);
1297 extendPHIRange(B, SubLRC, S, PS.
LaneMask, Undefs);
1303 void SplitEditor::rewriteAssigned(
bool ExtendRanges) {
1306 : MO(O), RegIdx(R), Next(N) {}
1316 RE =
MRI.reg_end(); RI != RE;) {
1330 SlotIndex Idx = LIS.getInstructionIndex(*MI);
1335 unsigned RegIdx = RegAssign.lookup(Idx);
1339 <<
'\t' << Idx <<
':' << RegIdx <<
'\t' << *MI);
1342 if (!ExtendRanges || MO.
isUndef())
1352 if (!Edit->getParent().liveAt(Idx))
1364 ExtPoints.
push_back(ExtPoint(MO, RegIdx, Next));
1371 for (ExtPoint &EP : ExtPoints) {
1372 LiveInterval &LI = LIS.getInterval(Edit->get(EP.RegIdx));
1376 unsigned Reg = EP.MO.getReg(), Sub = EP.MO.getSubReg();
1378 :
MRI.getMaxLaneMaskForVReg(Reg);
1380 if ((S.LaneMask & LM).none())
1389 SubLRC.reset(&VRM.getMachineFunction(), LIS.getSlotIndexes(), &MDT,
1390 &LIS.getVNInfoAllocator());
1393 SubLRC.extend(S, EP.Next, 0, Undefs);
1397 for (
unsigned R : *Edit) {
1403 LIS.constructMainRangeFromSubranges(LI);
1407 void SplitEditor::deleteRematVictims() {
1418 assert(MI &&
"Missing instruction for dead def");
1432 Edit->eliminateDeadDefs(Dead,
None, &AA);
1435 void SplitEditor::forceRecomputeVNI(
const VNInfo &ParentVNI) {
1438 for (
unsigned I = 0,
E = Edit->size(); I !=
E; ++
I)
1439 forceRecompute(I, ParentVNI);
1446 Visited.
insert(&ParentVNI);
1450 const SlotIndexes &Indexes = *LIS.getSlotIndexes();
1454 for (
unsigned I = 0,
E = Edit->size(); I !=
E; ++
I)
1455 forceRecompute(I, VNI);
1463 assert(PredVNI &&
"Value available in PhiVNI predecessor");
1464 if (Visited.
insert(PredVNI).second)
1467 }
while(!WorkList.
empty());
1477 for (
const VNInfo *ParentVNI : Edit->getParent().valnos) {
1480 unsigned RegIdx = RegAssign.lookup(ParentVNI->
def);
1481 defValue(RegIdx, ParentVNI, ParentVNI->
def,
true);
1485 if (Edit->didRematerialize(ParentVNI))
1486 forceRecomputeVNI(*ParentVNI);
1490 switch (SpillMode) {
1501 bool Skipped = transferValues();
1504 rewriteAssigned(Skipped);
1507 extendPHIKillRanges();
1513 deleteRematVictims();
1516 for (
unsigned Reg : *Edit) {
1525 for (
unsigned i = 0, e = Edit->size(); i != e; ++i)
1531 for (
unsigned i = 0, e = Edit->size(); i != e; ++i) {
1533 unsigned VReg = Edit->get(i);
1536 LIS.splitSeparateComponents(LI, SplitLIs);
1537 unsigned Original = VRM.getOriginal(VReg);
1539 VRM.setIsSplitFromReg(SplitLI->reg, Original);
1543 LRMap->
resize(Edit->size(), i);
1547 Edit->calculateRegClassAndHint(VRM.getMachineFunction(), SA.Loops, MBFI);
1549 assert(!LRMap || LRMap->
size() == Edit->size());
1557 bool SingleInstrs)
const {
1568 if (LIS.getInstructionFromIndex(BI.
FirstInstr)->isCopyLike())
1602 unsigned IntvOut,
SlotIndex EnterAfter){
1604 std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(MBBNum);
1606 LLVM_DEBUG(
dbgs() <<
"%bb." << MBBNum <<
" [" << Start <<
';' << Stop
1607 <<
") intf " << LeaveBefore <<
'-' << EnterAfter
1608 <<
", live-through " << IntvIn <<
" -> " << IntvOut);
1610 assert((IntvIn || IntvOut) &&
"Use splitSingleBlock for isolated blocks");
1612 assert((!LeaveBefore || LeaveBefore < Stop) &&
"Interference after block");
1613 assert((!IntvIn || !LeaveBefore || LeaveBefore > Start) &&
"Impossible intf");
1614 assert((!EnterAfter || EnterAfter >= Start) &&
"Interference before block");
1627 assert((!LeaveBefore || Idx <= LeaveBefore) &&
"Interference");
1641 assert((!EnterAfter || Idx >= EnterAfter) &&
"Interference");
1646 if (IntvIn == IntvOut && !LeaveBefore && !EnterAfter) {
1658 SlotIndex LSP = SA.getLastSplitPoint(MBBNum);
1659 assert((!IntvOut || !EnterAfter || EnterAfter < LSP) &&
"Impossible intf");
1661 if (IntvIn != IntvOut && (!LeaveBefore || !EnterAfter ||
1671 if (LeaveBefore && LeaveBefore < LSP) {
1679 assert((!LeaveBefore || Idx <= LeaveBefore) &&
"Interference");
1680 assert((!EnterAfter || Idx >= EnterAfter) &&
"Interference");
1690 assert(LeaveBefore <= EnterAfter &&
"Missed case");
1695 assert((!EnterAfter || Idx >= EnterAfter) &&
"Interference");
1700 assert((!LeaveBefore || Idx <= LeaveBefore) &&
"Interference");
1704 unsigned IntvIn,
SlotIndex LeaveBefore) {
1706 std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(BI.
MBB);
1709 << Stop <<
"), uses " << BI.
FirstInstr <<
'-' 1710 << BI.
LastInstr <<
", reg-in " << IntvIn
1711 <<
", leave before " << LeaveBefore
1712 << (BI.
LiveOut ?
", stack-out" :
", killed in block"));
1714 assert(IntvIn &&
"Must have register in");
1716 assert((!LeaveBefore || LeaveBefore > Start) &&
"Bad interference");
1744 LLVM_DEBUG(
dbgs() <<
", spill after last use before interference.\n");
1748 assert((!LeaveBefore || Idx <= LeaveBefore) &&
"Interference");
1755 assert((!LeaveBefore || Idx <= LeaveBefore) &&
"Interference");
1765 LLVM_DEBUG(
dbgs() <<
", creating local interval " << LocalIntv <<
".\n");
1778 assert((!LeaveBefore || From <= LeaveBefore) &&
"Interference");
1793 assert((!LeaveBefore || From <= LeaveBefore) &&
"Interference");
1797 unsigned IntvOut,
SlotIndex EnterAfter) {
1799 std::tie(Start, Stop) = LIS.getSlotIndexes()->getMBBRange(BI.
MBB);
1802 << Stop <<
"), uses " << BI.
FirstInstr <<
'-' 1803 << BI.
LastInstr <<
", reg-out " << IntvOut
1804 <<
", enter after " << EnterAfter
1805 << (BI.
LiveIn ?
", stack-in" :
", defined in block"));
1809 assert(IntvOut &&
"Must have register out");
1811 assert((!EnterAfter || EnterAfter < LSP) &&
"Bad interference");
1835 assert((!EnterAfter || Idx >= EnterAfter) &&
"Interference");
1851 assert((!EnterAfter || Idx >= EnterAfter) &&
"Interference");
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
void RenumberValues()
RenumberValues - Renumber all values in order of appearance and remove unused values.
unsigned getNumLanes() const
void bundleWithPred()
Bundle this instruction with its predecessor.
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
const_iterator end(StringRef path)
Get end iterator over path.
void setInt(IntType IntVal)
A common definition of LaneBitmask for use in TableGen and CodeGen.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
typename SuperClass::const_iterator const_iterator
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
SlotIndex def
The index of the defining instruction.
void RemoveMachineInstrFromMaps(MachineInstr &MI)
LaneBitmask getMaxLaneMaskForVReg(unsigned Reg) const
Returns a mask covering all bits that can appear in lane masks of subregisters of the virtual registe...
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
bool anyRematerializable(AliasAnalysis *)
anyRematerializable - Return true if any parent values may be rematerializable.
PointerTy getPointer() const
void reset(LiveRangeEdit &, ComplementSpillMode=SM_Partition)
reset - Prepare for a new split.
void dump() const
dump - print the current interval mapping to dbgs().
bool addRegisterDead(unsigned Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
void setLiveOutValue(MachineBasicBlock *MBB, VNInfo *VNI)
setLiveOutValue - Indicate that VNI is live out from MBB.
Segments::iterator iterator
unsigned getLoopDepth() const
Return the nesting level of this loop.
void push_back(const T &Elt)
LiveInterval - This class represents the liveness of a register, or stack slot.
iterator_range< use_nodbg_iterator > use_nodbg_operands(unsigned Reg) const
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
Describe properties that are true of each instruction in the target description file.
SM_Speed - Overlap intervals to minimize the expected execution frequency of the inserted copies...
iterator advanceTo(iterator I, SlotIndex Pos)
advanceTo - Advance the specified iterator to point to the Segment containing the specified position...
unsigned getSubReg() const
SlotIndex FirstDef
First non-phi valno->def, or SlotIndex().
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
const MachineLoopInfo & Loops
ComplementSpillMode
ComplementSpillMode - Select how the complement live range should be created.
A live range for subregisters.
bool isValid() const
Returns true if this is a valid index.
This represents a simple continuous liveness interval for a value.
unsigned getInternalReadRegState(bool B)
STATISTIC(NumFunctions, "Total number of functions")
SplitAnalysis(const VirtRegMap &vrm, const LiveIntervals &lis, const MachineLoopInfo &mli)
unsigned const TargetRegisterInfo * TRI
bool didRematerialize(const VNInfo *ParentVNI) const
didRematerialize - Return true if ParentVNI was rematerialized anywhere.
friend class const_iterator
SlotIndex enterIntvAtEnd(MachineBasicBlock &MBB)
enterIntvAtEnd - Enter the open interval at the end of MBB.
VNInfo - Value Number Information.
void splitRegInBlock(const SplitAnalysis::BlockInfo &BI, unsigned IntvIn, SlotIndex LeaveBefore)
splitRegInBlock - Split CurLI in the given block such that it enters the block in IntvIn and leaves i...
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
const_iterator begin() const
iterator_range< succ_iterator > successors()
This class represents the liveness of a register, stack slot, etc.
bool isUnused() const
Returns true if this value is unused.
unsigned getNumLiveBlocks() const
getNumLiveBlocks - Return the number of blocks where CurLI is live.
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
isEarlierInstr - Return true if A refers to an instruction earlier than B.
bool isEarlyClobber() const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
void analyze(const LiveInterval *li)
analyze - set CurLI to the specified interval, and analyze how it may be split.
void removeEmptySubRanges()
Removes all subranges without any segments (subranges without segments are not considered valid and s...
void clear()
clear - Removes all bits from the bitvector. Does not change capacity.
MachineFunction & getMachineFunction() const
void splitSingleBlock(const SplitAnalysis::BlockInfo &BI)
splitSingleBlock - Split CurLI into a separate live interval around the uses in a single block...
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
const HexagonInstrInfo * TII
const TargetInstrInfo & TII
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
bool isLiveInToMBB(const LiveRange &LR, const MachineBasicBlock *mbb) const
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.
SlotIndex getLastInsertPoint(const LiveInterval &CurLI, const MachineBasicBlock &MBB)
Return the base index of the last valid insert point for in .
VNInfo::Allocator & getVNInfoAllocator()
iterator_range< subrange_iterator > subranges()
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
static constexpr LaneBitmask getAll()
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
bool hasSubRanges() const
Returns true if subregister liveness information is available.
virtual const TargetRegisterClass * getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const
Returns the largest legal sub-class of RC that supports the sub-register index Idx.
void overlapIntv(SlotIndex Start, SlotIndex End)
overlapIntv - Indicate that all instructions in range should use the open interval, but also let the complement interval be live.
ValT lookup(KeyT x, ValT NotFound=ValT()) const
lookup - Return the mapped value at x or NotFound.
static constexpr LaneBitmask getNone()
unsigned openIntv()
Create a new virtual register and live interval.
BlockT * getHeader() const
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
SlotIndex leaveIntvAfter(SlotIndex Idx)
leaveIntvAfter - Leave the open interval after the instruction at Idx.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
void addLiveInBlock(LiveRange &LR, MachineDomTreeNode *DomNode, SlotIndex Kill=SlotIndex())
addLiveInBlock - Add a block with an unknown live-in value.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
bool canRematerializeAt(Remat &RM, VNInfo *OrigVNI, SlotIndex UseIdx, bool cheapAsAMove)
canRematerializeAt - Determine if ParentVNI can be rematerialized at UseIdx.
Base class for the actual dominator tree node.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void clear()
clear - Remove all entries.
SlotIndex getNextSlot() const
Returns the next slot in the index list.
void extend(LiveRange &LR, SlotIndex Use, unsigned PhysReg, ArrayRef< SlotIndex > Undefs)
Extend the live range of LR to reach Use.
const LiveIntervals & LIS
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
void finish(SmallVectorImpl< unsigned > *LRMap=nullptr)
finish - after all the new live ranges have been created, compute the remaining live range...
MachineBasicBlock * findNearestCommonDominator(MachineBasicBlock *A, MachineBasicBlock *B)
findNearestCommonDominator - Find nearest common dominator basic block for basic block A and B...
unsigned getUndefRegState(bool B)
VNInfo * createDeadDef(SlotIndex Def, VNInfo::Allocator &VNIAlloc)
createDeadDef - Make sure the range has a value defined at Def.
bool allDefsAreDead() const
Return true if all the defs of this instruction are dead.
SlotIndex LastInstr
Last instr accessing current reg.
MachineBasicBlock::iterator getLastInsertPointIter(const LiveInterval &CurLI, MachineBasicBlock &MBB)
Returns the last insert point as an iterator for in .
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void useIntv(const MachineBasicBlock &MBB)
useIntv - indicate that all instructions in MBB should use OpenLI.
unsigned const MachineRegisterInfo * MRI
PointerIntPair - This class implements a pair of a pointer and small integer.
Allocate memory in an ever growing pool, as if by bump-pointer.
bool readsVirtualRegister(unsigned Reg) const
Return true if the MachineInstr reads the specified virtual register.
bool liveAt(SlotIndex index) const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
SM_Partition(Default) - Try to create the complement interval so it doesn't overlap any other interva...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SM_Size - Overlap intervals to minimize the number of inserted COPY instructions. ...
BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const
getblockFreq - Return block frequency.
iterator_range< mop_iterator > defs()
Returns a range over all explicit operands that are register definitions.
self_iterator getIterator()
constexpr bool all() const
iterator_range< pred_iterator > predecessors()
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
SlotIndex leaveIntvAtTop(MachineBasicBlock &MBB)
leaveIntvAtTop - Leave the interval at the top of MBB.
void refineSubRanges(BumpPtrAllocator &Allocator, LaneBitmask LaneMask, std::function< void(LiveInterval::SubRange &)> Apply)
Refines the subranges to support LaneMask.
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Return the first index in the given basic block.
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
void selectIntv(unsigned Idx)
selectIntv - Select a previously opened interval index.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void insert(KeyT a, KeyT b, ValT y)
insert - Add a mapping of [a;b] to y, coalesce with adjacent intervals.
void splitRegOutBlock(const SplitAnalysis::BlockInfo &BI, unsigned IntvOut, SlotIndex EnterAfter)
splitRegOutBlock - Split CurLI in the given block such that it enters the block on the stack (or isn'...
MachineBasicBlock::iterator getLastSplitPointIter(MachineBasicBlock *BB)
iterator find(SlotIndex Pos)
find - Return an iterator pointing to the first segment that ends after Pos, or end().
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
unsigned id
The ID number of this value.
void removeSegment(SlotIndex Start, SlotIndex End, bool RemoveDeadValNo=false)
Remove the specified segment from this range.
LiveInterval & getParent() const
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
BlockVerifier::State From
void reset(const MachineFunction *mf, SlotIndexes *SI, MachineDominatorTree *MDT, VNInfo::Allocator *VNIA)
reset - Prepare caches for a new set of non-overlapping live ranges.
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
const MachineFunction & MF
Segments::const_iterator const_iterator
SlotIndex FirstInstr
First instr accessing current reg.
SlotIndex leaveIntvBefore(SlotIndex Idx)
leaveIntvBefore - Leave the open interval before the instruction at Idx.
bool isDebugValue() const
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
MachineInstrBuilder MachineInstrBuilder & DefMI
Additional information about basic blocks where the current variable is live.
SplitAnalysis - Analyze a LiveInterval, looking for live range splitting opportunities.
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx. ...
LiveInterval & getInterval(unsigned Reg)
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...
void computeSubRangeUndefs(SmallVectorImpl< SlotIndex > &Undefs, LaneBitmask LaneMask, const MachineRegisterInfo &MRI, const SlotIndexes &Indexes) const
For a given lane mask LaneMask, compute indexes at which the lane is marked undefined by subregister ...
bool shouldSplitSingleBlock(const BlockInfo &BI, bool SingleInstrs) const
shouldSplitSingleBlock - Returns true if it would help to create a local live range for the instructi...
bool empty() const
empty - Return true when no intervals are mapped.
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
bool LiveOut
Current reg is live out.
iterator insert(iterator I, T &&Elt)
VNInfo * getValNumInfo(unsigned ValNo)
getValNumInfo - Returns pointer to the specified val#.
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.
unsigned getNumValNums() const
void clear()
clear - clear all data structures so SplitAnalysis is ready to analyze a new interval.
Representation of each machine instruction.
void splitLiveThroughBlock(unsigned MBBNum, unsigned IntvIn, SlotIndex LeaveBefore, unsigned IntvOut, SlotIndex EnterAfter)
splitLiveThroughBlock - Split CurLI in the given block such that it enters the block in IntvIn and le...
InsertPointAnalysis(const LiveIntervals &lis, unsigned BBNum)
SlotIndex rematerializeAt(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, unsigned DestReg, const Remat &RM, const TargetRegisterInfo &, bool Late=false)
rematerializeAt - Rematerialize RM.ParentVNI into DestReg by inserting an instruction into MBB before...
SmallVectorImpl< unsigned >::const_iterator iterator
Iterator for accessing the new registers added by this edit.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
LLVM_NODISCARD bool empty() const
Represents a single loop in the control flow graph.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
void setReg(unsigned Reg)
Change the register this operand corresponds to.
SlotIndex enterIntvBefore(SlotIndex Idx)
enterIntvBefore - Enter the open interval before the instruction at Idx.
constexpr bool any() const
unsigned getNumSubRegIndices() const
Return the number of sub-register indices understood by the target.
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
static bool removeDeadSegment(SlotIndex Def, LiveRange &LR)
SlotIndexes * getSlotIndexes() const
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Remat - Information needed to rematerialize at a specific location.
bool isOriginalEndpoint(SlotIndex Idx) const
isOriginalEndpoint - Return true if the original live range was killed or (re-)defined at Idx...
const Segment * getSegmentContaining(SlotIndex Idx) const
Return the segment that contains the specified index, or null if there is none.
const std::pair< SlotIndex, SlotIndex > & getMBBRange(unsigned Num) const
Return the (start,end) range of the given basic block number.
unsigned countLiveBlocks(const LiveInterval *li) const
countLiveBlocks - Return the number of blocks where li is live.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::pair< VNInfo *, bool > extendInBlock(ArrayRef< SlotIndex > Undefs, SlotIndex StartIdx, SlotIndex Kill)
Attempt to extend a value defined after StartIdx to include Use.
bool isOneInstr() const
isOneInstr - Returns true when this BlockInfo describes a single instruction.
SplitEditor(SplitAnalysis &sa, AliasAnalysis &aa, LiveIntervals &lis, VirtRegMap &vrm, MachineDominatorTree &mdt, MachineBlockFrequencyInfo &mbfi)
Create a new SplitEditor for editing the LiveInterval analyzed by SA.
LiveInterval & createEmptyInterval()
create - Create a new register with the same class and original slot as parent.
iterator SkipPHIsLabelsAndDebug(iterator I)
Return the first instruction in MBB after I that is not a PHI, label or debug.
SlotIndex enterIntvAfter(SlotIndex Idx)
enterIntvAfter - Enter the open interval after the instruction at Idx.
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
bool LiveIn
Current reg is live in.
SlotIndex - An opaque wrapper around machine indexes.
reg_begin/reg_end - Provide iteration support to walk over all definitions and uses of a register wit...
unsigned getOriginal(unsigned VirtReg) const
getOriginal - Return the original virtual register that VirtReg descends from through splitting...
void calculateValues()
calculateValues - Calculate the value that will be live-in to each block added with addLiveInBlock...
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
unsigned get(unsigned idx) const
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
void removeVRegDefAt(LiveInterval &LI, SlotIndex Pos)
Remove value number and related live segments of LI and its subranges that start at position Pos...