]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/CodeGen/MachineBranchProbabilityInfo.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / CodeGen / MachineBranchProbabilityInfo.h
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
16 #include "llvm/CodeGen/MachineBasicBlock.h"
17 #include "llvm/Pass.h"
18 #include "llvm/Support/BranchProbability.h"
19 #include <climits>
20 #include <numeric>
21
22 namespace llvm {
23
24 class MachineBranchProbabilityInfo : public ImmutablePass {
25   virtual void anchor();
26
27   // Default weight value. Used when we don't have information about the edge.
28   // TODO: DEFAULT_WEIGHT makes sense during static predication, when none of
29   // the successors have a weight yet. But it doesn't make sense when providing
30   // weight to an edge that may have siblings with non-zero weights. This can
31   // be handled various ways, but it's probably fine for an edge with unknown
32   // weight to just "inherit" the non-zero weight of an adjacent successor.
33   static const uint32_t DEFAULT_WEIGHT = 16;
34
35 public:
36   static char ID;
37
38   MachineBranchProbabilityInfo() : ImmutablePass(ID) {
39     PassRegistry &Registry = *PassRegistry::getPassRegistry();
40     initializeMachineBranchProbabilityInfoPass(Registry);
41   }
42
43   void getAnalysisUsage(AnalysisUsage &AU) const override {
44     AU.setPreservesAll();
45   }
46
47   // Return edge probability.
48   BranchProbability getEdgeProbability(const MachineBasicBlock *Src,
49                                        const MachineBasicBlock *Dst) const;
50
51   // Same as above, but using a const_succ_iterator from Src. This is faster
52   // when the iterator is already available.
53   BranchProbability
54   getEdgeProbability(const MachineBasicBlock *Src,
55                      MachineBasicBlock::const_succ_iterator Dst) const;
56
57   // A 'Hot' edge is an edge which probability is >= 80%.
58   bool isEdgeHot(const MachineBasicBlock *Src,
59                  const MachineBasicBlock *Dst) const;
60
61   // Return a hot successor for the block BB or null if there isn't one.
62   // NB: This routine's complexity is linear on the number of successors.
63   MachineBasicBlock *getHotSucc(MachineBasicBlock *MBB) const;
64
65   // Print value between 0 (0% probability) and 1 (100% probability),
66   // however the value is never equal to 0, and can be 1 only iff SRC block
67   // has only one successor.
68   raw_ostream &printEdgeProbability(raw_ostream &OS,
69                                     const MachineBasicBlock *Src,
70                                     const MachineBasicBlock *Dst) const;
71 };
72
73 }
74
75
76 #endif