1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

[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
This commit is contained in:
Mircea Trofin 2020-09-29 09:09:25 -07:00
parent 034d4ae31a
commit e13a3a826a
5 changed files with 22 additions and 33 deletions

View File

@ -91,17 +91,11 @@ class VirtRegMap;
/// \return The spill weight. Returns negative weight for unspillable li. /// \return The spill weight. Returns negative weight for unspillable li.
float weightCalcHelper(LiveInterval &li, SlotIndex *start = nullptr, float weightCalcHelper(LiveInterval &li, SlotIndex *start = nullptr,
SlotIndex *end = nullptr); SlotIndex *end = nullptr);
};
/// Compute spill weights and allocation hints for all virtual register /// Compute spill weights and allocation hints for all virtual register
/// live intervals. /// live intervals.
void calculateSpillWeightsAndHints(LiveIntervals &LIS, MachineFunction &MF, void calculateSpillWeightsAndHints();
VirtRegMap *VRM, };
const MachineLoopInfo &MLI,
const MachineBlockFrequencyInfo &MBFI,
VirtRegAuxInfo::NormalizingFn norm =
normalizeSpillWeight);
} // end namespace llvm } // end namespace llvm
#endif // LLVM_CODEGEN_CALCSPILLWEIGHTS_H #endif // LLVM_CODEGEN_CALCSPILLWEIGHTS_H

View File

@ -28,22 +28,16 @@ using namespace llvm;
#define DEBUG_TYPE "calcspillweights" #define DEBUG_TYPE "calcspillweights"
void llvm::calculateSpillWeightsAndHints(LiveIntervals &LIS, void VirtRegAuxInfo::calculateSpillWeightsAndHints() {
MachineFunction &MF,
VirtRegMap *VRM,
const MachineLoopInfo &MLI,
const MachineBlockFrequencyInfo &MBFI,
VirtRegAuxInfo::NormalizingFn norm) {
LLVM_DEBUG(dbgs() << "********** Compute Spill Weights **********\n" LLVM_DEBUG(dbgs() << "********** Compute Spill Weights **********\n"
<< "********** Function: " << MF.getName() << '\n'); << "********** Function: " << MF.getName() << '\n');
MachineRegisterInfo &MRI = MF.getRegInfo(); MachineRegisterInfo &MRI = MF.getRegInfo();
VirtRegAuxInfo VRAI(MF, LIS, VRM, MLI, MBFI, norm); for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
for (unsigned i = 0, e = MRI.getNumVirtRegs(); i != e; ++i) { unsigned Reg = Register::index2VirtReg(I);
unsigned Reg = Register::index2VirtReg(i);
if (MRI.reg_nodbg_empty(Reg)) if (MRI.reg_nodbg_empty(Reg))
continue; continue;
VRAI.calculateSpillWeightAndHint(LIS.getInterval(Reg)); calculateSpillWeightAndHint(LIS.getInterval(Reg));
} }
} }

View File

@ -311,10 +311,9 @@ bool RABasic::runOnMachineFunction(MachineFunction &mf) {
RegAllocBase::init(getAnalysis<VirtRegMap>(), RegAllocBase::init(getAnalysis<VirtRegMap>(),
getAnalysis<LiveIntervals>(), getAnalysis<LiveIntervals>(),
getAnalysis<LiveRegMatrix>()); getAnalysis<LiveRegMatrix>());
VirtRegAuxInfo VRAI(*MF, *LIS, VRM, getAnalysis<MachineLoopInfo>(),
calculateSpillWeightsAndHints(*LIS, *MF, VRM,
getAnalysis<MachineLoopInfo>(),
getAnalysis<MachineBlockFrequencyInfo>()); getAnalysis<MachineBlockFrequencyInfo>());
VRAI.calculateSpillWeightsAndHints();
SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM)); SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));

View File

