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"
22 #define DEBUG_TYPE "lazy-branch-prob"
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)
30 char LazyBranchProbabilityInfoPass::ID
= 0;
32 LazyBranchProbabilityInfoPass::LazyBranchProbabilityInfoPass()
34 initializeLazyBranchProbabilityInfoPassPass(*PassRegistry::getPassRegistry());
37 void LazyBranchProbabilityInfoPass::print(raw_ostream
&OS
,
38 const Module
*) const {
39 LBPI
->getCalculated().print(OS
);
42 void LazyBranchProbabilityInfoPass::getAnalysisUsage(AnalysisUsage
&AU
) const {
43 AU
.addRequired
<LoopInfoWrapperPass
>();
47 void LazyBranchProbabilityInfoPass::releaseMemory() { LBPI
.reset(); }
49 bool LazyBranchProbabilityInfoPass::runOnFunction(Function
&F
) {
50 LoopInfo
&LI
= getAnalysis
<LoopInfoWrapperPass
>().getLoopInfo();
51 LBPI
= llvm::make_unique
<LazyBranchProbabilityInfo
>(&F
, &LI
);
55 void LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AnalysisUsage
&AU
) {
56 AU
.addRequired
<LazyBranchProbabilityInfoPass
>();
57 AU
.addRequired
<LoopInfoWrapperPass
>();
60 void llvm::initializeLazyBPIPassPass(PassRegistry
&Registry
) {
61 INITIALIZE_PASS_DEPENDENCY(LazyBranchProbabilityInfoPass
);
62 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass
);