2011-07-25 19:25:40 +00:00
|
|
|
//====----- MachineBlockFrequencyInfo.cpp - Machine Block Frequency Analysis ----====//
|
2011-07-16 20:23:20 +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/CodeGen/MachineBlockFrequencyInfo.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Analysis/BlockFrequencyImpl.h"
|
2011-07-16 20:23:20 +00:00
|
|
|
#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
|
|
|
#include "llvm/InitializePasses.h"
|
2011-07-16 20:23:20 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
INITIALIZE_PASS_BEGIN(MachineBlockFrequencyInfo, "machine-block-freq",
|
2011-07-16 20:23:20 +00:00
|
|
|
"Machine Block Frequency Analysis", true, true)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
|
2011-07-25 19:25:40 +00:00
|
|
|
INITIALIZE_PASS_END(MachineBlockFrequencyInfo, "machine-block-freq",
|
2011-07-16 20:23:20 +00:00
|
|
|
"Machine Block Frequency Analysis", true, true)
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
char MachineBlockFrequencyInfo::ID = 0;
|
2011-07-16 20:23:20 +00:00
|
|
|
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
MachineBlockFrequencyInfo::MachineBlockFrequencyInfo() : MachineFunctionPass(ID) {
|
|
|
|
initializeMachineBlockFrequencyInfoPass(*PassRegistry::getPassRegistry());
|
2011-07-16 20:23:20 +00:00
|
|
|
MBFI = new BlockFrequencyImpl<MachineBasicBlock, MachineFunction,
|
|
|
|
MachineBranchProbabilityInfo>();
|
|
|
|
}
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() {
|
2011-07-16 20:23:20 +00:00
|
|
|
delete MBFI;
|
|
|
|
}
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
void MachineBlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const {
|
2011-07-16 20:23:20 +00:00
|
|
|
AU.addRequired<MachineBranchProbabilityInfo>();
|
|
|
|
AU.setPreservesAll();
|
2011-07-21 22:59:09 +00:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
2011-07-16 20:23:20 +00:00
|
|
|
}
|
|
|
|
|
2011-07-25 19:25:40 +00:00
|
|
|
bool MachineBlockFrequencyInfo::runOnMachineFunction(MachineFunction &F) {
|
2011-07-16 20:23:20 +00:00
|
|
|
MachineBranchProbabilityInfo &MBPI = getAnalysis<MachineBranchProbabilityInfo>();
|
|
|
|
MBFI->doFunction(&F, &MBPI);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-03 21:30:57 +00:00
|
|
|
BlockFrequency MachineBlockFrequencyInfo::
|
2011-12-20 20:03:10 +00:00
|
|
|
getBlockFreq(const MachineBasicBlock *MBB) const {
|
2011-07-16 20:23:20 +00:00
|
|
|
return MBFI->getBlockFreq(MBB);
|
|
|
|
}
|