LLVM 19.0.0git
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
19
20using namespace llvm;
21
22#define DEBUG_TYPE "lazy-machine-block-freq"
23
25 "Lazy Machine Block Frequency Analysis", true, true)
29 "Lazy Machine Block Frequency Analysis", true, true)
30
32
37}
38
40 const Module *M) const {
41 getBFI().print(OS, M);
42}
43
45 AnalysisUsage &AU) const {
47 AU.setPreservesAll();
49}
50
52 OwnedMBFI.reset();
53 OwnedMLI.reset();
54 OwnedMDT.reset();
55}
56
58LazyMachineBlockFrequencyInfoPass::calculateIfNotAvailable() const {
59 auto *MBFI = getAnalysisIfAvailable<MachineBlockFrequencyInfo>();
60 if (MBFI) {
61 LLVM_DEBUG(dbgs() << "MachineBlockFrequencyInfo is available\n");
62 return *MBFI;
63 }
64
65 auto &MBPI = getAnalysis<MachineBranchProbabilityInfo>();
66 auto *MLI = getAnalysisIfAvailable<MachineLoopInfo>();
67 auto *MDTWrapper = getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
68 auto *MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr;
69 LLVM_DEBUG(dbgs() << "Building MachineBlockFrequencyInfo on the fly\n");
70 LLVM_DEBUG(if (MLI) dbgs() << "LoopInfo is available\n");
71
72 if (!MLI) {
73 LLVM_DEBUG(dbgs() << "Building LoopInfo on the fly\n");
74 // First create a dominator tree.
75 LLVM_DEBUG(if (MDT) dbgs() << "DominatorTree is available\n");
76
77 if (!MDT) {
78 LLVM_DEBUG(dbgs() << "Building DominatorTree on the fly\n");
79 OwnedMDT = std::make_unique<MachineDominatorTree>();
80 OwnedMDT->getBase().recalculate(*MF);
81 MDT = OwnedMDT.get();
82 }
83
84 // Generate LoopInfo from it.
85 OwnedMLI = std::make_unique<MachineLoopInfo>();
86 OwnedMLI->getBase().analyze(MDT->getBase());
87 MLI = OwnedMLI.get();
88 }
89
90 OwnedMBFI = std::make_unique<MachineBlockFrequencyInfo>();
91 OwnedMBFI->calculate(*MF, MBPI, *MLI);
92 return *OwnedMBFI;
93}
94
97 MF = &F;
98 return false;
99}
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:371
#define LLVM_DEBUG(X)
Definition: Debug.h:101
Lazy Machine Block Frequency true
Lazy Machine Block Frequency Analysis
===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*–===//
#define F(x, y, z)
Definition: MD5.cpp:55
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:55
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:59
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:52
raw_pwrite_stream & OS
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
This is an alternative analysis pass to MachineBlockFrequencyInfo.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
MachineBlockFrequencyInfo & getBFI()
Compute and return the block frequencies.
void print(raw_ostream &OS, const Module *M) const override
print - Print out the internal state of the pass.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:130
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
void initializeLazyMachineBlockFrequencyInfoPassPass(PassRegistry &)