Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions llvm/lib/CodeGen/CalcSpillWeights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,

// CopyHint is a sortable hint derived from a COPY instruction.
struct CopyHint {
const Register Reg;
const float Weight;
Register Reg;
float Weight;
CopyHint(Register R, float W) : Reg(R), Weight(W) {}
bool operator<(const CopyHint &Rhs) const {
// Always prefer any physreg hint.
Expand All @@ -223,8 +223,7 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
};

bool IsExiting = false;
std::set<CopyHint> CopyHints;
SmallDenseMap<unsigned, float, 8> Hint;
SmallDenseMap<Register, float, 8> Hint;
for (MachineRegisterInfo::reg_instr_nodbg_iterator
I = MRI.reg_instr_nodbg_begin(LI.reg()),
E = MRI.reg_instr_nodbg_end();
Expand Down Expand Up @@ -260,8 +259,7 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
return -1.0f;
}

// Force Weight onto the stack so that x86 doesn't add hidden precision,
// similar to HWeight below.
// Force Weight onto the stack so that x86 doesn't add hidden precision.
stack_float_t Weight = 1.0f;
if (IsSpillable) {
// Get loop info for mi.
Expand All @@ -287,29 +285,26 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
if (!TII.isCopyInstr(*MI))
continue;
Register HintReg = copyHint(MI, LI.reg(), TRI, MRI);
if (!HintReg)
continue;
// Force HWeight onto the stack so that x86 doesn't add hidden precision,
// making the comparison incorrectly pass (i.e., 1 > 1 == true??).
stack_float_t HWeight = Hint[HintReg] += Weight;
if (HintReg.isVirtual() || MRI.isAllocatable(HintReg))
CopyHints.insert(CopyHint(HintReg, HWeight));
if (HintReg && (HintReg.isVirtual() || MRI.isAllocatable(HintReg)))
Hint[HintReg] += Weight;
}

// Pass all the sorted copy hints to mri.
if (ShouldUpdateLI && CopyHints.size()) {
if (ShouldUpdateLI && Hint.size()) {
// Remove a generic hint if previously added by target.
if (TargetHint.first == 0 && TargetHint.second)
MRI.clearSimpleHint(LI.reg());

SmallSet<Register, 4> HintedRegs;
for (const auto &Hint : CopyHints) {
if (!HintedRegs.insert(Hint.Reg).second ||
(TargetHint.first != 0 && Hint.Reg == TargetHint.second))
// Don't add the same reg twice or the target-type hint again.
continue;
MRI.addRegAllocationHint(LI.reg(), Hint.Reg);
// Don't add the target-type hint again.
Register SkipReg = TargetHint.first != 0 ? TargetHint.second : Register();
SmallVector<CopyHint, 8> RegHints;
for (const auto &[Reg, Weight] : Hint) {
if (Reg != SkipReg)
RegHints.emplace_back(Reg, Weight);
}
sort(RegHints);
for (const auto &[Reg, Weight] : RegHints)
MRI.addRegAllocationHint(LI.reg(), Reg);

// Weakly boost the spill weight of hinted registers.
TotalWeight *= 1.01F;
Expand Down
Loading