LLVM API Documentation

BlockFrequency.cpp
Go to the documentation of this file.
00001 //====--------------- lib/Support/BlockFrequency.cpp -----------*- C++ -*-====//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements Block Frequency class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/Support/BranchProbability.h"
00015 #include "llvm/Support/BlockFrequency.h"
00016 #include "llvm/Support/raw_ostream.h"
00017 #include <cassert>
00018 
00019 using namespace llvm;
00020 
00021 BlockFrequency &BlockFrequency::operator*=(const BranchProbability &Prob) {
00022   Frequency = Prob.scale(Frequency);
00023   return *this;
00024 }
00025 
00026 const BlockFrequency
00027 BlockFrequency::operator*(const BranchProbability &Prob) const {
00028   BlockFrequency Freq(Frequency);
00029   Freq *= Prob;
00030   return Freq;
00031 }
00032 
00033 BlockFrequency &BlockFrequency::operator/=(const BranchProbability &Prob) {
00034   Frequency = Prob.scaleByInverse(Frequency);
00035   return *this;
00036 }
00037 
00038 BlockFrequency BlockFrequency::operator/(const BranchProbability &Prob) const {
00039   BlockFrequency Freq(Frequency);
00040   Freq /= Prob;
00041   return Freq;
00042 }
00043 
00044 BlockFrequency &BlockFrequency::operator+=(const BlockFrequency &Freq) {
00045   uint64_t Before = Freq.Frequency;
00046   Frequency += Freq.Frequency;
00047 
00048   // If overflow, set frequency to the maximum value.
00049   if (Frequency < Before)
00050     Frequency = UINT64_MAX;
00051 
00052   return *this;
00053 }
00054 
00055 const BlockFrequency
00056 BlockFrequency::operator+(const BlockFrequency &Prob) const {
00057   BlockFrequency Freq(Frequency);
00058   Freq += Prob;
00059   return Freq;
00060 }
00061 
00062 BlockFrequency &BlockFrequency::operator>>=(const unsigned count) {
00063   // Frequency can never be 0 by design.
00064   assert(Frequency != 0);
00065 
00066   // Shift right by count.
00067   Frequency >>= count;
00068 
00069   // Saturate to 1 if we are 0.
00070   Frequency |= Frequency == 0;
00071   return *this;
00072 }