Precompute block frequencies, pow() isn't free.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126975 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jakob Stoklund Olesen 2011-03-04 00:58:40 +00:00
parent 13ba2dab63
commit 40a42a2cca
3 changed files with 15 additions and 17 deletions

View File

@ -602,7 +602,7 @@ float RAGreedy::calcInterferenceInfo(LiveInterval &VirtReg, unsigned PhysReg) {
// The local cost of spill code in this block is the block frequency times // The local cost of spill code in this block is the block frequency times
// the number of spill instructions inserted. // the number of spill instructions inserted.
if (Inserts) if (Inserts)
LocalCost += Inserts * SpillPlacer->getBlockFrequency(BI.MBB); LocalCost += Inserts * SpillPlacer->getBlockFrequency(BC.Number);
} }
DEBUG(dbgs() << "Local cost of " << PrintReg(PhysReg, TRI) << " = " DEBUG(dbgs() << "Local cost of " << PrintReg(PhysReg, TRI) << " = "
<< LocalCost << '\n'); << LocalCost << '\n');
@ -625,8 +625,7 @@ float RAGreedy::calcGlobalSplitCost(const BitVector &LiveBundles) {
Inserts += LiveBundles[Bundles->getBundle(BC.Number, 1)] != Inserts += LiveBundles[Bundles->getBundle(BC.Number, 1)] !=
(BC.Exit == SpillPlacement::PrefReg); (BC.Exit == SpillPlacement::PrefReg);
if (Inserts) if (Inserts)
GlobalCost += GlobalCost += Inserts * SpillPlacer->getBlockFrequency(BC.Number);
Inserts * SpillPlacer->getBlockFrequency(SA->LiveBlocks[i].MBB);
} }
DEBUG(dbgs() << "Global cost = " << GlobalCost << '\n'); DEBUG(dbgs() << "Global cost = " << GlobalCost << '\n');
return GlobalCost; return GlobalCost;
@ -1089,7 +1088,7 @@ 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); const float blockFreq = SpillPlacer->getBlockFrequency(BI.MBB->getNumber());
SmallVector<float, 8> GapWeight; SmallVector<float, 8> GapWeight;
Order.rewind(); Order.rewind();

View File

@ -175,9 +175,12 @@ bool SpillPlacement::runOnMachineFunction(MachineFunction &mf) {
nodes = new Node[bundles->getNumBundles()]; nodes = new Node[bundles->getNumBundles()];
// Compute total ingoing and outgoing block frequencies for all bundles. // 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) { 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(); unsigned Num = I->getNumber();
BlockFrequency[Num] = Freq;
nodes[bundles->getBundle(Num, 1)].Frequency[0] += Freq; nodes[bundles->getBundle(Num, 1)].Frequency[0] += Freq;
nodes[bundles->getBundle(Num, 0)].Frequency[1] += Freq; nodes[bundles->getBundle(Num, 0)].Frequency[1] += Freq;
} }
@ -206,8 +209,7 @@ void SpillPlacement::
prepareNodes(const SmallVectorImpl<BlockConstraint> &LiveBlocks) { prepareNodes(const SmallVectorImpl<BlockConstraint> &LiveBlocks) {
for (SmallVectorImpl<BlockConstraint>::const_iterator I = LiveBlocks.begin(), for (SmallVectorImpl<BlockConstraint>::const_iterator I = LiveBlocks.begin(),
E = LiveBlocks.end(); I != E; ++I) { E = LiveBlocks.end(); I != E; ++I) {
MachineBasicBlock *MBB = MF->getBlockNumbered(I->Number); float Freq = getBlockFrequency(I->Number);
float Freq = getBlockFrequency(MBB);
// Is this a transparent block? Link ingoing and outgoing bundles. // Is this a transparent block? Link ingoing and outgoing bundles.
if (I->Entry == DontCare && I->Exit == DontCare) { if (I->Entry == DontCare && I->Exit == DontCare) {
@ -320,11 +322,3 @@ SpillPlacement::placeSpills(const SmallVectorImpl<BlockConstraint> &LiveBlocks,
} }
return Perfect; 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));
}

View File

@ -27,6 +27,7 @@
#ifndef LLVM_CODEGEN_SPILLPLACEMENT_H #ifndef LLVM_CODEGEN_SPILLPLACEMENT_H
#define LLVM_CODEGEN_SPILLPLACEMENT_H #define LLVM_CODEGEN_SPILLPLACEMENT_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineFunctionPass.h"
namespace llvm { namespace llvm {
@ -35,7 +36,6 @@ class BitVector;
class EdgeBundles; class EdgeBundles;
class MachineBasicBlock; class MachineBasicBlock;
class MachineLoopInfo; class MachineLoopInfo;
template <typename> class SmallVectorImpl;
class SpillPlacement : public MachineFunctionPass { class SpillPlacement : public MachineFunctionPass {
struct Node; struct Node;
@ -48,6 +48,9 @@ class SpillPlacement : public MachineFunctionPass {
// caller. // caller.
BitVector *ActiveNodes; BitVector *ActiveNodes;
// Block frequencies are computed once. Indexed by block number.
SmallVector<float, 4> BlockFrequency;
public: public:
static char ID; // Pass identification, replacement for typeid. static char ID; // Pass identification, replacement for typeid.
@ -91,7 +94,9 @@ public:
/// getBlockFrequency - Return the estimated block execution frequency per /// getBlockFrequency - Return the estimated block execution frequency per
/// function invocation. /// function invocation.
float getBlockFrequency(const MachineBasicBlock*); float getBlockFrequency(unsigned Number) const {
return BlockFrequency[Number];
}
private: private:
virtual bool runOnMachineFunction(MachineFunction&); virtual bool runOnMachineFunction(MachineFunction&);