LLVM  6.0.0svn
LazyMachineBlockFrequencyInfo.cpp
Go to the documentation of this file.
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 
18 
19 using namespace llvm;
20 
21 #define DEBUG_TYPE "lazy-machine-block-freq"
22 
24  "Lazy Machine Block Frequency Analysis", true, true)
28  "Lazy Machine Block Frequency Analysis", true, true)
29 
30 char LazyMachineBlockFrequencyInfoPass::ID = 0;
31 
32 LazyMachineBlockFrequencyInfoPass::LazyMachineBlockFrequencyInfoPass()
33  : MachineFunctionPass(ID) {
36 }
37 
39  const Module *M) const {
40  getBFI().print(OS, M);
41 }
42 
44  AnalysisUsage &AU) const {
46  AU.setPreservesAll();
48 }
49 
51  OwnedMBFI.reset();
52  OwnedMLI.reset();
53  OwnedMDT.reset();
54 }
55 
57 LazyMachineBlockFrequencyInfoPass::calculateIfNotAvailable() const {
58  auto *MBFI = getAnalysisIfAvailable<MachineBlockFrequencyInfo>();
59  if (MBFI) {
60  DEBUG(dbgs() << "MachineBlockFrequencyInfo is available\n");
61  return *MBFI;
62  }
63 
64  auto &MBPI = getAnalysis<MachineBranchProbabilityInfo>();
65  auto *MLI = getAnalysisIfAvailable<MachineLoopInfo>();
66  auto *MDT = getAnalysisIfAvailable<MachineDominatorTree>();
67  DEBUG(dbgs() << "Building MachineBlockFrequencyInfo on the fly\n");
68  DEBUG(if (MLI) dbgs() << "LoopInfo is available\n");
69 
70  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  if (!MDT) {
76  DEBUG(dbgs() << "Building DominatorTree on the fly\n");
77  OwnedMDT = make_unique<MachineDominatorTree>();
78  OwnedMDT->getBase().recalculate(*MF);
79  MDT = OwnedMDT.get();
80  }
81 
82  // Generate LoopInfo from it.
83  OwnedMLI = make_unique<MachineLoopInfo>();
84  OwnedMLI->getBase().analyze(MDT->getBase());
85  MLI = OwnedMLI.get();
86  }
87 
88  OwnedMBFI = make_unique<MachineBlockFrequencyInfo>();
89  OwnedMBFI->calculate(*MF, MBPI, *MLI);
90  return *OwnedMBFI.get();
91 }
92 
94  MachineFunction &F) {
95  MF = &F;
96  return false;
97 }
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
F(f)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
void print(raw_ostream &OS, const Module *M) const override
print - Print out the internal state of the pass.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
MachineBlockFrequencyInfo & getBFI()
Compute and return the block frequencies.
===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*–===//
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:363
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
This is an alternative analysis pass to MachineBlockFrequencyInfo.
Represent the analysis usage information of a pass.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
INITIALIZE_PASS_BEGIN(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE, "Lazy Machine Block Frequency Analysis", true, true) INITIALIZE_PASS_END(LazyMachineBlockFrequencyInfoPass
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
void setPreservesAll()
Set by analyses that do not transform their input at all.
Lazy Machine Block Frequency Analysis
Lazy Machine Block Frequency true
void initializeLazyMachineBlockFrequencyInfoPassPass(PassRegistry &)
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:123
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
#define DEBUG(X)
Definition: Debug.h:118