summaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2011-03-05 03:28:51 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2011-03-05 03:28:51 +0000
commit874be74179b087be36a6e7869f3aa8b70732aca1 (patch)
tree1ac94704a496c88b99d381df79ab4efa1b62ca7b /lib/CodeGen
parent89be0acecfa4fe5662c5f9e0ba501a79a041b59f (diff)
downloadllvm-874be74179b087be36a6e7869f3aa8b70732aca1.tar.gz
llvm-874be74179b087be36a6e7869f3aa8b70732aca1.tar.bz2
llvm-874be74179b087be36a6e7869f3aa8b70732aca1.tar.xz
Rework the global split cost calculation.
The global cost is the sum of block frequencies for spill code that must be inserted because preferences weren't met. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127062 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/RegAllocGreedy.cpp51
1 files changed, 30 insertions, 21 deletions
diff --git a/lib/CodeGen/RegAllocGreedy.cpp b/lib/CodeGen/RegAllocGreedy.cpp
index 061e38640b..642805e08a 100644
--- a/lib/CodeGen/RegAllocGreedy.cpp
+++ b/lib/CodeGen/RegAllocGreedy.cpp
@@ -558,24 +558,24 @@ float RAGreedy::calcSplitConstraints(const SmallVectorImpl<IndexPair> &Intf) {
///
float RAGreedy::calcGlobalSplitCost(const BitVector &LiveBundles) {
float GlobalCost = 0;
- for (unsigned i = 0, e = SplitConstraints.size(); i != e; ++i) {
+ for (unsigned i = 0, e = SA->LiveBlocks.size(); i != e; ++i) {
+ SplitAnalysis::BlockInfo &BI = SA->LiveBlocks[i];
SpillPlacement::BlockConstraint &BC = SplitConstraints[i];
- unsigned Inserts = 0;
- // Broken entry preference?
- Inserts += LiveBundles[Bundles->getBundle(BC.Number, 0)] !=
- (BC.Entry == SpillPlacement::PrefReg);
- // Broken exit preference?
- Inserts += LiveBundles[Bundles->getBundle(BC.Number, 1)] !=
- (BC.Exit == SpillPlacement::PrefReg);
- if (Inserts)
- GlobalCost += Inserts * SpillPlacer->getBlockFrequency(BC.Number);
+ bool RegIn = LiveBundles[Bundles->getBundle(BC.Number, 0)];
+ bool RegOut = LiveBundles[Bundles->getBundle(BC.Number, 1)];
+ unsigned Ins = 0;
+
+ if (!BI.Uses)
+ Ins += RegIn != RegOut;
+ else {
+ if (BI.LiveIn)
+ Ins += RegIn != (BC.Entry == SpillPlacement::PrefReg);
+ if (BI.LiveOut)
+ Ins += RegOut != (BC.Exit == SpillPlacement::PrefReg);
+ }
+ if (Ins)
+ GlobalCost += Ins * SpillPlacer->getBlockFrequency(BC.Number);
}
- DEBUG({
- dbgs() << "Global cost = " << GlobalCost << " with bundles";
- for (int i = LiveBundles.find_first(); i>=0; i = LiveBundles.find_next(i))
- dbgs() << " EB#" << i;
- dbgs() << ".\n";
- });
return GlobalCost;
}
@@ -843,20 +843,29 @@ unsigned RAGreedy::tryRegionSplit(LiveInterval &VirtReg, AllocationOrder &Order,
mapGlobalInterference(PhysReg, GlobalCand[Cand].Interference);
float Cost = calcSplitConstraints(GlobalCand[Cand].Interference);
- DEBUG(dbgs() << PrintReg(PhysReg, TRI) << " static split cost = " << Cost
- << '\n');
- if (BestReg && Cost >= BestCost)
+ DEBUG(dbgs() << PrintReg(PhysReg, TRI) << "\tstatic = " << Cost);
+ if (BestReg && Cost >= BestCost) {
+ DEBUG(dbgs() << " higher.\n");
continue;
+ }
SpillPlacer->placeSpills(SplitConstraints, LiveBundles);
// No live bundles, defer to splitSingleBlocks().
- if (!LiveBundles.any())
+ if (!LiveBundles.any()) {
+ DEBUG(dbgs() << " no bundles.\n");
continue;
+ }
Cost += calcGlobalSplitCost(LiveBundles);
+ DEBUG({
+ dbgs() << ", total = " << Cost << " with bundles";
+ for (int i = LiveBundles.find_first(); i>=0; i = LiveBundles.find_next(i))
+ dbgs() << " EB#" << i;
+ dbgs() << ".\n";
+ });
if (!BestReg || Cost < BestCost) {
BestReg = PhysReg;
- BestCost = Cost;
+ BestCost = 0.98f * Cost; // Prevent rounding effects.
BestBundles.swap(LiveBundles);
}
}