Branch profiling: floating-point avoidance.

Patch by: Jakub Staszak!

Introduces BranchProbability. Changes unsigned to uint32_t all over and
uint64_t only when overflow is expected.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@132867 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Andrew Trick
2011-06-11 01:05:22 +00:00
parent b5923db192
commit f289df2d95
5 changed files with 176 additions and 62 deletions

View File

@@ -15,19 +15,24 @@
#define LLVM_ANALYSIS_BRANCHPROBABILITYINFO_H
#include "llvm/InitializePasses.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Support/Debug.h"
namespace llvm {
class raw_ostream;
class BranchProbabilityInfo : public FunctionPass {
// Default weight value. Used when we don't have information about the edge.
static const unsigned int DEFAULT_WEIGHT = 16;
static const uint32_t DEFAULT_WEIGHT = 16;
typedef std::pair<BasicBlock *, BasicBlock *> Edge;
DenseMap<Edge, unsigned> Weights;
DenseMap<Edge, uint32_t> Weights;
// Get sum of the block successors' weights.
uint32_t getSumForBlock(BasicBlock *BB) const;
public:
static char ID;
@@ -43,12 +48,12 @@ public:
bool runOnFunction(Function &F);
// Returned value is between 1 and UINT_MAX. Look at BranchProbabilityInfo.cpp
// for details.
unsigned getEdgeWeight(BasicBlock *Src, BasicBlock *Dst) const;
// Returned value is between 1 and UINT32_MAX. Look at
// BranchProbabilityInfo.cpp for details.
uint32_t getEdgeWeight(BasicBlock *Src, BasicBlock *Dst) const;
// Look at BranchProbabilityInfo.cpp for details. Use it with caution!
void setEdgeWeight(BasicBlock *Src, BasicBlock *Dst, unsigned Weight);
void setEdgeWeight(BasicBlock *Src, BasicBlock *Dst, uint32_t Weight);
// A 'Hot' edge is an edge which probability is >= 80%.
bool isEdgeHot(BasicBlock *Src, BasicBlock *Dst) const;
@@ -56,11 +61,16 @@ public:
// Return a hot successor for the block BB or null if there isn't one.
BasicBlock *getHotSucc(BasicBlock *BB) const;
// 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;
// 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
// has only one successor.
raw_ostream &printEdgeProbability(raw_ostream &OS, BasicBlock *Src,
BasicBlock *Dst) const;
BasicBlock *Dst) const;
};
}