]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Analysis/LazyBlockFrequencyInfo.cpp
MFV r337204: 9439 ZFS double-free due to failure to dirty indirect block
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Analysis / LazyBlockFrequencyInfo.cpp
1 //===- LazyBlockFrequencyInfo.cpp - Lazy Block Frequency 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 BlockFrequencyInfoWrapperPass.  The
11 // difference is that with this pass the block frequencies are not computed when
12 // the analysis pass is executed but rather when the BFI result is explicitly
13 // requested by the analysis client.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #include "llvm/Analysis/LazyBlockFrequencyInfo.h"
18 #include "llvm/Analysis/LazyBranchProbabilityInfo.h"
19 #include "llvm/Analysis/LoopInfo.h"
20
21 using namespace llvm;
22
23 #define DEBUG_TYPE "lazy-block-freq"
24
25 INITIALIZE_PASS_BEGIN(LazyBlockFrequencyInfoPass, DEBUG_TYPE,
26                       "Lazy Block Frequency Analysis", true, true)
27 INITIALIZE_PASS_DEPENDENCY(LazyBPIPass)
28 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
29 INITIALIZE_PASS_END(LazyBlockFrequencyInfoPass, DEBUG_TYPE,
30                     "Lazy Block Frequency Analysis", true, true)
31
32 char LazyBlockFrequencyInfoPass::ID = 0;
33
34 LazyBlockFrequencyInfoPass::LazyBlockFrequencyInfoPass() : FunctionPass(ID) {
35   initializeLazyBlockFrequencyInfoPassPass(*PassRegistry::getPassRegistry());
36 }
37
38 void LazyBlockFrequencyInfoPass::print(raw_ostream &OS, const Module *) const {
39   LBFI.getCalculated().print(OS);
40 }
41
42 void LazyBlockFrequencyInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
43   LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU);
44   AU.addRequired<LoopInfoWrapperPass>();
45   AU.setPreservesAll();
46 }
47
48 void LazyBlockFrequencyInfoPass::releaseMemory() { LBFI.releaseMemory(); }
49
50 bool LazyBlockFrequencyInfoPass::runOnFunction(Function &F) {
51   auto &BPIPass = getAnalysis<LazyBranchProbabilityInfoPass>();
52   LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
53   LBFI.setAnalysis(&F, &BPIPass, &LI);
54   return false;
55 }
56
57 void LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AnalysisUsage &AU) {
58   LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU);
59   AU.addRequired<LazyBlockFrequencyInfoPass>();
60   AU.addRequired<LoopInfoWrapperPass>();
61 }
62
63 void llvm::initializeLazyBFIPassPass(PassRegistry &Registry) {
64   initializeLazyBPIPassPass(Registry);
65   INITIALIZE_PASS_DEPENDENCY(LazyBlockFrequencyInfoPass);
66   INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
67 }