forked from OSchip/llvm-project
Limit the search space in RAGreedy::tryEvict().
When tryEvict() is looking for a cheaper register in the allocation order, skip the tail of too expensive registers when possible. llvm-svn: 172281
This commit is contained in:
parent
8f644449af
commit
3dd236cdd8
|
@ -39,6 +39,9 @@ public:
|
||||||
const VirtRegMap &VRM,
|
const VirtRegMap &VRM,
|
||||||
const RegisterClassInfo &RegClassInfo);
|
const RegisterClassInfo &RegClassInfo);
|
||||||
|
|
||||||
|
/// Get the allocation order without reordered hints.
|
||||||
|
ArrayRef<MCPhysReg> getOrder() const { return Order; }
|
||||||
|
|
||||||
/// Return the next physical register in the allocation order, or 0.
|
/// Return the next physical register in the allocation order, or 0.
|
||||||
/// It is safe to call next() again after it returned 0, it will keep
|
/// It is safe to call next() again after it returned 0, it will keep
|
||||||
/// returning 0 until rewind() is called.
|
/// returning 0 until rewind() is called.
|
||||||
|
@ -53,6 +56,18 @@ public:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// As next(), but allow duplicates to be returned, and stop before the
|
||||||
|
/// Limit'th register in the RegisterClassInfo allocation order.
|
||||||
|
///
|
||||||
|
/// This can produce more than Limit registers if there are hints.
|
||||||
|
unsigned nextWithDups(unsigned Limit) {
|
||||||
|
if (Pos < 0)
|
||||||
|
return Hints.end()[Pos++];
|
||||||
|
if (Pos < int(Limit))
|
||||||
|
return Order[Pos++];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// Start over from the beginning.
|
/// Start over from the beginning.
|
||||||
void rewind() { Pos = -int(Hints.size()); }
|
void rewind() { Pos = -int(Hints.size()); }
|
||||||
|
|
||||||
|
|
|
@ -632,16 +632,33 @@ unsigned RAGreedy::tryEvict(LiveInterval &VirtReg,
|
||||||
// Keep track of the cheapest interference seen so far.
|
// Keep track of the cheapest interference seen so far.
|
||||||
EvictionCost BestCost(~0u);
|
EvictionCost BestCost(~0u);
|
||||||
unsigned BestPhys = 0;
|
unsigned BestPhys = 0;
|
||||||
|
unsigned OrderLimit = Order.getOrder().size();
|
||||||
|
|
||||||
// When we are just looking for a reduced cost per use, don't break any
|
// When we are just looking for a reduced cost per use, don't break any
|
||||||
// hints, and only evict smaller spill weights.
|
// hints, and only evict smaller spill weights.
|
||||||
if (CostPerUseLimit < ~0u) {
|
if (CostPerUseLimit < ~0u) {
|
||||||
BestCost.BrokenHints = 0;
|
BestCost.BrokenHints = 0;
|
||||||
BestCost.MaxWeight = VirtReg.weight;
|
BestCost.MaxWeight = VirtReg.weight;
|
||||||
|
|
||||||
|
// Check of any registers in RC are below CostPerUseLimit.
|
||||||
|
const TargetRegisterClass *RC = MRI->getRegClass(VirtReg.reg);
|
||||||
|
unsigned MinCost = RegClassInfo.getMinCost(RC);
|
||||||
|
if (MinCost >= CostPerUseLimit) {
|
||||||
|
DEBUG(dbgs() << RC->getName() << " minimum cost = " << MinCost
|
||||||
|
<< ", no cheaper registers to be found.\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// It is normal for register classes to have a long tail of registers with
|
||||||
|
// the same cost. We don't need to look at them if they're too expensive.
|
||||||
|
if (TRI->getCostPerUse(Order.getOrder().back()) >= CostPerUseLimit) {
|
||||||
|
OrderLimit = RegClassInfo.getLastCostChange(RC);
|
||||||
|
DEBUG(dbgs() << "Only trying the first " << OrderLimit << " regs.\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Order.rewind();
|
Order.rewind();
|
||||||
while (unsigned PhysReg = Order.next()) {
|
while (unsigned PhysReg = Order.nextWithDups(OrderLimit)) {
|
||||||
if (TRI->getCostPerUse(PhysReg) >= CostPerUseLimit)
|
if (TRI->getCostPerUse(PhysReg) >= CostPerUseLimit)
|
||||||
continue;
|
continue;
|
||||||
// The first use of a callee-saved register in a function has cost 1.
|
// The first use of a callee-saved register in a function has cost 1.
|
||||||
|
|
Loading…
Reference in New Issue