Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Support/BlockFrequency.cpp
Line
Count
Source
1
//====--------------- lib/Support/BlockFrequency.cpp -----------*- C++ -*-====//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file implements Block Frequency class.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "llvm/Support/BlockFrequency.h"
14
#include <cassert>
15
16
using namespace llvm;
17
18
8.05M
BlockFrequency &BlockFrequency::operator*=(BranchProbability Prob) {
19
8.05M
  Frequency = Prob.scale(Frequency);
20
8.05M
  return *this;
21
8.05M
}
22
23
7.78M
BlockFrequency BlockFrequency::operator*(BranchProbability Prob) const {
24
7.78M
  BlockFrequency Freq(Frequency);
25
7.78M
  Freq *= Prob;
26
7.78M
  return Freq;
27
7.78M
}
28
29
121k
BlockFrequency &BlockFrequency::operator/=(BranchProbability Prob) {
30
121k
  Frequency = Prob.scaleByInverse(Frequency);
31
121k
  return *this;
32
121k
}
33
34
113k
BlockFrequency BlockFrequency::operator/(BranchProbability Prob) const {
35
113k
  BlockFrequency Freq(Frequency);
36
113k
  Freq /= Prob;
37
113k
  return Freq;
38
113k
}
39
40
632M
BlockFrequency &BlockFrequency::operator+=(BlockFrequency Freq) {
41
632M
  uint64_t Before = Freq.Frequency;
42
632M
  Frequency += Freq.Frequency;
43
632M
44
632M
  // If overflow, set frequency to the maximum value.
45
632M
  if (Frequency < Before)
46
1.76M
    Frequency = UINT64_MAX;
47
632M
48
632M
  return *this;
49
632M
}
50
51
242M
BlockFrequency BlockFrequency::operator+(BlockFrequency Freq) const {
52
242M
  BlockFrequency NewFreq(Frequency);
53
242M
  NewFreq += Freq;
54
242M
  return NewFreq;
55
242M
}
56
57
238k
BlockFrequency &BlockFrequency::operator-=(BlockFrequency Freq) {
58
238k
  // If underflow, set frequency to 0.
59
238k
  if (Frequency <= Freq.Frequency)
60
64.2k
    Frequency = 0;
61
174k
  else
62
174k
    Frequency -= Freq.Frequency;
63
238k
  return *this;
64
238k
}
65
66
238k
BlockFrequency BlockFrequency::operator-(BlockFrequency Freq) const {
67
238k
  BlockFrequency NewFreq(Frequency);
68
238k
  NewFreq -= Freq;
69
238k
  return NewFreq;
70
238k
}
71
72
2
BlockFrequency &BlockFrequency::operator>>=(const unsigned count) {
73
2
  // Frequency can never be 0 by design.
74
2
  assert(Frequency != 0);
75
2
76
2
  // Shift right by count.
77
2
  Frequency >>= count;
78
2
79
2
  // Saturate to 1 if we are 0.
80
2
  Frequency |= Frequency == 0;
81
2
  return *this;
82
2
}