Skip to content

Commit d6de40f

Browse files
committed
[NFC][regalloc] Make VirtRegAuxInfo part of allocator state
All the state of VRAI is allocator-wide, so we can avoid creating it every time we need it. In addition, the normalization function is allocator-specific. In a next change, we can simplify that design in favor of just having it as a virtual member. Differential Revision: https://reviews.llvm.org/D88499
1 parent f425418 commit d6de40f

File tree

5 files changed

+22
-33
lines changed

5 files changed

+22
-33
lines changed

llvm/include/llvm/CodeGen/CalcSpillWeights.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,11 @@ class VirtRegMap;
9191
/// \return The spill weight. Returns negative weight for unspillable li.
9292
float weightCalcHelper(LiveInterval &li, SlotIndex *start = nullptr,
9393
SlotIndex *end = nullptr);
94-
};
95-
96-
/// Compute spill weights and allocation hints for all virtual register
97-
/// live intervals.
98-
void calculateSpillWeightsAndHints(LiveIntervals &LIS, MachineFunction &MF,
99-
VirtRegMap *VRM,
100-
const MachineLoopInfo &MLI,
101-
const MachineBlockFrequencyInfo &MBFI,
102-
VirtRegAuxInfo::NormalizingFn norm =
103-
normalizeSpillWeight);
10494

95+
/// Compute spill weights and allocation hints for all virtual register
96+
/// live intervals.
97+
void calculateSpillWeightsAndHints();
98+
};
10599
} // end namespace llvm
106100

107101
#endif // LLVM_CODEGEN_CALCSPILLWEIGHTS_H

llvm/lib/CodeGen/CalcSpillWeights.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,16 @@ using namespace llvm;
2828

2929
#define DEBUG_TYPE "calcspillweights"
3030

31-
void llvm::calculateSpillWeightsAndHints(LiveIntervals &LIS,
32-
MachineFunction &MF,
33-
VirtRegMap *VRM,
34-
const MachineLoopInfo &MLI,
35-
const MachineBlockFrequencyInfo &MBFI,
36-
VirtRegAuxInfo::NormalizingFn norm) {
31+
void VirtRegAuxInfo::calculateSpillWeightsAndHints() {
3732
LLVM_DEBUG(dbgs() << "********** Compute Spill Weights **********\n"
3833
<< "********** Function: " << MF.getName() << '\n');
3934

4035
MachineRegisterInfo &MRI = MF.getRegInfo();
41-
VirtRegAuxInfo VRAI(MF, LIS, VRM, MLI, MBFI, norm);
42-
for (unsigned i = 0, e = MRI.getNumVirtRegs(); i != e; ++i) {
43-
unsigned Reg = Register::index2VirtReg(i);
36+
for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
37+
unsigned Reg = Register::index2VirtReg(I);
4438
if (MRI.reg_nodbg_empty(Reg))
4539
continue;
46-
VRAI.calculateSpillWeightAndHint(LIS.getInterval(Reg));
40+
calculateSpillWeightAndHint(LIS.getInterval(Reg));
4741
}
4842
}
4943

llvm/lib/CodeGen/RegAllocBasic.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,9 @@ bool RABasic::runOnMachineFunction(MachineFunction &mf) {
311311
RegAllocBase::init(getAnalysis<VirtRegMap>(),
312312
getAnalysis<LiveIntervals>(),
313313
getAnalysis<LiveRegMatrix>());
314-
315-
calculateSpillWeightsAndHints(*LIS, *MF, VRM,
316-
getAnalysis<MachineLoopInfo>(),
317-
getAnalysis<MachineBlockFrequencyInfo>());
314+
VirtRegAuxInfo VRAI(*MF, *LIS, VRM, getAnalysis<MachineLoopInfo>(),
315+
getAnalysis<MachineBlockFrequencyInfo>());
316+
VRAI.calculateSpillWeightsAndHints();
318317

319318
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));
320319

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class RAGreedy : public MachineFunctionPass,
172172
std::unique_ptr<Spiller> SpillerInstance;
173173
PQueue Queue;
174174
unsigned NextCascade;
175+
std::unique_ptr<VirtRegAuxInfo> VRAI;
175176

176177
// Live ranges pass through a number of stages as we try to allocate them.
177178
// Some of the stages may also create new live ranges:
@@ -1507,10 +1508,9 @@ bool RAGreedy::splitCanCauseEvictionChain(unsigned Evictee,
15071508
// Now, check to see if the local interval we will create is going to be
15081509
// expensive enough to evict somebody If so, this may cause a bad eviction
15091510
// chain.
1510-
VirtRegAuxInfo VRAI(*MF, *LIS, VRM, getAnalysis<MachineLoopInfo>(), *MBFI);
15111511
float splitArtifactWeight =
1512-
VRAI.futureWeight(LIS->getInterval(Evictee),
1513-
Cand.Intf.first().getPrevIndex(), Cand.Intf.last());
1512+
VRAI->futureWeight(LIS->getInterval(Evictee),
1513+
Cand.Intf.first().getPrevIndex(), Cand.Intf.last());
15141514
if (splitArtifactWeight >= 0 && splitArtifactWeight < MaxWeight)
15151515
return false;
15161516

@@ -1550,10 +1550,9 @@ bool RAGreedy::splitCanCauseLocalSpill(unsigned VirtRegToSplit,
15501550

15511551
// Have we found an interval that can be evicted?
15521552
if (FutureEvictedPhysReg) {
1553-
VirtRegAuxInfo VRAI(*MF, *LIS, VRM, getAnalysis<MachineLoopInfo>(), *MBFI);
15541553
float splitArtifactWeight =
1555-
VRAI.futureWeight(LIS->getInterval(VirtRegToSplit),
1556-
Cand.Intf.first().getPrevIndex(), Cand.Intf.last());
1554+
VRAI->futureWeight(LIS->getInterval(VirtRegToSplit),
1555+
Cand.Intf.first().getPrevIndex(), Cand.Intf.last());
15571556
// Will the weight of the local interval be higher than the cheapest evictee
15581557
// weight? If so it will evict it and will not cause a spill.
15591558
if (splitArtifactWeight >= 0 && splitArtifactWeight > CheapestEvictWeight)
@@ -3228,7 +3227,9 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
32283227

32293228
initializeCSRCost();
32303229

3231-
calculateSpillWeightsAndHints(*LIS, mf, VRM, *Loops, *MBFI);
3230+
VRAI = std::make_unique<VirtRegAuxInfo>(*MF, *LIS, VRM, *Loops, *MBFI);
3231+
3232+
VRAI->calculateSpillWeightsAndHints();
32323233

32333234
LLVM_DEBUG(LIS->dump());
32343235

llvm/lib/CodeGen/RegAllocPBQP.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,9 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
792792

793793
VirtRegMap &VRM = getAnalysis<VirtRegMap>();
794794

795-
calculateSpillWeightsAndHints(LIS, MF, &VRM, getAnalysis<MachineLoopInfo>(),
796-
MBFI, normalizePBQPSpillWeight);
795+
VirtRegAuxInfo VRAI(MF, LIS, &VRM, getAnalysis<MachineLoopInfo>(), MBFI,
796+
normalizePBQPSpillWeight);
797+
VRAI.calculateSpillWeightsAndHints();
797798

798799
std::unique_ptr<Spiller> VRegSpiller(createInlineSpiller(*this, MF, VRM));
799800

0 commit comments

Comments
 (0)