LLVM  14.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 
17 #include "llvm/InitializePasses.h"
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 
31 
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  LLVM_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  LLVM_DEBUG(dbgs() << "Building MachineBlockFrequencyInfo on the fly\n");
68  LLVM_DEBUG(if (MLI) dbgs() << "LoopInfo is available\n");
69 
70  if (!MLI) {
71  LLVM_DEBUG(dbgs() << "Building LoopInfo on the fly\n");
72  // First create a dominator tree.
73  LLVM_DEBUG(if (MDT) dbgs() << "DominatorTree is available\n");
74 
75  if (!MDT) {
76  LLVM_DEBUG(dbgs() << "Building DominatorTree on the fly\n");
77  OwnedMDT = std::make_unique<MachineDominatorTree>();
78  OwnedMDT->getBase().recalculate(*MF);
79  MDT = OwnedMDT.get();
80  }
81 
82  // Generate LoopInfo from it.
83  OwnedMLI = std::make_unique<MachineLoopInfo>();
84  OwnedMLI->getBase().analyze(MDT->getBase());
85  MLI = OwnedMLI.get();
86  }
87 
88  OwnedMBFI = std::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 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::LazyMachineBlockFrequencyInfoPass::releaseMemory
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Definition: LazyMachineBlockFrequencyInfo.cpp:50
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::LazyMachineBlockFrequencyInfoPass::getBFI
MachineBlockFrequencyInfo & getBFI()
Compute and return the block frequencies.
Definition: LazyMachineBlockFrequencyInfo.h:61
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:102
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::MachineLoopInfo
Definition: MachineLoopInfo.h:90
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::MachineBlockFrequencyInfo
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
Definition: MachineBlockFrequencyInfo.h:33
llvm::MachineBranchProbabilityInfo
Definition: MachineBranchProbabilityInfo.h:24
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::Pass::print
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:125
LazyMachineBlockFrequencyInfo.h
===- LazyMachineBlockFrequencyInfo.h - Lazy Block Frequency -*- C++ -*–===//
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(LazyMachineBlockFrequencyInfoPass, DEBUG_TYPE, "Lazy Machine Block Frequency Analysis", true, true) INITIALIZE_PASS_END(LazyMachineBlockFrequencyInfoPass
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
llvm::LazyMachineBlockFrequencyInfoPass::print
void print(raw_ostream &OS, const Module *M) const override
print - Print out the internal state of the pass.
Definition: LazyMachineBlockFrequencyInfo.cpp:38
llvm::initializeLazyMachineBlockFrequencyInfoPassPass
void initializeLazyMachineBlockFrequencyInfoPassPass(PassRegistry &)
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::LazyMachineBlockFrequencyInfoPass
This is an alternative analysis pass to MachineBlockFrequencyInfo.
Definition: LazyMachineBlockFrequencyInfo.h:37
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
llvm::LazyMachineBlockFrequencyInfoPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: LazyMachineBlockFrequencyInfo.cpp:43
DEBUG_TYPE
#define DEBUG_TYPE
Definition: LazyMachineBlockFrequencyInfo.cpp:21
Machine
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:366
true
Lazy Machine Block Frequency true
Definition: LazyMachineBlockFrequencyInfo.cpp:28
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
InitializePasses.h
llvm::LazyMachineBlockFrequencyInfoPass::runOnMachineFunction
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: LazyMachineBlockFrequencyInfo.cpp:93
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38