1 //====----- MachineBlockFrequencyInfo.cpp - Machine 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/CodeGen/MachineBlockFrequencyInfo.h"
17 #include "llvm/CodeGen/Passes.h"
18 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
22 INITIALIZE_PASS_BEGIN(MachineBlockFrequencyInfo, "machine-block-freq",
23 "Machine Block Frequency Analysis", true, true)
24 INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
25 INITIALIZE_PASS_END(MachineBlockFrequencyInfo, "machine-block-freq",
26 "Machine Block Frequency Analysis", true, true)
28 char MachineBlockFrequencyInfo::ID = 0;
31 MachineBlockFrequencyInfo::MachineBlockFrequencyInfo() : MachineFunctionPass(ID) {
32 initializeMachineBlockFrequencyInfoPass(*PassRegistry::getPassRegistry());
33 MBFI = new BlockFrequencyImpl<MachineBasicBlock, MachineFunction,
34 MachineBranchProbabilityInfo>();
37 MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() {
41 void MachineBlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const {
42 AU.addRequired<MachineBranchProbabilityInfo>();
44 MachineFunctionPass::getAnalysisUsage(AU);
47 bool MachineBlockFrequencyInfo::runOnMachineFunction(MachineFunction &F) {
48 MachineBranchProbabilityInfo &MBPI = getAnalysis<MachineBranchProbabilityInfo>();
49 MBFI->doFunction(&F, &MBPI);
53 /// getblockFreq - Return block frequency. Return 0 if we don't have the
54 /// information. Please note that initial frequency is equal to 1024. It means
55 /// that we should not rely on the value itself, but only on the comparison to
56 /// the other block frequencies. We do this to avoid using of floating points.
58 BlockFrequency MachineBlockFrequencyInfo::
59 getBlockFreq(MachineBasicBlock *MBB) const {
60 return MBFI->getBlockFreq(MBB);