Minor spiller tweak to unfavor reload into load/store instructions.
authorEvan Cheng <evan.cheng@apple.com>
Thu, 19 Jun 2008 01:16:17 +0000 (01:16 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Thu, 19 Jun 2008 01:16:17 +0000 (01:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52477 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/LiveIntervalAnalysis.h
include/llvm/CodeGen/MachineRegisterInfo.h
lib/CodeGen/LiveIntervalAnalysis.cpp

index 473cc8e099694acd35a1143580b46a2be7b7dd34..84c6d6791941c7930c9d01ce8c62d13ac1cf8769 100644 (file)
@@ -121,8 +121,12 @@ namespace llvm {
       return getBaseIndex(index) + InstrSlots::STORE;
     }
 
-    static float getSpillWeight(bool isDef, bool isUse, unsigned loopDepth) {
-      return (isDef + isUse) * powf(10.0F, (float)loopDepth);
+    static float getSpillWeight(bool isDef, bool isUse, bool isMem,
+                                unsigned loopDepth) {
+      float Weight = isDef;
+      if (isUse)
+        Weight += isMem ? 1.2f : 1.0f;
+      return Weight * powf(10.0F, (float)loopDepth);
     }
 
     typedef Reg2IntervalMap::iterator iterator;
index b93794c1be256404ef6986ea0bde52cdad8d1665..bfa6d1ccd0a6c7cb46ad8df41246ac017c6b651a 100644 (file)
@@ -135,6 +135,13 @@ public:
     assert(Reg < VRegInfo.size() && "Invalid vreg!");
     return VRegInfo[Reg].first;
   }
+
+  /// setRegClass - Set the register class of the specified virtual register.
+  void setRegClass(unsigned Reg, const TargetRegisterClass *RC) {
+    Reg -= TargetRegisterInfo::FirstVirtualRegister;
+    assert(Reg < VRegInfo.size() && "Invalid vreg!");
+    VRegInfo[Reg].first = RC;
+  }
   
   /// createVirtualRegister - Create and return a new virtual register in the
   /// function with the specified register class.
index 26f551386cf3e890ded381f45882bef6062a5761..94952d681251b6315246812a4199943e8ee4b7ed 100644 (file)
@@ -988,6 +988,7 @@ rewriteInstructionForSpills(const LiveInterval &li, const VNInfo *VNI,
   unsigned loopDepth = loopInfo->getLoopDepth(MBB);
   bool CanFold = false;
  RestartInstruction:
+  bool isMem = MI->getDesc().mayLoad() || MI->getDesc().mayStore();
   for (unsigned i = 0; i != MI->getNumOperands(); ++i) {
     MachineOperand& mop = MI->getOperand(i);
     if (!mop.isRegister())
@@ -1055,7 +1056,7 @@ rewriteInstructionForSpills(const LiveInterval &li, const VNInfo *VNI,
     }
 
     // Update stack slot spill weight if we are splitting.
-    float Weight = getSpillWeight(HasDef, HasUse, loopDepth);
+    float Weight = getSpillWeight(HasDef, HasUse, isMem, loopDepth);
       if (!TrySplit)
       SSWeight += Weight;
 
@@ -1248,6 +1249,7 @@ rewriteInstructionsForSpills(const LiveInterval &li, bool TrySplit,
     bool MIHasUse = rwi.HasUse;
     bool MIHasDef = rwi.HasDef;
     MachineInstr *MI = rwi.MI;
+    bool isMem = MI->getDesc().mayLoad() || MI->getDesc().mayStore();
     // If MI def and/or use the same register multiple times, then there
     // are multiple entries.
     unsigned NumUses = MIHasUse;
@@ -1395,7 +1397,7 @@ rewriteInstructionsForSpills(const LiveInterval &li, bool TrySplit,
 
     // Update spill weight.
     unsigned loopDepth = loopInfo->getLoopDepth(MBB);
-    nI.weight += getSpillWeight(HasDef, HasUse, loopDepth);
+    nI.weight += getSpillWeight(HasDef, HasUse, isMem, loopDepth);
   }
 
   if (NewVReg && TrySplit && AllCanFold) {
@@ -1637,6 +1639,7 @@ addIntervalsForSpills(const LiveInterval &li,
         LiveInterval &nI = getOrCreateInterval(VReg);
         bool isReMat = vrm.isReMaterialized(VReg);
         MachineInstr *MI = getInstructionFromIndex(index);
+        bool isMem = MI->getDesc().mayLoad() || MI->getDesc().mayStore();
         bool CanFold = false;
         bool FoundUse = false;
         Ops.clear();
@@ -1689,7 +1692,7 @@ addIntervalsForSpills(const LiveInterval &li,
 
         // Update spill slot weight.
         if (!isReMat)
-          SSWeight += getSpillWeight(true, false, loopDepth);
+          SSWeight += getSpillWeight(true, false, isMem, loopDepth);
       }
       Id = SpillMBBs.find_next(Id);
     }
@@ -1709,6 +1712,7 @@ addIntervalsForSpills(const LiveInterval &li,
       LiveInterval &nI = getOrCreateInterval(VReg);
       bool isReMat = vrm.isReMaterialized(VReg);
       MachineInstr *MI = getInstructionFromIndex(index);
+      bool isMem = MI->getDesc().mayLoad() || MI->getDesc().mayStore();
       bool CanFold = false;
       Ops.clear();
       if (restores[i].canFold) {
@@ -1762,7 +1766,7 @@ addIntervalsForSpills(const LiveInterval &li,
 
       // Update spill slot weight.
       if (!isReMat)
-        SSWeight += getSpillWeight(false, true, loopDepth);
+        SSWeight += getSpillWeight(false, true, isMem, loopDepth);
     }
     Id = RestoreMBBs.find_next(Id);
   }