RegisterPressure: Unify the sparse sets in LiveRegsSet; NFC

Also do some cleanups comment improvements.

llvm-svn: 250598
This commit is contained in:
Matthias Braun 2015-10-17 01:03:44 +00:00
parent 8228198049
commit 65e6d4a3f8
2 changed files with 60 additions and 27 deletions

View File

@ -193,30 +193,56 @@ struct RegPressureDelta {
}
};
/// \brief A set of live virtual registers and physical register units.
/// A set of live virtual registers and physical register units.
///
/// Virtual and physical register numbers require separate sparse sets, but most
/// of the RegisterPressureTracker handles them uniformly.
struct LiveRegSet {
SparseSet<unsigned> PhysRegs;
SparseSet<unsigned, VirtReg2IndexFunctor> VirtRegs;
/// This is a wrapper around a SparseSet which deals with mapping register unit
/// and virtual register indexes to an index usable by the sparse set.
class LiveRegSet {
private:
SparseSet<unsigned> Regs;
unsigned NumRegUnits;
unsigned getSparseIndexFromReg(unsigned Reg) const {
if (TargetRegisterInfo::isVirtualRegister(Reg))
return TargetRegisterInfo::virtReg2Index(Reg) + NumRegUnits;
assert(Reg < NumRegUnits);
return Reg;
}
unsigned getRegFromSparseIndex(unsigned SparseIndex) const {
if (SparseIndex >= NumRegUnits)
return TargetRegisterInfo::index2VirtReg(SparseIndex-NumRegUnits);
return SparseIndex;
}
public:
void clear();
void init(const MachineRegisterInfo &MRI);
bool contains(unsigned Reg) const {
if (TargetRegisterInfo::isVirtualRegister(Reg))
return VirtRegs.count(Reg);
return PhysRegs.count(Reg);
unsigned SparseIndex = getSparseIndexFromReg(Reg);
return Regs.count(SparseIndex);
}
bool insert(unsigned Reg) {
if (TargetRegisterInfo::isVirtualRegister(Reg))
return VirtRegs.insert(Reg).second;
return PhysRegs.insert(Reg).second;
unsigned SparseIndex = getSparseIndexFromReg(Reg);
return Regs.insert(SparseIndex).second;
}
bool erase(unsigned Reg) {
if (TargetRegisterInfo::isVirtualRegister(Reg))
return VirtRegs.erase(Reg);
return PhysRegs.erase(Reg);
unsigned SparseIndex = getSparseIndexFromReg(Reg);
return Regs.erase(SparseIndex);
}
size_t size() const {
return Regs.size();
}
template<typename ContainerT>
void appendTo(ContainerT &To) const {
for (unsigned I : Regs) {
unsigned Reg = getRegFromSparseIndex(I);
To.push_back(Reg);
}
}
};

View File

@ -157,6 +157,18 @@ void RegionPressure::openBottom(MachineBasicBlock::const_iterator PrevBottom) {
LiveInRegs.clear();
}
void LiveRegSet::init(const MachineRegisterInfo &MRI) {
const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
unsigned NumRegUnits = TRI.getNumRegs();
unsigned NumVirtRegs = MRI.getNumVirtRegs();
Regs.setUniverse(NumRegUnits + NumVirtRegs);
this->NumRegUnits = NumRegUnits;
}
void LiveRegSet::clear() {
Regs.clear();
}
const LiveRange *RegPressureTracker::getLiveRange(unsigned Reg) const {
if (TargetRegisterInfo::isVirtualRegister(Reg))
return &LIS->getInterval(Reg);
@ -176,8 +188,7 @@ void RegPressureTracker::reset() {
else
static_cast<RegionPressure&>(P).reset();
LiveRegs.PhysRegs.clear();
LiveRegs.VirtRegs.clear();
LiveRegs.clear();
UntiedDefs.clear();
}
@ -210,8 +221,7 @@ void RegPressureTracker::init(const MachineFunction *mf,
P.MaxSetPressure = CurrSetPressure;
LiveRegs.PhysRegs.setUniverse(TRI->getNumRegUnits());
LiveRegs.VirtRegs.setUniverse(MRI->getNumVirtRegs());
LiveRegs.init(*MRI);
if (TrackUntiedDefs)
UntiedDefs.setUniverse(MRI->getNumVirtRegs());
}
@ -250,9 +260,8 @@ void RegPressureTracker::closeTop() {
static_cast<RegionPressure&>(P).TopPos = CurrPos;
assert(P.LiveInRegs.empty() && "inconsistent max pressure result");
P.LiveInRegs.reserve(LiveRegs.PhysRegs.size() + LiveRegs.VirtRegs.size());
P.LiveInRegs.append(LiveRegs.PhysRegs.begin(), LiveRegs.PhysRegs.end());
P.LiveInRegs.append(LiveRegs.VirtRegs.begin(), LiveRegs.VirtRegs.end());
P.LiveInRegs.reserve(LiveRegs.size());
LiveRegs.appendTo(P.LiveInRegs);
}
/// Set the boundary for the bottom of the region and summarize live outs.
@ -263,16 +272,14 @@ void RegPressureTracker::closeBottom() {
static_cast<RegionPressure&>(P).BottomPos = CurrPos;
assert(P.LiveOutRegs.empty() && "inconsistent max pressure result");
P.LiveOutRegs.reserve(LiveRegs.PhysRegs.size() + LiveRegs.VirtRegs.size());
P.LiveOutRegs.append(LiveRegs.PhysRegs.begin(), LiveRegs.PhysRegs.end());
P.LiveOutRegs.append(LiveRegs.VirtRegs.begin(), LiveRegs.VirtRegs.end());
P.LiveOutRegs.reserve(LiveRegs.size());
LiveRegs.appendTo(P.LiveOutRegs);
}
/// Finalize the region boundaries and record live ins and live outs.
void RegPressureTracker::closeRegion() {
if (!isTopClosed() && !isBottomClosed()) {
assert(LiveRegs.PhysRegs.empty() && LiveRegs.VirtRegs.empty() &&
"no region boundary");
assert(LiveRegs.size() == 0 && "no region boundary");
return;
}
if (!isBottomClosed())