Abort the constraint calculation early when all positive bias is lost.

Without any positive bias, there is nothing for the spill placer to to. It will
spill everywhere.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129029 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jakob Stoklund Olesen 2011-04-06 21:32:38 +00:00
parent b0923771c9
commit 1b400e840f

View File

@ -169,7 +169,7 @@ private:
void LRE_WillShrinkVirtReg(unsigned); void LRE_WillShrinkVirtReg(unsigned);
void LRE_DidCloneVirtReg(unsigned, unsigned); void LRE_DidCloneVirtReg(unsigned, unsigned);
float calcSplitConstraints(unsigned); bool addSplitConstraints(unsigned, float&);
float calcGlobalSplitCost(const BitVector&); float calcGlobalSplitCost(const BitVector&);
void splitAroundRegion(LiveInterval&, unsigned, const BitVector&, void splitAroundRegion(LiveInterval&, unsigned, const BitVector&,
SmallVectorImpl<LiveInterval*>&); SmallVectorImpl<LiveInterval*>&);
@ -409,10 +409,12 @@ unsigned RAGreedy::tryEvict(LiveInterval &VirtReg,
// Region Splitting // Region Splitting
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// calcSplitConstraints - Fill out the SplitConstraints vector based on the /// addSplitConstraints - Fill out the SplitConstraints vector based on the
/// interference pattern in Physreg and its aliases. Return the static cost of /// interference pattern in Physreg and its aliases. Add the constraints to
/// this split, assuming that all preferences in SplitConstraints are met. /// SpillPlacement and return the static cost of this split in Cost, assuming
float RAGreedy::calcSplitConstraints(unsigned PhysReg) { /// that all preferences in SplitConstraints are met.
/// If it is evident that no bundles will be live, abort early and return false.
bool RAGreedy::addSplitConstraints(unsigned PhysReg, float &Cost) {
InterferenceCache::Cursor Intf(IntfCache, PhysReg); InterferenceCache::Cursor Intf(IntfCache, PhysReg);
ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks(); ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks();
@ -459,33 +461,58 @@ float RAGreedy::calcSplitConstraints(unsigned PhysReg) {
StaticCost += Ins * SpillPlacer->getBlockFrequency(BC.Number); StaticCost += Ins * SpillPlacer->getBlockFrequency(BC.Number);
} }
// Now handle the live-through blocks without uses. // Add constraints for use-blocks. Note that these are the only constraints
// that may add a positive bias, it is downhill from here.
SpillPlacer->addConstraints(SplitConstraints);
if (SpillPlacer->getPositiveNodes() == 0)
return false;
Cost = StaticCost;
// Now handle the live-through blocks without uses. These can only add
// negative bias, so we can abort whenever there are no more positive nodes.
// Compute constraints for a group of 8 blocks at a time.
const unsigned GroupSize = 8;
SpillPlacement::BlockConstraint BCS[GroupSize];
unsigned B = 0;
ArrayRef<unsigned> ThroughBlocks = SA->getThroughBlocks(); ArrayRef<unsigned> ThroughBlocks = SA->getThroughBlocks();
SplitConstraints.resize(UseBlocks.size() + ThroughBlocks.size());
for (unsigned i = 0; i != ThroughBlocks.size(); ++i) { for (unsigned i = 0; i != ThroughBlocks.size(); ++i) {
SpillPlacement::BlockConstraint &BC = SplitConstraints[UseBlocks.size()+i]; unsigned Number = ThroughBlocks[i];
BC.Number = ThroughBlocks[i]; assert(B < GroupSize && "Array overflow");
BC.Entry = SpillPlacement::DontCare; BCS[B].Number = Number;
BC.Exit = SpillPlacement::DontCare; Intf.moveToBlock(Number);
Intf.moveToBlock(BC.Number); if (Intf.hasInterference()) {
if (!Intf.hasInterference()) // Interference for the live-in value.
continue; if (Intf.first() <= Indexes->getMBBStartIdx(Number))
BCS[B].Entry = SpillPlacement::MustSpill;
else
BCS[B].Entry = SpillPlacement::PrefSpill;
// Interference for the live-in value. // Interference for the live-out value.
if (Intf.first() <= Indexes->getMBBStartIdx(BC.Number)) if (Intf.last() >= SA->getLastSplitPoint(Number))
BC.Entry = SpillPlacement::MustSpill; BCS[B].Exit = SpillPlacement::MustSpill;
else else
BC.Entry = SpillPlacement::PrefSpill; BCS[B].Exit = SpillPlacement::PrefSpill;
} else {
// No interference, transparent block.
BCS[B].Entry = BCS[B].Exit = SpillPlacement::DontCare;
}
// Interference for the live-out value. if (++B == GroupSize) {
if (Intf.last() >= SA->getLastSplitPoint(BC.Number)) ArrayRef<SpillPlacement::BlockConstraint> Array(BCS, B);
BC.Exit = SpillPlacement::MustSpill; SpillPlacer->addConstraints(Array);
else B = 0;
BC.Exit = SpillPlacement::PrefSpill; // Abort early when all hope is lost.
if (SpillPlacer->getPositiveNodes() == 0)
return false;
}
} }
return StaticCost; ArrayRef<SpillPlacement::BlockConstraint> Array(BCS, B);
SpillPlacer->addConstraints(Array);
return SpillPlacer->getPositiveNodes() != 0;
} }
@ -763,16 +790,19 @@ unsigned RAGreedy::tryRegionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
GlobalCand.resize(Cand+1); GlobalCand.resize(Cand+1);
GlobalCand[Cand].PhysReg = PhysReg; GlobalCand[Cand].PhysReg = PhysReg;
float Cost = calcSplitConstraints(PhysReg); SpillPlacer->prepare(LiveBundles);
DEBUG(dbgs() << PrintReg(PhysReg, TRI) << "\tstatic = " << Cost); float Cost;
if (!addSplitConstraints(PhysReg, Cost)) {
DEBUG(dbgs() << PrintReg(PhysReg, TRI) << "\tno positive bias\n");
continue;
}
DEBUG(dbgs() << PrintReg(PhysReg, TRI) << "\tbiased = "
<< SpillPlacer->getPositiveNodes() << ", static = " << Cost);
if (BestReg && Cost >= BestCost) { if (BestReg && Cost >= BestCost) {
DEBUG(dbgs() << " higher.\n"); DEBUG(dbgs() << " worse than " << PrintReg(BestReg, TRI) << '\n');
continue; continue;
} }
SpillPlacer->prepare(LiveBundles);
SpillPlacer->addConstraints(SplitConstraints);
DEBUG(dbgs() << ", " << SpillPlacer->getPositiveNodes() << " biased nodes");
SpillPlacer->finish(); SpillPlacer->finish();
// No live bundles, defer to splitSingleBlocks(). // No live bundles, defer to splitSingleBlocks().