[PM/AA] Run clang-format over this code to establish a clean baseline
[oota-llvm.git] / include / llvm / Analysis / BlockFrequencyInfo.h
1 //===- BlockFrequencyInfo.h - Block 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_ANALYSIS_BLOCKFREQUENCYINFO_H
15 #define LLVM_ANALYSIS_BLOCKFREQUENCYINFO_H
16
17 #include "llvm/Pass.h"
18 #include "llvm/Support/BlockFrequency.h"
19 #include <climits>
20
21 namespace llvm {
22
23 class BranchProbabilityInfo;
24 class LoopInfo;
25 template <class BlockT> class BlockFrequencyInfoImpl;
26
27 /// BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to
28 /// estimate IR basic block frequencies.
29 class BlockFrequencyInfo {
30   typedef BlockFrequencyInfoImpl<BasicBlock> ImplType;
31   std::unique_ptr<ImplType> BFI;
32
33 public:
34   BlockFrequencyInfo();
35   BlockFrequencyInfo(const Function &F, const BranchProbabilityInfo &BPI,
36                      const LoopInfo &LI);
37
38   const Function *getFunction() const;
39   void view() const;
40
41   /// getblockFreq - Return block frequency. Return 0 if we don't have the
42   /// information. Please note that initial frequency is equal to ENTRY_FREQ. It
43   /// means that we should not rely on the value itself, but only on the
44   /// comparison to the other block frequencies. We do this to avoid using of
45   /// floating points.
46   BlockFrequency getBlockFreq(const BasicBlock *BB) const;
47
48   /// calculate - compute block frequency info for the given function.
49   void calculate(const Function &F, const BranchProbabilityInfo &BPI,
50                  const LoopInfo &LI);
51
52   // Print the block frequency Freq to OS using the current functions entry
53   // frequency to convert freq into a relative decimal form.
54   raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
55
56   // Convenience method that attempts to look up the frequency associated with
57   // BB and print it to OS.
58   raw_ostream &printBlockFreq(raw_ostream &OS, const BasicBlock *BB) const;
59
60   uint64_t getEntryFreq() const;
61   void releaseMemory();
62   void print(raw_ostream &OS) const;
63 };
64
65 /// \brief Legacy analysis pass which computes \c BlockFrequencyInfo.
66 class BlockFrequencyInfoWrapperPass : public FunctionPass {
67   BlockFrequencyInfo BFI;
68
69 public:
70   static char ID;
71
72   BlockFrequencyInfoWrapperPass();
73   ~BlockFrequencyInfoWrapperPass() override;
74
75   BlockFrequencyInfo &getBFI() { return BFI; }
76   const BlockFrequencyInfo &getBFI() const { return BFI; }
77
78   void getAnalysisUsage(AnalysisUsage &AU) const override;
79
80   bool runOnFunction(Function &F) override;
81   void releaseMemory() override;
82   void print(raw_ostream &OS, const Module *M) const override;
83 };
84
85 }
86
87 #endif