@ -172,6 +172,7 @@ class RAGreedy : public MachineFunctionPass,
std::unique_ptr<Spiller> SpillerInstance; std::unique_ptr<Spiller> SpillerInstance;
PQueue Queue; PQueue Queue;
unsigned NextCascade; unsigned NextCascade;
std::unique_ptr<VirtRegAuxInfo> VRAI;
// Live ranges pass through a number of stages as we try to allocate them. // Live ranges pass through a number of stages as we try to allocate them.
// Some of the stages may also create new live ranges: // Some of the stages may also create new live ranges:
@ -1507,9 +1508,8 @@ bool RAGreedy::splitCanCauseEvictionChain(unsigned Evictee,
// Now, check to see if the local interval we will create is going to be // Now, check to see if the local interval we will create is going to be
// expensive enough to evict somebody If so, this may cause a bad eviction // expensive enough to evict somebody If so, this may cause a bad eviction
// chain. // chain.
VirtRegAuxInfo VRAI(*MF, *LIS, VRM, getAnalysis<MachineLoopInfo>(), *MBFI);
float splitArtifactWeight = float splitArtifactWeight =
VRAI.futureWeight(LIS->getInterval(Evictee), VRAI->futureWeight(LIS->getInterval(Evictee),
Cand.Intf.first().getPrevIndex(), Cand.Intf.last()); Cand.Intf.first().getPrevIndex(), Cand.Intf.last());
if (splitArtifactWeight >= 0 && splitArtifactWeight < MaxWeight) if (splitArtifactWeight >= 0 && splitArtifactWeight < MaxWeight)
return false; return false;
@ -1550,9 +1550,8 @@ bool RAGreedy::splitCanCauseLocalSpill(unsigned VirtRegToSplit,
// Have we found an interval that can be evicted? // Have we found an interval that can be evicted?
if (FutureEvictedPhysReg) { if (FutureEvictedPhysReg) {
VirtRegAuxInfo VRAI(*MF, *LIS, VRM, getAnalysis<MachineLoopInfo>(), *MBFI);
float splitArtifactWeight = float splitArtifactWeight =
VRAI.futureWeight(LIS->getInterval(VirtRegToSplit), VRAI->futureWeight(LIS->getInterval(VirtRegToSplit),
Cand.Intf.first().getPrevIndex(), Cand.Intf.last()); Cand.Intf.first().getPrevIndex(), Cand.Intf.last());
// Will the weight of the local interval be higher than the cheapest evictee // Will the weight of the local interval be higher than the cheapest evictee
// weight? If so it will evict it and will not cause a spill. // weight? If so it will evict it and will not cause a spill.
@ -3228,7 +3227,9 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
initializeCSRCost(); initializeCSRCost();
calculateSpillWeightsAndHints(*LIS, mf, VRM, *Loops, *MBFI); VRAI = std::make_unique<VirtRegAuxInfo>(*MF, *LIS, VRM, *Loops, *MBFI);
VRAI->calculateSpillWeightsAndHints();
LLVM_DEBUG(LIS->dump()); LLVM_DEBUG(LIS->dump());

View File

@ -792,8 +792,9 @@ bool RegAllocPBQP::runOnMachineFunction(MachineFunction &MF) {
VirtRegMap &VRM = getAnalysis<VirtRegMap>(); VirtRegMap &VRM = getAnalysis<VirtRegMap>();
calculateSpillWeightsAndHints(LIS, MF, &VRM, getAnalysis<MachineLoopInfo>(), VirtRegAuxInfo VRAI(MF, LIS, &VRM, getAnalysis<MachineLoopInfo>(), MBFI,
MBFI, normalizePBQPSpillWeight); normalizePBQPSpillWeight);
VRAI.calculateSpillWeightsAndHints();
std::unique_ptr<Spiller> VRegSpiller(createInlineSpiller(*this, MF, VRM)); std::unique_ptr<Spiller> VRegSpiller(createInlineSpiller(*this, MF, VRM));