/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/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 | | |
11 | | #ifndef LLVM_CODEGEN_CALCSPILLWEIGHTS_H |
12 | | #define LLVM_CODEGEN_CALCSPILLWEIGHTS_H |
13 | | |
14 | | #include "llvm/ADT/DenseMap.h" |
15 | | #include "llvm/CodeGen/SlotIndexes.h" |
16 | | |
17 | | namespace llvm { |
18 | | |
19 | | class LiveInterval; |
20 | | class LiveIntervals; |
21 | | class MachineBlockFrequencyInfo; |
22 | | class MachineLoopInfo; |
23 | | class VirtRegMap; |
24 | | |
25 | | /// \brief 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 | | /// |
36 | | static inline float normalizeSpillWeight(float UseDefFreq, unsigned Size, |
37 | 7.94M | unsigned NumInstr) { |
38 | 7.94M | // The constant 25 instructions is added to avoid depending too much on |
39 | 7.94M | // accidental SlotIndex gaps for small intervals. The effect is that small |
40 | 7.94M | // intervals have a spill weight that is mostly proportional to the number |
41 | 7.94M | // of uses, while large intervals get a spill weight that is closer to a use |
42 | 7.94M | // density. |
43 | 7.94M | return UseDefFreq / (Size + 25*SlotIndex::InstrDist); |
44 | 7.94M | } Unexecuted instantiation: CalcSpillWeights.cpp:llvm::normalizeSpillWeight(float, unsigned int, unsigned int) LiveRangeEdit.cpp:llvm::normalizeSpillWeight(float, unsigned int, unsigned int) Line | Count | Source | 37 | 315k | unsigned NumInstr) { | 38 | 315k | // The constant 25 instructions is added to avoid depending too much on | 39 | 315k | // accidental SlotIndex gaps for small intervals. The effect is that small | 40 | 315k | // intervals have a spill weight that is mostly proportional to the number | 41 | 315k | // of uses, while large intervals get a spill weight that is closer to a use | 42 | 315k | // density. | 43 | 315k | return UseDefFreq / (Size + 25*SlotIndex::InstrDist); | 44 | 315k | } |
RegAllocBasic.cpp:llvm::normalizeSpillWeight(float, unsigned int, unsigned int) Line | Count | Source | 37 | 1.47k | unsigned NumInstr) { | 38 | 1.47k | // The constant 25 instructions is added to avoid depending too much on | 39 | 1.47k | // accidental SlotIndex gaps for small intervals. The effect is that small | 40 | 1.47k | // intervals have a spill weight that is mostly proportional to the number | 41 | 1.47k | // of uses, while large intervals get a spill weight that is closer to a use | 42 | 1.47k | // density. | 43 | 1.47k | return UseDefFreq / (Size + 25*SlotIndex::InstrDist); | 44 | 1.47k | } |
RegAllocGreedy.cpp:llvm::normalizeSpillWeight(float, unsigned int, unsigned int) Line | Count | Source | 37 | 7.62M | unsigned NumInstr) { | 38 | 7.62M | // The constant 25 instructions is added to avoid depending too much on | 39 | 7.62M | // accidental SlotIndex gaps for small intervals. The effect is that small | 40 | 7.62M | // intervals have a spill weight that is mostly proportional to the number | 41 | 7.62M | // of uses, while large intervals get a spill weight that is closer to a use | 42 | 7.62M | // density. | 43 | 7.62M | return UseDefFreq / (Size + 25*SlotIndex::InstrDist); | 44 | 7.62M | } |
RegAllocPBQP.cpp:llvm::normalizeSpillWeight(float, unsigned int, unsigned int) Line | Count | Source | 37 | 134 | unsigned NumInstr) { | 38 | 134 | // The constant 25 instructions is added to avoid depending too much on | 39 | 134 | // accidental SlotIndex gaps for small intervals. The effect is that small | 40 | 134 | // intervals have a spill weight that is mostly proportional to the number | 41 | 134 | // of uses, while large intervals get a spill weight that is closer to a use | 42 | 134 | // density. | 43 | 134 | return UseDefFreq / (Size + 25*SlotIndex::InstrDist); | 44 | 134 | } |
|
45 | | |
46 | | /// \brief Calculate auxiliary information for a virtual register such as its |
47 | | /// spill weight and allocation hint. |
48 | | class VirtRegAuxInfo { |
49 | | public: |
50 | | typedef float (*NormalizingFn)(float, unsigned, unsigned); |
51 | | |
52 | | private: |
53 | | MachineFunction &MF; |
54 | | LiveIntervals &LIS; |
55 | | VirtRegMap *VRM; |
56 | | const MachineLoopInfo &Loops; |
57 | | const MachineBlockFrequencyInfo &MBFI; |
58 | | DenseMap<unsigned, float> Hint; |
59 | | NormalizingFn normalize; |
60 | | |
61 | | public: |
62 | | VirtRegAuxInfo(MachineFunction &mf, LiveIntervals &lis, |
63 | | VirtRegMap *vrm, const MachineLoopInfo &loops, |
64 | | const MachineBlockFrequencyInfo &mbfi, |
65 | | NormalizingFn norm = normalizeSpillWeight) |
66 | 997k | : MF(mf), LIS(lis), VRM(vrm), Loops(loops), MBFI(mbfi), normalize(norm) {} |
67 | | |
68 | | /// \brief (re)compute li's spill weight and allocation hint. |
69 | | void calculateSpillWeightAndHint(LiveInterval &li); |
70 | | }; |
71 | | |
72 | | /// \brief Compute spill weights and allocation hints for all virtual register |
73 | | /// live intervals. |
74 | | void calculateSpillWeightsAndHints(LiveIntervals &LIS, MachineFunction &MF, |
75 | | VirtRegMap *VRM, |
76 | | const MachineLoopInfo &MLI, |
77 | | const MachineBlockFrequencyInfo &MBFI, |
78 | | VirtRegAuxInfo::NormalizingFn norm = |
79 | | normalizeSpillWeight); |
80 | | } |
81 | | |
82 | | #endif // LLVM_CODEGEN_CALCSPILLWEIGHTS_H |