1 //===--- BranchProbabilityInfo.h - Branch Probability Analysis --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This pass is used to evaluate branch probabilties.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_BRANCHPROBABILITYINFO_H
15 #define LLVM_ANALYSIS_BRANCHPROBABILITYINFO_H
17 #include "llvm/InitializePasses.h"
18 #include "llvm/Analysis/LoopInfo.h"
19 #include "llvm/Support/Debug.h"
23 class BranchProbabilityInfo : public FunctionPass {
25 // Default weight value. Used when we don't have information about the edge.
26 static const unsigned int DEFAULT_WEIGHT = 16;
28 typedef std::pair<BasicBlock *, BasicBlock *> Edge;
30 DenseMap<Edge, unsigned> Weights;
35 BranchProbabilityInfo() : FunctionPass(ID) {
36 initializeBranchProbabilityInfoPass(*PassRegistry::getPassRegistry());
39 void getAnalysisUsage(AnalysisUsage &AU) const {
40 AU.addRequired<LoopInfo>();
44 bool runOnFunction(Function &F);
46 // Returned value is between 1 and UINT_MAX. Look at BranchProbabilityInfo.cpp
48 unsigned getEdgeWeight(BasicBlock *Src, BasicBlock *Dst) const;
50 // Look at BranchProbabilityInfo.cpp for details. Use it with caution!
51 void setEdgeWeight(BasicBlock *Src, BasicBlock *Dst, unsigned Weight);
53 // A 'Hot' edge is an edge which probability is >= 80%.
54 bool isEdgeHot(BasicBlock *Src, BasicBlock *Dst) const;
56 // Return a hot successor for the block BB or null if there isn't one.
57 BasicBlock *getHotSucc(BasicBlock *BB) const;
59 // Print value between 0 (0% probability) and 1 (100% probability),
60 // however the value is never equal to 0, and can be 1 only iff SRC block
61 // has only one successor.
62 raw_ostream &printEdgeProbability(raw_ostream &OS, BasicBlock *Src,
63 BasicBlock *Dst) const;