LLVM API Documentation

BlockFrequencyInfo.h
Go to the documentation of this file.
00001 //===- BlockFrequencyInfo.h - Block Frequency Analysis ----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // Loops should be simplified before this analysis.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_ANALYSIS_BLOCKFREQUENCYINFO_H
00015 #define LLVM_ANALYSIS_BLOCKFREQUENCYINFO_H
00016 
00017 #include "llvm/Pass.h"
00018 #include "llvm/Support/BlockFrequency.h"
00019 #include <climits>
00020 
00021 namespace llvm {
00022 
00023 class BranchProbabilityInfo;
00024 template <class BlockT> class BlockFrequencyInfoImpl;
00025 
00026 /// BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to
00027 /// estimate IR basic block frequencies.
00028 class BlockFrequencyInfo : public FunctionPass {
00029   typedef BlockFrequencyInfoImpl<BasicBlock> ImplType;
00030   std::unique_ptr<ImplType> BFI;
00031 
00032 public:
00033   static char ID;
00034 
00035   BlockFrequencyInfo();
00036 
00037   ~BlockFrequencyInfo();
00038 
00039   void getAnalysisUsage(AnalysisUsage &AU) const override;
00040 
00041   bool runOnFunction(Function &F) override;
00042   void releaseMemory() override;
00043   void print(raw_ostream &O, const Module *M) const override;
00044   const Function *getFunction() const;
00045   void view() const;
00046 
00047   /// getblockFreq - Return block frequency. Return 0 if we don't have the
00048   /// information. Please note that initial frequency is equal to ENTRY_FREQ. It
00049   /// means that we should not rely on the value itself, but only on the
00050   /// comparison to the other block frequencies. We do this to avoid using of
00051   /// floating points.
00052   BlockFrequency getBlockFreq(const BasicBlock *BB) const;
00053 
00054   // Print the block frequency Freq to OS using the current functions entry
00055   // frequency to convert freq into a relative decimal form.
00056   raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
00057 
00058   // Convenience method that attempts to look up the frequency associated with
00059   // BB and print it to OS.
00060   raw_ostream &printBlockFreq(raw_ostream &OS, const BasicBlock *BB) const;
00061 
00062   uint64_t getEntryFreq() const;
00063 
00064 };
00065 
00066 }
00067 
00068 #endif