2011-07-25 21:25:40 +02:00
|
|
|
//=======-------- BlockFrequencyInfo.cpp - Block Frequency Analysis -------=======//
|
2011-06-23 23:56:59 +02: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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/InitializePasses.h"
|
|
|
|
#include "llvm/Analysis/BlockFrequencyImpl.h"
|
2011-07-25 21:25:40 +02:00
|
|
|
#include "llvm/Analysis/BlockFrequencyInfo.h"
|
2011-06-23 23:56:59 +02:00
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
|
|
|
#include "llvm/Analysis/Passes.h"
|
|
|
|
#include "llvm/Analysis/BranchProbabilityInfo.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2011-07-25 21:25:40 +02:00
|
|
|
INITIALIZE_PASS_BEGIN(BlockFrequencyInfo, "block-freq", "Block Frequency Analysis",
|
2011-06-23 23:56:59 +02:00
|
|
|
true, true)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfo)
|
2011-07-25 21:25:40 +02:00
|
|
|
INITIALIZE_PASS_END(BlockFrequencyInfo, "block-freq", "Block Frequency Analysis",
|
2011-06-23 23:56:59 +02:00
|
|
|
true, true)
|
|
|
|
|
2011-07-25 21:25:40 +02:00
|
|
|
char BlockFrequencyInfo::ID = 0;
|
2011-06-23 23:56:59 +02:00
|
|
|
|
|
|
|
|
2011-07-25 21:25:40 +02:00
|
|
|
BlockFrequencyInfo::BlockFrequencyInfo() : FunctionPass(ID) {
|
|
|
|
initializeBlockFrequencyInfoPass(*PassRegistry::getPassRegistry());
|
2011-06-23 23:56:59 +02:00
|
|
|
BFI = new BlockFrequencyImpl<BasicBlock, Function, BranchProbabilityInfo>();
|
|
|
|
}
|
|
|
|
|
2011-07-25 21:25:40 +02:00
|
|
|
BlockFrequencyInfo::~BlockFrequencyInfo() {
|
2011-06-23 23:56:59 +02:00
|
|
|
delete BFI;
|
|
|
|
}
|
|
|
|
|
2011-07-25 21:25:40 +02:00
|
|
|
void BlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const {
|
2011-06-23 23:56:59 +02:00
|
|
|
AU.addRequired<BranchProbabilityInfo>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2011-07-25 21:25:40 +02:00
|
|
|
bool BlockFrequencyInfo::runOnFunction(Function &F) {
|
2011-06-23 23:56:59 +02:00
|
|
|
BranchProbabilityInfo &BPI = getAnalysis<BranchProbabilityInfo>();
|
|
|
|
BFI->doFunction(&F, &BPI);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-19 12:12:41 +02:00
|
|
|
void BlockFrequencyInfo::print(raw_ostream &O, const Module *) const {
|
|
|
|
if (BFI) BFI->print(O);
|
|
|
|
}
|
|
|
|
|
2011-07-22 04:24:57 +02:00
|
|
|
/// getblockFreq - Return block frequency. Return 0 if we don't have the
|
|
|
|
/// information. Please note that initial frequency is equal to 1024. It means
|
|
|
|
/// that we should not rely on the value itself, but only on the comparison to
|
|
|
|
/// the other block frequencies. We do this to avoid using of floating points.
|
2011-06-23 23:56:59 +02:00
|
|
|
///
|
2011-12-20 21:03:10 +01:00
|
|
|
BlockFrequency BlockFrequencyInfo::getBlockFreq(const BasicBlock *BB) const {
|
2011-06-23 23:56:59 +02:00
|
|
|
return BFI->getBlockFreq(BB);
|
|
|
|
}
|