From c11c20fb0036bc8f69b2028422f050ee66acbb64 Mon Sep 17 00:00:00 2001 From: Mircea Trofin Date: Fri, 9 Oct 2020 13:35:56 -0700 Subject: [PATCH] [NFC][Regalloc] VirtRegAuxInfo::Hint does not need to be a field It is only used in weightCalcHelper, and cleared upon its finishing its job there. The patch further cleans up style guide discrepancies, and simplifies CopyHint by removing duplicate 'IsPhys' information (it's what the Reg field would report). --- llvm/include/llvm/CodeGen/CalcSpillWeights.h | 1 - llvm/lib/CodeGen/CalcSpillWeights.cpp | 42 +++++++++++++--------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/llvm/include/llvm/CodeGen/CalcSpillWeights.h b/llvm/include/llvm/CodeGen/CalcSpillWeights.h index a4deefc..c345c42 100644 --- a/llvm/include/llvm/CodeGen/CalcSpillWeights.h +++ b/llvm/include/llvm/CodeGen/CalcSpillWeights.h @@ -49,7 +49,6 @@ class VirtRegMap; VirtRegMap *const VRM; const MachineLoopInfo &Loops; const MachineBlockFrequencyInfo &MBFI; - DenseMap Hint; public: VirtRegAuxInfo(MachineFunction &MF, LiveIntervals &LIS, VirtRegMap *VRM, diff --git a/llvm/lib/CodeGen/CalcSpillWeights.cpp b/llvm/lib/CodeGen/CalcSpillWeights.cpp index b096593..0349064 100644 --- a/llvm/lib/CodeGen/CalcSpillWeights.cpp +++ b/llvm/lib/CodeGen/CalcSpillWeights.cpp @@ -150,10 +150,10 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start, MachineLoop *Loop = nullptr; bool IsExiting = false; float TotalWeight = 0; - unsigned NumInstr = 0; // Number of instructions using li + unsigned NumInstr = 0; // Number of instructions using LI SmallPtrSet Visited; - std::pair TargetHint = MRI.getRegAllocationHint(LI.reg()); + std::pair TargetHint = MRI.getRegAllocationHint(LI.reg()); if (LI.isSpillable() && VRM) { Register Reg = LI.reg(); @@ -192,22 +192,21 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start, // CopyHint is a sortable hint derived from a COPY instruction. struct CopyHint { - unsigned Reg; - float Weight; - bool IsPhys; - CopyHint(unsigned R, float W, bool P) : - Reg(R), Weight(W), IsPhys(P) {} - bool operator<(const CopyHint &rhs) const { + const Register Reg; + const float Weight; + CopyHint(Register R, float W) : Reg(R), Weight(W) {} + bool operator<(const CopyHint &Rhs) const { // Always prefer any physreg hint. - if (IsPhys != rhs.IsPhys) - return (IsPhys && !rhs.IsPhys); - if (Weight != rhs.Weight) - return (Weight > rhs.Weight); - return Reg < rhs.Reg; // Tie-breaker. + if (Reg.isPhysical() != Rhs.Reg.isPhysical()) + return Reg.isPhysical(); + if (Weight != Rhs.Weight) + return (Weight > Rhs.Weight); + return Reg.id() < Rhs.Reg.id(); // Tie-breaker. } }; - std::set CopyHints; + std::set CopyHints; + DenseMap Hint; for (MachineRegisterInfo::reg_instr_nodbg_iterator I = MRI.reg_instr_nodbg_begin(LI.reg()), E = MRI.reg_instr_nodbg_end(); @@ -250,28 +249,25 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start, // Get allocation hints from copies. if (!MI->isCopy()) continue; - Register hint = copyHint(MI, LI.reg(), TRI, MRI); - if (!hint) + 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??). // // FIXME: we probably shouldn't use floats at all. - volatile float HWeight = Hint[hint] += Weight; - if (Register::isVirtualRegister(hint) || MRI.isAllocatable(hint)) - CopyHints.insert( - CopyHint(hint, HWeight, Register::isPhysicalRegister(hint))); + volatile float HWeight = Hint[HintReg] += Weight; + if (HintReg.isVirtual() || MRI.isAllocatable(HintReg)) + CopyHints.insert(CopyHint(HintReg, HWeight)); } - Hint.clear(); - // Pass all the sorted copy hints to mri. if (ShouldUpdateLI && CopyHints.size()) { // Remove a generic hint if previously added by target. if (TargetHint.first == 0 && TargetHint.second) MRI.clearSimpleHint(LI.reg()); - std::set HintedRegs; + std::set HintedRegs; for (auto &Hint : CopyHints) { if (!HintedRegs.insert(Hint.Reg).second || (TargetHint.first != 0 && Hint.Reg == TargetHint.second)) -- 2.7.4