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;
24 template <class BlockT> class BlockFrequencyInfoImpl;
26 /// BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to
27 /// estimate IR basic block frequencies.
28 class BlockFrequencyInfo : public FunctionPass {
29 typedef BlockFrequencyInfoImpl<BasicBlock> ImplType;
30 std::unique_ptr<ImplType> BFI;
37 ~BlockFrequencyInfo();
39 void getAnalysisUsage(AnalysisUsage &AU) const override;
41 bool runOnFunction(Function &F) override;
42 void releaseMemory() override;
43 void print(raw_ostream &O, const Module *M) const override;
44 const Function *getFunction() const;
47 /// getblockFreq - Return block frequency. Return 0 if we don't have the
48 /// information. Please note that initial frequency is equal to ENTRY_FREQ. It
49 /// means that we should not rely on the value itself, but only on the
50 /// comparison to the other block frequencies. We do this to avoid using of
52 BlockFrequency getBlockFreq(const BasicBlock *BB) const;
54 // Print the block frequency Freq to OS using the current functions entry
55 // frequency to convert freq into a relative decimal form.
56 raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
58 // Convenience method that attempts to look up the frequency associated with
59 // BB and print it to OS.
60 raw_ostream &printBlockFreq(raw_ostream &OS, const BasicBlock *BB) const;
62 uint64_t getEntryFreq() const;