blob: b51c6beb795928277a674f70d50fd7b109fecb50 [file] [log] [blame]
Adam Nemetaa3506c2016-07-28 23:31:12 +00001//===- 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
20using namespace llvm;
21
22#define DEBUG_TYPE "lazy-branch-prob"
23
24INITIALIZE_PASS_BEGIN(LazyBranchProbabilityInfoPass, DEBUG_TYPE,
25 "Lazy Branch Probability Analysis", true, true)
26INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
27INITIALIZE_PASS_END(LazyBranchProbabilityInfoPass, DEBUG_TYPE,
28 "Lazy Branch Probability Analysis", true, true)
29
30char LazyBranchProbabilityInfoPass::ID = 0;
31
32LazyBranchProbabilityInfoPass::LazyBranchProbabilityInfoPass()
33 : FunctionPass(ID) {
34 initializeLazyBranchProbabilityInfoPassPass(*PassRegistry::getPassRegistry());
35}
36
37void LazyBranchProbabilityInfoPass::print(raw_ostream &OS,
38 const Module *) const {
39 LBPI->getCalculated().print(OS);
40}
41
42void LazyBranchProbabilityInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
43 AU.addRequired<LoopInfoWrapperPass>();
44 AU.setPreservesAll();
45}
46
47void LazyBranchProbabilityInfoPass::releaseMemory() { LBPI.reset(); }
48
49bool LazyBranchProbabilityInfoPass::runOnFunction(Function &F) {
50 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
51 LBPI = llvm::make_unique<LazyBranchProbabilityInfo>(&F, &LI);
52 return false;
53}
54
55void LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AnalysisUsage &AU) {
56 AU.addRequired<LazyBranchProbabilityInfoPass>();
57 AU.addRequired<LoopInfoWrapperPass>();
58}
59
60void llvm::initializeLazyBPIPassPass(PassRegistry &Registry) {
61 INITIALIZE_PASS_DEPENDENCY(LazyBranchProbabilityInfoPass);
62 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
63}