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