[llvm] c11c20f - [NFC][Regalloc] VirtRegAuxInfo::Hint does not need to be a field

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 9 13:42:33 PDT 2020


Author: Mircea Trofin
Date: 2020-10-09T13:42:23-07:00
New Revision: c11c20fb0036bc8f69b2028422f050ee66acbb64

URL: https://github.com/llvm/llvm-project/commit/c11c20fb0036bc8f69b2028422f050ee66acbb64
DIFF: https://github.com/llvm/llvm-project/commit/c11c20fb0036bc8f69b2028422f050ee66acbb64.diff

LOG: [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).

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/CalcSpillWeights.h
    llvm/lib/CodeGen/CalcSpillWeights.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/CalcSpillWeights.h b/llvm/include/llvm/CodeGen/CalcSpillWeights.h
index a4deefca7565..c345c42c7774 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<unsigned, float> Hint;
 
   public:
     VirtRegAuxInfo(MachineFunction &MF, LiveIntervals &LIS, VirtRegMap *VRM,

diff  --git a/llvm/lib/CodeGen/CalcSpillWeights.cpp b/llvm/lib/CodeGen/CalcSpillWeights.cpp
index b096593ac620..03490643339f 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<MachineInstr *, 8> Visited;
 
-  std::pair<unsigned, unsigned> TargetHint = MRI.getRegAllocationHint(LI.reg());
+  std::pair<Register, Register> 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<CopyHint> CopyHints;
 
+  std::set<CopyHint> CopyHints;
+  DenseMap<unsigned, float> 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<unsigned> HintedRegs;
+    std::set<Register> HintedRegs;
     for (auto &Hint : CopyHints) {
       if (!HintedRegs.insert(Hint.Reg).second ||
           (TargetHint.first != 0 && Hint.Reg == TargetHint.second))


        


More information about the llvm-commits mailing list