mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
Add more constantness in BranchProbabilityInfo.
llvm-svn: 136502
This commit is contained in:
parent
944f1cc9a6
commit
02fa079dc3
@ -33,12 +33,12 @@ class BranchProbabilityInfo : public FunctionPass {
|
|||||||
// weight to just "inherit" the non-zero weight of an adjacent successor.
|
// weight to just "inherit" the non-zero weight of an adjacent successor.
|
||||||
static const uint32_t DEFAULT_WEIGHT = 16;
|
static const uint32_t DEFAULT_WEIGHT = 16;
|
||||||
|
|
||||||
typedef std::pair<BasicBlock *, BasicBlock *> Edge;
|
typedef std::pair<const BasicBlock *, const BasicBlock *> Edge;
|
||||||
|
|
||||||
DenseMap<Edge, uint32_t> Weights;
|
DenseMap<Edge, uint32_t> Weights;
|
||||||
|
|
||||||
// Get sum of the block successors' weights.
|
// Get sum of the block successors' weights.
|
||||||
uint32_t getSumForBlock(BasicBlock *BB) const;
|
uint32_t getSumForBlock(const BasicBlock *BB) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
static char ID;
|
||||||
@ -53,13 +53,14 @@ public:
|
|||||||
|
|
||||||
// Returned value is between 1 and UINT32_MAX. Look at
|
// Returned value is between 1 and UINT32_MAX. Look at
|
||||||
// BranchProbabilityInfo.cpp for details.
|
// BranchProbabilityInfo.cpp for details.
|
||||||
uint32_t getEdgeWeight(BasicBlock *Src, BasicBlock *Dst) const;
|
uint32_t getEdgeWeight(const BasicBlock *Src, const BasicBlock *Dst) const;
|
||||||
|
|
||||||
// Look at BranchProbabilityInfo.cpp for details. Use it with caution!
|
// Look at BranchProbabilityInfo.cpp for details. Use it with caution!
|
||||||
void setEdgeWeight(BasicBlock *Src, BasicBlock *Dst, uint32_t Weight);
|
void setEdgeWeight(const BasicBlock *Src, const BasicBlock *Dst,
|
||||||
|
uint32_t Weight);
|
||||||
|
|
||||||
// A 'Hot' edge is an edge which probability is >= 80%.
|
// A 'Hot' edge is an edge which probability is >= 80%.
|
||||||
bool isEdgeHot(BasicBlock *Src, BasicBlock *Dst) const;
|
bool isEdgeHot(const BasicBlock *Src, const BasicBlock *Dst) const;
|
||||||
|
|
||||||
// Return a hot successor for the block BB or null if there isn't one.
|
// Return a hot successor for the block BB or null if there isn't one.
|
||||||
BasicBlock *getHotSucc(BasicBlock *BB) const;
|
BasicBlock *getHotSucc(BasicBlock *BB) const;
|
||||||
@ -67,7 +68,8 @@ public:
|
|||||||
// Return a probability as a fraction between 0 (0% probability) and
|
// Return a probability as a fraction between 0 (0% probability) and
|
||||||
// 1 (100% probability), however the value is never equal to 0, and can be 1
|
// 1 (100% probability), however the value is never equal to 0, and can be 1
|
||||||
// only iff SRC block has only one successor.
|
// only iff SRC block has only one successor.
|
||||||
BranchProbability getEdgeProbability(BasicBlock *Src, BasicBlock *Dst) const;
|
BranchProbability getEdgeProbability(const BasicBlock *Src,
|
||||||
|
const BasicBlock *Dst) const;
|
||||||
|
|
||||||
// Print value between 0 (0% probability) and 1 (100% probability),
|
// Print value between 0 (0% probability) and 1 (100% probability),
|
||||||
// however the value is never equal to 0, and can be 1 only iff SRC block
|
// however the value is never equal to 0, and can be 1 only iff SRC block
|
||||||
|
@ -33,7 +33,7 @@ namespace {
|
|||||||
// private methods are hidden in the .cpp file.
|
// private methods are hidden in the .cpp file.
|
||||||
class BranchProbabilityAnalysis {
|
class BranchProbabilityAnalysis {
|
||||||
|
|
||||||
typedef std::pair<BasicBlock *, BasicBlock *> Edge;
|
typedef std::pair<const BasicBlock *, const BasicBlock *> Edge;
|
||||||
|
|
||||||
DenseMap<Edge, uint32_t> *Weights;
|
DenseMap<Edge, uint32_t> *Weights;
|
||||||
|
|
||||||
@ -301,11 +301,11 @@ bool BranchProbabilityInfo::runOnFunction(Function &F) {
|
|||||||
return BPA.runOnFunction(F);
|
return BPA.runOnFunction(F);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BranchProbabilityInfo::getSumForBlock(BasicBlock *BB) const {
|
uint32_t BranchProbabilityInfo::getSumForBlock(const BasicBlock *BB) const {
|
||||||
uint32_t Sum = 0;
|
uint32_t Sum = 0;
|
||||||
|
|
||||||
for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
|
for (succ_const_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
|
||||||
BasicBlock *Succ = *I;
|
const BasicBlock *Succ = *I;
|
||||||
uint32_t Weight = getEdgeWeight(BB, Succ);
|
uint32_t Weight = getEdgeWeight(BB, Succ);
|
||||||
uint32_t PrevSum = Sum;
|
uint32_t PrevSum = Sum;
|
||||||
|
|
||||||
@ -316,7 +316,8 @@ uint32_t BranchProbabilityInfo::getSumForBlock(BasicBlock *BB) const {
|
|||||||
return Sum;
|
return Sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BranchProbabilityInfo::isEdgeHot(BasicBlock *Src, BasicBlock *Dst) const {
|
bool BranchProbabilityInfo::
|
||||||
|
isEdgeHot(const BasicBlock *Src, const BasicBlock *Dst) const {
|
||||||
// Hot probability is at least 4/5 = 80%
|
// Hot probability is at least 4/5 = 80%
|
||||||
uint32_t Weight = getEdgeWeight(Src, Dst);
|
uint32_t Weight = getEdgeWeight(Src, Dst);
|
||||||
uint32_t Sum = getSumForBlock(Src);
|
uint32_t Sum = getSumForBlock(Src);
|
||||||
@ -353,8 +354,8 @@ BasicBlock *BranchProbabilityInfo::getHotSucc(BasicBlock *BB) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return edge's weight. If can't find it, return DEFAULT_WEIGHT value.
|
// Return edge's weight. If can't find it, return DEFAULT_WEIGHT value.
|
||||||
uint32_t
|
uint32_t BranchProbabilityInfo::
|
||||||
BranchProbabilityInfo::getEdgeWeight(BasicBlock *Src, BasicBlock *Dst) const {
|
getEdgeWeight(const BasicBlock *Src, const BasicBlock *Dst) const {
|
||||||
Edge E(Src, Dst);
|
Edge E(Src, Dst);
|
||||||
DenseMap<Edge, uint32_t>::const_iterator I = Weights.find(E);
|
DenseMap<Edge, uint32_t>::const_iterator I = Weights.find(E);
|
||||||
|
|
||||||
@ -364,8 +365,8 @@ BranchProbabilityInfo::getEdgeWeight(BasicBlock *Src, BasicBlock *Dst) const {
|
|||||||
return DEFAULT_WEIGHT;
|
return DEFAULT_WEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BranchProbabilityInfo::setEdgeWeight(BasicBlock *Src, BasicBlock *Dst,
|
void BranchProbabilityInfo::
|
||||||
uint32_t Weight) {
|
setEdgeWeight(const BasicBlock *Src, const BasicBlock *Dst, uint32_t Weight) {
|
||||||
Weights[std::make_pair(Src, Dst)] = Weight;
|
Weights[std::make_pair(Src, Dst)] = Weight;
|
||||||
DEBUG(dbgs() << "set edge " << Src->getNameStr() << " -> "
|
DEBUG(dbgs() << "set edge " << Src->getNameStr() << " -> "
|
||||||
<< Dst->getNameStr() << " weight to " << Weight
|
<< Dst->getNameStr() << " weight to " << Weight
|
||||||
@ -374,7 +375,7 @@ void BranchProbabilityInfo::setEdgeWeight(BasicBlock *Src, BasicBlock *Dst,
|
|||||||
|
|
||||||
|
|
||||||
BranchProbability BranchProbabilityInfo::
|
BranchProbability BranchProbabilityInfo::
|
||||||
getEdgeProbability(BasicBlock *Src, BasicBlock *Dst) const {
|
getEdgeProbability(const BasicBlock *Src, const BasicBlock *Dst) const {
|
||||||
|
|
||||||
uint32_t N = getEdgeWeight(Src, Dst);
|
uint32_t N = getEdgeWeight(Src, Dst);
|
||||||
uint32_t D = getSumForBlock(Src);
|
uint32_t D = getSumForBlock(Src);
|
||||||
|
Loading…
Reference in New Issue
Block a user