/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/CodeGen/LazyMachineBlockFrequencyInfo.cpp
Line | Count | Source (jump to first uncovered line) |
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 | 36.7k | INITIALIZE_PASS_BEGIN36.7k (LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE,
|
24 | 36.7k | "Lazy Machine Block Frequency Analysis", true, true) |
25 | 36.7k | INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo) |
26 | 36.7k | INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo) |
27 | 36.7k | INITIALIZE_PASS_END(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE, |
28 | | "Lazy Machine Block Frequency Analysis", true, true) |
29 | | |
30 | | char LazyMachineBlockFrequencyInfoPass::ID = 0; |
31 | | |
32 | | LazyMachineBlockFrequencyInfoPass::LazyMachineBlockFrequencyInfoPass() |
33 | 98.4k | : MachineFunctionPass(ID) { |
34 | 98.4k | initializeLazyMachineBlockFrequencyInfoPassPass( |
35 | 98.4k | *PassRegistry::getPassRegistry()); |
36 | 98.4k | } |
37 | | |
38 | | void LazyMachineBlockFrequencyInfoPass::print(raw_ostream &OS, |
39 | 0 | const Module *M) const { |
40 | 0 | getBFI().print(OS, M); |
41 | 0 | } |
42 | | |
43 | | void LazyMachineBlockFrequencyInfoPass::getAnalysisUsage( |
44 | 98.4k | AnalysisUsage &AU) const { |
45 | 98.4k | AU.addRequired<MachineBranchProbabilityInfo>(); |
46 | 98.4k | AU.setPreservesAll(); |
47 | 98.4k | MachineFunctionPass::getAnalysisUsage(AU); |
48 | 98.4k | } |
49 | | |
50 | 1.77M | void LazyMachineBlockFrequencyInfoPass::releaseMemory() { |
51 | 1.77M | OwnedMBFI.reset(); |
52 | 1.77M | OwnedMLI.reset(); |
53 | 1.77M | OwnedMDT.reset(); |
54 | 1.77M | } |
55 | | |
56 | | MachineBlockFrequencyInfo & |
57 | 39 | LazyMachineBlockFrequencyInfoPass::calculateIfNotAvailable() const { |
58 | 39 | auto *MBFI = getAnalysisIfAvailable<MachineBlockFrequencyInfo>(); |
59 | 39 | if (MBFI39 ) { |
60 | 26 | DEBUG(dbgs() << "MachineBlockFrequencyInfo is available\n"); |
61 | 26 | return *MBFI; |
62 | 26 | } |
63 | 13 | |
64 | 13 | auto &MBPI = getAnalysis<MachineBranchProbabilityInfo>(); |
65 | 13 | auto *MLI = getAnalysisIfAvailable<MachineLoopInfo>(); |
66 | 13 | auto *MDT = getAnalysisIfAvailable<MachineDominatorTree>(); |
67 | 13 | DEBUG(dbgs() << "Building MachineBlockFrequencyInfo on the fly\n"); |
68 | 13 | DEBUG(if (MLI) dbgs() << "LoopInfo is available\n"); |
69 | 13 | |
70 | 13 | if (!MLI13 ) { |
71 | 13 | DEBUG(dbgs() << "Building LoopInfo on the fly\n"); |
72 | 13 | // First create a dominator tree. |
73 | 13 | DEBUG(if (MDT) dbgs() << "DominatorTree is available\n"); |
74 | 13 | |
75 | 13 | if (!MDT13 ) { |
76 | 13 | DEBUG(dbgs() << "Building DominatorTree on the fly\n"); |
77 | 13 | OwnedMDT = make_unique<MachineDominatorTree>(); |
78 | 13 | OwnedMDT->getBase().recalculate(*MF); |
79 | 13 | MDT = OwnedMDT.get(); |
80 | 13 | } |
81 | 13 | |
82 | 13 | // Generate LoopInfo from it. |
83 | 13 | OwnedMLI = make_unique<MachineLoopInfo>(); |
84 | 13 | OwnedMLI->getBase().analyze(MDT->getBase()); |
85 | 13 | MLI = OwnedMLI.get(); |
86 | 13 | } |
87 | 39 | |
88 | 39 | OwnedMBFI = make_unique<MachineBlockFrequencyInfo>(); |
89 | 39 | OwnedMBFI->calculate(*MF, MBPI, *MLI); |
90 | 39 | return *OwnedMBFI.get(); |
91 | 39 | } |
92 | | |
93 | | bool LazyMachineBlockFrequencyInfoPass::runOnMachineFunction( |
94 | 1.77M | MachineFunction &F) { |
95 | 1.77M | MF = &F; |
96 | 1.77M | return false; |
97 | 1.77M | } |