[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / llvm / lib / Support / BlockFrequency.cpp
blob329f1e12cdc29b2af30925facface1308290a996
1 //====--------------- lib/Support/BlockFrequency.cpp -----------*- 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.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/Support/BlockFrequency.h"
14 #include "llvm/Support/BranchProbability.h"
15 #include "llvm/Support/MathExtras.h"
17 using namespace llvm;
19 BlockFrequency &BlockFrequency::operator*=(BranchProbability Prob) {
20 Frequency = Prob.scale(Frequency);
21 return *this;
24 BlockFrequency BlockFrequency::operator*(BranchProbability Prob) const {
25 BlockFrequency Freq(Frequency);
26 Freq *= Prob;
27 return Freq;
30 BlockFrequency &BlockFrequency::operator/=(BranchProbability Prob) {
31 Frequency = Prob.scaleByInverse(Frequency);
32 return *this;
35 BlockFrequency BlockFrequency::operator/(BranchProbability Prob) const {
36 BlockFrequency Freq(Frequency);
37 Freq /= Prob;
38 return Freq;
41 std::optional<BlockFrequency> BlockFrequency::mul(uint64_t Factor) const {
42 bool Overflow;
43 uint64_t ResultFrequency = SaturatingMultiply(Frequency, Factor, &Overflow);
44 if (Overflow)
45 return {};
46 return BlockFrequency(ResultFrequency);