BlockFrequencyInfo.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //===- BlockFrequencyInfo.h - Block 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_ANALYSIS_BLOCKFREQUENCYINFO_H
  14. #define LLVM_ANALYSIS_BLOCKFREQUENCYINFO_H
  15. #include "llvm/Pass.h"
  16. #include "llvm/Support/BlockFrequency.h"
  17. #include <climits>
  18. namespace llvm {
  19. class BranchProbabilityInfo;
  20. template <class BlockT> class BlockFrequencyInfoImpl;
  21. /// BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to
  22. /// estimate IR basic block frequencies.
  23. class BlockFrequencyInfo : public FunctionPass {
  24. typedef BlockFrequencyInfoImpl<BasicBlock> ImplType;
  25. std::unique_ptr<ImplType> BFI;
  26. public:
  27. static char ID;
  28. BlockFrequencyInfo();
  29. ~BlockFrequencyInfo() override;
  30. void getAnalysisUsage(AnalysisUsage &AU) const override;
  31. bool runOnFunction(Function &F) override;
  32. void releaseMemory() override;
  33. void print(raw_ostream &O, const Module *M) const override;
  34. const Function *getFunction() const;
  35. void view() const;
  36. /// getblockFreq - Return block frequency. Return 0 if we don't have the
  37. /// information. Please note that initial frequency is equal to ENTRY_FREQ. It
  38. /// means that we should not rely on the value itself, but only on the
  39. /// comparison to the other block frequencies. We do this to avoid using of
  40. /// floating points.
  41. BlockFrequency getBlockFreq(const BasicBlock *BB) 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, const BasicBlock *BB) const;
  48. uint64_t getEntryFreq() const;
  49. };
  50. }
  51. #endif