1 //====--------------- lib/Support/BlockFrequency.cpp -----------*- C++ -*-====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements Block Frequency class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/BranchProbability.h"
15 #include "llvm/Support/BlockFrequency.h"
16 #include "llvm/Support/raw_ostream.h"
21 BlockFrequency &BlockFrequency::operator*=(const BranchProbability &Prob) {
22 Frequency = Prob.scale(Frequency);
27 BlockFrequency::operator*(const BranchProbability &Prob) const {
28 BlockFrequency Freq(Frequency);
33 BlockFrequency &BlockFrequency::operator/=(const BranchProbability &Prob) {
34 Frequency = Prob.scaleByInverse(Frequency);
38 BlockFrequency BlockFrequency::operator/(const BranchProbability &Prob) const {
39 BlockFrequency Freq(Frequency);
44 BlockFrequency &BlockFrequency::operator+=(const BlockFrequency &Freq) {
45 uint64_t Before = Freq.Frequency;
46 Frequency += Freq.Frequency;
48 // If overflow, set frequency to the maximum value.
49 if (Frequency < Before)
50 Frequency = UINT64_MAX;
56 BlockFrequency::operator+(const BlockFrequency &Prob) const {
57 BlockFrequency Freq(Frequency);
62 BlockFrequency &BlockFrequency::operator>>=(const unsigned count) {
63 // Frequency can never be 0 by design.
64 assert(Frequency != 0);
66 // Shift right by count.
69 // Saturate to 1 if we are 0.
70 Frequency |= Frequency == 0;