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