1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

Add a convenient PSetIterator for visiting pressure sets affected by a register.

llvm-svn: 189121
This commit is contained in:
Andrew Trick 2013-08-23 17:48:46 +00:00
parent d56a8b8df8
commit 7e77ff64a2
2 changed files with 68 additions and 69 deletions

View File

@ -22,6 +22,7 @@
#include <vector>
namespace llvm {
class PSetIterator;
/// MachineRegisterInfo - Keep track of information for virtual and physical
/// registers, including vreg register classes, use/def chains for registers,
@ -326,6 +327,11 @@ public:
/// a physreg.
bool isConstantPhysReg(unsigned PhysReg, const MachineFunction &MF) const;
/// Get an iterator over the pressure sets affected by the given physical or
/// virtual register. If RegUnit is physical, it must be a register unit (from
/// MCRegUnitIterator).
PSetIterator getPressureSets(unsigned RegUnit) const;
//===--------------------------------------------------------------------===//
// Virtual Register Info
//===--------------------------------------------------------------------===//
@ -647,9 +653,49 @@ public:
return Op->getParent();
}
};
};
/// Iterate over the pressure sets affected by the given physical or virtual
/// register. If Reg is physical, it must be a register unit (from
/// MCRegUnitIterator).
class PSetIterator {
const int *PSet;
unsigned Weight;
public:
PSetIterator(): PSet(0), Weight(0) {}
PSetIterator(unsigned RegUnit, const MachineRegisterInfo *MRI) {
const TargetRegisterInfo *TRI = MRI->getTargetRegisterInfo();
if (TargetRegisterInfo::isVirtualRegister(RegUnit)) {
const TargetRegisterClass *RC = MRI->getRegClass(RegUnit);
PSet = TRI->getRegClassPressureSets(RC);
Weight = TRI->getRegClassWeight(RC).RegWeight;
}
else {
PSet = TRI->getRegUnitPressureSets(RegUnit);
Weight = TRI->getRegUnitWeight(RegUnit);
}
if (*PSet == -1)
PSet = 0;
}
bool isValid() const { return PSet; }
unsigned getWeight() const { return Weight; }
unsigned operator*() const { return *PSet; }
void operator++() {
assert(isValid() && "Invalid PSetIterator.");
++PSet;
if (*PSet == -1)
PSet = 0;
}
};
inline PSetIterator MachineRegisterInfo::
getPressureSets(unsigned RegUnit) const {
return PSetIterator(RegUnit, this);
}
} // End llvm namespace
#endif

View File

