LLVM  3.7.0
CalcSpillWeights.h
Go to the documentation of this file.
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 
11 #ifndef LLVM_CODEGEN_CALCSPILLWEIGHTS_H
12 #define LLVM_CODEGEN_CALCSPILLWEIGHTS_H
13 
14 #include "llvm/ADT/DenseMap.h"
16 
17 namespace llvm {
18 
19  class LiveInterval;
20  class LiveIntervals;
21  class MachineBlockFrequencyInfo;
22  class MachineLoopInfo;
23 
24  /// \brief Normalize the spill weight of a live interval
25  ///
26  /// The spill weight of a live interval is computed as:
27  ///
28  /// (sum(use freq) + sum(def freq)) / (K + size)
29  ///
30  /// @param UseDefFreq Expected number of executed use and def instructions
31  /// per function call. Derived from block frequencies.
32  /// @param Size Size of live interval as returnexd by getSize()
33  /// @param NumInstr Number of instructions using this live interval
34  ///
35  static inline float normalizeSpillWeight(float UseDefFreq, unsigned Size,
36  unsigned NumInstr) {
37  // The constant 25 instructions is added to avoid depending too much on
38  // accidental SlotIndex gaps for small intervals. The effect is that small
39  // intervals have a spill weight that is mostly proportional to the number
40  // of uses, while large intervals get a spill weight that is closer to a use
41  // density.
42  return UseDefFreq / (Size + 25*SlotIndex::InstrDist);
43  }
44 
45  /// \brief Calculate auxiliary information for a virtual register such as its
46  /// spill weight and allocation hint.
48  public:
49  typedef float (*NormalizingFn)(float, unsigned, unsigned);
50 
51  private:
52  MachineFunction &MF;
53  LiveIntervals &LIS;
54  const MachineLoopInfo &Loops;
55  const MachineBlockFrequencyInfo &MBFI;
57  NormalizingFn normalize;
58 
59  public:
61  const MachineLoopInfo &loops,
62  const MachineBlockFrequencyInfo &mbfi,
64  : MF(mf), LIS(lis), Loops(loops), MBFI(mbfi), normalize(norm) {}
65 
66  /// \brief (re)compute li's spill weight and allocation hint.
68  };
69 
70  /// \brief Compute spill weights and allocation hints for all virtual register
71  /// live intervals.
72  void calculateSpillWeightsAndHints(LiveIntervals &LIS, MachineFunction &MF,
73  const MachineLoopInfo &MLI,
74  const MachineBlockFrequencyInfo &MBFI,
77 }
78 
79 #endif // LLVM_CODEGEN_CALCSPILLWEIGHTS_H
Calculate auxiliary information for a virtual register such as its spill weight and allocation hint...
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition: LiveInterval.h:588
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
void calculateSpillWeightsAndHints(LiveIntervals &LIS, MachineFunction &MF, const MachineLoopInfo &MLI, const MachineBlockFrequencyInfo &MBFI, VirtRegAuxInfo::NormalizingFn norm=normalizeSpillWeight)
Compute spill weights and allocation hints for all virtual register live intervals.
float(* NormalizingFn)(float, unsigned, unsigned)
The default distance between instructions as returned by distance().
Definition: SlotIndexes.h:146
VirtRegAuxInfo(MachineFunction &mf, LiveIntervals &lis, const MachineLoopInfo &loops, const MachineBlockFrequencyInfo &mbfi, NormalizingFn norm=normalizeSpillWeight)
void calculateSpillWeightAndHint(LiveInterval &li)
(re)compute li's spill weight and allocation hint.
static float normalizeSpillWeight(float UseDefFreq, unsigned Size, unsigned NumInstr)
Normalize the spill weight of a live interval.
loops
Definition: LoopInfo.cpp:696