58 #define DEBUG_TYPE "regalloc"
63 "Live Interval Analysis",
false,
false)
73 cl::desc(
"Eagerly compute live intervals for all physreg units."));
83 "Use segment set for the computation of the live ranges of physregs."));
110 for (
unsigned i = 0, e = VirtRegIntervals.size(); i != e; ++i)
112 VirtRegIntervals.clear();
113 RegMaskSlots.clear();
115 RegMaskBlocks.
clear();
119 RegUnitRanges.clear();
122 VNInfoAllocator.
Reset();
130 AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
131 Indexes = &getAnalysis<SlotIndexes>();
132 DomTree = &getAnalysis<MachineDominatorTree>();
142 computeLiveInRegUnits();
155 OS <<
"********** INTERVALS **********\n";
158 for (
unsigned Unit = 0, UnitE = RegUnitRanges.size();
Unit != UnitE; ++
Unit)
177 void LiveIntervals::printInstrs(
raw_ostream &OS)
const {
178 OS <<
"********** MACHINEINSTRS **********\n";
179 MF->
print(OS, Indexes);
182 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
188 LiveInterval* LiveIntervals::createInterval(
unsigned reg) {
194 void LiveIntervals::computeVirtRegInterval(
LiveInterval &LI) {
195 assert(LRCalc &&
"LRCalc not initialized.");
196 assert(LI.
empty() &&
"Should only compute empty intervals.");
199 computeDeadValues(LI,
nullptr);
202 void LiveIntervals::computeVirtRegs() {
211 void LiveIntervals::computeRegMasks() {
216 std::pair<unsigned, unsigned> &RMB = RegMaskBlocks[MBB.getNumber()];
217 RMB.first = RegMaskSlots.size();
220 if (
const uint32_t *
Mask = MBB.getBeginClobberMask(TRI)) {
237 if (
const uint32_t *
Mask = MBB.getEndClobberMask(TRI)) {
238 assert(!MBB.empty() &&
"empty return block?");
239 RegMaskSlots.push_back(
245 RMB.second = RegMaskSlots.size() - RMB.first;
263 void LiveIntervals::computeRegUnitRange(
LiveRange &LR,
unsigned Unit) {
264 assert(LRCalc &&
"LRCalc not initialized.");
272 bool IsReserved =
true;
276 unsigned Reg = *Super;
292 unsigned Reg = *Super;
294 LRCalc->extendToUses(LR, Reg);
307 void LiveIntervals::computeLiveInRegUnits() {
309 DEBUG(
dbgs() <<
"Computing live-in reg-units in ABI blocks.\n");
317 if ((&MBB != &MF->front() && !MBB.isEHPad()) || MBB.livein_empty())
322 DEBUG(
dbgs() << Begin <<
"\tBB#" << MBB.getNumber());
323 for (
const auto &LI : MBB.liveins()) {
325 unsigned Unit = *Units;
339 DEBUG(
dbgs() <<
"Created " << NewRanges.
size() <<
" new intervals.\n");
342 for (
unsigned Unit : NewRanges)
343 computeRegUnitRange(*RegUnitRanges[Unit], Unit);
348 for (
VNInfo *VNI : VNIs) {
367 while (!WorkList.
empty()) {
376 assert(ExtVNI == VNI &&
"Unexpected existing value number");
380 !UsedPHIs.
insert(VNI).second)
384 if (!LiveOut.
insert(Pred).second)
389 WorkList.
push_back(std::make_pair(Stop, PVNI));
395 DEBUG(
dbgs() <<
" live-in at " << BlockStart <<
'\n');
400 if (!LiveOut.
insert(Pred).second)
404 "Wrong value out of predecessor");
405 WorkList.
push_back(std::make_pair(Stop, VNI));
412 DEBUG(
dbgs() <<
"Shrink: " << *li <<
'\n');
414 &&
"Can only shrink virtual registers");
417 bool NeedsCleanup =
false;
430 unsigned Reg = li->
reg;
432 if (
UseMI.isDebugValue() || !
UseMI.readsVirtualRegister(Reg))
442 <<
"Warning: Instr claims to read non-existent value in "
451 WorkList.
push_back(std::make_pair(Idx, VNI));
463 bool CanSeparate = computeDeadValues(*li, dead);
464 DEBUG(
dbgs() <<
"Shrunk: " << *li <<
'\n');
470 bool MayHaveSplitComponents =
false;
476 assert(I != LI.
end() &&
"Missing segment for VNI");
480 unsigned VReg = LI.
reg;
494 DEBUG(
dbgs() <<
"Dead PHI at " << Def <<
" may separate interval\n");
495 MayHaveSplitComponents =
true;
499 assert(MI &&
"No instruction defining live value");
502 DEBUG(
dbgs() <<
"All defs dead: " << Def <<
'\t' << *MI);
507 return MayHaveSplitComponents;
511 DEBUG(
dbgs() <<
"Shrink: " << SR <<
'\n');
513 &&
"Can only shrink virtual registers");
524 unsigned SubReg = MO.getSubReg();
527 if ((LaneMask & SR.
LaneMask).none())
549 WorkList.
push_back(std::make_pair(Idx, VNI));
565 assert(Segment !=
nullptr &&
"Missing segment for VNI");
570 DEBUG(
dbgs() <<
"Dead PHI at " << VNI->
def <<
" may separate interval\n");
576 DEBUG(
dbgs() <<
"Shrunk: " << SR <<
'\n');
582 assert(LRCalc &&
"LRCalc not initialized.");
585 LRCalc->
extend(LR, Idx, 0, Undefs);
607 if (EndPoints) EndPoints->
push_back(MBBEnd);
622 std::tie(MBBStart, MBBEnd) = Indexes->
getMBBRange(MBB);
640 if (EndPoints) EndPoints->
push_back(MBBEnd);
678 for (
const LiveInterval::SubRange &SR : LI.
subranges()) {
679 SRs.push_back(std::make_pair(&SR, SR.find(LI.
begin()->end)));
688 if (RI->end.isBlock())
702 for (
auto &RUP : RU) {
704 LiveRange::const_iterator &I = RUP.second;
705 if (I == RURange.
end())
708 if (I == RURange.
end() || I->start >= RI->end)
730 for (
auto &SRP : SRs) {
731 const LiveInterval::SubRange &SR = *SRP.first;
732 LiveRange::const_iterator &I = SRP.second;
736 if (I == SR.
end() || I->start >= RI->end)
744 bool IsFullWrite =
false;
746 if (!MO.isReg() || MO.getReg() !=
Reg)
751 if ((UseMask & ~DefinedLanesMask).any())
753 }
else if (MO.getSubReg() == 0) {
766 LiveRange::const_iterator
N = std::next(RI);
767 if (N != LI.
end() && N->start == RI->end)
801 return MBB1 == MBB2 ? MBB1 :
nullptr;
865 std::lower_bound(Slots.
begin(), Slots.
end(), LiveI->start);
874 assert(*SlotI >= LiveI->start);
876 while (*SlotI < LiveI->
end) {
886 if (++SlotI == SlotE)
894 while (*SlotI < LiveI->start)
895 if (++SlotI == SlotE)
919 : LIS(LIS), MRI(MRI), TRI(TRI), OldIdx(OldIdx), NewIdx(NewIdx),
920 UpdateFlags(UpdateFlags) {}
928 return &LIS.getRegUnit(Unit);
929 return LIS.getCachedRegUnit(Unit);
935 DEBUG(
dbgs() <<
"handleMove " << OldIdx <<
" -> " << NewIdx <<
": " << *MI);
936 bool hasRegMask =
false;
950 unsigned Reg = MO.getReg();
956 unsigned SubReg = MO.getSubReg();
957 LaneBitmask LaneMask = SubReg ? TRI.getSubRegIndexLaneMask(SubReg)
958 :
MRI.getMaxLaneMaskForVReg(Reg);
960 if ((S.LaneMask & LaneMask).none())
962 updateRange(S, Reg, S.LaneMask);
976 updateRegMaskSlots();
983 if (!Updated.insert(&LR).second)
994 dbgs() <<
":\t" << LR <<
'\n';
999 handleMoveUp(LR, Reg, LaneMask);
1000 DEBUG(
dbgs() <<
" -->\t" << LR <<
'\n');
1024 if (
MachineInstr *KillMI = LIS.getInstructionFromIndex(OldIdxIn->end))
1026 if (MO->isReg() && MO->isUse())
1027 MO->setIsKill(
false);
1036 LR.
advanceTo(Next, NewIdx.getBaseIndex());
1038 if (NewIdxIn == E ||
1041 Prev->end = NewIdx.getRegSlot();
1044 OldIdxIn->end = Next->start;
1051 OldIdxIn->end = NewIdx.getRegSlot(OldIdxIn->end.isEarlyClobber());
1061 OldIdxOut = OldIdxIn;
1068 VNInfo *OldIdxVNI = OldIdxOut->valno;
1069 assert(OldIdxVNI->
def == OldIdxOut->start &&
"Inconsistent def");
1075 OldIdxVNI->
def = NewIdxDef;
1076 OldIdxOut->start = OldIdxVNI->
def;
1085 = LR.
advanceTo(OldIdxOut, NewIdx.getRegSlot());
1086 bool OldIdxDefIsDead = OldIdxOut->end.isDead();
1087 if (!OldIdxDefIsDead &&
1091 if (OldIdxOut != LR.
begin() &&
1093 OldIdxOut->start)) {
1098 IPrev->end = OldIdxOut->end;
1102 assert(INext != E &&
"Must have following segment");
1108 INext->start = OldIdxOut->end;
1109 INext->valno->
def = INext->start;
1112 if (AfterNewIdx == E) {
1117 std::copy(std::next(OldIdxOut), E, OldIdxOut);
1122 DefVNI->
def = NewIdxDef;
1125 Prev->end = NewIdxDef;
1131 std::copy(std::next(OldIdxOut), std::next(AfterNewIdx), OldIdxOut);
1139 Prev->valno->def = NewIdxDef;
1142 DefVNI->
def = Prev->start;
1147 DefVNI->
def = NewIdxDef;
1148 assert(DefVNI != AfterNewIdx->valno);
1154 if (AfterNewIdx != E &&
1158 assert(AfterNewIdx->valno != OldIdxVNI &&
"Multiple defs of value?");
1166 assert(AfterNewIdx != OldIdxOut &&
"Inconsistent iterators");
1167 std::copy(std::next(OldIdxOut), AfterNewIdx, OldIdxOut);
1170 VNInfo *NewSegmentVNI = OldIdxVNI;
1171 NewSegmentVNI->
def = NewIdxDef;
1201 =
std::max(OldIdxIn->start.getDeadSlot(),
1202 NewIdx.getRegSlot(OldIdxIn->end.isEarlyClobber()));
1203 OldIdxIn->end = findLastUseBefore(DefBeforeOldIdx, Reg, LaneMask);
1206 OldIdxOut = std::next(OldIdxIn);
1210 OldIdxOut = OldIdxIn;
1211 OldIdxIn = OldIdxOut != LR.
begin() ? std::prev(OldIdxOut) : E;
1218 VNInfo *OldIdxVNI = OldIdxOut->valno;
1219 assert(OldIdxVNI->
def == OldIdxOut->start &&
"Inconsistent def");
1220 bool OldIdxDefIsDead = OldIdxOut->end.isDead();
1226 assert(NewIdxOut->valno != OldIdxVNI &&
1227 "Same value defined more than once?");
1229 if (!OldIdxDefIsDead) {
1232 OldIdxVNI->
def = NewIdxDef;
1233 OldIdxOut->start = NewIdxDef;
1242 if (!OldIdxDefIsDead) {
1244 if (OldIdxIn != E &&
1248 assert(NewIdxIn == LR.
find(NewIdx.getBaseIndex()));
1250 OldIdxVNI = OldIdxIn->valno;
1253 OldIdxOut->valno->
def = OldIdxIn->start;
1260 std::copy_backward(NewIdxIn, OldIdxIn, OldIdxOut);
1270 Next->valno->def = SplitPos;
1275 NewSegment->valno->def = SplitPos;
1279 OldIdxOut->start = NewIdxDef;
1280 OldIdxVNI->
def = NewIdxDef;
1290 std::copy_backward(NewIdxOut, OldIdxOut, std::next(OldIdxOut));
1293 VNInfo *NewSegmentVNI = OldIdxVNI;
1296 NewSegmentVNI->
def = NewIdxDef;
1301 void updateRegMaskSlots() {
1303 std::lower_bound(LIS.RegMaskSlots.begin(), LIS.RegMaskSlots.end(),
1305 assert(RI != LIS.RegMaskSlots.
end() && *RI == OldIdx.getRegSlot() &&
1306 "No RegMask at OldIdx.");
1307 *RI = NewIdx.getRegSlot();
1308 assert((RI == LIS.RegMaskSlots.begin() ||
1310 "Cannot move regmask instruction above another call");
1311 assert((std::next(RI) == LIS.RegMaskSlots.end() ||
1313 "Cannot move regmask instruction below another call");
1324 unsigned SubReg = MO.getSubReg();
1325 if (SubReg != 0 && LaneMask.
any()
1326 && (TRI.getSubRegIndexLaneMask(SubReg) & LaneMask).none())
1330 SlotIndex InstSlot = LIS.getSlotIndexes()->getInstructionIndex(MI);
1331 if (InstSlot > LastUse && InstSlot < OldIdx)
1339 assert(Before < OldIdx &&
"Expected upwards move");
1352 while (MII != Begin) {
1353 if ((--MII)->isDebugValue())
1363 if (MO->isReg() && !MO->isUndef() &&
1365 TRI.hasRegUnit(MO->getReg(),
Reg))
1380 "Cannot handle moves across basic block boundaries.");
1382 HMEditor HME(*
this, *MRI, *TRI, OldIndex, NewIndex, UpdateFlags);
1391 HMEditor HME(*
this, *MRI, *TRI, OldIndex, NewIndex, UpdateFlags);
1402 if (LII == LR.
begin()) {
1407 if (LII != LR.
end() && LII->start < endIdx)
1408 lastUseIdx = LII->end;
1433 if ((Mask & LaneMask).none())
1437 if (!isStartValid) {
1438 if (LII->end.isDead()) {
1440 if (LII != LR.
begin())
1441 prevStart = std::prev(LII)->start;
1447 LII = LR.
find(prevStart);
1466 }
else if (LII->start != instrIdx.
getRegSlot()) {
1476 }
else if (MO.
isUse()) {
1480 if (!isEndValid && !LII->end.isBlock())
1498 while (End != MBB->
end() && !Indexes->
hasIndex(*End))
1502 if (End == MBB->
end())
1516 MOI != MOE; ++MOI) {
1525 for (
unsigned Reg : OrigRegs) {
1535 repairOldRegInRange(Begin, End, endIdx, S, Reg, S.LaneMask);
1537 repairOldRegInRange(Begin, End, endIdx, LI, Reg);
1553 if (VNI !=
nullptr) {
1560 if (
VNInfo *SVNI = S.getVNInfoAt(Pos))
1562 S.removeValNo(SVNI);
1570 unsigned NumComp = ConEQ.
Classify(LI);
1573 DEBUG(
dbgs() <<
" Split " << NumComp <<
" components: " << LI <<
'\n');
1574 unsigned Reg = LI.
reg;
1576 for (
unsigned I = 1; I < NumComp; ++
I) {
1585 assert(LRCalc &&
"LRCalc not initialized.");
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
mop_iterator operands_end()
bool isValid() const
Check if the iterator is at the end of the list.
A common definition of LaneBitmask for use in TableGen and CodeGen.
const Segment * getSegmentContaining(SlotIndex Idx) const
Return the segment that contains the specified index, or null if there is none.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
ArrayRef< SlotIndex > getRegMaskSlots() const
Returns a sorted array of slot indices of all instructions with register mask operands.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
SlotIndex getInstructionIndex(const MachineInstr &MI) const
Returns the base index for the given instruction.
cl::opt< bool > UseSegmentSetForPhysRegs
SlotIndex def
The index of the defining instruction.
void createDeadDefs(LiveRange &LR, unsigned Reg)
createDeadDefs - Create a dead def in LI for every def operand of Reg.
void updateAllRanges(MachineInstr *MI)
Update all live ranges touched by MI, assuming a move from OldIdx to NewIdx.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
void removePhysRegDefAt(unsigned Reg, SlotIndex Pos)
Remove value numbers and related live segments starting at position Pos that are part of any liverang...
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
A Module instance is used to store all the information related to an LLVM module. ...
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
void setRegisterDefReadUndef(unsigned Reg, bool IsUndef=true)
Mark all subregister defs of register Reg with the undef flag.
bool addRegisterDead(unsigned Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
bool runOnMachineFunction(MachineFunction &) override
Pass entry point; Calculates LiveIntervals.
Interval Class - An Interval is a set of nodes defined such that every node in the interval has all o...
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Segments::iterator iterator
static LaneBitmask getAll()
char & MachineDominatorsID
MachineDominators - This pass is a machine dominators analysis pass.
LiveInterval - This class represents the liveness of a register, or stack slot.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
MIBundleOperands - Iterate over all operands in a bundle of machine instructions. ...
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
void removeMachineInstrFromMaps(MachineInstr &MI)
Removes machine instruction (bundle) MI from the mapping.
iterator advanceTo(iterator I, SlotIndex Pos)
advanceTo - Advance the specified iterator to point to the Segment containing the specified position...
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
INITIALIZE_PASS_BEGIN(LiveIntervals,"liveintervals","Live Interval Analysis", false, false) INITIALIZE_PASS_END(LiveIntervals
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
void constructMainRangeFromSubranges(LiveInterval &LI)
For live interval LI with correct SubRanges construct matching information for the main live range...
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
A live range for subregisters.
This represents a simple continuous liveness interval for a value.
SlotIndex endPoint() const
Return the end point of the last live range segment to interact with the instruction, if any.
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
void splitSeparateComponents(LiveInterval &LI, SmallVectorImpl< LiveInterval * > &SplitLIs)
Split separate components in LiveInterval LI into separate intervals.
void markUnused()
Mark this value as unused.
LaneBitmask getSubRegIndexLaneMask(unsigned SubIdx) const
Return a bitmask representing the parts of a register that are covered by SubIdx. ...
VNInfo - Value Number Information.
void print(raw_ostream &O, const Module *=nullptr) const override
Implement the dump method.
iterator_range< mop_iterator > operands()
bool checkRegMaskInterference(LiveInterval &LI, BitVector &UsableRegs)
Test if LI is live across any register mask instructions, and compute a bit mask of physical register...
void flushSegmentSet()
Flush segment set into the regular segment vector.
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const
getblockFreq - Return block frequency.
bool allDefsAreDead() const
Return true if all the defs of this instruction are dead.
void Distribute(LiveInterval &LI, LiveInterval *LIV[], MachineRegisterInfo &MRI)
Distribute values in LI into a separate LiveIntervals for each connected component.
LiveInterval::Segment addSegmentToEndOfBlock(unsigned reg, MachineInstr &startInst)
Given a register and an instruction, adds a live segment from that instruction to the end of its MBB...
iterator_range< succ_iterator > successors()
This class represents the liveness of a register, stack slot, etc.
static bool isEarlierInstr(SlotIndex A, SlotIndex B)
isEarlierInstr - Return true if A refers to an instruction earlier than B.
void removeEmptySubRanges()
Removes all subranges without any segments (subranges without segments are not considered valid and s...
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
void pruneValue(LiveRange &LR, SlotIndex Kill, SmallVectorImpl< SlotIndex > *EndPoints)
If LR has a live value at Kill, prune its live range by removing any liveness reachable from Kill...
uint64_t getEntryFreq() const
void clear()
clear - Removes all bits from the bitvector. Does not change capacity.
MachineBasicBlock * intervalIsInOneMBB(const LiveInterval &LI) const
If LI is confined to a single basic block, return a pointer to that block.
char & MachineLoopInfoID
MachineLoopInfo - This pass is a loop analysis pass.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MCSuperRegIterator enumerates all super-registers of Reg.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
ArrayRef< SlotIndex > getRegMaskSlotsInBlock(unsigned MBBNum) const
Returns a sorted array of slot indices of all instructions with register mask operands in the basic b...
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it...
ArrayRef< const uint32_t * > getRegMaskBits() const
Returns an array of register mask pointers corresponding to getRegMaskSlots().
bool hasIndex(const MachineInstr &instr) const
Returns true if the given machine instr is mapped to an index, otherwise returns false.
VNInfo::Allocator & getVNInfoAllocator()
bool isReg() const
isReg - Tests if this is a MO_Register operand.
iterator_range< subrange_iterator > subranges()
Result of a LiveRange query.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
bool isBlock() const
isBlock - Returns true if this is a block boundary slot.
SlotIndex getDeadSlot() const
Returns the dead def kill slot for the current instruction.
constexpr bool any() const
LLVM_NODISCARD bool empty() const
bool isUnused() const
Returns true if this value is unused.
SlotIndex getNextNonNullIndex(SlotIndex Index)
Returns the next non-null index, if one exists.
void extendToIndices(LiveRange &LR, ArrayRef< SlotIndex > Indices, ArrayRef< SlotIndex > Undefs)
Extend the live range LR to reach all points in Indices.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
void constructMainRangeFromSubranges(LiveInterval &LI)
For live interval LI with correct SubRanges construct matching information for the main live range...
iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
MCRegUnitRootIterator enumerates the root registers of a register unit.
bool isBundled() const
Return true if this instruction part of a bundle.
VNInfo * valueOutOrDead() const
Returns the value alive at the end of the instruction, if any.
bool shrinkToUses(LiveInterval *li, SmallVectorImpl< MachineInstr * > *dead=nullptr)
After removing some uses of a register, shrink its live range to just the remaining uses...
static void extendSegmentsToUses(LiveRange &LR, const SlotIndexes &Indexes, ShrinkToUsesWorkList &WorkList, const LiveRange &OldRange)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
AnalysisUsage & addPreservedID(const void *ID)
void extend(LiveRange &LR, SlotIndex Use, unsigned PhysReg, ArrayRef< SlotIndex > Undefs)
Extend the live range of LR to reach Use.
const float huge_valf
Use this rather than HUGE_VALF; the latter causes warnings on MSVC.
char & LiveIntervalsID
LiveIntervals - This analysis keeps track of the live ranges of virtual and physical registers...
Printable PrintReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubRegIdx=0)
Prints virtual and physical registers with or without a TRI instance.
LiveRange * getCachedRegUnit(unsigned Unit)
Return the live range for register unit Unit if it has already been computed, or nullptr if it hasn't...
void clearRegisterKills(unsigned Reg, const TargetRegisterInfo *RegInfo)
Clear all kill flags affecting Reg.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
const MachineBasicBlock * getParent() const
bool hasPHIKill(const LiveInterval &LI, const VNInfo *VNI) const
Returns true if VNI is killed by any PHI-def values in LI.
bool isDebugValue() const
void reset(const MachineFunction *MF, SlotIndexes *, MachineDominatorTree *, VNInfo::Allocator *)
reset - Prepare caches for a new set of non-overlapping live ranges.
SlotIndex insertMachineInstrInMaps(MachineInstr &MI, bool Late=false)
Insert the given machine instruction into the mapping.
void removeValNo(VNInfo *ValNo)
removeValNo - Remove all the segments defined by the specified value#.
initializer< Ty > init(const Ty &Val)
bool hasAtLeastOneValue() const
void clearBitsNotInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
clearBitsNotInMask - Clear a bit in this vector for every '0' bit in Mask.
SlotIndexes * getSlotIndexes() const
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
bool isValid() const
Returns true if this is a valid index.
iterator_range< reg_instr_iterator > reg_instructions(unsigned Reg) const
unsigned const MachineRegisterInfo * MRI
iterator_range< use_nodbg_iterator > use_nodbg_operands(unsigned Reg) const
void swap(SmallVectorImpl &RHS)
std::pair< VNInfo *, bool > extendInBlock(ArrayRef< SlotIndex > Undefs, SlotIndex StartIdx, SlotIndex Use)
Attempt to extend a value defined after StartIdx to include Use.
df_ext_iterator< T, SetTy > df_ext_end(const T &G, SetTy &S)
MachineInstrBuilder & UseMI
bool isReserved(unsigned PhysReg) const
isReserved - Returns true when PhysReg is a reserved register.
unsigned Classify(const LiveRange &LR)
Classify the values in LR into connected components.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Live Interval static false cl::opt< bool > EnablePrecomputePhysRegs("precompute-phys-liveness", cl::Hidden, cl::desc("Eagerly compute live intervals for all physreg units."))
Represent the analysis usage information of a pass.
df_ext_iterator< T, SetTy > df_ext_begin(const T &G, SetTy &S)
void initializeLiveIntervalsPass(PassRegistry &)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
static const unsigned End
VNInfo * valueDefined() const
Return the value defined by this instruction, if any.
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
HMEditor(LiveIntervals &LIS, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI, SlotIndex OldIdx, SlotIndex NewIdx, bool UpdateFlags)
iterator_range< pred_iterator > predecessors()
void verify() const
Walk the range and assert if any invariants fail to hold.
bool subRegLivenessEnabled() const
void repairIntervalsInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, ArrayRef< unsigned > OrigRegs)
Update live intervals for instructions in a range of iterators.
unsigned getSubReg() const
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...
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction for the given index, or null if the given index has no instruction associated...
iterator find(SlotIndex Pos)
find - Return an iterator pointing to the first segment that ends after Pos, or end().
unsigned id
The ID number of this value.
void removeSegment(SlotIndex Start, SlotIndex End, bool RemoveDeadValNo=false)
Remove the specified segment from this range.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Toolkit used by handleMove to trim or extend live intervals.
ArrayRef< const uint32_t * > getRegMaskBitsInBlock(unsigned MBBNum) const
Returns an array of mask pointers corresponding to getRegMaskSlotsInBlock(MBBNum).
Printable PrintRegUnit(unsigned Unit, const TargetRegisterInfo *TRI)
Create Printable object to print register units on a raw_ostream.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static bool isSameInstr(SlotIndex A, SlotIndex B)
isSameInstr - Return true if A and B refer to the same instruction.
Segments::const_iterator const_iterator
ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a LiveInterval into equivalence cl...
MachineOperand class - Representation of each machine instruction operand.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
Returns the basic block which the given index falls in.
static LaneBitmask getNone()
LiveRange * getRegUnitLI(unsigned Unit)
void setPreservesCFG()
This function should be called by the pass, iff they do not:
LiveInterval & getInterval(unsigned Reg)
static float getSpillWeight(bool isDef, bool isUse, const MachineBlockFrequencyInfo *MBFI, const MachineInstr &Instr)
Calculate the spill weight to assign to a single instruction.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
SlotIndex getMBBEndIdx(unsigned Num) const
Returns the last index in the given basic block number.
A range adaptor for a pair of iterators.
void repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End)
Repair indexes after adding and removing instructions.
typename SuperClass::iterator iterator
LiveInterval & createEmptyInterval(unsigned Reg)
Interval creation.
unsigned getNumRegUnits() const
Return the number of (native) register units in the target.
void calculate(LiveInterval &LI, bool TrackSubRegs)
Calculates liveness for the register specified in live interval LI.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
SlotIndex beginIndex() const
beginIndex - Return the lowest numbered slot covered.
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
static bool isEarlierEqualInstr(SlotIndex A, SlotIndex B)
Return true if A refers to the same instruction as B or an earlier one.
pointer data()
Return a pointer to the vector's buffer, even if empty().
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void addKillFlags(const VirtRegMap *)
Add kill flags to any instruction that kills a virtual register.
VNInfo * createDeadDef(SlotIndex Def, VNInfo::Allocator &VNInfoAllocator)
createDeadDef - Make sure the range has a value defined at Def.
SlotIndex endIndex() const
endNumber - return the maximum point of the range of the whole, exclusive.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream...
AnalysisUsage & addRequiredTransitiveID(char &ID)
AnalysisUsage & addRequiredTransitive()
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
bool hasInterval(unsigned Reg) const
bool reg_empty(unsigned RegNo) const
reg_empty - Return true if there are no instructions using or defining the specified register (it may...
~LiveIntervals() override
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def...
std::vector< uint8_t > Unit
unsigned getReg() const
getReg - Returns the register number.
bool isValid() const
isValid - Returns true until all the operands have been visited.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
VNInfo * getNextValue(SlotIndex def, VNInfo::Allocator &VNInfoAllocator)
getNextValue - Create a new value number and return it.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual const TargetInstrInfo * getInstrInfo() const
mop_iterator operands_begin()
static LLVM_ATTRIBUTE_UNUSED Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
void handleMoveIntoBundle(MachineInstr &MI, MachineInstr &BundleStart, bool UpdateFlags=false)
Update intervals for operands of MI so that they begin/end on the SlotIndex for BundleStart.
This class implements an extremely fast bulk output stream that can only output to a stream...
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Return the first index in the given basic block.
bool addRegisterKilled(unsigned IncomingReg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI kills a register.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
unsigned getPhys(unsigned virtReg) const
returns the physical register mapped to the specified virtual register
iterator FindSegmentContaining(SlotIndex Idx)
Return an iterator to the segment that contains the specified index, or end() if there is none...
VNInfo * valueIn() const
Return the value that is live-in to the instruction.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
bool hasSubRanges() const
Returns true if subregister liveness information is available.
SlotIndex - An opaque wrapper around machine indexes.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
unsigned pred_size() const
bool reg_nodbg_empty(unsigned RegNo) const
reg_nodbg_empty - Return true if the only instructions using or defining Reg are Debug instructions...
LiveRange & getRegUnit(unsigned Unit)
Return the live range for register unit Unit.
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarilly including Idx...
bool shouldTrackSubRegLiveness(const TargetRegisterClass &RC) const
Returns true if liveness for register class RC should be tracked at the subregister level...
void handleMove(MachineInstr &MI, bool UpdateFlags=false)
Call this method to notify LiveIntervals that instruction MI has been moved within a basic block...
LiveInterval & createAndComputeVirtRegInterval(unsigned Reg)
static void createSegmentsForValues(LiveRange &LR, iterator_range< LiveInterval::vni_iterator > VNIs)
void removeVRegDefAt(LiveInterval &LI, SlotIndex Pos)
Remove value number and related live segments of LI and its subranges that start at position Pos...
const std::pair< SlotIndex, SlotIndex > & getMBBRange(unsigned Num) const
Return the (start,end) range of the given basic block number.