Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/LazyMachineBlockFrequencyInfo.cpp
Line
Count
Source (jump to first uncovered line)
1
///===- LazyMachineBlockFrequencyInfo.cpp - Lazy Machine Block Frequency --===//
2
///
3
/// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
/// See https://llvm.org/LICENSE.txt for license information.
5
/// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
///
7
///===---------------------------------------------------------------------===//
8
/// \file
9
/// This is an alternative analysis pass to MachineBlockFrequencyInfo.  The
10
/// difference is that with this pass the block frequencies are not computed
11
/// when the analysis pass is executed but rather when the BFI result is
12
/// explicitly requested by the analysis client.
13
///
14
///===---------------------------------------------------------------------===//
15
16
#include "llvm/CodeGen/LazyMachineBlockFrequencyInfo.h"
17
18
using namespace llvm;
19
20
#define DEBUG_TYPE "lazy-machine-block-freq"
21
22
42.3k
INITIALIZE_PASS_BEGIN(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE,
23
42.3k
                      "Lazy Machine Block Frequency Analysis", true, true)
24
42.3k
INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo)
25
42.3k
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
26
42.3k
INITIALIZE_PASS_END(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE,
27
                    "Lazy Machine Block Frequency Analysis", true, true)
28
29
char LazyMachineBlockFrequencyInfoPass::ID = 0;
30
31
LazyMachineBlockFrequencyInfoPass::LazyMachineBlockFrequencyInfoPass()
32
105k
    : MachineFunctionPass(ID) {
33
105k
  initializeLazyMachineBlockFrequencyInfoPassPass(
34
105k
      *PassRegistry::getPassRegistry());
35
105k
}
36
37
void LazyMachineBlockFrequencyInfoPass::print(raw_ostream &OS,
38
0
                                              const Module *M) const {
39
0
  getBFI().print(OS, M);
40
0
}
41
42
void LazyMachineBlockFrequencyInfoPass::getAnalysisUsage(
43
105k
    AnalysisUsage &AU) const {
44
105k
  AU.addRequired<MachineBranchProbabilityInfo>();
45
105k
  AU.setPreservesAll();
46
105k
  MachineFunctionPass::getAnalysisUsage(AU);
47
105k
}
48
49
1.47M
void LazyMachineBlockFrequencyInfoPass::releaseMemory() {
50
1.47M
  OwnedMBFI.reset();
51
1.47M
  OwnedMLI.reset();
52
1.47M
  OwnedMDT.reset();
53
1.47M
}
54
55
MachineBlockFrequencyInfo &
56
60
LazyMachineBlockFrequencyInfoPass::calculateIfNotAvailable() const {
57
60
  auto *MBFI = getAnalysisIfAvailable<MachineBlockFrequencyInfo>();
58
60
  if (MBFI) {
59
40
    LLVM_DEBUG(dbgs() << "MachineBlockFrequencyInfo is available\n");
60
40
    return *MBFI;
61
40
  }
62
20
63
20
  auto &MBPI = getAnalysis<MachineBranchProbabilityInfo>();
64
20
  auto *MLI = getAnalysisIfAvailable<MachineLoopInfo>();
65
20
  auto *MDT = getAnalysisIfAvailable<MachineDominatorTree>();
66
20
  LLVM_DEBUG(dbgs() << "Building MachineBlockFrequencyInfo on the fly\n");
67
20
  LLVM_DEBUG(if (MLI) dbgs() << "LoopInfo is available\n");
68
20
69
20
  if (!MLI) {
70
20
    LLVM_DEBUG(dbgs() << "Building LoopInfo on the fly\n");
71
20
    // First create a dominator tree.
72
20
    LLVM_DEBUG(if (MDT) dbgs() << "DominatorTree is available\n");
73
20
74
20
    if (!MDT) {
75
20
      LLVM_DEBUG(dbgs() << "Building DominatorTree on the fly\n");
76
20
      OwnedMDT = make_unique<MachineDominatorTree>();
77
20
      OwnedMDT->getBase().recalculate(*MF);
78
20
      MDT = OwnedMDT.get();
79
20
    }
80
20
81
20
    // Generate LoopInfo from it.
82
20
    OwnedMLI = make_unique<MachineLoopInfo>();
83
20
    OwnedMLI->getBase().analyze(MDT->getBase());
84
20
    MLI = OwnedMLI.get();
85
20
  }
86
20
87
20
  OwnedMBFI = make_unique<MachineBlockFrequencyInfo>();
88
20
  OwnedMBFI->calculate(*MF, MBPI, *MLI);
89
20
  return *OwnedMBFI.get();
90
20
}
91
92
bool LazyMachineBlockFrequencyInfoPass::runOnMachineFunction(
93
1.47M
    MachineFunction &F) {
94
1.47M
  MF = &F;
95
1.47M
  return false;
96
1.47M
}