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/BlockFrequency.h"
15 #include "llvm/Support/raw_ostream.h"
20 BlockFrequency &BlockFrequency::operator*=(BranchProbability Prob) {
21 Frequency = Prob.scale(Frequency);
26 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 BlockFrequency &BlockFrequency::operator+=(const BlockFrequency &Freq) {
44 uint64_t Before = Freq.Frequency;
45 Frequency += Freq.Frequency;
47 // If overflow, set frequency to the maximum value.
48 if (Frequency < Before)
49 Frequency = UINT64_MAX;
55 BlockFrequency::operator+(const BlockFrequency &Prob) const {
56 BlockFrequency Freq(Frequency);
61 BlockFrequency &BlockFrequency::operator>>=(const unsigned count) {
62 // Frequency can never be 0 by design.
63 assert(Frequency != 0);
65 // Shift right by count.
68 // Saturate to 1 if we are 0.
69 Frequency |= Frequency == 0;