LLVM API Documentation

MachineBlockFrequencyInfo.h
Go to the documentation of this file.
00001 //===- MachineBlockFrequencyInfo.h - MBB 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_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
00015 #define LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
00016 
00017 #include "llvm/CodeGen/MachineFunctionPass.h"
00018 #include "llvm/Support/BlockFrequency.h"
00019 #include <climits>
00020 
00021 namespace llvm {
00022 
00023 class MachineBasicBlock;
00024 class MachineBranchProbabilityInfo;
00025 template <class BlockT> class BlockFrequencyInfoImpl;
00026 
00027 /// MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation
00028 /// to estimate machine basic block frequencies.
00029 class MachineBlockFrequencyInfo : public MachineFunctionPass {
00030   typedef BlockFrequencyInfoImpl<MachineBasicBlock> ImplType;
00031   std::unique_ptr<ImplType> MBFI;
00032 
00033 public:
00034   static char ID;
00035 
00036   MachineBlockFrequencyInfo();
00037 
00038   ~MachineBlockFrequencyInfo();
00039 
00040   void getAnalysisUsage(AnalysisUsage &AU) const override;
00041 
00042   bool runOnMachineFunction(MachineFunction &F) override;
00043 
00044   void releaseMemory() override;
00045 
00046   /// getblockFreq - Return block frequency. Return 0 if we don't have the
00047   /// information. Please note that initial frequency is equal to 1024. It means
00048   /// that we should not rely on the value itself, but only on the comparison to
00049   /// the other block frequencies. We do this to avoid using of floating points.
00050   ///
00051   BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
00052 
00053   const MachineFunction *getFunction() const;
00054   void view() const;
00055 
00056   // Print the block frequency Freq to OS using the current functions entry
00057   // frequency to convert freq into a relative decimal form.
00058   raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
00059 
00060   // Convenience method that attempts to look up the frequency associated with
00061   // BB and print it to OS.
00062   raw_ostream &printBlockFreq(raw_ostream &OS,
00063                               const MachineBasicBlock *MBB) const;
00064 
00065   uint64_t getEntryFreq() const;
00066 
00067 };
00068 
00069 }
00070 
00071 #endif