blob: 7debfde87d2a3c9781ccf41827f0e9690fbd3c29 [file] [log] [blame]
Adam Nemetc2f791d2016-07-13 05:01:48 +00001//===- 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 results is explicitly
13// requested by the analysis client.
14//
15//===----------------------------------------------------------------------===//
16
17#include "llvm/Analysis/LazyBlockFrequencyInfo.h"
18#include "llvm/Analysis/BranchProbabilityInfo.h"
19#include "llvm/Analysis/LoopInfo.h"
20
21using namespace llvm;
22
23#define DEBUG_TYPE "lazy-block-freq"
24
25INITIALIZE_PASS_BEGIN(LazyBlockFrequencyInfoPass, DEBUG_TYPE,
26 "Lazy Block Frequency Analysis", true, true)
27INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass)
28INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
29INITIALIZE_PASS_END(LazyBlockFrequencyInfoPass, DEBUG_TYPE,
30 "Lazy Block Frequency Analysis", true, true)
31
32char LazyBlockFrequencyInfoPass::ID = 0;
33
34LazyBlockFrequencyInfoPass::LazyBlockFrequencyInfoPass() : FunctionPass(ID) {
35 initializeLazyBlockFrequencyInfoPassPass(*PassRegistry::getPassRegistry());
36}
37
38void LazyBlockFrequencyInfoPass::print(raw_ostream &OS, const Module *) const {
39 LBFI.getCalculated().print(OS);
40}
41
42void LazyBlockFrequencyInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
43 AU.addRequired<BranchProbabilityInfoWrapperPass>();
44 AU.addRequired<LoopInfoWrapperPass>();
45 AU.setPreservesAll();
46}
47
48void LazyBlockFrequencyInfoPass::releaseMemory() { LBFI.releaseMemory(); }
49
50bool LazyBlockFrequencyInfoPass::runOnFunction(Function &F) {
51 BranchProbabilityInfo &BPI =
52 getAnalysis<BranchProbabilityInfoWrapperPass>().getBPI();
53 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
54 LBFI.setAnalysis(&F, &BPI, &LI);
55 return false;
56}
57
58void LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AnalysisUsage &AU) {
59 AU.addRequired<BranchProbabilityInfoWrapperPass>();
60 AU.addRequired<LazyBlockFrequencyInfoPass>();
61 AU.addRequired<LoopInfoWrapperPass>();
62}
63
64void llvm::initializeLazyBFIPassPass(PassRegistry &Registry) {
65 INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfoWrapperPass);
66 INITIALIZE_PASS_DEPENDENCY(LazyBlockFrequencyInfoPass);
67 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
68}