MachineBlockFrequencyInfo.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //===- MachineBlockFrequencyInfo.h - MBB Frequency Analysis -*- C++ -*-----===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // Loops should be simplified before this analysis.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
  14. #define LLVM_CODEGEN_MACHINEBLOCKFREQUENCYINFO_H
  15. #include "llvm/CodeGen/MachineFunctionPass.h"
  16. #include "llvm/Support/BlockFrequency.h"
  17. #include <climits>
  18. namespace llvm {
  19. class MachineBasicBlock;
  20. class MachineBranchProbabilityInfo;
  21. template <class BlockT> class BlockFrequencyInfoImpl;
  22. /// MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation
  23. /// to estimate machine basic block frequencies.
  24. class MachineBlockFrequencyInfo : public MachineFunctionPass {
  25. typedef BlockFrequencyInfoImpl<MachineBasicBlock> ImplType;
  26. std::unique_ptr<ImplType> MBFI;
  27. public:
  28. static char ID;
  29. MachineBlockFrequencyInfo();
  30. ~MachineBlockFrequencyInfo() override;
  31. void getAnalysisUsage(AnalysisUsage &AU) const override;
  32. bool runOnMachineFunction(MachineFunction &F) override;
  33. void releaseMemory() override;
  34. /// getblockFreq - Return block frequency. Return 0 if we don't have the
  35. /// information. Please note that initial frequency is equal to 1024. It means
  36. /// that we should not rely on the value itself, but only on the comparison to
  37. /// the other block frequencies. We do this to avoid using of floating points.
  38. ///
  39. BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const;
  40. const MachineFunction *getFunction() const;
  41. void view() const;
  42. // Print the block frequency Freq to OS using the current functions entry
  43. // frequency to convert freq into a relative decimal form.
  44. raw_ostream &printBlockFreq(raw_ostream &OS, const BlockFrequency Freq) const;
  45. // Convenience method that attempts to look up the frequency associated with
  46. // BB and print it to OS.
  47. raw_ostream &printBlockFreq(raw_ostream &OS,
  48. const MachineBasicBlock *MBB) const;
  49. uint64_t getEntryFreq() const;
  50. };
  51. }
  52. #endif