blockfreq: Implement Pass::releaseMemory()
[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 template<class BlockT, class FunctionT, class BranchProbInfoT>
25 class BlockFrequencyImpl;
26
27 /// BlockFrequencyInfo pass uses BlockFrequencyImpl implementation to estimate
28 /// IR basic block frequencies.
29 class BlockFrequencyInfo : public FunctionPass {
30   typedef BlockFrequencyImpl<BasicBlock, Function, BranchProbabilityInfo>
31   ImplType;
32   std::unique_ptr<ImplType> BFI;
33
34 public:
35   static char ID;
36
37   BlockFrequencyInfo();
38
39   ~BlockFrequencyInfo();
40
41   void getAnalysisUsage(AnalysisUsage &AU) const override;
42
43   bool runOnFunction(Function &F) override;
44   void releaseMemory() override;
45   void print(raw_ostream &O, const Module *M) const override;
46   const Function *getFunction() const;
47   void view() const;
48
49   /// getblockFreq - Return block frequency. Return 0 if we don't have the
50   /// information. Please note that initial frequency is equal to ENTRY_FREQ. It
51   /// means that we should not rely on the value itself, but only on the
52   /// comparison to the other block frequencies. We do this to avoid using of
53   /// floating points.
54   BlockFrequency getBlockFreq(const BasicBlock *BB) const;
55
56   // Print the block frequency Freq to OS using the current functions entry
57   // frequency to convert freq into a relative decimal form.
58   raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
59
60   // Convenience method that attempts to look up the frequency associated with
61   // BB and print it to OS.
62   raw_ostream &printBlockFreq(raw_ostream &OS, const BasicBlock *BB) const;
63
64   uint64_t getEntryFreq() const;
65
66 };
67
68 }
69
70 #endif