Coverage Report

Created: 2018-07-19 03:59

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/CalcSpillWeights.h
Line
Count
Source
1
//===- lib/CodeGen/CalcSpillWeights.h ---------------------------*- 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
#ifndef LLVM_CODEGEN_CALCSPILLWEIGHTS_H
11
#define LLVM_CODEGEN_CALCSPILLWEIGHTS_H
12
13
#include "llvm/ADT/DenseMap.h"
14
#include "llvm/CodeGen/SlotIndexes.h"
15
16
namespace llvm {
17
18
class LiveInterval;
19
class LiveIntervals;
20
class MachineBlockFrequencyInfo;
21
class MachineFunction;
22
class MachineLoopInfo;
23
class VirtRegMap;
24
25
  /// Normalize the spill weight of a live interval
26
  ///
27
  /// The spill weight of a live interval is computed as:
28
  ///
29
  ///   (sum(use freq) + sum(def freq)) / (K + size)
30
  ///
31
  /// @param UseDefFreq Expected number of executed use and def instructions
32
  ///                   per function call. Derived from block frequencies.
33
  /// @param Size       Size of live interval as returnexd by getSize()
34
  /// @param NumInstr   Number of instructions using this live interval
35
  static inline float normalizeSpillWeight(float UseDefFreq, unsigned Size,
36
6.41M
                                           unsigned NumInstr) {
37
6.41M
    // The constant 25 instructions is added to avoid depending too much on
38
6.41M
    // accidental SlotIndex gaps for small intervals. The effect is that small
39
6.41M
    // intervals have a spill weight that is mostly proportional to the number
40
6.41M
    // of uses, while large intervals get a spill weight that is closer to a use
41
6.41M
    // density.
42
6.41M
    return UseDefFreq / (Size + 25*SlotIndex::InstrDist);
43
6.41M
  }
Unexecuted instantiation: CalcSpillWeights.cpp:llvm::normalizeSpillWeight(float, unsigned int, unsigned int)
LiveRangeEdit.cpp:llvm::normalizeSpillWeight(float, unsigned int, unsigned int)
Line
Count
Source
36
314k
                                           unsigned NumInstr) {
37
314k
    // The constant 25 instructions is added to avoid depending too much on
38
314k
    // accidental SlotIndex gaps for small intervals. The effect is that small
39
314k
    // intervals have a spill weight that is mostly proportional to the number
40
314k
    // of uses, while large intervals get a spill weight that is closer to a use
41
314k
    // density.
42
314k
    return UseDefFreq / (Size + 25*SlotIndex::InstrDist);
43
314k
  }
RegAllocBasic.cpp:llvm::normalizeSpillWeight(float, unsigned int, unsigned int)
Line
Count
Source
36
1.48k
                                           unsigned NumInstr) {
37
1.48k
    // The constant 25 instructions is added to avoid depending too much on
38
1.48k
    // accidental SlotIndex gaps for small intervals. The effect is that small
39
1.48k
    // intervals have a spill weight that is mostly proportional to the number
40
1.48k
    // of uses, while large intervals get a spill weight that is closer to a use
41
1.48k
    // density.
42
1.48k
    return UseDefFreq / (Size + 25*SlotIndex::InstrDist);
43
1.48k
  }
RegAllocGreedy.cpp:llvm::normalizeSpillWeight(float, unsigned int, unsigned int)
Line
Count
Source
36
6.09M
                                           unsigned NumInstr) {
37
6.09M
    // The constant 25 instructions is added to avoid depending too much on
38
6.09M
    // accidental SlotIndex gaps for small intervals. The effect is that small
39
6.09M
    // intervals have a spill weight that is mostly proportional to the number
40
6.09M
    // of uses, while large intervals get a spill weight that is closer to a use
41
6.09M
    // density.
42
6.09M
    return UseDefFreq / (Size + 25*SlotIndex::InstrDist);
43
6.09M
  }
RegAllocPBQP.cpp:llvm::normalizeSpillWeight(float, unsigned int, unsigned int)
Line
Count
Source
36
132
                                           unsigned NumInstr) {
37
132
    // The constant 25 instructions is added to avoid depending too much on
38
132
    // accidental SlotIndex gaps for small intervals. The effect is that small
39
132
    // intervals have a spill weight that is mostly proportional to the number
40
132
    // of uses, while large intervals get a spill weight that is closer to a use
41
132
    // density.
42
132
    return UseDefFreq / (Size + 25*SlotIndex::InstrDist);
43
132
  }
44
45
  /// Calculate auxiliary information for a virtual register such as its
46
  /// spill weight and allocation hint.
47
  class VirtRegAuxInfo {
48
  public:
49
    using NormalizingFn = float (*)(float, unsigned, unsigned);
50
51
  private:
52
    MachineFunction &MF;
53
    LiveIntervals &LIS;
54
    VirtRegMap *VRM;
55
    const MachineLoopInfo &Loops;
56
    const MachineBlockFrequencyInfo &MBFI;
57
    DenseMap<unsigned, float> Hint;
58
    NormalizingFn normalize;
59
60
  public:
61
    VirtRegAuxInfo(MachineFunction &mf, LiveIntervals &lis,
62
                   VirtRegMap *vrm, const MachineLoopInfo &loops,
63
                   const MachineBlockFrequencyInfo &mbfi,
64
                   NormalizingFn norm = normalizeSpillWeight)
65
856k
        : MF(mf), LIS(lis), VRM(vrm), Loops(loops), MBFI(mbfi), normalize(norm) {}
66
67
    /// (re)compute li's spill weight and allocation hint.
68
    void calculateSpillWeightAndHint(LiveInterval &li);
69
70
    /// Compute future expected spill weight of a split artifact of li
71
    /// that will span between start and end slot indexes.
72
    /// \param li     The live interval to be split.
73
    /// \param start  The expected begining of the split artifact. Instructions
74
    ///               before start will not affect the weight.
75
    /// \param end    The expected end of the split artifact. Instructions
76
    ///               after end will not affect the weight.
77
    /// \return The expected spill weight of the split artifact. Returns
78
    /// negative weight for unspillable li.
79
    float futureWeight(LiveInterval &li, SlotIndex start, SlotIndex end);
80
81
    /// Helper function for weight calculations.
82
    /// (Re)compute li's spill weight and allocation hint, or, for non null
83
    /// start and end - compute future expected spill weight of a split
84
    /// artifact of li that will span between start and end slot indexes.
85
    /// \param li     The live interval for which to compute the weight.
86
    /// \param start  The expected begining of the split artifact. Instructions
87
    ///               before start will not affect the weight. Relevant for
88
    ///               weight calculation of future split artifact.
89
    /// \param end    The expected end of the split artifact. Instructions
90
    ///               after end will not affect the weight. Relevant for
91
    ///               weight calculation of future split artifact.
92
    /// \return The spill weight. Returns negative weight for unspillable li.
93
    float weightCalcHelper(LiveInterval &li, SlotIndex *start = nullptr,
94
                           SlotIndex *end = nullptr);
95
  };
96
97
  /// Compute spill weights and allocation hints for all virtual register
98
  /// live intervals.
99
  void calculateSpillWeightsAndHints(LiveIntervals &LIS, MachineFunction &MF,
100
                                     VirtRegMap *VRM,
101
                                     const MachineLoopInfo &MLI,
102
                                     const MachineBlockFrequencyInfo &MBFI,
103
                                     VirtRegAuxInfo::NormalizingFn norm =
104
                                         normalizeSpillWeight);
105
106
} // end namespace llvm
107
108
#endif // LLVM_CODEGEN_CALCSPILLWEIGHTS_H