LLVM 20.0.0git
MachineBranchProbabilityInfo.cpp
Go to the documentation of this file.
1//===- MachineBranchProbabilityInfo.cpp - Machine Branch Probability Info -===//
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//
9// This analysis uses probability info stored in Machine Basic Blocks.
10//
11//===----------------------------------------------------------------------===//
12
18
19using namespace llvm;
20
22 "machine-branch-prob",
23 "Machine Branch Probability Analysis", false, true)
25 "machine-branch-prob",
26 "Machine Branch Probability Analysis", false, true)
27
28namespace llvm {
30 StaticLikelyProb("static-likely-prob",
31 cl::desc("branch probability threshold in percentage"
32 "to be considered very likely"),
33 cl::init(80), cl::Hidden);
34
36 "profile-likely-prob",
37 cl::desc("branch probability threshold in percentage to be considered"
38 " very likely when profile is available"),
39 cl::init(51), cl::Hidden);
40} // namespace llvm
41
46}
47
51 OS << "Printing analysis 'Machine Branch Probability Analysis' for machine "
52 "function '"
53 << MF.getName() << "':\n";
54 auto &MBPI = MFAM.getResult<MachineBranchProbabilityAnalysis>(MF);
55 for (const MachineBasicBlock &MBB : MF) {
56 for (const MachineBasicBlock *Succ : MBB.successors())
57 MBPI.printEdgeProbability(OS << " ", &MBB, Succ);
58 }
60}
61
63
66 : ImmutablePass(ID) {
69}
70
71void MachineBranchProbabilityInfoWrapperPass::anchor() {}
72
73AnalysisKey MachineBranchProbabilityAnalysis::Key;
74
79 return !PAC.preservedWhenStateless();
80}
81
83 const MachineBasicBlock *Src,
85 return Src->getSuccProbability(Dst);
86}
87
89 const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const {
90 // This is a linear search. Try to use the const_succ_iterator version when
91 // possible.
92 return getEdgeProbability(Src, find(Src->successors(), Dst));
93}
94
96 const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const {
98 return getEdgeProbability(Src, Dst) > HotProb;
99}
100
102 raw_ostream &OS, const MachineBasicBlock *Src,
103 const MachineBasicBlock *Dst) const {
104
105 const BranchProbability Prob = getEdgeProbability(Src, Dst);
106 OS << "edge " << printMBBReference(*Src) << " -> " << printMBBReference(*Dst)
107 << " probability is " << Prob
108 << (isEdgeHot(Src, Dst) ? " [HOT edge]\n" : "\n");
109
110 return OS;
111}
MachineBasicBlock & MBB
basic Basic Alias true
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:390
machine branch Machine Branch Probability Analysis
machine branch prob
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:57
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:52
raw_pwrite_stream & OS
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:292
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:410
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:281
SmallVectorImpl< MachineBasicBlock * >::const_iterator const_succ_iterator
iterator_range< succ_iterator > successors()
Result run(MachineFunction &, MachineFunctionAnalysisManager &)
raw_ostream & printEdgeProbability(raw_ostream &OS, const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
bool invalidate(MachineFunction &, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &)
bool isEdgeHot(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
BranchProbability getEdgeProbability(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:37
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition: Analysis.h:264
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition: Registry.h:44
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1759
cl::opt< unsigned > ProfileLikelyProb
cl::opt< unsigned > StaticLikelyProb
void initializeMachineBranchProbabilityInfoWrapperPassPass(PassRegistry &)
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28