LLVM  14.0.0git
BlockFrequency.h
Go to the documentation of this file.
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 
17 #include "llvm/Support/DataTypes.h"
18 
19 namespace llvm {
20 
21 class raw_ostream;
22 
23 // This class represents Block Frequency as a 64-bit value.
25  uint64_t Frequency;
26 
27 public:
28  BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { }
29 
30  /// Returns the maximum possible frequency, the saturation value.
31  static uint64_t getMaxFrequency() { return -1ULL; }
32 
33  /// Returns the frequency as a fixpoint number scaled by the entry
34  /// frequency.
35  uint64_t getFrequency() const { return Frequency; }
36 
37  /// Multiplies with a branch probability. The computation will never
38  /// overflow.
41 
42  /// Divide by a non-zero branch probability using saturating
43  /// arithmetic.
46 
47  /// Adds another block frequency using saturating arithmetic.
50 
51  /// Subtracts another block frequency using saturating arithmetic.
54 
55  /// Shift block frequency to the right by count digits saturating to 1.
56  BlockFrequency &operator>>=(const unsigned count);
57 
58  bool operator<(BlockFrequency RHS) const {
59  return Frequency < RHS.Frequency;
60  }
61 
62  bool operator<=(BlockFrequency RHS) const {
63  return Frequency <= RHS.Frequency;
64  }
65 
66  bool operator>(BlockFrequency RHS) const {
67  return Frequency > RHS.Frequency;
68  }
69 
70  bool operator>=(BlockFrequency RHS) const {
71  return Frequency >= RHS.Frequency;
72  }
73 
74  bool operator==(BlockFrequency RHS) const {
75  return Frequency == RHS.Frequency;
76  }
77 };
78 
79 }
80 
81 #endif
llvm::BlockFrequency::operator+
BlockFrequency operator+(BlockFrequency Freq) const
Definition: BlockFrequency.cpp:51
llvm::BlockFrequency::operator-=
BlockFrequency & operator-=(BlockFrequency Freq)
Subtracts another block frequency using saturating arithmetic.
Definition: BlockFrequency.cpp:57
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::BlockFrequency::operator+=
BlockFrequency & operator+=(BlockFrequency Freq)
Adds another block frequency using saturating arithmetic.
Definition: BlockFrequency.cpp:40
llvm::BlockFrequency::getMaxFrequency
static uint64_t getMaxFrequency()
Returns the maximum possible frequency, the saturation value.
Definition: BlockFrequency.h:31
llvm::BlockFrequency::operator*=
BlockFrequency & operator*=(BranchProbability Prob)
Multiplies with a branch probability.
Definition: BlockFrequency.cpp:18
llvm::BlockFrequency::operator>>=
BlockFrequency & operator>>=(const unsigned count)
Shift block frequency to the right by count digits saturating to 1.
Definition: BlockFrequency.cpp:72
llvm::BlockFrequency::operator>=
bool operator>=(BlockFrequency RHS) const
Definition: BlockFrequency.h:70
BranchProbability.h
llvm::BlockFrequency
Definition: BlockFrequency.h:24
llvm::count
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:1634
uint64_t
llvm::BlockFrequency::getFrequency
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
Definition: BlockFrequency.h:35
llvm::BranchProbability
Definition: BranchProbability.h:30
llvm::BlockFrequency::operator<
bool operator<(BlockFrequency RHS) const
Definition: BlockFrequency.h:58
llvm::BlockFrequency::operator==
bool operator==(BlockFrequency RHS) const
Definition: BlockFrequency.h:74
llvm::BlockFrequency::BlockFrequency
BlockFrequency(uint64_t Freq=0)
Definition: BlockFrequency.h:28
llvm::BlockFrequency::operator/=
BlockFrequency & operator/=(BranchProbability Prob)
Divide by a non-zero branch probability using saturating arithmetic.
Definition: BlockFrequency.cpp:29
llvm::BlockFrequency::operator/
BlockFrequency operator/(BranchProbability Prob) const
Definition: BlockFrequency.cpp:34
DataTypes.h
llvm::BlockFrequency::operator*
BlockFrequency operator*(BranchProbability Prob) const
Definition: BlockFrequency.cpp:23
llvm::BlockFrequency::operator-
BlockFrequency operator-(BlockFrequency Freq) const
Definition: BlockFrequency.cpp:66
llvm::BlockFrequency::operator>
bool operator>(BlockFrequency RHS) const
Definition: BlockFrequency.h:66
llvm::BlockFrequency::operator<=
bool operator<=(BlockFrequency RHS) const
Definition: BlockFrequency.h:62