]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/CodeGen/MachineBlockFrequencyInfo.h
MFV r312996:
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / CodeGen / MachineBlockFrequencyInfo.h
1 //===- MachineBlockFrequencyInfo.h - MBB Frequency Analysis -*- C++ -*-----===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Loops should be simplified before this analysis.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
15 #define LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
16
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/Support/BlockFrequency.h"
20 #include <climits>
21
22 namespace llvm {
23
24 class MachineBasicBlock;
25 class MachineBranchProbabilityInfo;
26 template <class BlockT> class BlockFrequencyInfoImpl;
27
28 /// MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation
29 /// to estimate machine basic block frequencies.
30 class MachineBlockFrequencyInfo : public MachineFunctionPass {
31   typedef BlockFrequencyInfoImpl<MachineBasicBlock> ImplType;
32   std::unique_ptr<ImplType> MBFI;
33
34 public:
35   static char ID;
36
37   MachineBlockFrequencyInfo();
38
39   ~MachineBlockFrequencyInfo() override;
40
41   void getAnalysisUsage(AnalysisUsage &AU) const override;
42
43   bool runOnMachineFunction(MachineFunction &F) override;
44
45   void releaseMemory() override;
46
47   /// getblockFreq - Return block frequency. Return 0 if we don't have the
48   /// information. Please note that initial frequency is equal to 1024. It means
49   /// that we should not rely on the value itself, but only on the comparison to
50   /// the other block frequencies. We do this to avoid using of floating points.
51   ///
52   BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
53
54   Optional<uint64_t> getBlockProfileCount(const MachineBasicBlock *MBB) const;
55
56   const MachineFunction *getFunction() const;
57   const MachineBranchProbabilityInfo *getMBPI() const;
58   void view() const;
59
60   // Print the block frequency Freq to OS using the current functions entry
61   // frequency to convert freq into a relative decimal form.
62   raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
63
64   // Convenience method that attempts to look up the frequency associated with
65   // BB and print it to OS.
66   raw_ostream &printBlockFreq(raw_ostream &OS,
67                               const MachineBasicBlock *MBB) const;
68
69   uint64_t getEntryFreq() const;
70
71 };
72
73 }
74
75 #endif