BlockFrequency.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-------- BlockFrequency.h - Block Frequency Wrapper --------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file implements Block Frequency class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_SUPPORT_BLOCKFREQUENCY_H
  18. #define LLVM_SUPPORT_BLOCKFREQUENCY_H
  19. #include <cstdint>
  20. namespace llvm {
  21. class BranchProbability;
  22. // This class represents Block Frequency as a 64-bit value.
  23. class BlockFrequency {
  24. uint64_t Frequency;
  25. public:
  26. BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { }
  27. /// Returns the maximum possible frequency, the saturation value.
  28. static uint64_t getMaxFrequency() { return -1ULL; }
  29. /// Returns the frequency as a fixpoint number scaled by the entry
  30. /// frequency.
  31. uint64_t getFrequency() const { return Frequency; }
  32. /// Multiplies with a branch probability. The computation will never
  33. /// overflow.
  34. BlockFrequency &operator*=(BranchProbability Prob);
  35. BlockFrequency operator*(BranchProbability Prob) const;
  36. /// Divide by a non-zero branch probability using saturating
  37. /// arithmetic.
  38. BlockFrequency &operator/=(BranchProbability Prob);
  39. BlockFrequency operator/(BranchProbability Prob) const;
  40. /// Adds another block frequency using saturating arithmetic.
  41. BlockFrequency &operator+=(BlockFrequency Freq);
  42. BlockFrequency operator+(BlockFrequency Freq) const;
  43. /// Subtracts another block frequency using saturating arithmetic.
  44. BlockFrequency &operator-=(BlockFrequency Freq);
  45. BlockFrequency operator-(BlockFrequency Freq) const;
  46. /// Shift block frequency to the right by count digits saturating to 1.
  47. BlockFrequency &operator>>=(const unsigned count);
  48. bool operator<(BlockFrequency RHS) const {
  49. return Frequency < RHS.Frequency;
  50. }
  51. bool operator<=(BlockFrequency RHS) const {
  52. return Frequency <= RHS.Frequency;
  53. }
  54. bool operator>(BlockFrequency RHS) const {
  55. return Frequency > RHS.Frequency;
  56. }
  57. bool operator>=(BlockFrequency RHS) const {
  58. return Frequency >= RHS.Frequency;
  59. }
  60. bool operator==(BlockFrequency RHS) const {
  61. return Frequency == RHS.Frequency;
  62. }
  63. };
  64. }
  65. #endif
  66. #ifdef __GNUC__
  67. #pragma GCC diagnostic pop
  68. #endif