LLVM API Documentation
00001 //====----- MachineBlockFrequencyInfo.cpp - Machine Block Frequency Analysis ----====// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Loops should be simplified before this analysis. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/CodeGen/MachineBlockFrequencyInfo.h" 00015 #include "llvm/Analysis/BlockFrequencyImpl.h" 00016 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h" 00017 #include "llvm/CodeGen/Passes.h" 00018 #include "llvm/InitializePasses.h" 00019 00020 using namespace llvm; 00021 00022 INITIALIZE_PASS_BEGIN(MachineBlockFrequencyInfo, "machine-block-freq", 00023 "Machine Block Frequency Analysis", true, true) 00024 INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo) 00025 INITIALIZE_PASS_END(MachineBlockFrequencyInfo, "machine-block-freq", 00026 "Machine Block Frequency Analysis", true, true) 00027 00028 char MachineBlockFrequencyInfo::ID = 0; 00029 00030 00031 MachineBlockFrequencyInfo::MachineBlockFrequencyInfo() : MachineFunctionPass(ID) { 00032 initializeMachineBlockFrequencyInfoPass(*PassRegistry::getPassRegistry()); 00033 MBFI = new BlockFrequencyImpl<MachineBasicBlock, MachineFunction, 00034 MachineBranchProbabilityInfo>(); 00035 } 00036 00037 MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() { 00038 delete MBFI; 00039 } 00040 00041 void MachineBlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const { 00042 AU.addRequired<MachineBranchProbabilityInfo>(); 00043 AU.setPreservesAll(); 00044 MachineFunctionPass::getAnalysisUsage(AU); 00045 } 00046 00047 bool MachineBlockFrequencyInfo::runOnMachineFunction(MachineFunction &F) { 00048 MachineBranchProbabilityInfo &MBPI = getAnalysis<MachineBranchProbabilityInfo>(); 00049 MBFI->doFunction(&F, &MBPI); 00050 return false; 00051 } 00052 00053 /// getblockFreq - Return block frequency. Return 0 if we don't have the 00054 /// information. Please note that initial frequency is equal to 1024. It means 00055 /// that we should not rely on the value itself, but only on the comparison to 00056 /// the other block frequencies. We do this to avoid using of floating points. 00057 /// 00058 BlockFrequency MachineBlockFrequencyInfo:: 00059 getBlockFreq(const MachineBasicBlock *MBB) const { 00060 return MBFI->getBlockFreq(MBB); 00061 }