[llvm-commits] [llvm] r126975 - in /llvm/trunk/lib/CodeGen: RegAllocGreedy.cpp SpillPlacement.cpp SpillPlacement.h
Jakob Stoklund Olesen
stoklund at 2pi.dk
Thu Mar 3 16:58:40 PST 2011
Author: stoklund
Date: Thu Mar 3 18:58:40 2011
New Revision: 126975
URL: http://llvm.org/viewvc/llvm-project?rev=126975&view=rev
Log:
Precompute block frequencies, pow() isn't free.
Modified:
llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp
llvm/trunk/lib/CodeGen/SpillPlacement.cpp
llvm/trunk/lib/CodeGen/SpillPlacement.h
Modified: llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp?rev=126975&r1=126974&r2=126975&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegAllocGreedy.cpp Thu Mar 3 18:58:40 2011
@@ -602,7 +602,7 @@
// The local cost of spill code in this block is the block frequency times
// the number of spill instructions inserted.
if (Inserts)
- LocalCost += Inserts * SpillPlacer->getBlockFrequency(BI.MBB);
+ LocalCost += Inserts * SpillPlacer->getBlockFrequency(BC.Number);
}
DEBUG(dbgs() << "Local cost of " << PrintReg(PhysReg, TRI) << " = "
<< LocalCost << '\n');
@@ -625,8 +625,7 @@
Inserts += LiveBundles[Bundles->getBundle(BC.Number, 1)] !=
(BC.Exit == SpillPlacement::PrefReg);
if (Inserts)
- GlobalCost +=
- Inserts * SpillPlacer->getBlockFrequency(SA->LiveBlocks[i].MBB);
+ GlobalCost += Inserts * SpillPlacer->getBlockFrequency(BC.Number);
}
DEBUG(dbgs() << "Global cost = " << GlobalCost << '\n');
return GlobalCost;
@@ -1089,7 +1088,7 @@
unsigned BestAfter = 0;
float BestDiff = 0;
- const float blockFreq = SpillPlacer->getBlockFrequency(BI.MBB);
+ const float blockFreq = SpillPlacer->getBlockFrequency(BI.MBB->getNumber());
SmallVector<float, 8> GapWeight;
Order.rewind();
Modified: llvm/trunk/lib/CodeGen/SpillPlacement.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SpillPlacement.cpp?rev=126975&r1=126974&r2=126975&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SpillPlacement.cpp (original)
+++ llvm/trunk/lib/CodeGen/SpillPlacement.cpp Thu Mar 3 18:58:40 2011
@@ -175,9 +175,12 @@
nodes = new Node[bundles->getNumBundles()];
// Compute total ingoing and outgoing block frequencies for all bundles.
+ BlockFrequency.resize(mf.getNumBlockIDs());
for (MachineFunction::iterator I = mf.begin(), E = mf.end(); I != E; ++I) {
- float Freq = getBlockFrequency(I);
+ float Freq = LiveIntervals::getSpillWeight(true, false,
+ loops->getLoopDepth(I));
unsigned Num = I->getNumber();
+ BlockFrequency[Num] = Freq;
nodes[bundles->getBundle(Num, 1)].Frequency[0] += Freq;
nodes[bundles->getBundle(Num, 0)].Frequency[1] += Freq;
}
@@ -206,8 +209,7 @@
prepareNodes(const SmallVectorImpl<BlockConstraint> &LiveBlocks) {
for (SmallVectorImpl<BlockConstraint>::const_iterator I = LiveBlocks.begin(),
E = LiveBlocks.end(); I != E; ++I) {
- MachineBasicBlock *MBB = MF->getBlockNumbered(I->Number);
- float Freq = getBlockFrequency(MBB);
+ float Freq = getBlockFrequency(I->Number);
// Is this a transparent block? Link ingoing and outgoing bundles.
if (I->Entry == DontCare && I->Exit == DontCare) {
@@ -320,11 +322,3 @@
}
return Perfect;
}
-
-/// getBlockFrequency - Return our best estimate of the block frequency which is
-/// the expected number of block executions per function invocation.
-float SpillPlacement::getBlockFrequency(const MachineBasicBlock *MBB) {
- // Use the unnormalized spill weight for real block frequencies.
- return LiveIntervals::getSpillWeight(true, false, loops->getLoopDepth(MBB));
-}
-
Modified: llvm/trunk/lib/CodeGen/SpillPlacement.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SpillPlacement.h?rev=126975&r1=126974&r2=126975&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SpillPlacement.h (original)
+++ llvm/trunk/lib/CodeGen/SpillPlacement.h Thu Mar 3 18:58:40 2011
@@ -27,6 +27,7 @@
#ifndef LLVM_CODEGEN_SPILLPLACEMENT_H
#define LLVM_CODEGEN_SPILLPLACEMENT_H
+#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
namespace llvm {
@@ -35,7 +36,6 @@
class EdgeBundles;
class MachineBasicBlock;
class MachineLoopInfo;
-template <typename> class SmallVectorImpl;
class SpillPlacement : public MachineFunctionPass {
struct Node;
@@ -48,6 +48,9 @@
// caller.
BitVector *ActiveNodes;
+ // Block frequencies are computed once. Indexed by block number.
+ SmallVector<float, 4> BlockFrequency;
+
public:
static char ID; // Pass identification, replacement for typeid.
@@ -91,7 +94,9 @@
/// getBlockFrequency - Return the estimated block execution frequency per
/// function invocation.
- float getBlockFrequency(const MachineBasicBlock*);
+ float getBlockFrequency(unsigned Number) const {
+ return BlockFrequency[Number];
+ }
private:
virtual bool runOnMachineFunction(MachineFunction&);
More information about the llvm-commits
mailing list