BlockFrequency.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //===-------- BlockFrequency.h - Block Frequency Wrapper --------*- 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. // This file implements Block Frequency class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_SUPPORT_BLOCKFREQUENCY_H
  14. #define LLVM_SUPPORT_BLOCKFREQUENCY_H
  15. #include "llvm/Support/DataTypes.h"
  16. namespace llvm {
  17. class raw_ostream;
  18. class BranchProbability;
  19. // This class represents Block Frequency as a 64-bit value.
  20. class BlockFrequency {
  21. uint64_t Frequency;
  22. public:
  23. BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { }
  24. /// \brief Returns the maximum possible frequency, the saturation value.
  25. static uint64_t getMaxFrequency() { return -1ULL; }
  26. /// \brief Returns the frequency as a fixpoint number scaled by the entry
  27. /// frequency.
  28. uint64_t getFrequency() const { return Frequency; }
  29. /// \brief Multiplies with a branch probability. The computation will never
  30. /// overflow.
  31. BlockFrequency &operator*=(const BranchProbability &Prob);
  32. const BlockFrequency operator*(const BranchProbability &Prob) const;
  33. /// \brief Divide by a non-zero branch probability using saturating
  34. /// arithmetic.
  35. BlockFrequency &operator/=(const BranchProbability &Prob);
  36. BlockFrequency operator/(const BranchProbability &Prob) const;
  37. /// \brief Adds another block frequency using saturating arithmetic.
  38. BlockFrequency &operator+=(const BlockFrequency &Freq);
  39. const BlockFrequency operator+(const BlockFrequency &Freq) const;
  40. /// \brief Shift block frequency to the right by count digits saturating to 1.
  41. BlockFrequency &operator>>=(const unsigned count);
  42. bool operator<(const BlockFrequency &RHS) const {
  43. return Frequency < RHS.Frequency;
  44. }
  45. bool operator<=(const BlockFrequency &RHS) const {
  46. return Frequency <= RHS.Frequency;
  47. }
  48. bool operator>(const BlockFrequency &RHS) const {
  49. return Frequency > RHS.Frequency;
  50. }
  51. bool operator>=(const BlockFrequency &RHS) const {
  52. return Frequency >= RHS.Frequency;
  53. }
  54. };
  55. }
  56. #endif