29 for (; PSetI.
isValid(); ++PSetI)
30 CurrSetPressure[*PSetI] += Weight;
37 for (; PSetI.
isValid(); ++PSetI) {
38 assert(CurrSetPressure[*PSetI] >= Weight &&
"register pressure underflow");
39 CurrSetPressure[*PSetI] -= Weight;
47 for (
unsigned i = 0, e = SetPressure.
size(); i < e; ++i) {
48 if (SetPressure[i] != 0) {
59 dbgs() <<
"Max Pressure: ";
61 dbgs() <<
"Live In: ";
65 dbgs() <<
"Live Out: ";
74 dbgs() <<
"Curr Pressure: ";
93 for (
unsigned i = 0, e = RegUnits.
size(); i != e; ++i) {
96 for (; PSetI.
isValid(); ++PSetI) {
97 CurrSetPressure[*PSetI] += Weight;
107 for (
unsigned I = 0, E = RegUnits.
size();
I != E; ++
I)
170 CurrSetPressure.clear();
171 LiveThruPressure.clear();
174 if (RequireIntervals)
192 bool ShouldTrackUntiedDefs)
201 TrackUntiedDefs = ShouldTrackUntiedDefs;
203 if (RequireIntervals) {
204 assert(lis &&
"IntervalPressure requires LiveIntervals");
221 if (RequireIntervals)
223 return (static_cast<RegionPressure&>(P).TopPos ==
229 if (RequireIntervals)
231 return (static_cast<RegionPressure&>(P).BottomPos ==
238 while (IdxPos != MBB->
end() && IdxPos->isDebugValue())
240 if (IdxPos == MBB->
end())
247 if (RequireIntervals)
265 if (RequireIntervals)
285 "no region boundary");
301 assert(
isBottomClosed() &&
"need bottom-up tracking to intialize.");
314 return std::find(RegUnits.
begin(), RegUnits.
end(), RegUnit) != RegUnits.
end();
322 class RegisterOperands {
334 TRI(tri), MRI(mri), IgnoreDead(
ID) {}
341 pushRegUnits(MO.
getReg(), Uses);
345 pushRegUnits(MO.
getReg(), DeadDefs);
348 pushRegUnits(MO.
getReg(), Defs);
359 else if (MRI->isAllocatable(Reg)) {
372 RegisterOperands &RegOpers) {
374 RegOpers.collect(*OperI);
378 std::remove_if(RegOpers.DeadDefs.begin(), RegOpers.DeadDefs.end(),
379 std::bind1st(std::ptr_fun(
containsReg), RegOpers.Defs));
380 RegOpers.DeadDefs.erase(I, RegOpers.DeadDefs.end());
400 for (; PSetI.
isValid(); ++PSetI) {
403 for (; I != E && I->
isValid(); ++
I) {
426 for (
unsigned i = 0, e = RegOpers.Defs.size(); i != e; ++i)
429 for (
unsigned i = 0, e = RegOpers.Uses.size(); i != e; ++i)
435 for (
unsigned i = 0, e = Regs.
size(); i != e; ++i) {
436 if (LiveRegs.
insert(Regs[i]))
443 assert(!LiveRegs.
contains(Reg) &&
"avoid bumping max pressure twice");
454 assert(!LiveRegs.
contains(Reg) &&
"avoid bumping max pressure twice");
471 if (CurrPos == MBB->
begin()) {
485 while (CurrPos != MBB->
begin() && CurrPos->isDebugValue());
487 if (CurrPos->isDebugValue()) {
492 if (RequireIntervals)
499 RegisterOperands RegOpers(TRI, MRI);
511 for (
unsigned i = 0, e = RegOpers.Defs.size(); i < e; ++i) {
512 unsigned Reg = RegOpers.Defs[i];
513 bool DeadDef =
false;
514 if (RequireIntervals) {
528 if (LiveRegs.
erase(Reg))
536 for (
unsigned i = 0, e = RegOpers.Uses.size(); i < e; ++i) {
537 unsigned Reg = RegOpers.Uses[i];
540 if (RequireIntervals) {
554 if (TrackUntiedDefs) {
555 for (
unsigned i = 0, e = RegOpers.Defs.size(); i < e; ++i) {
556 unsigned Reg = RegOpers.Defs[i];
558 UntiedDefs.insert(Reg);
566 assert(!TrackUntiedDefs &&
"unsupported mode");
569 if (CurrPos == MBB->
end()) {
577 if (RequireIntervals)
582 if (RequireIntervals)
588 RegisterOperands RegOpers(TRI, MRI);
591 for (
unsigned i = 0, e = RegOpers.Uses.size(); i < e; ++i) {
592 unsigned Reg = RegOpers.Uses[i];
594 bool isLive = LiveRegs.
contains(Reg);
598 bool lastUse =
false;
599 if (RequireIntervals) {
607 if (lastUse && isLive) {
611 else if (!lastUse && !isLive)
616 for (
unsigned i = 0, e = RegOpers.Defs.size(); i < e; ++i) {
617 unsigned Reg = RegOpers.Defs[i];
629 while (CurrPos != MBB->
end() && CurrPos->isDebugValue());
640 for (
unsigned i = 0, e = OldPressureVec.
size(); i < e; ++i) {
641 unsigned POld = OldPressureVec[i];
642 unsigned PNew = NewPressureVec[i];
643 int PDiff = (
int)PNew - (
int)POld;
648 if (!LiveThruPressureVec.
empty())
649 Limit += LiveThruPressureVec[i];
655 PDiff = PNew - Limit;
657 else if (Limit > PNew)
658 PDiff = Limit - POld;
682 unsigned CritIdx = 0, CritEnd = CriticalPSets.
size();
683 for (
unsigned i = 0, e = OldMaxPressureVec.
size(); i < e; ++i) {
684 unsigned POld = OldMaxPressureVec[i];
685 unsigned PNew = NewMaxPressureVec[i];
690 while (CritIdx != CritEnd && CriticalPSets[CritIdx].getPSet() < i)
693 if (CritIdx != CritEnd && CriticalPSets[CritIdx].getPSet() == i) {
694 int PDiff = (
int)PNew - (
int)CriticalPSets[CritIdx].getUnitInc();
719 assert(!MI->
isDebugValue() &&
"Expect a nondebug instruction.");
722 RegisterOperands RegOpers(TRI, MRI,
true);
731 for (
unsigned i = 0, e = RegOpers.Defs.size(); i < e; ++i) {
732 unsigned Reg = RegOpers.Defs[i];
733 bool DeadDef =
false;
734 if (RequireIntervals) {
748 for (
unsigned i = 0, e = RegOpers.Uses.size(); i < e; ++i) {
749 unsigned Reg = RegOpers.Uses[i];
776 std::vector<unsigned> SavedPressure = CurrSetPressure;
784 MaxPressureLimit, Delta);
790 CurrSetPressure.swap(SavedPressure);
799 if (Delta != Delta2) {
802 dbgs() <<
"DELTA: " << *
MI;
841 unsigned CritIdx = 0, CritEnd = CriticalPSets.
size();
843 PDiffI = PDiff.
begin(), PDiffE = PDiff.
end();
844 PDiffI != PDiffE && PDiffI->
isValid(); ++PDiffI) {
846 unsigned PSetID = PDiffI->getPSet();
848 if (!LiveThruPressure.empty())
849 Limit += LiveThruPressure[PSetID];
851 unsigned POld = CurrSetPressure[PSetID];
853 unsigned MNew = MOld;
855 unsigned PNew = POld + PDiffI->getUnitInc();
856 assert((PDiffI->getUnitInc() >= 0) == (PNew >= POld) &&
"PSet overflow");
861 unsigned ExcessInc = 0;
863 ExcessInc = POld > Limit ? PNew - POld : PNew - Limit;
864 else if (POld > Limit)
865 ExcessInc = Limit - POld;
875 while (CritIdx != CritEnd && CriticalPSets[CritIdx].getPSet() < PSetID)
878 if (CritIdx != CritEnd && CriticalPSets[CritIdx].getPSet() == PSetID) {
879 int CritInc = (
int)MNew - (
int)CriticalPSets[CritIdx].getUnitInc();
880 if (CritInc > 0 && CritInc <= INT16_MAX) {
906 if (InstSlot >= PriorUseIdx && InstSlot < NextUseIdx)
919 assert(!MI->
isDebugValue() &&
"Expect a nondebug instruction.");
922 RegisterOperands RegOpers(TRI, MRI);
928 if (RequireIntervals)
931 for (
unsigned i = 0, e = RegOpers.Uses.size(); i < e; ++i) {
932 unsigned Reg = RegOpers.Uses[i];
933 if (RequireIntervals) {
975 std::vector<unsigned> SavedPressure = CurrSetPressure;
983 MaxPressureLimit, Delta);
989 CurrSetPressure.swap(SavedPressure);
995 std::vector<unsigned> &PressureResult,
996 std::vector<unsigned> &MaxPressureResult) {
998 PressureResult = CurrSetPressure;
1005 CurrSetPressure.swap(PressureResult);
1011 std::vector<unsigned> &PressureResult,
1012 std::vector<unsigned> &MaxPressureResult) {
1014 PressureResult = CurrSetPressure;
1021 CurrSetPressure.swap(PressureResult);
void dump(const TargetRegisterInfo *TRI) const
void push_back(const T &Elt)
bool advance()
Advance across the current instruction.
void increaseRegPressure(ArrayRef< unsigned > Regs)
Increase the current pressure as impacted by these registers and bump the high water mark if needed...
virtual unsigned getNumRegPressureSets() const =0
Get the number of dimensions of register pressure.
static void increaseSetPressure(std::vector< unsigned > &CurrSetPressure, PSetIterator PSetI)
Increase pressure for each pressure set provided by TargetRegisterInfo.
void addPressureChange(unsigned RegUnit, bool IsDec, const MachineRegisterInfo *MRI)
Add a change in pressure to the pressure diff of a given instruction.
#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 init(unsigned N)
Initialize an array of N PressureDiffs.
use_instr_nodbg_iterator use_instr_nodbg_begin(unsigned RegNo) const
SlotIndex getInstructionIndex(const MachineInstr *instr) const
Returns the base index of the given instruction.
static bool isVirtualRegister(unsigned Reg)
isVirtualRegister - Return true if the specified register number is in the virtual register namespace...
const LiveRange * getLiveRange(unsigned Reg) const
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
bool isKill() const
Return true if the live-in value is killed by this instruction.
void closeRegion()
Finalize the region boundaries and recored live ins and live outs.
bool isTopClosed() const
Does this pressure result have a valid top position and live ins.
void openBottom(MachineBasicBlock::const_iterator PrevBottom)
If the current bottom is the previous instr (before advancing), open it.
void reserve(size_type N)
bool empty() const
empty - Returns true if the set is empty.
This class represents the liveness of a register, stack slot, etc.
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
SlotIndex TopIdx
Record the boundary of the region being tracked.
void closeBottom()
Set the boundary for the bottom of the region and summarize live outs.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
virtual const char * getRegPressureSetName(unsigned Idx) const =0
Get the name of this register unit pressure set.
static void collectOperands(const MachineInstr *MI, RegisterOperands &RegOpers)
Collect physical and virtual register operands.
void openBottom(SlotIndex PrevBottom)
If the current bottom is not greater than the previous index, open it.
MachineBasicBlock::const_iterator TopPos
Record the boundary of the region being tracked.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
const_iterator end() const
Result of a LiveRange query.
Reg
All possible values of the reg field in the ModR/M byte.
void discoverLiveOut(unsigned Reg)
Add Reg to the live out set and increase max pressure.
defusechain_iterator - This class provides iterator support for machine operands in the function that...
SlotIndex getCurrSlot() const
Get the SlotIndex for the first nondebug instruction including or after the current position...
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
void openTop(SlotIndex NextTop)
If the current top is not less than or equal to the next index, open it.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
SparseSet< unsigned, VirtReg2IndexFunctor > VirtRegs
bool recede(SmallVectorImpl< unsigned > *LiveUses=nullptr, PressureDiff *PDiff=nullptr)
Recede across the previous instruction.
bool hasUntiedDef(unsigned VirtReg) const
size_t size() const
size - Get the array size.
LiveRange * getCachedRegUnit(unsigned Unit)
getCachedRegUnit - Return the live range for Unit if it has already been computed, or NULL if it hasn't been computed yet.
static bool containsReg(ArrayRef< unsigned > RegUnits, unsigned RegUnit)
Convenient wrapper for checking membership in RegisterOperands.
bool isDebugValue() const
bool isDeadDef() const
Return true if this instruction has a dead def.
void decreaseRegPressure(ArrayRef< unsigned > Regs)
Simply decrease the current pressure as impacted by these registers.
void getMaxDownwardPressureDelta(const MachineInstr *MI, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
Consider the pressure increase caused by traversing this instruction top-down.
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
size_type size() const
size - Returns the number of elements in the set.
PressureChange CurrentMax
RegisterPressure computed within a region of instructions delimited by TopIdx and BottomIdx...
void bumpDownwardPressure(const MachineInstr *MI)
Record the downward impact of a single instruction on current register pressure.
SparseSet< unsigned > PhysRegs
RegisterPressure computed within a region of instructions delimited by TopPos and BottomPos...
void openTop(MachineBasicBlock::const_iterator PrevTop)
If the current top is the previous instruction (before receding), open it.
Track the current register pressure at some position in the instruction stream, and remember the high...
SmallVector< unsigned, 8 > LiveOutRegs
VNInfo * valueDefined() const
Return the value defined by this instruction, if any.
List of PressureChanges in order of increasing, unique PSetID.
unsigned getRegPressureSetLimit(unsigned Idx) const
Get the register unit limit for the given pressure set index.
void setUniverse(unsigned U)
setUniverse - Set the universe size which determines the largest key the set can hold.
bool empty() const
empty - Check if the array is empty.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
static void collectPDiff(PressureDiff &PDiff, RegisterOperands &RegOpers, const MachineRegisterInfo *MRI)
Record the pressure difference induced by the given operand list.
iterator erase(iterator I)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
void initLiveThru(const RegPressureTracker &RPTracker)
Initialize the LiveThru pressure set based on the untied defs found in RPTracker. ...
const_iterator begin() const
std::vector< unsigned > MaxSetPressure
Map of max reg pressure indexed by pressure set ID, not class ID.
ConstMIBundleOperands - Iterate over all operands in a const bundle of machine instructions.
void discoverLiveIn(unsigned Reg)
Add Reg to the live in set and increase max pressure.
MachineOperand class - Representation of each machine instruction operand.
bool insert(unsigned Reg)
unsigned getWeight() const
void reset()
Clear the result so it can be used for another round of pressure tracking.
LiveInterval & getInterval(unsigned Reg)
bool contains(unsigned Reg) const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
PressureChange CriticalMax
PrintVRegOrUnit - It is often convenient to track virtual registers and physical register units in th...
void init(const MachineFunction *mf, const RegisterClassInfo *rci, const LiveIntervals *lis, const MachineBasicBlock *mbb, MachineBasicBlock::const_iterator pos, bool ShouldTrackUntiedDefs=false)
Setup the RegPressureTracker.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
void closeTop()
Set the boundary for the top of the region and summarize live ins.
static void decreaseSetPressure(std::vector< unsigned > &CurrSetPressure, PSetIterator PSetI)
Decrease pressure for each pressure set provided by TargetRegisterInfo.
Representation of each machine instruction.
bundle_iterator< const MachineInstr, const_instr_iterator > const_iterator
void dumpRegSetPressure(ArrayRef< unsigned > SetPressure, const TargetRegisterInfo *TRI)
SparseSet - Fast set implmentation for objects that can be identified by small unsigned keys...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Iterate over the pressure sets affected by the given physical or virtual register.
LLVM_DUMP_METHOD void dump(const TargetRegisterInfo &TRI) const
PSetIterator getPressureSets(unsigned RegUnit) const
Get an iterator over the pressure sets affected by the given physical or virtual register.
Capture a change in pressure for a single pressure set.
void getMaxUpwardPressureDelta(const MachineInstr *MI, PressureDiff *PDiff, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
Consider the pressure increase caused by traversing this instruction bottom-up.
void getUpwardPressure(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
Get the pressure of each PSet after traversing this instruction bottom-up.
void clear()
clear - Clears the set.
bool isBottomClosed() const
Does this pressure result have a valid bottom position and live outs.
void bumpUpwardPressure(const MachineInstr *MI)
Record the upward impact of a single instruction on current register pressure.
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.
bool isValid() const
isValid - Returns true until all the operands have been visited.
static use_instr_nodbg_iterator use_instr_nodbg_end()
Store the effects of a change in pressure on things that MI scheduler cares about.
void addLiveRegs(ArrayRef< unsigned > Regs)
Force liveness of virtual registers or physical register units.
static bool findUseBetween(unsigned Reg, SlotIndex PriorUseIdx, SlotIndex NextUseIdx, const MachineRegisterInfo *MRI, const LiveIntervals *LIS)
Helper to find a vreg use between two indices [PriorUseIdx, NextUseIdx).
static void computeMaxPressureDelta(ArrayRef< unsigned > OldMaxPressureVec, ArrayRef< unsigned > NewMaxPressureVec, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit, RegPressureDelta &Delta)
Find the max change in max pressure that either surpasses a critical PSet limit or exceeds the curren...
void reset()
Clear the result so it can be used for another round of pressure tracking.
SmallVector< unsigned, 8 > LiveInRegs
List of live in virtual registers or physical register units.
void getDownwardPressure(const MachineInstr *MI, std::vector< unsigned > &PressureResult, std::vector< unsigned > &MaxPressureResult)
Get the pressure of each PSet after traversing this instruction top-down.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register. ...
MachineBasicBlock::const_iterator BottomPos
SlotIndex - An opaque wrapper around machine indexes.
void getUpwardPressureDelta(const MachineInstr *MI, PressureDiff &PDiff, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit) const
This is the fast version of querying register pressure that does not directly depend on current liven...
static void computeExcessPressureDelta(ArrayRef< unsigned > OldPressureVec, ArrayRef< unsigned > NewPressureVec, RegPressureDelta &Delta, const RegisterClassInfo *RCI, ArrayRef< unsigned > LiveThruPressureVec)
Find the max change in excess pressure across all sets.