1 //===- LazyBranchProbabilityInfo.cpp - Lazy Branch Probability Analysis ---===//
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 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.
15 //===----------------------------------------------------------------------===//
17 #include "llvm/Analysis/LazyBranchProbabilityInfo.h"
18 #include "llvm/Analysis/LoopInfo.h"
19 #include "llvm/Analysis/TargetLibraryInfo.h"
23 #define DEBUG_TYPE "lazy-branch-prob"
25 INITIALIZE_PASS_BEGIN(LazyBranchProbabilityInfoPass, DEBUG_TYPE,
26 "Lazy Branch Probability Analysis", true, true)
27 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
28 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
29 INITIALIZE_PASS_END(LazyBranchProbabilityInfoPass, DEBUG_TYPE,
30 "Lazy Branch Probability Analysis", true, true)
32 char LazyBranchProbabilityInfoPass::ID = 0;
34 LazyBranchProbabilityInfoPass::LazyBranchProbabilityInfoPass()
36 initializeLazyBranchProbabilityInfoPassPass(*PassRegistry::getPassRegistry());
39 void LazyBranchProbabilityInfoPass::print(raw_ostream &OS,
40 const Module *) const {
41 LBPI->getCalculated().print(OS);
44 void LazyBranchProbabilityInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
45 AU.addRequired<LoopInfoWrapperPass>();
46 AU.addRequired<TargetLibraryInfoWrapperPass>();
50 void LazyBranchProbabilityInfoPass::releaseMemory() { LBPI.reset(); }
52 bool LazyBranchProbabilityInfoPass::runOnFunction(Function &F) {
53 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
54 TargetLibraryInfo &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
55 LBPI = llvm::make_unique<LazyBranchProbabilityInfo>(&F, &LI, &TLI);
59 void LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AnalysisUsage &AU) {
60 AU.addRequired<LazyBranchProbabilityInfoPass>();
61 AU.addRequired<LoopInfoWrapperPass>();
62 AU.addRequired<TargetLibraryInfoWrapperPass>();
65 void llvm::initializeLazyBPIPassPass(PassRegistry &Registry) {
66 INITIALIZE_PASS_DEPENDENCY(LazyBranchProbabilityInfoPass);
67 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
68 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass);