LCOV - code coverage report
Current view: top level - lib/CodeGen - LazyMachineBlockFrequencyInfo.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 29 32 90.6 %
Date: 2018-10-20 13:21:21 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       31780 : INITIALIZE_PASS_BEGIN(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE,
      24             :                       "Lazy Machine Block Frequency Analysis", true, true)
      25       31780 : INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
      26       31780 : INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
      27      137339 : INITIALIZE_PASS_END(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE,
      28             :                     "Lazy Machine Block Frequency Analysis", true, true)
      29             : 
      30             : char LazyMachineBlockFrequencyInfoPass::ID = 0;
      31             : 
      32       73779 : LazyMachineBlockFrequencyInfoPass::LazyMachineBlockFrequencyInfoPass()
      33       73779 :     : MachineFunctionPass(ID) {
      34       73779 :   initializeLazyMachineBlockFrequencyInfoPassPass(
      35       73779 :       *PassRegistry::getPassRegistry());
      36       73779 : }
      37             : 
      38           0 : void LazyMachineBlockFrequencyInfoPass::print(raw_ostream &OS,
      39             :                                               const Module *M) const {
      40           0 :   getBFI().print(OS, M);
      41           0 : }
      42             : 
      43       73779 : void LazyMachineBlockFrequencyInfoPass::getAnalysisUsage(
      44             :     AnalysisUsage &AU) const {
      45             :   AU.addRequired<MachineBranchProbabilityInfo>();
      46             :   AU.setPreservesAll();
      47       73779 :   MachineFunctionPass::getAnalysisUsage(AU);
      48       73779 : }
      49             : 
      50     1004220 : void LazyMachineBlockFrequencyInfoPass::releaseMemory() {
      51             :   OwnedMBFI.reset();
      52             :   OwnedMLI.reset();
      53             :   OwnedMDT.reset();
      54     1004220 : }
      55             : 
      56             : MachineBlockFrequencyInfo &
      57          66 : LazyMachineBlockFrequencyInfoPass::calculateIfNotAvailable() const {
      58          66 :   auto *MBFI = getAnalysisIfAvailable<MachineBlockFrequencyInfo>();
      59          66 :   if (MBFI) {
      60             :     LLVM_DEBUG(dbgs() << "MachineBlockFrequencyInfo is available\n");
      61             :     return *MBFI;
      62             :   }
      63             : 
      64          22 :   auto &MBPI = getAnalysis<MachineBranchProbabilityInfo>();
      65          22 :   auto *MLI = getAnalysisIfAvailable<MachineLoopInfo>();
      66          22 :   auto *MDT = getAnalysisIfAvailable<MachineDominatorTree>();
      67             :   LLVM_DEBUG(dbgs() << "Building MachineBlockFrequencyInfo on the fly\n");
      68             :   LLVM_DEBUG(if (MLI) dbgs() << "LoopInfo is available\n");
      69             : 
      70          22 :   if (!MLI) {
      71             :     LLVM_DEBUG(dbgs() << "Building LoopInfo on the fly\n");
      72             :     // First create a dominator tree.
      73             :     LLVM_DEBUG(if (MDT) dbgs() << "DominatorTree is available\n");
      74             : 
      75          22 :     if (!MDT) {
      76             :       LLVM_DEBUG(dbgs() << "Building DominatorTree on the fly\n");
      77             :       OwnedMDT = make_unique<MachineDominatorTree>();
      78          22 :       OwnedMDT->getBase().recalculate(*MF);
      79             :       MDT = OwnedMDT.get();
      80             :     }
      81             : 
      82             :     // Generate LoopInfo from it.
      83             :     OwnedMLI = make_unique<MachineLoopInfo>();
      84          22 :     OwnedMLI->getBase().analyze(MDT->getBase());
      85             :     MLI = OwnedMLI.get();
      86             :   }
      87             : 
      88             :   OwnedMBFI = make_unique<MachineBlockFrequencyInfo>();
      89          22 :   OwnedMBFI->calculate(*MF, MBPI, *MLI);
      90          22 :   return *OwnedMBFI.get();
      91             : }
      92             : 
      93     1004159 : bool LazyMachineBlockFrequencyInfoPass::runOnMachineFunction(
      94             :     MachineFunction &F) {
      95     1004159 :   MF = &F;
      96     1004159 :   return false;
      97             : }

Generated by: LCOV version 1.13