1 //=======-------- BlockFrequency.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/InitializePasses.h"
15 #include "llvm/Analysis/BlockFrequencyImpl.h"
16 #include "llvm/Analysis/BlockFrequency.h"
17 #include "llvm/Analysis/LoopInfo.h"
18 #include "llvm/Analysis/Passes.h"
19 #include "llvm/Analysis/BranchProbabilityInfo.h"
23 INITIALIZE_PASS_BEGIN(BlockFrequency
, "block-freq", "Block Frequency Analysis",
25 INITIALIZE_PASS_DEPENDENCY(BranchProbabilityInfo
)
26 INITIALIZE_PASS_END(BlockFrequency
, "block-freq", "Block Frequency Analysis",
29 char BlockFrequency::ID
= 0;
32 BlockFrequency::BlockFrequency() : FunctionPass(ID
) {
33 initializeBlockFrequencyPass(*PassRegistry::getPassRegistry());
34 BFI
= new BlockFrequencyImpl
<BasicBlock
, Function
, BranchProbabilityInfo
>();
37 BlockFrequency::~BlockFrequency() {
41 void BlockFrequency::getAnalysisUsage(AnalysisUsage
&AU
) const {
42 AU
.addRequired
<BranchProbabilityInfo
>();
46 bool BlockFrequency::runOnFunction(Function
&F
) {
47 BranchProbabilityInfo
&BPI
= getAnalysis
<BranchProbabilityInfo
>();
48 BFI
->doFunction(&F
, &BPI
);
52 /// getblockFreq - Return block frequency. Never return 0, value must be
53 /// positive. Please note that initial frequency is equal to 1024. It means that
54 /// we should not rely on the value itself, but only on the comparison to the
55 /// other block frequencies. We do this to avoid using of floating points.
57 uint32_t BlockFrequency::getBlockFreq(BasicBlock
*BB
) {
58 return BFI
->getBlockFreq(BB
);