1 //====--------------- lib/Support/BlockFrequency.cpp -----------*- 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 #include "llvm/Support/BlockFrequency.h"
14 #include "llvm/Support/BranchProbability.h"
15 #include "llvm/Support/MathExtras.h"
16 #include "llvm/Support/ScaledNumber.h"
17 #include "llvm/Support/raw_ostream.h"
21 BlockFrequency
&BlockFrequency::operator*=(BranchProbability Prob
) {
22 Frequency
= Prob
.scale(Frequency
);
26 BlockFrequency
BlockFrequency::operator*(BranchProbability Prob
) const {
27 BlockFrequency
Freq(Frequency
);
32 BlockFrequency
&BlockFrequency::operator/=(BranchProbability Prob
) {
33 Frequency
= Prob
.scaleByInverse(Frequency
);
37 BlockFrequency
BlockFrequency::operator/(BranchProbability Prob
) const {
38 BlockFrequency
Freq(Frequency
);
43 std::optional
<BlockFrequency
> BlockFrequency::mul(uint64_t Factor
) const {
45 uint64_t ResultFrequency
= SaturatingMultiply(Frequency
, Factor
, &Overflow
);
48 return BlockFrequency(ResultFrequency
);
51 void llvm::printRelativeBlockFreq(raw_ostream
&OS
, BlockFrequency EntryFreq
,
52 BlockFrequency Freq
) {
53 if (Freq
== BlockFrequency(0)) {
57 if (EntryFreq
== BlockFrequency(0)) {
58 OS
<< "<invalid BFI>";
61 ScaledNumber
<uint64_t> Block(Freq
.getFrequency(), 0);
62 ScaledNumber
<uint64_t> Entry(EntryFreq
.getFrequency(), 0);