blockfreq: Rename BlockFrequencyImpl to BlockFrequencyInfoImpl
[oota-llvm.git] / 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/CodeGen/MachineFunctionPass.h"
18 #include "llvm/Support/BlockFrequency.h"
19 #include <climits>
20
21 namespace llvm {
22
23 class MachineBasicBlock;
24 class MachineBranchProbabilityInfo;
25 template <class BlockT, class FunctionT, class BranchProbInfoT>
26 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, MachineFunction,
32                                  MachineBranchProbabilityInfo> ImplType;
33   std::unique_ptr<ImplType> MBFI;
34
35 public:
36   static char ID;
37
38   MachineBlockFrequencyInfo();
39
40   ~MachineBlockFrequencyInfo();
41
42   void getAnalysisUsage(AnalysisUsage &AU) const override;
43
44   bool runOnMachineFunction(MachineFunction &F) override;
45
46   void releaseMemory() override;
47
48   /// getblockFreq - Return block frequency. Return 0 if we don't have the
49   /// information. Please note that initial frequency is equal to 1024. It means
50   /// that we should not rely on the value itself, but only on the comparison to
51   /// the other block frequencies. We do this to avoid using of floating points.
52   ///
53   BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
54
55   const MachineFunction *getFunction() const;
56   void view() const;
57
58   // Print the block frequency Freq to OS using the current functions entry
59   // frequency to convert freq into a relative decimal form.
60   raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
61
62   // Convenience method that attempts to look up the frequency associated with
63   // BB and print it to OS.
64   raw_ostream &printBlockFreq(raw_ostream &OS,
65                               const MachineBasicBlock *MBB) const;
66
67   uint64_t getEntryFreq() const;
68
69 };
70
71 }
72
73 #endif