Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit d736763

Browse files
CalcSpillWeights: allow overidding the spill weight normalizing function
This will enable the PBQP register allocator to provide its own normalizing function. No functionnal change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194417 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ef572e3 commit d736763

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

include/llvm/CodeGen/CalcSpillWeights.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,23 @@ namespace llvm {
4343
/// \brief Calculate auxiliary information for a virtual register such as its
4444
/// spill weight and allocation hint.
4545
class VirtRegAuxInfo {
46+
public:
47+
typedef float (*NormalizingFn)(float, unsigned);
48+
49+
private:
4650
MachineFunction &MF;
4751
LiveIntervals &LIS;
4852
const MachineLoopInfo &Loops;
4953
const MachineBlockFrequencyInfo &MBFI;
5054
DenseMap<unsigned, float> Hint;
55+
NormalizingFn normalize;
56+
5157
public:
5258
VirtRegAuxInfo(MachineFunction &mf, LiveIntervals &lis,
5359
const MachineLoopInfo &loops,
54-
const MachineBlockFrequencyInfo &mbfi)
55-
: MF(mf), LIS(lis), Loops(loops), MBFI(mbfi) {}
60+
const MachineBlockFrequencyInfo &mbfi,
61+
NormalizingFn norm = normalizeSpillWeight)
62+
: MF(mf), LIS(lis), Loops(loops), MBFI(mbfi), normalize(norm) {}
5663

5764
/// \brief (re)compute li's spill weight and allocation hint.
5865
void calculateSpillWeightAndHint(LiveInterval &li);
@@ -62,7 +69,9 @@ namespace llvm {
6269
/// live intervals.
6370
void calculateSpillWeightsAndHints(LiveIntervals &LIS, MachineFunction &MF,
6471
const MachineLoopInfo &MLI,
65-
const MachineBlockFrequencyInfo &MBFI);
72+
const MachineBlockFrequencyInfo &MBFI,
73+
VirtRegAuxInfo::NormalizingFn norm =
74+
normalizeSpillWeight);
6675
}
6776

6877
#endif // LLVM_CODEGEN_CALCSPILLWEIGHTS_H

lib/CodeGen/CalcSpillWeights.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ using namespace llvm;
2525
void llvm::calculateSpillWeightsAndHints(LiveIntervals &LIS,
2626
MachineFunction &MF,
2727
const MachineLoopInfo &MLI,
28-
const MachineBlockFrequencyInfo &MBFI) {
28+
const MachineBlockFrequencyInfo &MBFI,
29+
VirtRegAuxInfo::NormalizingFn norm) {
2930
DEBUG(dbgs() << "********** Compute Spill Weights **********\n"
3031
<< "********** Function: " << MF.getName() << '\n');
3132

3233
MachineRegisterInfo &MRI = MF.getRegInfo();
33-
VirtRegAuxInfo VRAI(MF, LIS, MLI, MBFI);
34+
VirtRegAuxInfo VRAI(MF, LIS, MLI, MBFI, norm);
3435
for (unsigned i = 0, e = MRI.getNumVirtRegs(); i != e; ++i) {
3536
unsigned Reg = TargetRegisterInfo::index2VirtReg(i);
3637
if (MRI.reg_nodbg_empty(Reg))
@@ -182,5 +183,5 @@ VirtRegAuxInfo::calculateSpillWeightAndHint(LiveInterval &li) {
182183
if (isRematerializable(li, LIS, *MF.getTarget().getInstrInfo()))
183184
totalWeight *= 0.5F;
184185

185-
li.weight = normalizeSpillWeight(totalWeight, li.getSize());
186+
li.weight = normalize(totalWeight, li.getSize());
186187
}

0 commit comments

Comments
 (0)