LCOV - code coverage report
Current view: top level - lib/Support - BlockFrequency.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 37 37 100.0 %
Date: 2017-09-14 15:23:50 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //====--------------- lib/Support/BlockFrequency.cpp -----------*- C++ -*-====//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file implements Block Frequency class.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/Support/BlockFrequency.h"
      15             : #include "llvm/Support/raw_ostream.h"
      16             : #include <cassert>
      17             : 
      18             : using namespace llvm;
      19             : 
      20      382318 : BlockFrequency &BlockFrequency::operator*=(BranchProbability Prob) {
      21      382318 :   Frequency = Prob.scale(Frequency);
      22      382318 :   return *this;
      23             : }
      24             : 
      25      356741 : BlockFrequency BlockFrequency::operator*(BranchProbability Prob) const {
      26      713482 :   BlockFrequency Freq(Frequency);
      27      356741 :   Freq *= Prob;
      28      356741 :   return Freq;
      29             : }
      30             : 
      31        1615 : BlockFrequency &BlockFrequency::operator/=(BranchProbability Prob) {
      32        1615 :   Frequency = Prob.scaleByInverse(Frequency);
      33        1615 :   return *this;
      34             : }
      35             : 
      36        1591 : BlockFrequency BlockFrequency::operator/(BranchProbability Prob) const {
      37        3182 :   BlockFrequency Freq(Frequency);
      38        1591 :   Freq /= Prob;
      39        1591 :   return Freq;
      40             : }
      41             : 
      42    13690355 : BlockFrequency &BlockFrequency::operator+=(BlockFrequency Freq) {
      43    13690355 :   uint64_t Before = Freq.Frequency;
      44    13690355 :   Frequency += Freq.Frequency;
      45             : 
      46             :   // If overflow, set frequency to the maximum value.
      47    13690355 :   if (Frequency < Before)
      48       74242 :     Frequency = UINT64_MAX;
      49             : 
      50    13690355 :   return *this;
      51             : }
      52             : 
      53     6431149 : BlockFrequency BlockFrequency::operator+(BlockFrequency Freq) const {
      54    12862298 :   BlockFrequency NewFreq(Frequency);
      55     6431149 :   NewFreq += Freq;
      56     6431149 :   return NewFreq;
      57             : }
      58             : 
      59        1949 : BlockFrequency &BlockFrequency::operator-=(BlockFrequency Freq) {
      60             :   // If underflow, set frequency to 0.
      61        1949 :   if (Frequency <= Freq.Frequency)
      62        1101 :     Frequency = 0;
      63             :   else
      64         848 :     Frequency -= Freq.Frequency;
      65        1949 :   return *this;
      66             : }
      67             : 
      68        1949 : BlockFrequency BlockFrequency::operator-(BlockFrequency Freq) const {
      69        3898 :   BlockFrequency NewFreq(Frequency);
      70        1949 :   NewFreq -= Freq;
      71        1949 :   return NewFreq;
      72             : }
      73             : 
      74           2 : BlockFrequency &BlockFrequency::operator>>=(const unsigned count) {
      75             :   // Frequency can never be 0 by design.
      76             :   assert(Frequency != 0);
      77             : 
      78             :   // Shift right by count.
      79           2 :   Frequency >>= count;
      80             : 
      81             :   // Saturate to 1 if we are 0.
      82           2 :   Frequency |= Frequency == 0;
      83           2 :   return *this;
      84             : }

Generated by: LCOV version 1.13