mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 12:12:47 +01:00
Add some constantness to BranchProbabilityInfo and BlockFrequnencyInfo.
llvm-svn: 146986
This commit is contained in:
parent
3f48367a1b
commit
6f3beda2b4
@ -40,7 +40,7 @@ class MachineBlockFrequencyInfo;
|
||||
template<class BlockT, class FunctionT, class BlockProbInfoT>
|
||||
class BlockFrequencyImpl {
|
||||
|
||||
DenseMap<BlockT *, BlockFrequency> Freqs;
|
||||
DenseMap<const BlockT *, BlockFrequency> Freqs;
|
||||
|
||||
BlockProbInfoT *BPI;
|
||||
|
||||
@ -308,8 +308,9 @@ class BlockFrequencyImpl {
|
||||
|
||||
public:
|
||||
/// getBlockFreq - Return block frequency. Return 0 if we don't have it.
|
||||
BlockFrequency getBlockFreq(BlockT *BB) const {
|
||||
typename DenseMap<BlockT *, BlockFrequency>::const_iterator I = Freqs.find(BB);
|
||||
BlockFrequency getBlockFreq(const BlockT *BB) const {
|
||||
typename DenseMap<const BlockT *, BlockFrequency>::const_iterator
|
||||
I = Freqs.find(BB);
|
||||
if (I != Freqs.end())
|
||||
return I->second;
|
||||
return 0;
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
/// that we should not rely on the value itself, but only on the comparison to
|
||||
/// the other block frequencies. We do this to avoid using of floating points.
|
||||
///
|
||||
BlockFrequency getBlockFreq(BasicBlock *BB) const;
|
||||
BlockFrequency getBlockFreq(const BasicBlock *BB) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ class MachineBasicBlock : public ilist_node<MachineBasicBlock> {
|
||||
/// (disable optimization).
|
||||
std::vector<uint32_t> Weights;
|
||||
typedef std::vector<uint32_t>::iterator weight_iterator;
|
||||
typedef std::vector<uint32_t>::const_iterator const_weight_iterator;
|
||||
|
||||
/// LiveIns - Keep track of the physical registers that are livein of
|
||||
/// the basicblock.
|
||||
@ -589,13 +590,14 @@ private:
|
||||
/// getWeightIterator - Return weight iterator corresponding to the I
|
||||
/// successor iterator.
|
||||
weight_iterator getWeightIterator(succ_iterator I);
|
||||
const_weight_iterator getWeightIterator(const_succ_iterator I) const;
|
||||
|
||||
friend class MachineBranchProbabilityInfo;
|
||||
|
||||
/// getSuccWeight - Return weight of the edge from this block to MBB. This
|
||||
/// method should NOT be called directly, but by using getEdgeWeight method
|
||||
/// from MachineBranchProbabilityInfo class.
|
||||
uint32_t getSuccWeight(MachineBasicBlock *succ);
|
||||
uint32_t getSuccWeight(const MachineBasicBlock *succ) const;
|
||||
|
||||
|
||||
// Methods used to maintain doubly linked list of blocks...
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
/// that we should not rely on the value itself, but only on the comparison to
|
||||
/// the other block frequencies. We do this to avoid using of floating points.
|
||||
///
|
||||
BlockFrequency getBlockFreq(MachineBasicBlock *MBB) const;
|
||||
BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -49,12 +49,13 @@ public:
|
||||
|
||||
// Return edge weight. If we don't have any informations about it - return
|
||||
// DEFAULT_WEIGHT.
|
||||
uint32_t getEdgeWeight(MachineBasicBlock *Src, MachineBasicBlock *Dst) const;
|
||||
uint32_t getEdgeWeight(const MachineBasicBlock *Src,
|
||||
const MachineBasicBlock *Dst) const;
|
||||
|
||||
// Get sum of the block successors' weights, potentially scaling them to fit
|
||||
// within 32-bits. If scaling is required, sets Scale based on the necessary
|
||||
// adjustment. Any edge weights used with the sum should be divided by Scale.
|
||||
uint32_t getSumForBlock(MachineBasicBlock *MBB, uint32_t &Scale) const;
|
||||
uint32_t getSumForBlock(const MachineBasicBlock *MBB, uint32_t &Scale) const;
|
||||
|
||||
// A 'Hot' edge is an edge which probability is >= 80%.
|
||||
bool isEdgeHot(MachineBasicBlock *Src, MachineBasicBlock *Dst) const;
|
||||
|
@ -58,6 +58,6 @@ void BlockFrequencyInfo::print(raw_ostream &O, const Module *) const {
|
||||
/// that we should not rely on the value itself, but only on the comparison to
|
||||
/// the other block frequencies. We do this to avoid using of floating points.
|
||||
///
|
||||
BlockFrequency BlockFrequencyInfo::getBlockFreq(BasicBlock *BB) const {
|
||||
BlockFrequency BlockFrequencyInfo::getBlockFreq(const BasicBlock *BB) const {
|
||||
return BFI->getBlockFreq(BB);
|
||||
}
|
||||
|
@ -870,11 +870,11 @@ MachineBasicBlock::findDebugLoc(instr_iterator MBBI) {
|
||||
|
||||
/// getSuccWeight - Return weight of the edge from this block to MBB.
|
||||
///
|
||||
uint32_t MachineBasicBlock::getSuccWeight(MachineBasicBlock *succ) {
|
||||
uint32_t MachineBasicBlock::getSuccWeight(const MachineBasicBlock *succ) const {
|
||||
if (Weights.empty())
|
||||
return 0;
|
||||
|
||||
succ_iterator I = std::find(Successors.begin(), Successors.end(), succ);
|
||||
const_succ_iterator I = std::find(Successors.begin(), Successors.end(), succ);
|
||||
return *getWeightIterator(I);
|
||||
}
|
||||
|
||||
@ -888,6 +888,16 @@ getWeightIterator(MachineBasicBlock::succ_iterator I) {
|
||||
return Weights.begin() + index;
|
||||
}
|
||||
|
||||
/// getWeightIterator - Return wight iterator corresonding to the I successor
|
||||
/// iterator
|
||||
MachineBasicBlock::const_weight_iterator MachineBasicBlock::
|
||||
getWeightIterator(MachineBasicBlock::const_succ_iterator I) const {
|
||||
assert(Weights.size() == Successors.size() && "Async weight list!");
|
||||
const size_t index = std::distance(Successors.begin(), I);
|
||||
assert(index < Weights.size() && "Not a current successor!");
|
||||
return Weights.begin() + index;
|
||||
}
|
||||
|
||||
void llvm::WriteAsOperand(raw_ostream &OS, const MachineBasicBlock *MBB,
|
||||
bool t) {
|
||||
OS << "BB#" << MBB->getNumber();
|
||||
|
@ -56,6 +56,6 @@ bool MachineBlockFrequencyInfo::runOnMachineFunction(MachineFunction &F) {
|
||||
/// the other block frequencies. We do this to avoid using of floating points.
|
||||
///
|
||||
BlockFrequency MachineBlockFrequencyInfo::
|
||||
getBlockFreq(MachineBasicBlock *MBB) const {
|
||||
getBlockFreq(const MachineBasicBlock *MBB) const {
|
||||
return MBFI->getBlockFreq(MBB);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ char MachineBranchProbabilityInfo::ID = 0;
|
||||
void MachineBranchProbabilityInfo::anchor() { }
|
||||
|
||||
uint32_t MachineBranchProbabilityInfo::
|
||||
getSumForBlock(MachineBasicBlock *MBB, uint32_t &Scale) const {
|
||||
getSumForBlock(const MachineBasicBlock *MBB, uint32_t &Scale) const {
|
||||
// First we compute the sum with 64-bits of precision, ensuring that cannot
|
||||
// overflow by bounding the number of weights considered. Hopefully no one
|
||||
// actually needs 2^32 successors.
|
||||
@ -61,8 +61,8 @@ getSumForBlock(MachineBasicBlock *MBB, uint32_t &Scale) const {
|
||||
}
|
||||
|
||||
uint32_t
|
||||
MachineBranchProbabilityInfo::getEdgeWeight(MachineBasicBlock *Src,
|
||||
MachineBasicBlock *Dst) const {
|
||||
MachineBranchProbabilityInfo::getEdgeWeight(const MachineBasicBlock *Src,
|
||||
const MachineBasicBlock *Dst) const {
|
||||
uint32_t Weight = Src->getSuccWeight(Dst);
|
||||
if (!Weight)
|
||||
return DEFAULT_WEIGHT;
|
||||
|
@ -1287,8 +1287,8 @@ bool SelectionDAGBuilder::isExportableFromCurrentBlock(const Value *V,
|
||||
}
|
||||
|
||||
/// Return branch probability calculated by BranchProbabilityInfo for IR blocks.
|
||||
uint32_t SelectionDAGBuilder::getEdgeWeight(MachineBasicBlock *Src,
|
||||
MachineBasicBlock *Dst) {
|
||||
uint32_t SelectionDAGBuilder::getEdgeWeight(const MachineBasicBlock *Src,
|
||||
const MachineBasicBlock *Dst) const {
|
||||
BranchProbabilityInfo *BPI = FuncInfo.BPI;
|
||||
if (!BPI)
|
||||
return 0;
|
||||
|
@ -454,7 +454,8 @@ private:
|
||||
MachineBasicBlock* Default,
|
||||
MachineBasicBlock *SwitchBB);
|
||||
|
||||
uint32_t getEdgeWeight(MachineBasicBlock *Src, MachineBasicBlock *Dst);
|
||||
uint32_t getEdgeWeight(const MachineBasicBlock *Src,
|
||||
const MachineBasicBlock *Dst) const;
|
||||
void addSuccessorWithWeight(MachineBasicBlock *Src, MachineBasicBlock *Dst,
|
||||
uint32_t Weight = 0);
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user