1 //===- BlockFrequencyInfo.h - Block Frequency Analysis ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Loops should be simplified before this analysis.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_BLOCKFREQUENCYINFO_H
15 #define LLVM_ANALYSIS_BLOCKFREQUENCYINFO_H
17 #include "llvm/Pass.h"
18 #include "llvm/Support/BlockFrequency.h"
23 class BranchProbabilityInfo;
25 template <class BlockT> class BlockFrequencyInfoImpl;
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;
34 const Function *getFunction() const;
37 /// getblockFreq - Return block frequency. Return 0 if we don't have the
38 /// information. Please note that initial frequency is equal to ENTRY_FREQ. It
39 /// means that we should not rely on the value itself, but only on the
40 /// comparison to the other block frequencies. We do this to avoid using of
42 BlockFrequency getBlockFreq(const BasicBlock *BB) const;
44 /// calculate - compute block frequency info for the given function.
45 void calculate(const Function &F, const BranchProbabilityInfo &BPI,
48 // Print the block frequency Freq to OS using the current functions entry
49 // frequency to convert freq into a relative decimal form.
50 raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
52 // Convenience method that attempts to look up the frequency associated with
53 // BB and print it to OS.
54 raw_ostream &printBlockFreq(raw_ostream &OS, const BasicBlock *BB) const;
56 uint64_t getEntryFreq() const;
58 void print(raw_ostream &OS) const;
61 /// \brief Legacy analysis pass which computes \c BlockFrequencyInfo.
62 class BlockFrequencyInfoWrapperPass : public FunctionPass {
63 BlockFrequencyInfo BFI;
68 BlockFrequencyInfoWrapperPass();
69 ~BlockFrequencyInfoWrapperPass() override;
71 BlockFrequencyInfo &getBFI() { return BFI; }
72 const BlockFrequencyInfo &getBFI() const { return BFI; }
74 void getAnalysisUsage(AnalysisUsage &AU) const override;
76 bool runOnFunction(Function &F) override;
77 void releaseMemory() override;
78 void print(raw_ostream &OS, const Module *M) const override;