LLVM 20.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
18#include "llvm/Pass.h"
20
21namespace llvm {
22
24 // Default weight value. Used when we don't have information about the edge.
25 // TODO: DEFAULT_WEIGHT makes sense during static predication, when none of
26 // the successors have a weight yet. But it doesn't make sense when providing
27 // weight to an edge that may have siblings with non-zero weights. This can
28 // be handled various ways, but it's probably fine for an edge with unknown
29 // weight to just "inherit" the non-zero weight of an adjacent successor.
30 static const uint32_t DEFAULT_WEIGHT = 16;
31
32public:
35
36 // Return edge probability.
38 const MachineBasicBlock *Dst) const;
39
40 // Same as above, but using a const_succ_iterator from Src. This is faster
41 // when the iterator is already available.
45
46 // A 'Hot' edge is an edge which probability is >= 80%.
47 bool isEdgeHot(const MachineBasicBlock *Src,
48 const MachineBasicBlock *Dst) const;
49
50 // Print value between 0 (0% probability) and 1 (100% probability),
51 // however the value is never equal to 0, and can be 1 only iff SRC block
52 // has only one successor.
54 const MachineBasicBlock *Src,
55 const MachineBasicBlock *Dst) const;
56};
57
59 : public AnalysisInfoMixin<MachineBranchProbabilityAnalysis> {
61
62 static AnalysisKey Key;
63
64public:
66
68};
69
71 : public PassInfoMixin<MachineBranchProbabilityPrinterPass> {
72 raw_ostream &OS;
73
74public:
78};
79
81 virtual void anchor();
82
84
85public:
86 static char ID;
87
89
90 void getAnalysisUsage(AnalysisUsage &AU) const override {
91 AU.setPreservesAll();
92 }
93
95 const MachineBranchProbabilityInfo &getMBPI() const { return MBPI; }
96};
97}
98
99
100#endif
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
Represent the analysis usage information of a pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
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
Result run(MachineFunction &, MachineFunctionAnalysisManager &)
const MachineBranchProbabilityInfo & getMBPI() const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
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)
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
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
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69