LLVM 17.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
18namespace llvm {
19
20class BranchProbability;
21
22// This class represents Block Frequency as a 64-bit value.
24 uint64_t Frequency;
25
26public:
27 BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { }
28
29 /// Returns the maximum possible frequency, the saturation value.
30 static uint64_t getMaxFrequency() { return UINT64_MAX; }
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} // namespace llvm
79
80#endif
Value * RHS
BlockFrequency operator-(BlockFrequency Freq) const
BlockFrequency operator/(BranchProbability Prob) const
bool operator>=(BlockFrequency RHS) const
BlockFrequency & operator-=(BlockFrequency Freq)
Subtracts another block frequency using saturating arithmetic.
BlockFrequency(uint64_t Freq=0)
BlockFrequency & operator+=(BlockFrequency Freq)
Adds another block frequency using saturating arithmetic.
BlockFrequency & operator>>=(const unsigned count)
Shift block frequency to the right by count digits saturating to 1.
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
bool operator<(BlockFrequency RHS) const
bool operator==(BlockFrequency RHS) const
BlockFrequency operator*(BranchProbability Prob) const
static uint64_t getMaxFrequency()
Returns the maximum possible frequency, the saturation value.
bool operator>(BlockFrequency RHS) const
bool operator<=(BlockFrequency RHS) const
BlockFrequency operator+(BlockFrequency Freq) const
BlockFrequency & operator*=(BranchProbability Prob)
Multiplies with a branch probability.
BlockFrequency & operator/=(BranchProbability Prob)
Divide by a non-zero branch probability using saturating arithmetic.
#define UINT64_MAX
Definition: DataTypes.h:77
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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:2011