Remove floats from live range splitting costs.

These floats all represented block frequencies anyway, so just use the
BlockFrequency class directly.

Some floating point computations remain in tryLocalSplit(). They are
estimating spill weights which are still floats.

llvm-svn: 186435
This commit is contained in:
Jakob Stoklund Olesen 2013-07-16 18:26:18 +00:00
parent c5454ff046
commit efeb3a1969
2 changed files with 28 additions and 26 deletions

View File

@ -251,11 +251,11 @@ private:
void LRE_WillShrinkVirtReg(unsigned); void LRE_WillShrinkVirtReg(unsigned);
void LRE_DidCloneVirtReg(unsigned, unsigned); void LRE_DidCloneVirtReg(unsigned, unsigned);
float calcSpillCost(); BlockFrequency calcSpillCost();
bool addSplitConstraints(InterferenceCache::Cursor, float&); bool addSplitConstraints(InterferenceCache::Cursor, BlockFrequency&);
void addThroughConstraints(InterferenceCache::Cursor, ArrayRef<unsigned>); void addThroughConstraints(InterferenceCache::Cursor, ArrayRef<unsigned>);
void growRegion(GlobalSplitCandidate &Cand); void growRegion(GlobalSplitCandidate &Cand);
float calcGlobalSplitCost(GlobalSplitCandidate&); BlockFrequency calcGlobalSplitCost(GlobalSplitCandidate&);
bool calcCompactRegion(GlobalSplitCandidate&); bool calcCompactRegion(GlobalSplitCandidate&);
void splitAroundRegion(LiveRangeEdit&, ArrayRef<unsigned>); void splitAroundRegion(LiveRangeEdit&, ArrayRef<unsigned>);
void calcGapWeights(unsigned, SmallVectorImpl<float>&); void calcGapWeights(unsigned, SmallVectorImpl<float>&);
@ -703,12 +703,12 @@ unsigned RAGreedy::tryEvict(LiveInterval &VirtReg,
/// that all preferences in SplitConstraints are met. /// that all preferences in SplitConstraints are met.
/// Return false if there are no bundles with positive bias. /// Return false if there are no bundles with positive bias.
bool RAGreedy::addSplitConstraints(InterferenceCache::Cursor Intf, bool RAGreedy::addSplitConstraints(InterferenceCache::Cursor Intf,
float &Cost) { BlockFrequency &Cost) {
ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks(); ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks();
// Reset interference dependent info. // Reset interference dependent info.
SplitConstraints.resize(UseBlocks.size()); SplitConstraints.resize(UseBlocks.size());
float StaticCost = 0; BlockFrequency StaticCost = 0;
for (unsigned i = 0; i != UseBlocks.size(); ++i) { for (unsigned i = 0; i != UseBlocks.size(); ++i) {
const SplitAnalysis::BlockInfo &BI = UseBlocks[i]; const SplitAnalysis::BlockInfo &BI = UseBlocks[i];
SpillPlacement::BlockConstraint &BC = SplitConstraints[i]; SpillPlacement::BlockConstraint &BC = SplitConstraints[i];
@ -746,8 +746,8 @@ bool RAGreedy::addSplitConstraints(InterferenceCache::Cursor Intf,
} }
// Accumulate the total frequency of inserted spill code. // Accumulate the total frequency of inserted spill code.
if (Ins) while (Ins--)
StaticCost += Ins * SpillPlacer->getBlockFrequency(BC.Number); StaticCost += SpillPlacer->getBlockFrequency(BC.Number);
} }
Cost = StaticCost; Cost = StaticCost;
@ -880,7 +880,7 @@ bool RAGreedy::calcCompactRegion(GlobalSplitCandidate &Cand) {
SpillPlacer->prepare(Cand.LiveBundles); SpillPlacer->prepare(Cand.LiveBundles);
// The static split cost will be zero since Cand.Intf reports no interference. // The static split cost will be zero since Cand.Intf reports no interference.
float Cost; BlockFrequency Cost;
if (!addSplitConstraints(Cand.Intf, Cost)) { if (!addSplitConstraints(Cand.Intf, Cost)) {
DEBUG(dbgs() << ", none.\n"); DEBUG(dbgs() << ", none.\n");
return false; return false;
@ -905,8 +905,8 @@ bool RAGreedy::calcCompactRegion(GlobalSplitCandidate &Cand) {
/// calcSpillCost - Compute how expensive it would be to split the live range in /// calcSpillCost - Compute how expensive it would be to split the live range in
/// SA around all use blocks instead of forming bundle regions. /// SA around all use blocks instead of forming bundle regions.
float RAGreedy::calcSpillCost() { BlockFrequency RAGreedy::calcSpillCost() {
float Cost = 0; BlockFrequency Cost = 0;
ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks(); ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks();
for (unsigned i = 0; i != UseBlocks.size(); ++i) { for (unsigned i = 0; i != UseBlocks.size(); ++i) {
const SplitAnalysis::BlockInfo &BI = UseBlocks[i]; const SplitAnalysis::BlockInfo &BI = UseBlocks[i];
@ -925,8 +925,8 @@ float RAGreedy::calcSpillCost() {
/// pattern in LiveBundles. This cost should be added to the local cost of the /// pattern in LiveBundles. This cost should be added to the local cost of the
/// interference pattern in SplitConstraints. /// interference pattern in SplitConstraints.
/// ///
float RAGreedy::calcGlobalSplitCost(GlobalSplitCandidate &Cand) { BlockFrequency RAGreedy::calcGlobalSplitCost(GlobalSplitCandidate &Cand) {
float GlobalCost = 0; BlockFrequency GlobalCost = 0;
const BitVector &LiveBundles = Cand.LiveBundles; const BitVector &LiveBundles = Cand.LiveBundles;
ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks(); ArrayRef<SplitAnalysis::BlockInfo> UseBlocks = SA->getUseBlocks();
for (unsigned i = 0; i != UseBlocks.size(); ++i) { for (unsigned i = 0; i != UseBlocks.size(); ++i) {
@ -940,8 +940,8 @@ float RAGreedy::calcGlobalSplitCost(GlobalSplitCandidate &Cand) {
Ins += RegIn != (BC.Entry == SpillPlacement::PrefReg); Ins += RegIn != (BC.Entry == SpillPlacement::PrefReg);
if (BI.LiveOut) if (BI.LiveOut)
Ins += RegOut != (BC.Exit == SpillPlacement::PrefReg); Ins += RegOut != (BC.Exit == SpillPlacement::PrefReg);
if (Ins) while (Ins--)
GlobalCost += Ins * SpillPlacer->getBlockFrequency(BC.Number); GlobalCost += SpillPlacer->getBlockFrequency(BC.Number);
} }
for (unsigned i = 0, e = Cand.ActiveBlocks.size(); i != e; ++i) { for (unsigned i = 0, e = Cand.ActiveBlocks.size(); i != e; ++i) {
@ -953,8 +953,10 @@ float RAGreedy::calcGlobalSplitCost(GlobalSplitCandidate &Cand) {
if (RegIn && RegOut) { if (RegIn && RegOut) {
// We need double spill code if this block has interference. // We need double spill code if this block has interference.
Cand.Intf.moveToBlock(Number); Cand.Intf.moveToBlock(Number);
if (Cand.Intf.hasInterference()) if (Cand.Intf.hasInterference()) {
GlobalCost += 2*SpillPlacer->getBlockFrequency(Number); GlobalCost += SpillPlacer->getBlockFrequency(Number);
GlobalCost += SpillPlacer->getBlockFrequency(Number);
}
continue; continue;
} }
// live-in / stack-out or stack-in live-out. // live-in / stack-out or stack-in live-out.
@ -1119,7 +1121,7 @@ unsigned RAGreedy::tryRegionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
SmallVectorImpl<LiveInterval*> &NewVRegs) { SmallVectorImpl<LiveInterval*> &NewVRegs) {
unsigned NumCands = 0; unsigned NumCands = 0;
unsigned BestCand = NoCand; unsigned BestCand = NoCand;
float BestCost; BlockFrequency BestCost;
SmallVector<unsigned, 8> UsedCands; SmallVector<unsigned, 8> UsedCands;
// Check if we can split this live range around a compact region. // Check if we can split this live range around a compact region.
@ -1127,11 +1129,11 @@ unsigned RAGreedy::tryRegionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
if (HasCompact) { if (HasCompact) {
// Yes, keep GlobalCand[0] as the compact region candidate. // Yes, keep GlobalCand[0] as the compact region candidate.
NumCands = 1; NumCands = 1;
BestCost = HUGE_VALF; BestCost = BlockFrequency::getMaxFrequency();
} else { } else {
// No benefit from the compact region, our fallback will be per-block // No benefit from the compact region, our fallback will be per-block
// splitting. Make sure we find a solution that is cheaper than spilling. // splitting. Make sure we find a solution that is cheaper than spilling.
BestCost = Hysteresis * calcSpillCost(); BestCost = calcSpillCost();
DEBUG(dbgs() << "Cost of isolating all blocks = " << BestCost << '\n'); DEBUG(dbgs() << "Cost of isolating all blocks = " << BestCost << '\n');
} }
@ -1161,7 +1163,7 @@ unsigned RAGreedy::tryRegionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
Cand.reset(IntfCache, PhysReg); Cand.reset(IntfCache, PhysReg);
SpillPlacer->prepare(Cand.LiveBundles); SpillPlacer->prepare(Cand.LiveBundles);
float Cost; BlockFrequency Cost;
if (!addSplitConstraints(Cand.Intf, Cost)) { if (!addSplitConstraints(Cand.Intf, Cost)) {
DEBUG(dbgs() << PrintReg(PhysReg, TRI) << "\tno positive bundles\n"); DEBUG(dbgs() << PrintReg(PhysReg, TRI) << "\tno positive bundles\n");
continue; continue;
@ -1197,7 +1199,7 @@ unsigned RAGreedy::tryRegionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
}); });
if (Cost < BestCost) { if (Cost < BestCost) {
BestCand = NumCands; BestCand = NumCands;
BestCost = Hysteresis * Cost; // Prevent rounding effects. BestCost = Cost;
} }
++NumCands; ++NumCands;
} }
@ -1515,7 +1517,9 @@ unsigned RAGreedy::tryLocalSplit(LiveInterval &VirtReg, AllocationOrder &Order,
unsigned BestAfter = 0; unsigned BestAfter = 0;
float BestDiff = 0; float BestDiff = 0;
const float blockFreq = SpillPlacer->getBlockFrequency(BI.MBB->getNumber()); const float blockFreq =
SpillPlacer->getBlockFrequency(BI.MBB->getNumber()).getFrequency() *
(1.0f / BlockFrequency::getEntryFrequency());
SmallVector<float, 8> GapWeight; SmallVector<float, 8> GapWeight;
Order.rewind(); Order.rewind();

View File

@ -140,10 +140,8 @@ public:
/// getBlockFrequency - Return the estimated block execution frequency per /// getBlockFrequency - Return the estimated block execution frequency per
/// function invocation. /// function invocation.
float getBlockFrequency(unsigned Number) const { BlockFrequency getBlockFrequency(unsigned Number) const {
// FIXME: Return the BlockFrequency directly. return BlockFrequencies[Number];
const float Scale = 1.0f / BlockFrequency::getEntryFrequency();
return BlockFrequencies[Number].getFrequency() * Scale;
} }
private: private: