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-09-23 13:06:45 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      660015 : BlockFrequency &BlockFrequency::operator*=(BranchProbability Prob) {
      20      660015 :   Frequency = Prob.scale(Frequency);
      21      660015 :   return *this;
      22             : }
      23             : 
      24      627085 : BlockFrequency BlockFrequency::operator*(BranchProbability Prob) const {
      25      627085 :   BlockFrequency Freq(Frequency);
      26      627085 :   Freq *= Prob;
      27      627085 :   return Freq;
      28             : }
      29             : 
      30        3165 : BlockFrequency &BlockFrequency::operator/=(BranchProbability Prob) {
      31        3165 :   Frequency = Prob.scaleByInverse(Frequency);
      32        3165 :   return *this;
      33             : }
      34             : 
      35        3136 : BlockFrequency BlockFrequency::operator/(BranchProbability Prob) const {
      36        3136 :   BlockFrequency Freq(Frequency);
      37        3136 :   Freq /= Prob;
      38        3136 :   return Freq;
      39             : }
      40             : 
      41    23355678 : BlockFrequency &BlockFrequency::operator+=(BlockFrequency Freq) {
      42             :   uint64_t Before = Freq.Frequency;
      43    23355678 :   Frequency += Freq.Frequency;
      44             : 
      45             :   // If overflow, set frequency to the maximum value.
      46    23355678 :   if (Frequency < Before)
      47      115528 :     Frequency = UINT64_MAX;
      48             : 
      49    23355678 :   return *this;
      50             : }
      51             : 
      52    10317598 : BlockFrequency BlockFrequency::operator+(BlockFrequency Freq) const {
      53    10317598 :   BlockFrequency NewFreq(Frequency);
      54    10317598 :   NewFreq += Freq;
      55    10317598 :   return NewFreq;
      56             : }
      57             : 
      58        4560 : BlockFrequency &BlockFrequency::operator-=(BlockFrequency Freq) {
      59             :   // If underflow, set frequency to 0.
      60        4560 :   if (Frequency <= Freq.Frequency)
      61        1987 :     Frequency = 0;
      62             :   else
      63        2573 :     Frequency -= Freq.Frequency;
      64        4560 :   return *this;
      65             : }
      66             : 
      67        4560 : BlockFrequency BlockFrequency::operator-(BlockFrequency Freq) const {
      68        4560 :   BlockFrequency NewFreq(Frequency);
      69        4560 :   NewFreq -= Freq;
      70        4560 :   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