1c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===--- BranchProbabilityInfo.h - Branch Probability Analysis --*- C++ -*-===// 2c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 3c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// The LLVM Compiler Infrastructure 4c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 5c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This file is distributed under the University of Illinois Open Source 6c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// License. See LICENSE.TXT for details. 7c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 8c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===// 9c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 10c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// This pass is used to evaluate branch probabilties. 11c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot// 12c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot//===----------------------------------------------------------------------===// 13c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 14c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#ifndef LLVM_ANALYSIS_BRANCHPROBABILITYINFO_H 15c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#define LLVM_ANALYSIS_BRANCHPROBABILITYINFO_H 16c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 17c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/DenseMap.h" 18c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/DenseSet.h" 19c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/ADT/SmallPtrSet.h" 20c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/IR/CFG.h" 21c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/IR/PassManager.h" 22c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/IR/ValueHandle.h" 23c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/InitializePasses.h" 24c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Pass.h" 25c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#include "llvm/Support/BranchProbability.h" 26c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 27c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotnamespace llvm { 28c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass LoopInfo; 29c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass TargetLibraryInfo; 30c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass raw_ostream; 31c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 32c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Analysis providing branch probability information. 33c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// 34c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// This is a function analysis which provides information on the relative 35c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// probabilities of each "edge" in the function's CFG where such an edge is 36c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// defined by a pair (PredBlock and an index in the successors). The 37c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// probability of an edge from one block is always relative to the 38c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// probabilities of other edges from the block. The probabilites of all edges 39c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// from a block sum to exactly one (100%). 40c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// We use a pair (PredBlock and an index in the successors) to uniquely 41c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// identify an edge, since we can have multiple edges from Src to Dst. 42c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// As an example, we can have a switch which jumps to Dst with value 0 and 43c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// value 10. 44c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass BranchProbabilityInfo { 45c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 46c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbabilityInfo() {} 47c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbabilityInfo(const Function &F, const LoopInfo &LI, 48c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const TargetLibraryInfo *TLI = nullptr) { 49c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot calculate(F, LI, TLI); 50c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 51c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 52c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbabilityInfo(BranchProbabilityInfo &&Arg) 53c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : Probs(std::move(Arg.Probs)), LastF(Arg.LastF), 54c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot PostDominatedByUnreachable(std::move(Arg.PostDominatedByUnreachable)), 55c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot PostDominatedByColdCall(std::move(Arg.PostDominatedByColdCall)) {} 56c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 57c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbabilityInfo &operator=(BranchProbabilityInfo &&RHS) { 58c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot releaseMemory(); 59c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot Probs = std::move(RHS.Probs); 60c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot PostDominatedByColdCall = std::move(RHS.PostDominatedByColdCall); 61c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot PostDominatedByUnreachable = std::move(RHS.PostDominatedByUnreachable); 62c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return *this; 63c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 64c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 65c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void releaseMemory(); 66c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 67c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void print(raw_ostream &OS) const; 68c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 69c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get an edge's probability, relative to other out-edges of the Src. 70c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 71c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This routine provides access to the fractional probability between zero 72c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// (0%) and one (100%) of this edge executing, relative to other edges 73c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// leaving the 'Src' block. The returned probability is never zero, and can 74c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// only be one if the source block has only one successor. 75c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbability getEdgeProbability(const BasicBlock *Src, 76c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot unsigned IndexInSuccessors) const; 77c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 78c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Get the probability of going from Src to Dst. 79c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 80c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// It returns the sum of all probabilities for edges from Src to Dst. 81c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbability getEdgeProbability(const BasicBlock *Src, 82c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const BasicBlock *Dst) const; 83c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 84c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbability getEdgeProbability(const BasicBlock *Src, 85c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot succ_const_iterator Dst) const; 86c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 87c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Test if an edge is hot relative to other out-edges of the Src. 88c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 89c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Check whether this edge out of the source block is 'hot'. We define hot 90c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// as having a relative probability >= 80%. 91c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool isEdgeHot(const BasicBlock *Src, const BasicBlock *Dst) const; 92c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 93c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Retrieve the hot successor of a block if one exists. 94c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 95c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Given a basic block, look through its successors and if one exists for 96c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// which \see isEdgeHot would return true, return that successor block. 97c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const BasicBlock *getHotSucc(const BasicBlock *BB) const; 98c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 99c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Print an edge's probability. 100c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 101c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Retrieves an edge's probability similarly to \see getEdgeProbability, but 102c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// then prints that probability to the provided stream. That stream is then 103c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// returned. 104c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot raw_ostream &printEdgeProbability(raw_ostream &OS, const BasicBlock *Src, 105c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const BasicBlock *Dst) const; 106c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 107c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Set the raw edge probability for the given edge. 108c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// 109c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// This allows a pass to explicitly set the edge probability for an edge. It 110c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// can be used when updating the CFG to update and preserve the branch 111c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// probability information. Read the implementation of how these edge 112c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// probabilities are calculated carefully before using! 113c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void setEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors, 114c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbability Prob); 115c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 116c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static BranchProbability getBranchProbStackProtector(bool IsLikely) { 117c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static const BranchProbability LikelyProb((1u << 20) - 1, 1u << 20); 118c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot return IsLikely ? LikelyProb : LikelyProb.getCompl(); 119c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 120c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 121c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void calculate(const Function &F, const LoopInfo &LI, 122c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const TargetLibraryInfo *TLI = nullptr); 123c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 124c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// Forget analysis results for the given basic block. 125c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void eraseBlock(const BasicBlock *BB); 126c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 127c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotprivate: 128c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void operator=(const BranchProbabilityInfo &) = delete; 129c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbabilityInfo(const BranchProbabilityInfo &) = delete; 130c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 131c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // We need to store CallbackVH's in order to correctly handle basic block 132c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // removal. 133c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot class BasicBlockCallbackVH final : public CallbackVH { 134c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbabilityInfo *BPI; 135c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void deleted() override { 136c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot assert(BPI != nullptr); 137c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BPI->eraseBlock(cast<BasicBlock>(getValPtr())); 138c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BPI->Handles.erase(*this); 139c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 140c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 141c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot public: 142c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BasicBlockCallbackVH(const Value *V, BranchProbabilityInfo *BPI=nullptr) 143c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : CallbackVH(const_cast<Value *>(V)), BPI(BPI) {} 144c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot }; 145c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DenseSet<BasicBlockCallbackVH, DenseMapInfo<Value*>> Handles; 146c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 147c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Since we allow duplicate edges from one basic block to another, we use 148c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // a pair (PredBlock and an index in the successors) to specify an edge. 149c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot typedef std::pair<const BasicBlock *, unsigned> Edge; 150c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 151c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // Default weight value. Used when we don't have information about the edge. 152c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // TODO: DEFAULT_WEIGHT makes sense during static predication, when none of 153c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // the successors have a weight yet. But it doesn't make sense when providing 154c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // weight to an edge that may have siblings with non-zero weights. This can 155c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // be handled various ways, but it's probably fine for an edge with unknown 156c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot // weight to just "inherit" the non-zero weight of an adjacent successor. 157c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static const uint32_t DEFAULT_WEIGHT = 16; 158c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 159c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot DenseMap<Edge, BranchProbability> Probs; 160c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 161c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Track the last function we run over for printing. 162c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const Function *LastF; 163c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 164c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Track the set of blocks directly succeeded by a returning block. 165c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SmallPtrSet<const BasicBlock *, 16> PostDominatedByUnreachable; 166c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 167c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Track the set of blocks that always lead to a cold call. 168c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot SmallPtrSet<const BasicBlock *, 16> PostDominatedByColdCall; 169c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 170c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void updatePostDominatedByUnreachable(const BasicBlock *BB); 171c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void updatePostDominatedByColdCall(const BasicBlock *BB); 172c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool calcUnreachableHeuristics(const BasicBlock *BB); 173c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool calcMetadataWeights(const BasicBlock *BB); 174c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool calcColdCallHeuristics(const BasicBlock *BB); 175c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool calcPointerHeuristics(const BasicBlock *BB); 176c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool calcLoopBranchHeuristics(const BasicBlock *BB, const LoopInfo &LI); 177c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool calcZeroHeuristics(const BasicBlock *BB, const TargetLibraryInfo *TLI); 178c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool calcFloatingPointHeuristics(const BasicBlock *BB); 179c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool calcInvokeHeuristics(const BasicBlock *BB); 180c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 181c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 182c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Analysis pass which computes \c BranchProbabilityInfo. 183c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass BranchProbabilityAnalysis 184c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : public AnalysisInfoMixin<BranchProbabilityAnalysis> { 185c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot friend AnalysisInfoMixin<BranchProbabilityAnalysis>; 186c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static AnalysisKey Key; 187c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 188c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 189c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Provide the result typedef for this analysis pass. 190c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot typedef BranchProbabilityInfo Result; 191c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 192c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot /// \brief Run the analysis pass over a function and produce BPI. 193c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbabilityInfo run(Function &F, FunctionAnalysisManager &AM); 194c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 195c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 196c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Printer pass for the \c BranchProbabilityAnalysis results. 197c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass BranchProbabilityPrinterPass 198c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot : public PassInfoMixin<BranchProbabilityPrinterPass> { 199c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot raw_ostream &OS; 200c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 201c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 202c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot explicit BranchProbabilityPrinterPass(raw_ostream &OS) : OS(OS) {} 203c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); 204c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 205c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 206c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot/// \brief Legacy analysis pass which computes \c BranchProbabilityInfo. 207c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotclass BranchProbabilityInfoWrapperPass : public FunctionPass { 208c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbabilityInfo BPI; 209c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 210c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robotpublic: 211c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot static char ID; 212c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 213c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbabilityInfoWrapperPass() : FunctionPass(ID) { 214c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot initializeBranchProbabilityInfoWrapperPassPass( 215c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot *PassRegistry::getPassRegistry()); 216c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot } 217c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 218c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot BranchProbabilityInfo &getBPI() { return BPI; } 219c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot const BranchProbabilityInfo &getBPI() const { return BPI; } 220c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 221c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void getAnalysisUsage(AnalysisUsage &AU) const override; 222c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot bool runOnFunction(Function &F) override; 223c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void releaseMemory() override; 224c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot void print(raw_ostream &OS, const Module *M = nullptr) const override; 225c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot}; 226c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 227c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot} 228c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot 229c9cc9e7d29b8970d8ddb734c88fb62d01e0b727android-build-team Robot#endif 230