LLVM  16.0.0git
MachineBranchProbabilityInfo.h
Go to the documentation of this file.
1 //=- MachineBranchProbabilityInfo.h - Branch Probability Analysis -*- C++ -*-=//
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 pass is used to evaluate branch probabilties on machine basic blocks.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CODEGEN_MACHINEBRANCHPROBABILITYINFO_H
14 #define LLVM_CODEGEN_MACHINEBRANCHPROBABILITYINFO_H
15 
17 #include "llvm/Pass.h"
19 
20 namespace llvm {
21 
23  virtual void anchor();
24 
25  // Default weight value. Used when we don't have information about the edge.
26  // TODO: DEFAULT_WEIGHT makes sense during static predication, when none of
27  // the successors have a weight yet. But it doesn't make sense when providing
28  // weight to an edge that may have siblings with non-zero weights. This can
29  // be handled various ways, but it's probably fine for an edge with unknown
30  // weight to just "inherit" the non-zero weight of an adjacent successor.
31  static const uint32_t DEFAULT_WEIGHT = 16;
32 
33 public:
34  static char ID;
35 
37 
38  void getAnalysisUsage(AnalysisUsage &AU) const override {
39  AU.setPreservesAll();
40  }
41 
42  // Return edge probability.
44  const MachineBasicBlock *Dst) const;
45 
46  // Same as above, but using a const_succ_iterator from Src. This is faster
47  // when the iterator is already available.
51 
52  // A 'Hot' edge is an edge which probability is >= 80%.
53  bool isEdgeHot(const MachineBasicBlock *Src,
54  const MachineBasicBlock *Dst) const;
55 
56  // Print value between 0 (0% probability) and 1 (100% probability),
57  // however the value is never equal to 0, and can be 1 only iff SRC block
58  // has only one successor.
60  const MachineBasicBlock *Src,
61  const MachineBasicBlock *Dst) const;
62 };
63 
64 }
65 
66 
67 #endif
llvm::MachineBranchProbabilityInfo::MachineBranchProbabilityInfo
MachineBranchProbabilityInfo()
Definition: MachineBranchProbabilityInfo.cpp:42
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::ImmutablePass
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:279
Pass.h
llvm::MachineBranchProbabilityInfo::ID
static char ID
Definition: MachineBranchProbabilityInfo.h:34
MachineBasicBlock.h
llvm::MachineBranchProbabilityInfo::printEdgeProbability
raw_ostream & printEdgeProbability(raw_ostream &OS, const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
Definition: MachineBranchProbabilityInfo.cpp:69
llvm::MachineBranchProbabilityInfo
Definition: MachineBranchProbabilityInfo.h:22
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::MachineBranchProbabilityInfo::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: MachineBranchProbabilityInfo.h:38
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
BranchProbability.h
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
llvm::MachineBranchProbabilityInfo::getEdgeProbability
BranchProbability getEdgeProbability(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
Definition: MachineBranchProbabilityInfo.cpp:56
uint32_t
llvm::BranchProbability
Definition: BranchProbability.h:30
llvm::AnalysisUsage::setPreservesAll
void setPreservesAll()
Set by analyses that do not transform their input at all.
Definition: PassAnalysisSupport.h:130
llvm::MachineBasicBlock::const_succ_iterator
std::vector< MachineBasicBlock * >::const_iterator const_succ_iterator
Definition: MachineBasicBlock.h:344
llvm::MachineBranchProbabilityInfo::isEdgeHot
bool isEdgeHot(const MachineBasicBlock *Src, const MachineBasicBlock *Dst) const
Definition: MachineBranchProbabilityInfo.cpp:63