1 //===- LazyBlockFrequencyInfo.cpp - Lazy Block Frequency 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 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.
15 //===----------------------------------------------------------------------===//
17 #include "llvm/Analysis/LazyBlockFrequencyInfo.h"
18 #include "llvm/Analysis/LazyBranchProbabilityInfo.h"
19 #include "llvm/Analysis/LoopInfo.h"
23 #define DEBUG_TYPE "lazy-block-freq"
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)
32 char LazyBlockFrequencyInfoPass::ID = 0;
34 LazyBlockFrequencyInfoPass::LazyBlockFrequencyInfoPass() : FunctionPass(ID) {
35 initializeLazyBlockFrequencyInfoPassPass(*PassRegistry::getPassRegistry());
38 void LazyBlockFrequencyInfoPass::print(raw_ostream &OS, const Module *) const {
39 LBFI.getCalculated().print(OS);
42 void LazyBlockFrequencyInfoPass::getAnalysisUsage(AnalysisUsage &AU) const {
43 LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU);
44 AU.addRequired<LoopInfoWrapperPass>();
48 void LazyBlockFrequencyInfoPass::releaseMemory() { LBFI.releaseMemory(); }
50 bool LazyBlockFrequencyInfoPass::runOnFunction(Function &F) {
51 auto &BPIPass = getAnalysis<LazyBranchProbabilityInfoPass>();
52 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
53 LBFI.setAnalysis(&F, &BPIPass, &LI);
57 void LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AnalysisUsage &AU) {
58 LazyBranchProbabilityInfoPass::getLazyBPIAnalysisUsage(AU);
59 AU.addRequired<LazyBlockFrequencyInfoPass>();
60 AU.addRequired<LoopInfoWrapperPass>();
63 void llvm::initializeLazyBFIPassPass(PassRegistry &Registry) {
64 initializeLazyBPIPassPass(Registry);
65 INITIALIZE_PASS_DEPENDENCY(LazyBlockFrequencyInfoPass);
66 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);