@ -26,52 +26,24 @@ using namespace llvm;
/// Increase pressure for each pressure set provided by TargetRegisterInfo.
static void increaseSetPressure(std::vector<unsigned> &CurrSetPressure,
std::vector<unsigned> &MaxSetPressure,
const int *PSet, unsigned Weight) {
for (; *PSet != -1; ++PSet) {
CurrSetPressure[*PSet] += Weight;
PSetIterator PSetI) {
unsigned Weight = PSetI.getWeight();
for (; PSetI.isValid(); ++PSetI) {
CurrSetPressure[*PSetI] += Weight;
if (&CurrSetPressure != &MaxSetPressure
&& CurrSetPressure[*PSet] > MaxSetPressure[*PSet]) {
MaxSetPressure[*PSet] = CurrSetPressure[*PSet];
&& CurrSetPressure[*PSetI] > MaxSetPressure[*PSetI]) {
MaxSetPressure[*PSetI] = CurrSetPressure[*PSetI];
}
}
}
/// Decrease pressure for each pressure set provided by TargetRegisterInfo.
static void decreaseSetPressure(std::vector<unsigned> &CurrSetPressure,
const int *PSet, unsigned Weight) {
for (; *PSet != -1; ++PSet) {
assert(CurrSetPressure[*PSet] >= Weight && "register pressure underflow");
CurrSetPressure[*PSet] -= Weight;
}
}
/// Directly increase pressure only within this RegisterPressure result.
void RegisterPressure::increase(unsigned Reg, const TargetRegisterInfo *TRI,
const MachineRegisterInfo *MRI) {
if (TargetRegisterInfo::isVirtualRegister(Reg)) {
const TargetRegisterClass *RC = MRI->getRegClass(Reg);
increaseSetPressure(MaxSetPressure, MaxSetPressure,
TRI->getRegClassPressureSets(RC),
TRI->getRegClassWeight(RC).RegWeight);
}
else {
increaseSetPressure(MaxSetPressure, MaxSetPressure,
TRI->getRegUnitPressureSets(Reg),
TRI->getRegUnitWeight(Reg));
}
}
/// Directly decrease pressure only within this RegisterPressure result.
void RegisterPressure::decrease(unsigned Reg, const TargetRegisterInfo *TRI,
const MachineRegisterInfo *MRI) {
if (TargetRegisterInfo::isVirtualRegister(Reg)) {
const TargetRegisterClass *RC = MRI->getRegClass(Reg);
decreaseSetPressure(MaxSetPressure, TRI->getRegClassPressureSets(RC),
TRI->getRegClassWeight(RC).RegWeight);
}
else {
decreaseSetPressure(MaxSetPressure, TRI->getRegUnitPressureSets(Reg),
TRI->getRegUnitWeight(Reg));
PSetIterator PSetI) {
unsigned Weight = PSetI.getWeight();
for (; PSetI.isValid(); ++PSetI) {
assert(CurrSetPressure[*PSetI] >= Weight && "register pressure underflow");
CurrSetPressure[*PSetI] -= Weight;
}
}
@ -114,35 +86,16 @@ void RegPressureTracker::dump() const {
/// Increase the current pressure as impacted by these registers and bump
/// the high water mark if needed.
void RegPressureTracker::increaseRegPressure(ArrayRef<unsigned> Regs) {
for (unsigned I = 0, E = Regs.size(); I != E; ++I) {
if (TargetRegisterInfo::isVirtualRegister(Regs[I])) {
const TargetRegisterClass *RC = MRI->getRegClass(Regs[I]);
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
increaseSetPressure(CurrSetPressure, P.MaxSetPressure,
TRI->getRegClassPressureSets(RC),
TRI->getRegClassWeight(RC).RegWeight);
}
else {
increaseSetPressure(CurrSetPressure, P.MaxSetPressure,
TRI->getRegUnitPressureSets(Regs[I]),
TRI->getRegUnitWeight(Regs[I]));
}
MRI->getPressureSets(Regs[i]));
}
}
/// Simply decrease the current pressure as impacted by these registers.
void RegPressureTracker::decreaseRegPressure(ArrayRef<unsigned> Regs) {
for (unsigned I = 0, E = Regs.size(); I != E; ++I) {
if (TargetRegisterInfo::isVirtualRegister(Regs[I])) {
const TargetRegisterClass *RC = MRI->getRegClass(Regs[I]);
decreaseSetPressure(CurrSetPressure,
TRI->getRegClassPressureSets(RC),
TRI->getRegClassWeight(RC).RegWeight);
}
else {
decreaseSetPressure(CurrSetPressure, TRI->getRegUnitPressureSets(Regs[I]),
TRI->getRegUnitWeight(Regs[I]));
}
}
for (unsigned I = 0, E = Regs.size(); I != E; ++I)
decreaseSetPressure(CurrSetPressure, MRI->getPressureSets(Regs[I]));
}
/// Clear the result so it can be used for another round of pressure tracking.
@ -328,10 +281,8 @@ void RegPressureTracker::initLiveThru(const RegPressureTracker &RPTracker) {
unsigned Reg = P.LiveOutRegs[i];
if (TargetRegisterInfo::isVirtualRegister(Reg)
&& !RPTracker.hasUntiedDef(Reg)) {
const TargetRegisterClass *RC = MRI->getRegClass(Reg);
increaseSetPressure(LiveThruPressure, LiveThruPressure,
TRI->getRegClassPressureSets(RC),
TRI->getRegClassWeight(RC).RegWeight);
MRI->getPressureSets(Reg));
}
}
}
@ -415,7 +366,8 @@ void RegPressureTracker::discoverLiveIn(unsigned Reg) {
// At live in discovery, unconditionally increase the high water mark.
P.LiveInRegs.push_back(Reg);
P.increase(Reg, TRI, MRI);
increaseSetPressure(P.MaxSetPressure, P.MaxSetPressure,
MRI->getPressureSets(Reg));
}
/// Add Reg to the live out set and increase max pressure.
@ -426,7 +378,8 @@ void RegPressureTracker::discoverLiveOut(unsigned Reg) {
// At live out discovery, unconditionally increase the high water mark.
P.LiveOutRegs.push_back(Reg);
P.increase(Reg, TRI, MRI);
increaseSetPressure(P.MaxSetPressure, P.MaxSetPressure,
MRI->getPressureSets(Reg));
}
/// Recede across the previous instruction.