2011-07-25 19:25:40 +00:00
|
|
|
//=======-------- BlockFrequencyInfo.cpp - Block Frequency Analysis -------=======//
|
2011-06-23 21:56:59 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Loops should be simplified before this analysis.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
#include "llvm/Analysis/BlockFrequencyInfo.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Analysis/BlockFrequencyImpl.h"
|
|
|
|
#include "llvm/Analysis/BranchProbabilityInfo.h"
|
2011-06-23 21:56:59 +00:00
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
|
|
|
#include "llvm/Analysis/Passes.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/InitializePasses.h"
|
2011-06-23 21:56:59 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
INITIALIZE_PASS_BEGIN(BlockFrequencyInfo, "block-freq", "Block Frequency Analysis",
|
2011-06-23 21:56:59 +00:00
|
|
|
true, true)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfo)
|
2011-07-25 19:25:40 +00:00
|
|
|
INITIALIZE_PASS_END(BlockFrequencyInfo, "block-freq", "Block Frequency Analysis",
|
2011-06-23 21:56:59 +00:00
|
|
|
true, true)
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
char BlockFrequencyInfo::ID = 0;
|
2011-06-23 21:56:59 +00:00
|
|
|
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
BlockFrequencyInfo::BlockFrequencyInfo() : FunctionPass(ID) {
|
|
|
|
initializeBlockFrequencyInfoPass(*PassRegistry::getPassRegistry());
|
2011-06-23 21:56:59 +00:00
|
|
|
BFI = new BlockFrequencyImpl<BasicBlock, Function, BranchProbabilityInfo>();
|
|
|
|
}
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
BlockFrequencyInfo::~BlockFrequencyInfo() {
|
2011-06-23 21:56:59 +00:00
|
|
|
delete BFI;
|
|
|
|
}
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
void BlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const {
|
2011-06-23 21:56:59 +00:00
|
|
|
AU.addRequired<BranchProbabilityInfo>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
bool BlockFrequencyInfo::runOnFunction(Function &F) {
|
2011-06-23 21:56:59 +00:00
|
|
|
BranchProbabilityInfo &BPI = getAnalysis<BranchProbabilityInfo>();
|
|
|
|
BFI->doFunction(&F, &BPI);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-19 10:12:41 +00:00
|
|
|
void BlockFrequencyInfo::print(raw_ostream &O, const Module *) const {
|
|
|
|
if (BFI) BFI->print(O);
|
|
|
|
}
|
|
|
|
|
2011-12-20 20:03:10 +00:00
|
|
|
BlockFrequency BlockFrequencyInfo::getBlockFreq(const BasicBlock *BB) const {
|
2011-06-23 21:56:59 +00:00
|
|
|
return BFI->getBlockFreq(BB);
|
|
|
|
}
|