[llvm-commits] [llvm] r45252 - /llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp

Evan Cheng evan.cheng at apple.com
Wed Dec 19 18:22:36 PST 2007


Author: evancheng
Date: Wed Dec 19 20:22:36 2007
New Revision: 45252

URL: http://llvm.org/viewvc/llvm-project?rev=45252&view=rev
Log:
Bring back a burr scheduling heuristic that's still needed.

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp?rev=45252&r1=45251&r2=45252&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp Wed Dec 19 20:22:36 2007
@@ -1198,6 +1198,26 @@
   return MaxCycle;
 }
 
+/// calcMaxScratches - Returns an cost estimate of the worse case requirement
+/// for scratch registers. Live-in operands and live-out results don't count
+/// since they are "fixed".
+static unsigned calcMaxScratches(const SUnit *SU) {
+  unsigned Scratches = 0;
+  for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
+       I != E; ++I) {
+    if (I->isCtrl) continue;  // ignore chain preds
+    if (I->Dep->Node->getOpcode() != ISD::CopyFromReg)
+      Scratches++;
+  }
+  for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
+       I != E; ++I) {
+    if (I->isCtrl) continue;  // ignore chain succs
+    if (I->Dep->Node->getOpcode() != ISD::CopyToReg)
+      Scratches += 10;
+  }
+  return Scratches;
+}
+
 // Bottom up
 bool bu_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const {
   // There used to be a special tie breaker here that looked for
@@ -1240,14 +1260,23 @@
     if (LDist < RDist)
       return true;
     else if (LDist == RDist) {
-      if (left->Height > right->Height)
+      // Intuitively, it's good to push down instructions whose results are
+      // liveout so their long live ranges won't conflict with other values
+      // which are needed inside the BB. Further prioritize liveout instructions
+      // by the number of operands which are calculated within the BB.
+      unsigned LScratch = calcMaxScratches(left);
+      unsigned RScratch = calcMaxScratches(right);
+      if (LScratch > RScratch)
         return true;
-      else if (left->Height == right->Height)
-        if (left->Depth < right->Depth)
+      else if (LScratch == RScratch)
+        if (left->Height > right->Height)
           return true;
-        else if (left->Depth == right->Depth)
-          if (left->CycleBound > right->CycleBound) 
+        else if (left->Height == right->Height)
+          if (left->Depth < right->Depth)
             return true;
+          else if (left->Depth == right->Depth)
+            if (left->CycleBound > right->CycleBound) 
+              return true;
     }
   }
   return false;





More information about the llvm-commits mailing list