30 for (; PSetI.
isValid(); ++PSetI)
31 CurrSetPressure[*PSetI] += Weight;
38 for (; PSetI.
isValid(); ++PSetI) {
39 assert(CurrSetPressure[*PSetI] >= Weight &&
"register pressure underflow");
40 CurrSetPressure[*PSetI] -= Weight;
44 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
48 for (
unsigned i = 0, e = SetPressure.
size(); i < e; ++i) {
49 if (SetPressure[i] != 0) {
59 dbgs() <<
"Max Pressure: ";
61 dbgs() <<
"Live In: ";
65 dbgs() <<
"Live Out: ";
73 dbgs() <<
"Curr Pressure: ";
83 for (
unsigned i = 0, e = RegUnits.
size(); i != e; ++i) {
86 for (; PSetI.
isValid(); ++PSetI) {
87 CurrSetPressure[*PSetI] += Weight;
97 for (
unsigned I = 0, E = RegUnits.
size();
I != E; ++
I)
160 CurrSetPressure.clear();
161 LiveThruPressure.clear();
164 if (RequireIntervals)
182 bool ShouldTrackUntiedDefs)
191 TrackUntiedDefs = ShouldTrackUntiedDefs;
193 if (RequireIntervals) {
194 assert(lis &&
"IntervalPressure requires LiveIntervals");
211 if (RequireIntervals)
213 return (static_cast<RegionPressure&>(P).TopPos ==
219 if (RequireIntervals)
221 return (static_cast<RegionPressure&>(P).BottomPos ==
228 while (IdxPos != MBB->
end() && IdxPos->isDebugValue())
230 if (IdxPos == MBB->
end())
237 if (RequireIntervals)
255 if (RequireIntervals)
275 "no region boundary");
291 assert(
isBottomClosed() &&
"need bottom-up tracking to intialize.");
304 return std::find(RegUnits.
begin(), RegUnits.
end(), RegUnit) != RegUnits.
end();
323 TRI(tri),
MRI(mri), IgnoreDead(
ID) {}
330 pushRegUnits(MO.
getReg(), Uses);
334 pushRegUnits(MO.
getReg(), DeadDefs);
337 pushRegUnits(MO.
getReg(), Defs);
348 else if (
MRI->isAllocatable(Reg)) {
388 for (; PSetI.
isValid(); ++PSetI) {
391 for (; I != E && I->
isValid(); ++
I) {
414 for (
unsigned i = 0, e = RegOpers.
Defs.
size(); i != e; ++i)
417 for (
unsigned i = 0, e = RegOpers.
Uses.
size(); i != e; ++i)
423 for (
unsigned i = 0, e = Regs.
size(); i != e; ++i) {
424 if (LiveRegs.
insert(Regs[i]))
431 assert(!LiveRegs.
contains(Reg) &&
"avoid bumping max pressure twice");
442 assert(!LiveRegs.
contains(Reg) &&
"avoid bumping max pressure twice");
459 if (CurrPos == MBB->
begin()) {
473 while (CurrPos != MBB->
begin() && CurrPos->isDebugValue());
475 if (CurrPos->isDebugValue()) {
480 if (RequireIntervals)
499 for (
unsigned i = 0, e = RegOpers.
Defs.
size(); i < e; ++i) {
500 unsigned Reg = RegOpers.
Defs[i];
501 bool DeadDef =
false;
502 if (RequireIntervals) {
510 if (LiveRegs.
erase(Reg))
518 for (
unsigned i = 0, e = RegOpers.
Uses.
size(); i < e; ++i) {
519 unsigned Reg = RegOpers.
Uses[i];
522 if (RequireIntervals) {
536 if (TrackUntiedDefs) {
537 for (
unsigned i = 0, e = RegOpers.
Defs.
size(); i < e; ++i) {
538 unsigned Reg = RegOpers.
Defs[i];
540 UntiedDefs.insert(Reg);
548 assert(!TrackUntiedDefs &&
"unsupported mode");
551 if (CurrPos == MBB->
end()) {
559 if (RequireIntervals)
564 if (RequireIntervals)
573 for (
unsigned i = 0, e = RegOpers.
Uses.
size(); i < e; ++i) {
574 unsigned Reg = RegOpers.
Uses[i];
576 bool isLive = LiveRegs.
contains(Reg);
580 bool lastUse =
false;
581 if (RequireIntervals) {
589 if (lastUse && isLive) {
593 else if (!lastUse && !isLive)
598 for (
unsigned i = 0, e = RegOpers.
Defs.
size(); i < e; ++i) {
599 unsigned Reg = RegOpers.
Defs[i];
611 while (CurrPos != MBB->
end() && CurrPos->isDebugValue());
622 for (
unsigned i = 0, e = OldPressureVec.
size(); i < e; ++i) {
623 unsigned POld = OldPressureVec[i];
624 unsigned PNew = NewPressureVec[i];
625 int PDiff = (int)PNew - (
int)POld;
630 if (!LiveThruPressureVec.
empty())
631 Limit += LiveThruPressureVec[i];
637 PDiff = PNew - Limit;
639 else if (Limit > PNew)
640 PDiff = Limit - POld;
664 unsigned CritIdx = 0, CritEnd = CriticalPSets.
size();
665 for (
unsigned i = 0, e = OldMaxPressureVec.
size(); i < e; ++i) {
666 unsigned POld = OldMaxPressureVec[i];
667 unsigned PNew = NewMaxPressureVec[i];
672 while (CritIdx != CritEnd && CriticalPSets[CritIdx].getPSet() < i)
675 if (CritIdx != CritEnd && CriticalPSets[CritIdx].getPSet() == i) {
676 int PDiff = (int)PNew - (
int)CriticalPSets[CritIdx].getUnitInc();
701 assert(!MI->
isDebugValue() &&
"Expect a nondebug instruction.");
713 for (
unsigned i = 0, e = RegOpers.Defs.size(); i < e; ++i) {
714 unsigned Reg = RegOpers.Defs[i];
715 bool DeadDef =
false;
716 if (RequireIntervals) {
730 for (
unsigned i = 0, e = RegOpers.Uses.size(); i < e; ++i) {
731 unsigned Reg = RegOpers.Uses[i];
756 std::vector<unsigned> SavedPressure = CurrSetPressure;
764 MaxPressureLimit, Delta);
770 CurrSetPressure.swap(SavedPressure);
779 if (Delta != Delta2) {
780 dbgs() <<
"DELTA: " << *
MI;
821 unsigned CritIdx = 0, CritEnd = CriticalPSets.
size();
823 PDiffI = PDiff.
begin(), PDiffE = PDiff.
end();
824 PDiffI != PDiffE && PDiffI->
isValid(); ++PDiffI) {
826 unsigned PSetID = PDiffI->getPSet();
828 if (!LiveThruPressure.empty())
829 Limit += LiveThruPressure[PSetID];
831 unsigned POld = CurrSetPressure[PSetID];
833 unsigned MNew = MOld;
835 unsigned PNew = POld + PDiffI->getUnitInc();
836 assert((PDiffI->getUnitInc() >= 0) == (PNew >= POld) &&
"PSet overflow");
841 unsigned ExcessInc = 0;
843 ExcessInc = POld > Limit ? PNew - POld : PNew - Limit;
844 else if (POld > Limit)
845 ExcessInc = Limit - POld;
855 while (CritIdx != CritEnd && CriticalPSets[CritIdx].getPSet() < PSetID)
858 if (CritIdx != CritEnd && CriticalPSets[CritIdx].getPSet() == PSetID) {
859 int CritInc = (int)MNew - (
int)CriticalPSets[CritIdx].getUnitInc();
860 if (CritInc > 0 && CritInc <= INT16_MAX) {
886 if (InstSlot >= PriorUseIdx && InstSlot < NextUseIdx)
899 assert(!MI->
isDebugValue() &&
"Expect a nondebug instruction.");
908 if (RequireIntervals)
911 for (
unsigned i = 0, e = RegOpers.Uses.size(); i < e; ++i) {
912 unsigned Reg = RegOpers.Uses[i];
913 if (RequireIntervals) {
950 std::vector<unsigned> SavedPressure = CurrSetPressure;
958 MaxPressureLimit, Delta);
964 CurrSetPressure.swap(SavedPressure);
970 std::vector<unsigned> &PressureResult,
971 std::vector<unsigned> &MaxPressureResult) {
973 PressureResult = CurrSetPressure;
980 CurrSetPressure.swap(PressureResult);
986 std::vector<unsigned> &PressureResult,
987 std::vector<unsigned> &MaxPressureResult) {
989 PressureResult = CurrSetPressure;
996 CurrSetPressure.swap(PressureResult);
void push_back(const T &Elt)
void dump(const TargetRegisterInfo *TRI) const
bool advance()
Advance across the current instruction.
void increaseRegPressure(ArrayRef< unsigned > Regs)
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.
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.
SlotIndex getInstructionIndex(const MachineInstr *instr) const
Returns the base index of the given instruction.
static bool isVirtualRegister(unsigned Reg)
const LiveRange * getLiveRange(unsigned Reg) const
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
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.
static use_nodbg_iterator use_nodbg_end()
unsigned getNumVirtRegs() const
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)
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
void discoverLiveOut(unsigned Reg)
Add Reg to the live out set and increase max pressure.
ID
LLVM Calling Convention Representation.
bool recede(SmallVectorImpl< unsigned > *LiveUses=0, PressureDiff *PDiff=0)
Recede across the previous instruction.
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)
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
SparseSet< unsigned, VirtReg2IndexFunctor > VirtRegs
SmallVector< unsigned, 8 > DeadDefs
bool hasUntiedDef(unsigned VirtReg) const
size_t size() const
size - Get the array size.
LiveRange * getCachedRegUnit(unsigned Unit)
static bool containsReg(ArrayRef< unsigned > RegUnits, unsigned RegUnit)
Convenient wrapper for checking membership in RegisterOperands. (std::count() doesn't have an early e...
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)
LiveQueryResult Query(SlotIndex Idx) const
PressureChange CurrentMax
void bumpDownwardPressure(const MachineInstr *MI)
SparseSet< unsigned > PhysRegs
void openTop(MachineBasicBlock::const_iterator PrevTop)
If the current top is the previous instruction (before receding), open it.
SmallVector< unsigned, 8 > LiveOutRegs
VNInfo * valueDefined() const
unsigned getRegPressureSetLimit(unsigned Idx) const
void setUniverse(unsigned U)
void dumpRegSetPressure(ArrayRef< unsigned > SetPressure, const TargetRegisterInfo *TRI)
bool empty() const
empty - Check if the array is empty.
void append(in_iter in_start, in_iter in_end)
static void collectPDiff(PressureDiff &PDiff, RegisterOperands &RegOpers, const MachineRegisterInfo *MRI)
Record the pressure difference induced by the given operand list.
iterator erase(iterator I)
void initLiveThru(const RegPressureTracker &RPTracker)
const_iterator begin() const
std::vector< unsigned > MaxSetPressure
Map of max reg pressure indexed by pressure set ID, not class ID.
void collect(const MachineOperand &MO)
Push this operand's register onto the correct vector.
void discoverLiveIn(unsigned Reg)
Add Reg to the live in set and increase max pressure.
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 - Return a circular-buffered debug stream.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
RegisterOperands(const TargetRegisterInfo *tri, const MachineRegisterInfo *mri, bool ID=false)
PressureChange CriticalMax
void init(const MachineFunction *mf, const RegisterClassInfo *rci, const LiveIntervals *lis, const MachineBasicBlock *mbb, MachineBasicBlock::const_iterator pos, bool ShouldTrackUntiedDefs=false)
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.
bundle_iterator< const MachineInstr, const_instr_iterator > const_iterator
MachineRegisterInfo & getRegInfo()
PSetIterator getPressureSets(unsigned RegUnit) const
SmallVector< unsigned, 8 > Defs
void getMaxUpwardPressureDelta(const MachineInstr *MI, PressureDiff *PDiff, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit)
const TargetMachine & getTarget() const
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.
virtual const TargetRegisterInfo * getRegisterInfo() const
bool isBottomClosed() const
Does this pressure result have a valid bottom position and live outs.
void bumpUpwardPressure(const MachineInstr *MI)
SlotIndex getRegSlot(bool EC=false) const
unsigned getReg() const
getReg - Returns the register number.
bool isValid() const
isValid - Returns true until all the operands have been visited.
void addLiveRegs(ArrayRef< unsigned > Regs)
Force liveness of registers.
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)
void reset()
Clear the result so it can be used for another round of pressure tracking.
SmallVector< unsigned, 8 > Uses
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.
const MCRegisterInfo & MRI
MachineBasicBlock::const_iterator BottomPos
SlotIndex - An opaque wrapper around machine indexes.
MachineInstr * skipInstruction()
void *calloc(size_t count, size_t size);
void pushRegUnits(unsigned Reg, SmallVectorImpl< unsigned > &RegUnits)
use_nodbg_iterator use_nodbg_begin(unsigned RegNo) const
void getUpwardPressureDelta(const MachineInstr *MI, PressureDiff &PDiff, RegPressureDelta &Delta, ArrayRef< PressureChange > CriticalPSets, ArrayRef< unsigned > MaxPressureLimit) const
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.