LCOV - code coverage report
Current view: top level - lib/CodeGen - LazyMachineBlockFrequencyInfo.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 39 42 92.9 %
Date: 2017-09-14 15:23:50 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : ///===- LazyMachineBlockFrequencyInfo.cpp - Lazy Machine Block Frequency --===//
       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             : /// \file
      10             : /// This is an alternative analysis pass to MachineBlockFrequencyInfo.  The
      11             : /// difference is that with this pass the block frequencies are not computed
      12             : /// when the analysis pass is executed but rather when the BFI result is
      13             : /// explicitly requested by the analysis client.
      14             : ///
      15             : ///===---------------------------------------------------------------------===//
      16             : 
      17             : #include "llvm/CodeGen/LazyMachineBlockFrequencyInfo.h"
      18             : 
      19             : using namespace llvm;
      20             : 
      21             : #define DEBUG_TYPE "lazy-machine-block-freq"
      22             : 
      23       20212 : INITIALIZE_PASS_BEGIN(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE,
      24             :                       "Lazy Machine Block Frequency Analysis", true, true)
      25       20212 : INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
      26       20212 : INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
      27      247433 : INITIALIZE_PASS_END(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE,
      28             :                     "Lazy Machine Block Frequency Analysis", true, true)
      29             : 
      30             : char LazyMachineBlockFrequencyInfoPass::ID = 0;
      31             : 
      32       48791 : LazyMachineBlockFrequencyInfoPass::LazyMachineBlockFrequencyInfoPass()
      33      195164 :     : MachineFunctionPass(ID) {
      34       48791 :   initializeLazyMachineBlockFrequencyInfoPassPass(
      35       48791 :       *PassRegistry::getPassRegistry());
      36       48791 : }
      37             : 
      38           0 : void LazyMachineBlockFrequencyInfoPass::print(raw_ostream &OS,
      39             :                                               const Module *M) const {
      40           0 :   getBFI().print(OS, M);
      41           0 : }
      42             : 
      43       48791 : void LazyMachineBlockFrequencyInfoPass::getAnalysisUsage(
      44             :     AnalysisUsage &AU) const {
      45       48791 :   AU.addRequired<MachineBranchProbabilityInfo>();
      46       48791 :   AU.setPreservesAll();
      47       48791 :   MachineFunctionPass::getAnalysisUsage(AU);
      48       48791 : }
      49             : 
      50      418690 : void LazyMachineBlockFrequencyInfoPass::releaseMemory() {
      51      837380 :   OwnedMBFI.reset();
      52      837380 :   OwnedMLI.reset();
      53      837380 :   OwnedMDT.reset();
      54      418690 : }
      55             : 
      56             : MachineBlockFrequencyInfo &
      57          39 : LazyMachineBlockFrequencyInfoPass::calculateIfNotAvailable() const {
      58          39 :   auto *MBFI = getAnalysisIfAvailable<MachineBlockFrequencyInfo>();
      59          39 :   if (MBFI) {
      60             :     DEBUG(dbgs() << "MachineBlockFrequencyInfo is available\n");
      61             :     return *MBFI;
      62             :   }
      63             : 
      64          13 :   auto &MBPI = getAnalysis<MachineBranchProbabilityInfo>();
      65          13 :   auto *MLI = getAnalysisIfAvailable<MachineLoopInfo>();
      66          13 :   auto *MDT = getAnalysisIfAvailable<MachineDominatorTree>();
      67             :   DEBUG(dbgs() << "Building MachineBlockFrequencyInfo on the fly\n");
      68             :   DEBUG(if (MLI) dbgs() << "LoopInfo is available\n");
      69             : 
      70          13 :   if (!MLI) {
      71             :     DEBUG(dbgs() << "Building LoopInfo on the fly\n");
      72             :     // First create a dominator tree.
      73             :     DEBUG(if (MDT) dbgs() << "DominatorTree is available\n");
      74             : 
      75          13 :     if (!MDT) {
      76             :       DEBUG(dbgs() << "Building DominatorTree on the fly\n");
      77          39 :       OwnedMDT = make_unique<MachineDominatorTree>();
      78          39 :       OwnedMDT->getBase().recalculate(*MF);
      79          26 :       MDT = OwnedMDT.get();
      80             :     }
      81             : 
      82             :     // Generate LoopInfo from it.
      83          39 :     OwnedMLI = make_unique<MachineLoopInfo>();
      84          39 :     OwnedMLI->getBase().analyze(MDT->getBase());
      85          26 :     MLI = OwnedMLI.get();
      86             :   }
      87             : 
      88          39 :   OwnedMBFI = make_unique<MachineBlockFrequencyInfo>();
      89          26 :   OwnedMBFI->calculate(*MF, MBPI, *MLI);
      90          26 :   return *OwnedMBFI.get();
      91             : }
      92             : 
      93      418615 : bool LazyMachineBlockFrequencyInfoPass::runOnMachineFunction(
      94             :     MachineFunction &F) {
      95      418615 :   MF = &F;
      96      418615 :   return false;
      97             : }

Generated by: LCOV version 1.13