forked from OSchip/llvm-project
Add a convenient PSetIterator for visiting pressure sets affected by a register.
llvm-svn: 189121
This commit is contained in:
parent
c01b00400d
commit
86a7061e5d
|
@ -22,6 +22,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
class PSetIterator;
|
||||||
|
|
||||||
/// MachineRegisterInfo - Keep track of information for virtual and physical
|
/// MachineRegisterInfo - Keep track of information for virtual and physical
|
||||||
/// registers, including vreg register classes, use/def chains for registers,
|
/// registers, including vreg register classes, use/def chains for registers,
|
||||||
|
@ -326,6 +327,11 @@ public:
|
||||||
/// a physreg.
|
/// a physreg.
|
||||||
bool isConstantPhysReg(unsigned PhysReg, const MachineFunction &MF) const;
|
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
|
// Virtual Register Info
|
||||||
//===--------------------------------------------------------------------===//
|
//===--------------------------------------------------------------------===//
|
||||||
|
@ -647,9 +653,49 @@ public:
|
||||||
return Op->getParent();
|
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
|
} // End llvm namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,52 +26,24 @@ using namespace llvm;
|
||||||
/// Increase pressure for each pressure set provided by TargetRegisterInfo.
|
/// Increase pressure for each pressure set provided by TargetRegisterInfo.
|
||||||
static void increaseSetPressure(std::vector<unsigned> &CurrSetPressure,
|
static void increaseSetPressure(std::vector<unsigned> &CurrSetPressure,
|
||||||
std::vector<unsigned> &MaxSetPressure,
|
std::vector<unsigned> &MaxSetPressure,
|
||||||
const int *PSet, unsigned Weight) {
|
PSetIterator PSetI) {
|
||||||
for (; *PSet != -1; ++PSet) {
|
unsigned Weight = PSetI.getWeight();
|
||||||
CurrSetPressure[*PSet] += Weight;
|
for (; PSetI.isValid(); ++PSetI) {
|
||||||
|
CurrSetPressure[*PSetI] += Weight;
|
||||||
if (&CurrSetPressure != &MaxSetPressure
|
if (&CurrSetPressure != &MaxSetPressure
|
||||||
&& CurrSetPressure[*PSet] > MaxSetPressure[*PSet]) {
|
&& CurrSetPressure[*PSetI] > MaxSetPressure[*PSetI]) {
|
||||||
MaxSetPressure[*PSet] = CurrSetPressure[*PSet];
|
MaxSetPressure[*PSetI] = CurrSetPressure[*PSetI];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decrease pressure for each pressure set provided by TargetRegisterInfo.
|
/// Decrease pressure for each pressure set provided by TargetRegisterInfo.
|
||||||
static void decreaseSetPressure(std::vector<unsigned> &CurrSetPressure,
|
static void decreaseSetPressure(std::vector<unsigned> &CurrSetPressure,
|
||||||
const int *PSet, unsigned Weight) {
|
PSetIterator PSetI) {
|
||||||
for (; *PSet != -1; ++PSet) {
|
unsigned Weight = PSetI.getWeight();
|
||||||
assert(CurrSetPressure[*PSet] >= Weight && "register pressure underflow");
|
for (; PSetI.isValid(); ++PSetI) {
|
||||||
CurrSetPressure[*PSet] -= Weight;
|
assert(CurrSetPressure[*PSetI] >= Weight && "register pressure underflow");
|
||||||
}
|
CurrSetPressure[*PSetI] -= 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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,35 +86,16 @@ void RegPressureTracker::dump() const {
|
||||||
/// Increase the current pressure as impacted by these registers and bump
|
/// Increase the current pressure as impacted by these registers and bump
|
||||||
/// the high water mark if needed.
|
/// the high water mark if needed.
|
||||||
void RegPressureTracker::increaseRegPressure(ArrayRef<unsigned> Regs) {
|
void RegPressureTracker::increaseRegPressure(ArrayRef<unsigned> Regs) {
|
||||||
for (unsigned I = 0, E = Regs.size(); I != E; ++I) {
|
for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
|
||||||
if (TargetRegisterInfo::isVirtualRegister(Regs[I])) {
|
increaseSetPressure(CurrSetPressure, P.MaxSetPressure,
|
||||||
const TargetRegisterClass *RC = MRI->getRegClass(Regs[I]);
|
MRI->getPressureSets(Regs[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]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Simply decrease the current pressure as impacted by these registers.
|
/// Simply decrease the current pressure as impacted by these registers.
|
||||||
void RegPressureTracker::decreaseRegPressure(ArrayRef<unsigned> Regs) {
|
void RegPressureTracker::decreaseRegPressure(ArrayRef<unsigned> Regs) {
|
||||||
for (unsigned I = 0, E = Regs.size(); I != E; ++I) {
|
for (unsigned I = 0, E = Regs.size(); I != E; ++I)
|
||||||
if (TargetRegisterInfo::isVirtualRegister(Regs[I])) {
|
decreaseSetPressure(CurrSetPressure, MRI->getPressureSets(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]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear the result so it can be used for another round of pressure tracking.
|
/// 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];
|
unsigned Reg = P.LiveOutRegs[i];
|
||||||
if (TargetRegisterInfo::isVirtualRegister(Reg)
|
if (TargetRegisterInfo::isVirtualRegister(Reg)
|
||||||
&& !RPTracker.hasUntiedDef(Reg)) {
|
&& !RPTracker.hasUntiedDef(Reg)) {
|
||||||
const TargetRegisterClass *RC = MRI->getRegClass(Reg);
|
|
||||||
increaseSetPressure(LiveThruPressure, LiveThruPressure,
|
increaseSetPressure(LiveThruPressure, LiveThruPressure,
|
||||||
TRI->getRegClassPressureSets(RC),
|
MRI->getPressureSets(Reg));
|
||||||
TRI->getRegClassWeight(RC).RegWeight);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,7 +366,8 @@ void RegPressureTracker::discoverLiveIn(unsigned Reg) {
|
||||||
|
|
||||||
// At live in discovery, unconditionally increase the high water mark.
|
// At live in discovery, unconditionally increase the high water mark.
|
||||||
P.LiveInRegs.push_back(Reg);
|
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.
|
/// 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.
|
// At live out discovery, unconditionally increase the high water mark.
|
||||||
P.LiveOutRegs.push_back(Reg);
|
P.LiveOutRegs.push_back(Reg);
|
||||||
P.increase(Reg, TRI, MRI);
|
increaseSetPressure(P.MaxSetPressure, P.MaxSetPressure,
|
||||||
|
MRI->getPressureSets(Reg));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recede across the previous instruction.
|
/// Recede across the previous instruction.
|
||||||
|
|
Loading…
Reference in New Issue