Adam Nemet | aa3506c | 2016-07-28 23:31:12 +0000 | [diff] [blame] | 1 | //===- LazyBranchProbabilityInfo.cpp - Lazy Branch Probability Analysis ---===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is an alternative analysis pass to BranchProbabilityInfoWrapperPass. |
| 11 | // The difference is that with this pass the branch probabilities are not |
| 12 | // computed when the analysis pass is executed but rather when the BPI results |
| 13 | // is explicitly requested by the analysis client. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #include "llvm/Analysis/LazyBranchProbabilityInfo.h" |
| 18 | #include "llvm/Analysis/LoopInfo.h" |
| 19 | |
| 20 | using namespace llvm; |
| 21 | |
| 22 | #define DEBUG_TYPE "lazy-branch-prob" |
| 23 | |
| 24 | INITIALIZE_PASS_BEGIN(LazyBranchProbabilityInfoPass, DEBUG_TYPE, |
| 25 | "Lazy Branch Probability Analysis", true, true) |
| 26 | INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) |
| 27 | INITIALIZE_PASS_END(LazyBranchProbabilityInfoPass, DEBUG_TYPE, |
| 28 | "Lazy Branch Probability Analysis", true, true) |
| 29 | |
| 30 | char LazyBranchProbabilityInfoPass::ID = 0; |
| 31 | |
| 32 | LazyBranchProbabilityInfoPass::LazyBranchProbabilityInfoPass() |
| 33 | : FunctionPass(ID) { |
| 34 | initializeLazyBranchProbabilityInfoPassPass(*PassRegistry::getPassRegistry()); |
| 35 | } |
| 36 | |
| 37 | void LazyBranchProbabilityInfoPass::print(raw_ostream &OS, |
| 38 | const Module *) const { |
| 39 | LBPI->getCalculated().print(OS); |
| 40 | } |
| 41 | |
| 42 | void LazyBranchProbabilityInfoPass::getAnalysisUsage(AnalysisUsage &AU) const { |
| 43 | AU.addRequired<LoopInfoWrapperPass>(); |
| 44 | AU.setPreservesAll(); |
| 45 | } |
| 46 | |
| 47 | void LazyBranchProbabilityInfoPass::releaseMemory() { LBPI.reset(); } |
| 48 | |
| 49 | bool LazyBranchProbabilityInfoPass::runOnFunction(Function &F) { |
| 50 | LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
| 51 | LBPI = llvm::make_unique<LazyBranchProbabilityInfo>(&F, &LI); |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | void LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AnalysisUsage &AU) { |
| 56 | AU.addRequired<LazyBranchProbabilityInfoPass>(); |
| 57 | AU.addRequired<LoopInfoWrapperPass>(); |
| 58 | } |
| 59 | |
| 60 | void llvm::initializeLazyBPIPassPass(PassRegistry &Registry) { |
| 61 | INITIALIZE_PASS_DEPENDENCY(LazyBranchProbabilityInfoPass); |
| 62 | INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass); |
| 63 | } |