mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 18:29:46 +00:00
Add more constantness in BranchProbabilityInfo.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136502 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
78621a851a
commit
6f6baf1bdd
@ -33,12 +33,12 @@ class BranchProbabilityInfo : public FunctionPass {
|
||||
// weight to just "inherit" the non-zero weight of an adjacent successor.
|
||||
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;
|
||||
|
||||
// Get sum of the block successors' weights.
|
||||
uint32_t getSumForBlock(BasicBlock *BB) const;
|
||||
uint32_t getSumForBlock(const BasicBlock *BB) const;
|
||||
|
||||
public:
|
||||
static char ID;
|
||||
@ -53,13 +53,14 @@ public:
|
||||
|
||||
// Returned value is between 1 and UINT32_MAX. Look at
|
||||
// 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!
|
||||
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%.
|
||||
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.
|
||||
BasicBlock *getHotSucc(BasicBlock *BB) const;
|
||||
@ -67,7 +68,8 @@ public:
|
||||
// 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
|
||||
// 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),
|
||||
// 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.
|
||||
class BranchProbabilityAnalysis {
|
||||
|
||||
typedef std::pair<BasicBlock *, BasicBlock *> Edge;
|
||||
typedef std::pair<const BasicBlock *, const BasicBlock *> Edge;
|
||||
|
||||
DenseMap<Edge, uint32_t> *Weights;
|
||||
|
||||
@ -301,11 +301,11 @@ bool BranchProbabilityInfo::runOnFunction(Function &F) {
|
||||
return BPA.runOnFunction(F);
|
||||
}
|
||||
|
||||
uint32_t BranchProbabilityInfo::getSumForBlock(BasicBlock *BB) const {
|
||||
uint32_t BranchProbabilityInfo::getSumForBlock(const BasicBlock *BB) const {
|
||||
uint32_t Sum = 0;
|
||||
|
||||
for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
|
||||
BasicBlock *Succ = *I;
|
||||
for (succ_const_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
|
||||
const BasicBlock *Succ = *I;
|
||||
uint32_t Weight = getEdgeWeight(BB, Succ);
|
||||
uint32_t PrevSum = Sum;
|
||||
|
||||
@ -316,7 +316,8 @@ uint32_t BranchProbabilityInfo::getSumForBlock(BasicBlock *BB) const {
|
||||
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%
|
||||
uint32_t Weight = getEdgeWeight(Src, Dst);
|
||||
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.
|
||||
uint32_t
|
||||
BranchProbabilityInfo::getEdgeWeight(BasicBlock *Src, BasicBlock *Dst) const {
|
||||
uint32_t BranchProbabilityInfo::
|
||||
getEdgeWeight(const BasicBlock *Src, const BasicBlock *Dst) const {
|
||||
Edge E(Src, Dst);
|
||||
DenseMap<Edge, uint32_t>::const_iterator I = Weights.find(E);
|
||||
|
||||
@ -364,8 +365,8 @@ BranchProbabilityInfo::getEdgeWeight(BasicBlock *Src, BasicBlock *Dst) const {
|
||||
return DEFAULT_WEIGHT;
|
||||
}
|
||||
|
||||
void BranchProbabilityInfo::setEdgeWeight(BasicBlock *Src, BasicBlock *Dst,
|
||||
uint32_t Weight) {
|
||||
void BranchProbabilityInfo::
|
||||
setEdgeWeight(const BasicBlock *Src, const BasicBlock *Dst, uint32_t Weight) {
|
||||
Weights[std::make_pair(Src, Dst)] = Weight;
|
||||
DEBUG(dbgs() << "set edge " << Src->getNameStr() << " -> "
|
||||
<< Dst->getNameStr() << " weight to " << Weight
|
||||
@ -374,7 +375,7 @@ void BranchProbabilityInfo::setEdgeWeight(BasicBlock *Src, BasicBlock *Dst,
|
||||
|
||||
|
||||
BranchProbability BranchProbabilityInfo::
|
||||
getEdgeProbability(BasicBlock *Src, BasicBlock *Dst) const {
|
||||
getEdgeProbability(const BasicBlock *Src, const BasicBlock *Dst) const {
|
||||
|
||||
uint32_t N = getEdgeWeight(Src, Dst);
|
||||
uint32_t D = getSumForBlock(Src);
|
||||
|
Loading…
Reference in New Issue
Block a user