]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Analysis/LazyBranchProbabilityInfo.cpp
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Analysis / LazyBranchProbabilityInfo.cpp
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 #include "llvm/Analysis/TargetLibraryInfo.h"
20
21 using namespace llvm;
22
23 #define DEBUG_TYPE "lazy-branch-prob"
24
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)
31
32 char LazyBranchProbabilityInfoPass::ID = 0;
33
34 LazyBranchProbabilityInfoPass::LazyBranchProbabilityInfoPass()
35     : FunctionPass(ID) {
36   initializeLazyBranchProbabilityInfoPassPass(*PassRegistry::getPassRegistry());
37 }
38
39 void LazyBranchProbabilityInfoPass::print(raw_ostream &OS,
40                                           const Module *) const {
41   LBPI->getCalculated().print(OS);
42 }
43
44 void LazyBranchProbabilityInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
45   AU.addRequired<LoopInfoWrapperPass>();
46   AU.addRequired<TargetLibraryInfoWrapperPass>();
47   AU.setPreservesAll();
48 }
49
50 void LazyBranchProbabilityInfoPass::releaseMemory() { LBPI.reset(); }
51
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);
56   return false;
57 }
58
59 void LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AnalysisUsage &AU) {
60   AU.addRequired<LazyBranchProbabilityInfoPass>();
61   AU.addRequired<LoopInfoWrapperPass>();
62   AU.addRequired<TargetLibraryInfoWrapperPass>();
63 }
64
65 void llvm::initializeLazyBPIPassPass(PassRegistry &Registry) {
66   INITIALIZE_PASS_DEPENDENCY(LazyBranchProbabilityInfoPass);
67   INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
68   INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass);
69 }