LLVM  10.0.0svn
LazyMachineBlockFrequencyInfo.cpp
Go to the documentation of this file.
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 
17 
18 using namespace llvm;
19 
20 #define DEBUG_TYPE "lazy-machine-block-freq"
21 
23  "Lazy Machine Block Frequency Analysis", true, true)
27  "Lazy Machine Block Frequency Analysis", true, true)
28 
29 char LazyMachineBlockFrequencyInfoPass::ID = 0;
30 
31 LazyMachineBlockFrequencyInfoPass::LazyMachineBlockFrequencyInfoPass()
32  : MachineFunctionPass(ID) {
35 }
36 
38  const Module *M) const {
39  getBFI().print(OS, M);
40 }
41 
43  AnalysisUsage &AU) const {
45  AU.setPreservesAll();
47 }
48 
50  OwnedMBFI.reset();
51  OwnedMLI.reset();
52  OwnedMDT.reset();
53 }
54 
56 LazyMachineBlockFrequencyInfoPass::calculateIfNotAvailable() const {
57  auto *MBFI = getAnalysisIfAvailable<MachineBlockFrequencyInfo>();
58  if (MBFI) {
59  LLVM_DEBUG(dbgs() << "MachineBlockFrequencyInfo is available\n");
60  return *MBFI;
61  }
62 
63  auto &MBPI = getAnalysis<MachineBranchProbabilityInfo>();
64  auto *MLI = getAnalysisIfAvailable<MachineLoopInfo>();
65  auto *MDT = getAnalysisIfAvailable<MachineDominatorTree>();
66  LLVM_DEBUG(dbgs() << "Building MachineBlockFrequencyInfo on the fly\n");
67  LLVM_DEBUG(if (MLI) dbgs() << "LoopInfo is available\n");
68 
69  if (!MLI) {
70  LLVM_DEBUG(dbgs() << "Building LoopInfo on the fly\n");
71  // First create a dominator tree.
72  LLVM_DEBUG(if (MDT) dbgs() << "DominatorTree is available\n");
73 
74  if (!MDT) {
75  LLVM_DEBUG(dbgs() << "Building DominatorTree on the fly\n");
76  OwnedMDT = std::make_unique<MachineDominatorTree>();
77  OwnedMDT->getBase().recalculate(*MF);
78  MDT = OwnedMDT.get();
79  }
80 
81  // Generate LoopInfo from it.
82  OwnedMLI = std::make_unique<MachineLoopInfo>();
83  OwnedMLI->getBase().analyze(MDT->getBase());
84  MLI = OwnedMLI.get();
85  }
86 
87  OwnedMBFI = std::make_unique<MachineBlockFrequencyInfo>();
88  OwnedMBFI->calculate(*MF, MBPI, *MLI);
89  return *OwnedMBFI.get();
90 }
91 
93  MachineFunction &F) {
94  MF = &F;
95  return false;
96 }
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
F(f)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:50
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:365
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 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:128
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
#define LLVM_DEBUG(X)
Definition: Debug.h:122