mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-28 22:20:43 +00:00
Remove LiveIntervalUnions from RegAllocBase.
They are living in LiveRegMatrix now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158868 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
042888db2b
commit
d4348a2dc2
@ -35,8 +35,6 @@
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
STATISTIC(NumAssigned , "Number of registers assigned");
|
||||
STATISTIC(NumUnassigned , "Number of registers unassigned");
|
||||
STATISTIC(NumNewQueued , "Number of new live ranges queued");
|
||||
|
||||
// Temporary verification option until we can put verification inside
|
||||
@ -48,69 +46,20 @@ VerifyRegAlloc("verify-regalloc", cl::location(RegAllocBase::VerifyEnabled),
|
||||
const char *RegAllocBase::TimerGroupName = "Register Allocation";
|
||||
bool RegAllocBase::VerifyEnabled = false;
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Verify each LiveIntervalUnion.
|
||||
void RegAllocBase::verify() {
|
||||
LiveVirtRegBitSet VisitedVRegs;
|
||||
OwningArrayPtr<LiveVirtRegBitSet>
|
||||
unionVRegs(new LiveVirtRegBitSet[TRI->getNumRegs()]);
|
||||
|
||||
// Verify disjoint unions.
|
||||
for (unsigned PhysReg = 0, NumRegs = TRI->getNumRegs(); PhysReg != NumRegs;
|
||||
++PhysReg) {
|
||||
DEBUG(PhysReg2LiveUnion[PhysReg].print(dbgs(), TRI));
|
||||
LiveVirtRegBitSet &VRegs = unionVRegs[PhysReg];
|
||||
PhysReg2LiveUnion[PhysReg].verify(VRegs);
|
||||
// Union + intersection test could be done efficiently in one pass, but
|
||||
// don't add a method to SparseBitVector unless we really need it.
|
||||
assert(!VisitedVRegs.intersects(VRegs) && "vreg in multiple unions");
|
||||
VisitedVRegs |= VRegs;
|
||||
}
|
||||
|
||||
// Verify vreg coverage.
|
||||
for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
|
||||
unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
|
||||
if (MRI->reg_nodbg_empty(Reg))
|
||||
continue;
|
||||
if (!VRM->hasPhys(Reg)) continue; // spilled?
|
||||
LiveInterval &LI = LIS->getInterval(Reg);
|
||||
if (LI.empty()) continue; // unionVRegs will only be filled if li is
|
||||
// non-empty
|
||||
unsigned PhysReg = VRM->getPhys(Reg);
|
||||
if (!unionVRegs[PhysReg].test(Reg)) {
|
||||
dbgs() << "LiveVirtReg " << PrintReg(Reg, TRI) << " not in union "
|
||||
<< TRI->getName(PhysReg) << "\n";
|
||||
llvm_unreachable("unallocated live vreg");
|
||||
}
|
||||
}
|
||||
// FIXME: I'm not sure how to verify spilled intervals.
|
||||
}
|
||||
#endif //!NDEBUG
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// RegAllocBase Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void RegAllocBase::init(VirtRegMap &vrm, LiveIntervals &lis) {
|
||||
NamedRegionTimer T("Initialize", TimerGroupName, TimePassesIsEnabled);
|
||||
void RegAllocBase::init(VirtRegMap &vrm,
|
||||
LiveIntervals &lis,
|
||||
LiveRegMatrix &mat) {
|
||||
TRI = &vrm.getTargetRegInfo();
|
||||
MRI = &vrm.getRegInfo();
|
||||
VRM = &vrm;
|
||||
LIS = &lis;
|
||||
Matrix = &mat;
|
||||
MRI->freezeReservedRegs(vrm.getMachineFunction());
|
||||
RegClassInfo.runOnMachineFunction(vrm.getMachineFunction());
|
||||
|
||||
const unsigned NumRegs = TRI->getNumRegs();
|
||||
if (NumRegs != PhysReg2LiveUnion.size()) {
|
||||
PhysReg2LiveUnion.init(UnionAllocator, NumRegs);
|
||||
// Cache an interferece query for each physical reg
|
||||
Queries.reset(new LiveIntervalUnion::Query[NumRegs]);
|
||||
}
|
||||
}
|
||||
|
||||
void RegAllocBase::releaseMemory() {
|
||||
for (unsigned r = 0, e = PhysReg2LiveUnion.size(); r != e; ++r)
|
||||
PhysReg2LiveUnion[r].clear();
|
||||
}
|
||||
|
||||
// Visit all the live registers. If they are already assigned to a physical
|
||||
@ -118,14 +67,6 @@ void RegAllocBase::releaseMemory() {
|
||||
// them on the priority queue for later assignment.
|
||||
void RegAllocBase::seedLiveRegs() {
|
||||
NamedRegionTimer T("Seed Live Regs", TimerGroupName, TimePassesIsEnabled);
|
||||
// Physregs.
|
||||
for (unsigned Reg = 1, e = TRI->getNumRegs(); Reg != e; ++Reg) {
|
||||
if (!LIS->hasInterval(Reg))
|
||||
continue;
|
||||
PhysReg2LiveUnion[Reg].unify(LIS->getInterval(Reg));
|
||||
}
|
||||
|
||||
// Virtregs.
|
||||
for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
|
||||
unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
|
||||
if (MRI->reg_nodbg_empty(Reg))
|
||||
@ -134,35 +75,6 @@ void RegAllocBase::seedLiveRegs() {
|
||||
}
|
||||
}
|
||||
|
||||
void RegAllocBase::assign(LiveInterval &VirtReg, unsigned PhysReg) {
|
||||
// FIXME: This diversion is temporary.
|
||||
if (Matrix) {
|
||||
Matrix->assign(VirtReg, PhysReg);
|
||||
return;
|
||||
}
|
||||
DEBUG(dbgs() << "assigning " << PrintReg(VirtReg.reg, TRI)
|
||||
<< " to " << PrintReg(PhysReg, TRI) << '\n');
|
||||
assert(!VRM->hasPhys(VirtReg.reg) && "Duplicate VirtReg assignment");
|
||||
VRM->assignVirt2Phys(VirtReg.reg, PhysReg);
|
||||
MRI->setPhysRegUsed(PhysReg);
|
||||
PhysReg2LiveUnion[PhysReg].unify(VirtReg);
|
||||
++NumAssigned;
|
||||
}
|
||||
|
||||
void RegAllocBase::unassign(LiveInterval &VirtReg, unsigned PhysReg) {
|
||||
// FIXME: This diversion is temporary.
|
||||
if (Matrix) {
|
||||
Matrix->unassign(VirtReg);
|
||||
return;
|
||||
}
|
||||
DEBUG(dbgs() << "unassigning " << PrintReg(VirtReg.reg, TRI)
|
||||
<< " from " << PrintReg(PhysReg, TRI) << '\n');
|
||||
assert(VRM->getPhys(VirtReg.reg) == PhysReg && "Inconsistent unassign");
|
||||
PhysReg2LiveUnion[PhysReg].extract(VirtReg);
|
||||
VRM->clearVirt(VirtReg.reg);
|
||||
++NumUnassigned;
|
||||
}
|
||||
|
||||
// Top-level driver to manage the queue of unassigned VirtRegs and call the
|
||||
// selectOrSplit implementation.
|
||||
void RegAllocBase::allocatePhysRegs() {
|
||||
@ -180,9 +92,7 @@ void RegAllocBase::allocatePhysRegs() {
|
||||
}
|
||||
|
||||
// Invalidate all interference queries, live ranges could have changed.
|
||||
invalidateVirtRegs();
|
||||
if (Matrix)
|
||||
Matrix->invalidateVirtRegs();
|
||||
Matrix->invalidateVirtRegs();
|
||||
|
||||
// selectOrSplit requests the allocator to return an available physical
|
||||
// register if possible and populate a list of new live intervals that
|
||||
@ -214,7 +124,7 @@ void RegAllocBase::allocatePhysRegs() {
|
||||
}
|
||||
|
||||
if (AvailablePhysReg)
|
||||
assign(*VirtReg, AvailablePhysReg);
|
||||
Matrix->assign(*VirtReg, AvailablePhysReg);
|
||||
|
||||
for (VirtRegVec::iterator I = SplitVRegs.begin(), E = SplitVRegs.end();
|
||||
I != E; ++I) {
|
||||
@ -233,14 +143,3 @@ void RegAllocBase::allocatePhysRegs() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if this live virtual register interferes with a physical register. If
|
||||
// not, then check for interference on each register that aliases with the
|
||||
// physical register. Return the interfering register.
|
||||
unsigned RegAllocBase::checkPhysRegInterference(LiveInterval &VirtReg,
|
||||
unsigned PhysReg) {
|
||||
for (MCRegAliasIterator AI(PhysReg, TRI, true); AI.isValid(); ++AI)
|
||||
if (query(VirtReg, *AI).checkInterference())
|
||||
return *AI;
|
||||
return 0;
|
||||
}
|
||||
|
@ -57,18 +57,6 @@ class Spiller;
|
||||
/// live range splitting. They must also override enqueue/dequeue to provide an
|
||||
/// assignment order.
|
||||
class RegAllocBase {
|
||||
LiveIntervalUnion::Allocator UnionAllocator;
|
||||
|
||||
// Cache tag for PhysReg2LiveUnion entries. Increment whenever virtual
|
||||
// registers may have changed.
|
||||
unsigned UserTag;
|
||||
|
||||
LiveIntervalUnion::Array PhysReg2LiveUnion;
|
||||
|
||||
// Current queries, one per physreg. They must be reinitialized each time we
|
||||
// query on a new live virtual register.
|
||||
OwningArrayPtr<LiveIntervalUnion::Query> Queries;
|
||||
|
||||
protected:
|
||||
const TargetRegisterInfo *TRI;
|
||||
MachineRegisterInfo *MRI;
|
||||
@ -77,30 +65,12 @@ protected:
|
||||
LiveRegMatrix *Matrix;
|
||||
RegisterClassInfo RegClassInfo;
|
||||
|
||||
RegAllocBase(): UserTag(0), TRI(0), MRI(0), VRM(0), LIS(0), Matrix(0) {}
|
||||
RegAllocBase(): TRI(0), MRI(0), VRM(0), LIS(0), Matrix(0) {}
|
||||
|
||||
virtual ~RegAllocBase() {}
|
||||
|
||||
// A RegAlloc pass should call this before allocatePhysRegs.
|
||||
void init(VirtRegMap &vrm, LiveIntervals &lis);
|
||||
|
||||
// Get an initialized query to check interferences between lvr and preg. Note
|
||||
// that Query::init must be called at least once for each physical register
|
||||
// before querying a new live virtual register. This ties Queries and
|
||||
// PhysReg2LiveUnion together.
|
||||
LiveIntervalUnion::Query &query(LiveInterval &VirtReg, unsigned PhysReg) {
|
||||
Queries[PhysReg].init(UserTag, &VirtReg, &PhysReg2LiveUnion[PhysReg]);
|
||||
return Queries[PhysReg];
|
||||
}
|
||||
|
||||
// Get direct access to the underlying LiveIntervalUnion for PhysReg.
|
||||
LiveIntervalUnion &getLiveUnion(unsigned PhysReg) {
|
||||
return PhysReg2LiveUnion[PhysReg];
|
||||
}
|
||||
|
||||
// Invalidate all cached information about virtual registers - live ranges may
|
||||
// have changed.
|
||||
void invalidateVirtRegs() { ++UserTag; }
|
||||
void init(VirtRegMap &vrm, LiveIntervals &lis, LiveRegMatrix &mat);
|
||||
|
||||
// The top-level driver. The output is a VirtRegMap that us updated with
|
||||
// physical register assignments.
|
||||
@ -122,28 +92,6 @@ protected:
|
||||
virtual unsigned selectOrSplit(LiveInterval &VirtReg,
|
||||
SmallVectorImpl<LiveInterval*> &splitLVRs) = 0;
|
||||
|
||||
// A RegAlloc pass should call this when PassManager releases its memory.
|
||||
virtual void releaseMemory();
|
||||
|
||||
// Helper for checking interference between a live virtual register and a
|
||||
// physical register, including all its register aliases. If an interference
|
||||
// exists, return the interfering register, which may be preg or an alias.
|
||||
unsigned checkPhysRegInterference(LiveInterval& VirtReg, unsigned PhysReg);
|
||||
|
||||
/// assign - Assign VirtReg to PhysReg.
|
||||
/// This should not be called from selectOrSplit for the current register.
|
||||
void assign(LiveInterval &VirtReg, unsigned PhysReg);
|
||||
|
||||
/// unassign - Undo a previous assignment of VirtReg to PhysReg.
|
||||
/// This can be invoked from selectOrSplit, but be careful to guarantee that
|
||||
/// allocation is making progress.
|
||||
void unassign(LiveInterval &VirtReg, unsigned PhysReg);
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Verify each LiveIntervalUnion.
|
||||
void verify();
|
||||
#endif
|
||||
|
||||
// Use this group name for NamedRegionTimer.
|
||||
static const char *TimerGroupName;
|
||||
|
||||
|
@ -169,7 +169,6 @@ void RABasic::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||
|
||||
void RABasic::releaseMemory() {
|
||||
SpillerInstance.reset(0);
|
||||
RegAllocBase::releaseMemory();
|
||||
}
|
||||
|
||||
|
||||
@ -287,8 +286,9 @@ bool RABasic::runOnMachineFunction(MachineFunction &mf) {
|
||||
MF = &mf;
|
||||
DEBUG(RMF = &getAnalysis<RenderMachineFunction>());
|
||||
|
||||
RegAllocBase::init(getAnalysis<VirtRegMap>(), getAnalysis<LiveIntervals>());
|
||||
Matrix = &getAnalysis<LiveRegMatrix>();
|
||||
RegAllocBase::init(getAnalysis<VirtRegMap>(),
|
||||
getAnalysis<LiveIntervals>(),
|
||||
getAnalysis<LiveRegMatrix>());
|
||||
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));
|
||||
|
||||
allocatePhysRegs();
|
||||
|
@ -390,7 +390,6 @@ void RAGreedy::releaseMemory() {
|
||||
SpillerInstance.reset(0);
|
||||
ExtraRegInfo.clear();
|
||||
GlobalCand.clear();
|
||||
RegAllocBase::releaseMemory();
|
||||
}
|
||||
|
||||
void RAGreedy::enqueue(LiveInterval *LI) {
|
||||
@ -1754,8 +1753,9 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
|
||||
if (VerifyEnabled)
|
||||
MF->verify(this, "Before greedy register allocator");
|
||||
|
||||
RegAllocBase::init(getAnalysis<VirtRegMap>(), getAnalysis<LiveIntervals>());
|
||||
Matrix = &getAnalysis<LiveRegMatrix>();
|
||||
RegAllocBase::init(getAnalysis<VirtRegMap>(),
|
||||
getAnalysis<LiveIntervals>(),
|
||||
getAnalysis<LiveRegMatrix>());
|
||||
Indexes = &getAnalysis<SlotIndexes>();
|
||||
DomTree = &getAnalysis<MachineDominatorTree>();
|
||||
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));
|
||||
|
Loading…
Reference in New Issue
Block a user