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"
19 BlockFrequency
&BlockFrequency::operator*=(BranchProbability Prob
) {
20 Frequency
= Prob
.scale(Frequency
);
24 BlockFrequency
BlockFrequency::operator*(BranchProbability Prob
) const {
25 BlockFrequency
Freq(Frequency
);
30 BlockFrequency
&BlockFrequency::operator/=(BranchProbability Prob
) {
31 Frequency
= Prob
.scaleByInverse(Frequency
);
35 BlockFrequency
BlockFrequency::operator/(BranchProbability Prob
) const {
36 BlockFrequency
Freq(Frequency
);
41 std::optional
<BlockFrequency
> BlockFrequency::mul(uint64_t Factor
) const {
43 uint64_t ResultFrequency
= SaturatingMultiply(Frequency
, Factor
, &Overflow
);
46 return BlockFrequency(ResultFrequency
);