LLVM 19.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 Probability Analysis", false, true)
24 "Machine Branch Probability Analysis", false, true)
25
26namespace llvm {
28 StaticLikelyProb("static-likely-prob",
29 cl::desc("branch probability threshold in percentage"
30 "to be considered very likely"),
31 cl::init(80), cl::Hidden);
32
34 "profile-likely-prob",
35 cl::desc("branch probability threshold in percentage to be considered"
36 " very likely when profile is available"),
37 cl::init(51), cl::Hidden);
38} // namespace llvm
39
41
43 : ImmutablePass(ID) {
46}
47
48void MachineBranchProbabilityInfo::anchor() {}
49
51 const MachineBasicBlock *Src,
53 return Src->getSuccProbability(Dst);
54}
55
57 const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const {
58 // This is a linear search. Try to use the const_succ_iterator version when
59 // possible.
60 return getEdgeProbability(Src, find(Src->successors(), Dst));
61}
62
64 const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const {
66 return getEdgeProbability(Src, Dst) > HotProb;
67}
68
70 raw_ostream &OS, const MachineBasicBlock *Src,
71 const MachineBasicBlock *Dst) const {
72
73 const BranchProbability Prob = getEdgeProbability(Src, Dst);
74 OS << "edge " << printMBBReference(*Src) << " -> " << printMBBReference(*Dst)
75 << " probability is " << Prob
76 << (isEdgeHot(Src, Dst) ? " [HOT edge]\n" : "\n");
77
78 return OS;
79}
basic Basic Alias true
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:371
machine branch Machine Branch Probability Analysis
machine branch prob
#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
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:282
std::vector< MachineBasicBlock * >::const_iterator const_succ_iterator
raw_ostream & printEdgeProbability(raw_ostream &OS, const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
bool isEdgeHot(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
BranchProbability getEdgeProbability(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
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 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:450
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:1751
void initializeMachineBranchProbabilityInfoPass(PassRegistry &)
cl::opt< unsigned > ProfileLikelyProb
cl::opt< unsigned > StaticLikelyProb
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.