1 //===-------- BlockFrequency.h - Block Frequency Wrapper --------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements Block Frequency class.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_SUPPORT_BLOCKFREQUENCY_H
14 #define LLVM_SUPPORT_BLOCKFREQUENCY_H
16 #include "llvm/Support/BranchProbability.h"
17 #include "llvm/Support/DataTypes.h"
23 // This class represents Block Frequency as a 64-bit value.
24 class BlockFrequency
{
28 BlockFrequency(uint64_t Freq
= 0) : Frequency(Freq
) { }
30 /// Returns the maximum possible frequency, the saturation value.
31 static uint64_t getMaxFrequency() { return -1ULL; }
33 /// Returns the frequency as a fixpoint number scaled by the entry
35 uint64_t getFrequency() const { return Frequency
; }
37 /// Multiplies with a branch probability. The computation will never
39 BlockFrequency
&operator*=(BranchProbability Prob
);
40 BlockFrequency
operator*(BranchProbability Prob
) const;
42 /// Divide by a non-zero branch probability using saturating
44 BlockFrequency
&operator/=(BranchProbability Prob
);
45 BlockFrequency
operator/(BranchProbability Prob
) const;
47 /// Adds another block frequency using saturating arithmetic.
48 BlockFrequency
&operator+=(BlockFrequency Freq
);
49 BlockFrequency
operator+(BlockFrequency Freq
) const;
51 /// Subtracts another block frequency using saturating arithmetic.
52 BlockFrequency
&operator-=(BlockFrequency Freq
);
53 BlockFrequency
operator-(BlockFrequency Freq
) const;
55 /// Shift block frequency to the right by count digits saturating to 1.
56 BlockFrequency
&operator>>=(const unsigned count
);
58 bool operator<(BlockFrequency RHS
) const {
59 return Frequency
< RHS
.Frequency
;
62 bool operator<=(BlockFrequency RHS
) const {
63 return Frequency
<= RHS
.Frequency
;
66 bool operator>(BlockFrequency RHS
) const {
67 return Frequency
> RHS
.Frequency
;
70 bool operator>=(BlockFrequency RHS
) const {
71 return Frequency
>= RHS
.Frequency
;
74 bool operator==(BlockFrequency RHS
) const {
75 return Frequency
== RHS
.Frequency
;