LCOV - code coverage report
Current view: top level - lib/Support - BlockFrequency.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 36 36 100.0 %
Date: 2018-06-17 00:07:59 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 <cassert>
      16             : 
      17             : using namespace llvm;
      18             : 
      19      427647 : BlockFrequency &BlockFrequency::operator*=(BranchProbability Prob) {
      20      427647 :   Frequency = Prob.scale(Frequency);
      21      427647 :   return *this;
      22             : }
      23             : 
      24      396760 : BlockFrequency BlockFrequency::operator*(BranchProbability Prob) const {
      25      396760 :   BlockFrequency Freq(Frequency);
      26      396760 :   Freq *= Prob;
      27      396760 :   return Freq;
      28             : }
      29             : 
      30        1805 : BlockFrequency &BlockFrequency::operator/=(BranchProbability Prob) {
      31        1805 :   Frequency = Prob.scaleByInverse(Frequency);
      32        1805 :   return *this;
      33             : }
      34             : 
      35        1777 : BlockFrequency BlockFrequency::operator/(BranchProbability Prob) const {
      36        1777 :   BlockFrequency Freq(Frequency);
      37        1777 :   Freq /= Prob;
      38        1777 :   return Freq;
      39             : }
      40             : 
      41    14039659 : BlockFrequency &BlockFrequency::operator+=(BlockFrequency Freq) {
      42             :   uint64_t Before = Freq.Frequency;
      43    14039659 :   Frequency += Freq.Frequency;
      44             : 
      45             :   // If overflow, set frequency to the maximum value.
      46    14039659 :   if (Frequency < Before)
      47      117497 :     Frequency = UINT64_MAX;
      48             : 
      49    14039659 :   return *this;
      50             : }
      51             : 
      52     6615641 : BlockFrequency BlockFrequency::operator+(BlockFrequency Freq) const {
      53     6615641 :   BlockFrequency NewFreq(Frequency);
      54     6615641 :   NewFreq += Freq;
      55     6615641 :   return NewFreq;
      56             : }
      57             : 
      58        2178 : BlockFrequency &BlockFrequency::operator-=(BlockFrequency Freq) {
      59             :   // If underflow, set frequency to 0.
      60        2178 :   if (Frequency <= Freq.Frequency)
      61        1261 :     Frequency = 0;
      62             :   else
      63         917 :     Frequency -= Freq.Frequency;
      64        2178 :   return *this;
      65             : }
      66             : 
      67        2178 : BlockFrequency BlockFrequency::operator-(BlockFrequency Freq) const {
      68        2178 :   BlockFrequency NewFreq(Frequency);
      69        2178 :   NewFreq -= Freq;
      70        2178 :   return NewFreq;
      71             : }
      72             : 
      73           2 : BlockFrequency &BlockFrequency::operator>>=(const unsigned count) {
      74             :   // Frequency can never be 0 by design.
      75             :   assert(Frequency != 0);
      76             : 
      77             :   // Shift right by count.
      78           2 :   Frequency >>= count;
      79             : 
      80             :   // Saturate to 1 if we are 0.
      81           2 :   Frequency |= Frequency == 0;
      82           2 :   return *this;
      83             : }

Generated by: LCOV version 1.13