LLVM  16.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 
16 #include <cstdint>
17 
18 namespace llvm {
19 
20 class BranchProbability;
21 
22 // This class represents Block Frequency as a 64-bit value.
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.
40 
41  /// Divide by a non-zero branch probability using saturating
42  /// arithmetic.
45 
46  /// Adds another block frequency using saturating arithmetic.
49 
50  /// Subtracts another block frequency using saturating arithmetic.
53 
54  /// Shift block frequency to the right by count digits saturating to 1.
55  BlockFrequency &operator>>=(const unsigned count);
56 
58  return Frequency < RHS.Frequency;
59  }
60 
62  return Frequency <= RHS.Frequency;
63  }
64 
66  return Frequency > RHS.Frequency;
67  }
68 
70  return Frequency >= RHS.Frequency;
71  }
72 
74  return Frequency == RHS.Frequency;
75  }
76 };
77 
78 }
79 
80 #endif
llvm::BlockFrequency::operator+
BlockFrequency operator+(BlockFrequency Freq) const
Definition: BlockFrequency.cpp:52
llvm::BlockFrequency::operator-=
BlockFrequency & operator-=(BlockFrequency Freq)
Subtracts another block frequency using saturating arithmetic.
Definition: BlockFrequency.cpp:58
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::BlockFrequency::operator+=
BlockFrequency & operator+=(BlockFrequency Freq)
Adds another block frequency using saturating arithmetic.
Definition: BlockFrequency.cpp:41
llvm::BlockFrequency::getMaxFrequency
static uint64_t getMaxFrequency()
Returns the maximum possible frequency, the saturation value.
Definition: BlockFrequency.h:30
llvm::BlockFrequency::operator*=
BlockFrequency & operator*=(BranchProbability Prob)
Multiplies with a branch probability.
Definition: BlockFrequency.cpp:19
llvm::BlockFrequency::operator>>=
BlockFrequency & operator>>=(const unsigned count)
Shift block frequency to the right by count digits saturating to 1.
Definition: BlockFrequency.cpp:73
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::BlockFrequency::operator>=
bool operator>=(BlockFrequency RHS) const
Definition: BlockFrequency.h:69
llvm::BlockFrequency
Definition: BlockFrequency.h:23
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:1870
uint64_t
llvm::BlockFrequency::getFrequency
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
Definition: BlockFrequency.h:34
llvm::BranchProbability
Definition: BranchProbability.h:30
llvm::BlockFrequency::operator<
bool operator<(BlockFrequency RHS) const
Definition: BlockFrequency.h:57
llvm::BlockFrequency::operator==
bool operator==(BlockFrequency RHS) const
Definition: BlockFrequency.h:73
llvm::BlockFrequency::BlockFrequency
BlockFrequency(uint64_t Freq=0)
Definition: BlockFrequency.h:27
llvm::BlockFrequency::operator/=
BlockFrequency & operator/=(BranchProbability Prob)
Divide by a non-zero branch probability using saturating arithmetic.
Definition: BlockFrequency.cpp:30
llvm::BlockFrequency::operator/
BlockFrequency operator/(BranchProbability Prob) const
Definition: BlockFrequency.cpp:35
llvm::BlockFrequency::operator*
BlockFrequency operator*(BranchProbability Prob) const
Definition: BlockFrequency.cpp:24
llvm::BlockFrequency::operator-
BlockFrequency operator-(BlockFrequency Freq) const
Definition: BlockFrequency.cpp:67
llvm::BlockFrequency::operator>
bool operator>(BlockFrequency RHS) const
Definition: BlockFrequency.h:65
llvm::BlockFrequency::operator<=
bool operator<=(BlockFrequency RHS) const
Definition: BlockFrequency.h:61