MIsched: Added biasCriticalPath.
authorAndrew Trick <atrick@apple.com>
Thu, 24 Jan 2013 02:09:55 +0000 (02:09 +0000)
committerAndrew Trick <atrick@apple.com>
Thu, 24 Jan 2013 02:09:55 +0000 (02:09 +0000)
Allow schedulers to order DAG edges by critical path. This makes
DFS-based heuristics more stable and effective.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173317 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/ScheduleDAG.h
lib/CodeGen/ScheduleDAG.cpp

index aa91b0300ac4a709547a535c767f6e9d4325d18e..9f4f66f860e70635908b53c4c0309dfe46833e91 100644 (file)
@@ -455,6 +455,10 @@ namespace llvm {
       return NumSuccsLeft == 0;
     }
 
+    /// \brief Order this node's predecessor edges such that the critical path
+    /// edge occurs first.
+    void biasCriticalPath();
+
     void dump(const ScheduleDAG *G) const;
     void dumpAll(const ScheduleDAG *G) const;
     void print(raw_ostream &O, const ScheduleDAG *G) const;
index e639c55a04f1979d2288507654eebe1dd98767e4..70ad94957133e99ad5f62fd3658eb6f57f72d267 100644 (file)
@@ -301,6 +301,21 @@ void SUnit::ComputeHeight() {
   } while (!WorkList.empty());
 }
 
+void SUnit::biasCriticalPath() {
+  if (NumPreds < 2)
+    return;
+
+  SUnit::pred_iterator BestI = Preds.begin();
+  unsigned MaxDepth = BestI->getSUnit()->getDepth();
+  for (SUnit::pred_iterator
+         I = llvm::next(BestI), E = Preds.end(); I != E; ++I) {
+    if (I->getKind() == SDep::Data && I->getSUnit()->getDepth() > MaxDepth)
+      BestI = I;
+  }
+  if (BestI != Preds.begin())
+    std::swap(*Preds.begin(), *BestI);
+}
+
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 /// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
 /// a group of nodes flagged together.