1 //====-- MachineBlockFrequencyInfo.h - MBB 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_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
15 #define LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
17 #include "llvm/CodeGen/MachineFunctionPass.h"
18 #include "llvm/Support/BlockFrequency.h"
23 class MachineBasicBlock;
24 class MachineBranchProbabilityInfo;
25 template<class BlockT, class FunctionT, class BranchProbInfoT>
26 class BlockFrequencyImpl;
28 /// MachineBlockFrequencyInfo pass uses BlockFrequencyImpl implementation to estimate
29 /// machine basic block frequencies.
30 class MachineBlockFrequencyInfo : public MachineFunctionPass {
32 BlockFrequencyImpl<MachineBasicBlock, MachineFunction,
33 MachineBranchProbabilityInfo> *MBFI;
38 MachineBlockFrequencyInfo();
40 ~MachineBlockFrequencyInfo();
42 void getAnalysisUsage(AnalysisUsage &AU) const override;
44 bool runOnMachineFunction(MachineFunction &F) override;
46 /// getblockFreq - Return block frequency. Return 0 if we don't have the
47 /// information. Please note that initial frequency is equal to 1024. It means
48 /// that we should not rely on the value itself, but only on the comparison to
49 /// the other block frequencies. We do this to avoid using of floating points.
51 BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
53 MachineFunction *getFunction() const;
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;
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,
63 const MachineBasicBlock *MBB) const;
65 uint64_t getEntryFreq() const;