Home | History | Annotate | Download | only in CodeGen
      1 //====----- MachineBlockFrequencyInfo.cpp - Machine Block Frequency Analysis ----====//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // Loops should be simplified before this analysis.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
     15 #include "llvm/Analysis/BlockFrequencyImpl.h"
     16 #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
     17 #include "llvm/CodeGen/Passes.h"
     18 #include "llvm/InitializePasses.h"
     19 
     20 using namespace llvm;
     21 
     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)
     27 
     28 char MachineBlockFrequencyInfo::ID = 0;
     29 
     30 
     31 MachineBlockFrequencyInfo::MachineBlockFrequencyInfo() : MachineFunctionPass(ID) {
     32   initializeMachineBlockFrequencyInfoPass(*PassRegistry::getPassRegistry());
     33   MBFI = new BlockFrequencyImpl<MachineBasicBlock, MachineFunction,
     34                                 MachineBranchProbabilityInfo>();
     35 }
     36 
     37 MachineBlockFrequencyInfo::~MachineBlockFrequencyInfo() {
     38   delete MBFI;
     39 }
     40 
     41 void MachineBlockFrequencyInfo::getAnalysisUsage(AnalysisUsage &AU) const {
     42   AU.addRequired<MachineBranchProbabilityInfo>();
     43   AU.setPreservesAll();
     44   MachineFunctionPass::getAnalysisUsage(AU);
     45 }
     46 
     47 bool MachineBlockFrequencyInfo::runOnMachineFunction(MachineFunction &F) {
     48   MachineBranchProbabilityInfo &MBPI = getAnalysis<MachineBranchProbabilityInfo>();
     49   MBFI->doFunction(&F, &MBPI);
     50   return false;
     51 }
     52 
     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.
     57 ///
     58 BlockFrequency MachineBlockFrequencyInfo::
     59 getBlockFreq(const MachineBasicBlock *MBB) const {
     60   return MBFI->getBlockFreq(MBB);
     61 }
     62