1 //=======-------- BlockFrequencyInfo.cpp - 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 // Loops should be simplified before this analysis.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Analysis/BlockFrequencyInfo.h"
15 #include "llvm/Analysis/BlockFrequencyImpl.h"
16 #include "llvm/Analysis/BranchProbabilityInfo.h"
17 #include "llvm/Analysis/LoopInfo.h"
18 #include "llvm/Analysis/Passes.h"
19 #include "llvm/InitializePasses.h"
23 INITIALIZE_PASS_BEGIN(BlockFrequencyInfo, "block-freq",
24 "Block Frequency Analysis", true, true)
25 INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfo)
26 INITIALIZE_PASS_END(BlockFrequencyInfo, "block-freq",
27 "Block Frequency Analysis", true, true)
29 char BlockFrequencyInfo::ID = 0;
32 BlockFrequencyInfo::BlockFrequencyInfo() : FunctionPass(ID) {
33 initializeBlockFrequencyInfoPass(*PassRegistry::getPassRegistry());
34 BFI = new BlockFrequencyImpl<BasicBlock, Function, BranchProbabilityInfo>();
37 BlockFrequencyInfo::~BlockFrequencyInfo() {
41 void BlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const {
42 AU.addRequired<BranchProbabilityInfo>();
46 bool BlockFrequencyInfo::runOnFunction(Function &F) {
47 BranchProbabilityInfo &BPI = getAnalysis<BranchProbabilityInfo>();
48 BFI->doFunction(&F, &BPI);
52 void BlockFrequencyInfo::print(raw_ostream &O, const Module *) const {
53 if (BFI) BFI->print(O);
56 BlockFrequency BlockFrequencyInfo::getBlockFreq(const BasicBlock *BB) const {
57 return BFI->getBlockFreq(BB);