Use struct SDep instead of std::pair for SUnit pred and succ lists. First step
authorEvan Cheng <evan.cheng@apple.com>
Wed, 19 Sep 2007 01:38:40 +0000 (01:38 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 19 Sep 2007 01:38:40 +0000 (01:38 +0000)
in tracking physical register output dependencies.

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

include/llvm/CodeGen/ScheduleDAG.h
lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
lib/CodeGen/SelectionDAG/ScheduleDAGList.cpp
lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp
lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp

index fdae9273e780e1c74b40f5341d9d4dfcb7879791..17938d784a11d6ce0d712cac7ce93e931c1d9480 100644 (file)
@@ -22,6 +22,7 @@
 
 namespace llvm {
   struct InstrStage;
+  struct SUnit;
   class MachineConstantPool;
   class MachineModuleInfo;
   class MachineInstr;
@@ -74,7 +75,18 @@ namespace llvm {
     virtual void EmitNoop() {
     }
   };
-  
+
+  /// SDep - Scheduling dependency. It keeps track of dependent nodes,
+  /// cost of the depdenency, etc.
+  struct SDep {
+    SUnit    *Dep;      // Dependent - either a predecessor or a successor.
+    bool      isCtrl;   // True iff it's a control dependency.
+    unsigned  PhyReg;   // If non-zero, this dep is a phy register dependency.
+    int       Cost;     // Cost of the dependency.
+    SDep(SUnit *d, bool c, unsigned r, int t)
+      : Dep(d), isCtrl(c), PhyReg(r), Cost(t) {}
+  };
+
   /// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
   /// a group of nodes flagged together.
   struct SUnit {
@@ -83,15 +95,13 @@ namespace llvm {
     
     // Preds/Succs - The SUnits before/after us in the graph.  The boolean value
     // is true if the edge is a token chain edge, false if it is a value edge. 
-    SmallVector<std::pair<SUnit*,bool>, 4> Preds;  // All sunit predecessors.
-    SmallVector<std::pair<SUnit*,bool>, 4> Succs;  // All sunit successors.
-
-    typedef SmallVector<std::pair<SUnit*,bool>, 4>::iterator pred_iterator;
-    typedef SmallVector<std::pair<SUnit*,bool>, 4>::iterator succ_iterator;
-    typedef SmallVector<std::pair<SUnit*,bool>, 4>::const_iterator 
-      const_pred_iterator;
-    typedef SmallVector<std::pair<SUnit*,bool>, 4>::const_iterator 
-      const_succ_iterator;
+    SmallVector<SDep, 4> Preds;  // All sunit predecessors.
+    SmallVector<SDep, 4> Succs;  // All sunit successors.
+
+    typedef SmallVector<SDep, 4>::iterator pred_iterator;
+    typedef SmallVector<SDep, 4>::iterator succ_iterator;
+    typedef SmallVector<SDep, 4>::const_iterator const_pred_iterator;
+    typedef SmallVector<SDep, 4>::const_iterator const_succ_iterator;
     
     short NumPreds;                     // # of preds.
     short NumSuccs;                     // # of sucss.
@@ -121,21 +131,21 @@ namespace llvm {
     
     /// addPred - This adds the specified node as a pred of the current node if
     /// not already.  This returns true if this is a new pred.
-    bool addPred(SUnit *N, bool isChain) {
+    bool addPred(SUnit *N, bool isCtrl, unsigned PhyReg = 0, int Cost = 1) {
       for (unsigned i = 0, e = Preds.size(); i != e; ++i)
-        if (Preds[i].first == N && Preds[i].second == isChain)
+        if (Preds[i].Dep == N && Preds[i].isCtrl == isCtrl)
           return false;
-      Preds.push_back(std::make_pair(N, isChain));
+      Preds.push_back(SDep(N, isCtrl, PhyReg, Cost));
       return true;
     }
 
     /// addSucc - This adds the specified node as a succ of the current node if
     /// not already.  This returns true if this is a new succ.
-    bool addSucc(SUnit *N, bool isChain) {
+    bool addSucc(SUnit *N, bool isCtrl, unsigned PhyReg = 0, int Cost = 1) {
       for (unsigned i = 0, e = Succs.size(); i != e; ++i)
-        if (Succs[i].first == N && Succs[i].second == isChain)
+        if (Succs[i].Dep == N && Succs[i].isCtrl == isCtrl)
           return false;
-      Succs.push_back(std::make_pair(N, isChain));
+      Succs.push_back(SDep(N, isCtrl, PhyReg, Cost));
       return true;
     }
     
@@ -340,7 +350,7 @@ namespace llvm {
     }
 
     pointer operator*() const {
-      return Node->Preds[Operand].first;
+      return Node->Preds[Operand].Dep;
     }
     pointer operator->() const { return operator*(); }
 
@@ -359,7 +369,7 @@ namespace llvm {
 
     unsigned getOperand() const { return Operand; }
     const SUnit *getNode() const { return Node; }
-    bool isChain() const { return Node->Preds[Operand].second; }
+    bool isCtrlDep() const { return Node->Preds[Operand].isCtrl; }
   };
 
   template <> struct GraphTraits<SUnit*> {
index 070fdbdc705c8d5ef035e4eba104ba9a69d13205..13465957b986ab7c5f866e73f466984a76b90133 100644 (file)
@@ -193,7 +193,7 @@ void ScheduleDAG::CalculateDepths() {
       SU->Depth = Depth;
       for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
            I != E; ++I)
-        WorkList.push_back(std::make_pair(I->first, Depth+1));
+        WorkList.push_back(std::make_pair(I->Dep, Depth+1));
     }
   }
 }
@@ -211,7 +211,7 @@ void ScheduleDAG::CalculateHeights() {
       SU->Height = Height;
       for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
            I != E; ++I)
-        WorkList.push_back(std::make_pair(I->first, Height+1));
+        WorkList.push_back(std::make_pair(I->Dep, Height+1));
     }
   }
 }
@@ -865,22 +865,22 @@ void SUnit::dumpAll(const SelectionDAG *G) const {
     cerr << "  Predecessors:\n";
     for (SUnit::const_succ_iterator I = Preds.begin(), E = Preds.end();
          I != E; ++I) {
-      if (I->second)
+      if (I->isCtrl)
         cerr << "   ch  #";
       else
         cerr << "   val #";
-      cerr << I->first << " - SU(" << I->first->NodeNum << ")\n";
+      cerr << I->Dep << " - SU(" << I->Dep->NodeNum << ")\n";
     }
   }
   if (Succs.size() != 0) {
     cerr << "  Successors:\n";
     for (SUnit::const_succ_iterator I = Succs.begin(), E = Succs.end();
          I != E; ++I) {
-      if (I->second)
+      if (I->isCtrl)
         cerr << "   ch  #";
       else
         cerr << "   val #";
-      cerr << I->first << " - SU(" << I->first->NodeNum << ")\n";
+      cerr << I->Dep << " - SU(" << I->Dep->NodeNum << ")\n";
     }
   }
   cerr << "\n";
index 9e4e46f1cc7568c48b6dee9324f1f47d556f5a4f..7b0974946236ae90a621239af96cd08db2c22b04 100644 (file)
@@ -134,9 +134,9 @@ void ScheduleDAGList::ReleaseSucc(SUnit *SuccSU, bool isChain) {
       // If this is a token edge, we don't need to wait for the latency of the
       // preceeding instruction (e.g. a long-latency load) unless there is also
       // some other data dependence.
-      SUnit &Pred = *I->first;
+      SUnit &Pred = *I->Dep;
       unsigned PredDoneCycle = Pred.Cycle;
-      if (!I->second)
+      if (!I->isCtrl)
         PredDoneCycle += Pred.Latency;
       else if (Pred.Latency)
         PredDoneCycle += 1;
@@ -161,7 +161,7 @@ void ScheduleDAGList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) {
   // Bottom up: release successors.
   for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
        I != E; ++I)
-    ReleaseSucc(I->first, I->second);
+    ReleaseSucc(I->Dep, I->isCtrl);
 }
 
 /// ListScheduleTopDown - The main loop of list scheduling for top-down
@@ -436,7 +436,7 @@ int LatencyPriorityQueue::CalcLatency(const SUnit &SU) {
   int MaxSuccLatency = 0;
   for (SUnit::const_succ_iterator I = SU.Succs.begin(), E = SU.Succs.end();
        I != E; ++I)
-    MaxSuccLatency = std::max(MaxSuccLatency, CalcLatency(*I->first));
+    MaxSuccLatency = std::max(MaxSuccLatency, CalcLatency(*I->Dep));
 
   return Latency = MaxSuccLatency + SU.Latency;
 }
@@ -456,7 +456,7 @@ SUnit *LatencyPriorityQueue::getSingleUnscheduledPred(SUnit *SU) {
   SUnit *OnlyAvailablePred = 0;
   for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
        I != E; ++I) {
-    SUnit &Pred = *I->first;
+    SUnit &Pred = *I->Dep;
     if (!Pred.isScheduled) {
       // We found an available, but not scheduled, predecessor.  If it's the
       // only one we have found, keep track of it... otherwise give up.
@@ -475,7 +475,7 @@ void LatencyPriorityQueue::push_impl(SUnit *SU) {
   unsigned NumNodesBlocking = 0;
   for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
        I != E; ++I)
-    if (getSingleUnscheduledPred(I->first) == SU)
+    if (getSingleUnscheduledPred(I->Dep) == SU)
       ++NumNodesBlocking;
   NumNodesSolelyBlocking[SU->NodeNum] = NumNodesBlocking;
   
@@ -490,7 +490,7 @@ void LatencyPriorityQueue::push_impl(SUnit *SU) {
 void LatencyPriorityQueue::ScheduledNode(SUnit *SU) {
   for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
        I != E; ++I)
-    AdjustPriorityOfUnscheduledPreds(I->first);
+    AdjustPriorityOfUnscheduledPreds(I->Dep);
 }
 
 /// AdjustPriorityOfUnscheduledPreds - One of the predecessors of SU was just
index 8c8648d63a0158c7477fe6223c02acf12390c2ee..ea23c278bab50f55014f640ac6ee57198c6889f7 100644 (file)
@@ -157,8 +157,8 @@ void ScheduleDAGRRList::CommuteNodesToReducePressure() {
 
     for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
          I != E; ++I) {
-      if (!I->second)
-        OperandSeen.insert(I->first);
+      if (!I->isCtrl)
+        OperandSeen.insert(I->Dep);
     }
   }
 }
@@ -214,7 +214,7 @@ void ScheduleDAGRRList::ScheduleNodeBottomUp(SUnit *SU, unsigned CurCycle) {
   // Bottom up: release predecessors
   for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
        I != E; ++I)
-    ReleasePred(I->first, I->second, CurCycle);
+    ReleasePred(I->Dep, I->isCtrl, CurCycle);
   SU->isScheduled = true;
 }
 
@@ -325,7 +325,7 @@ void ScheduleDAGRRList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) {
   // Top down: release successors
   for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
        I != E; ++I)
-    ReleaseSucc(I->first, I->second, CurCycle);
+    ReleaseSucc(I->Dep, I->isCtrl, CurCycle);
   SU->isScheduled = true;
 }
 
@@ -584,11 +584,11 @@ static unsigned closestSucc(const SUnit *SU) {
   unsigned MaxCycle = 0;
   for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
        I != E; ++I) {
-    unsigned Cycle = I->first->Cycle;
+    unsigned Cycle = I->Dep->Cycle;
     // If there are bunch of CopyToRegs stacked up, they should be considered
     // to be at the same position.
-    if (I->first->Node->getOpcode() == ISD::CopyToReg)
-      Cycle = closestSucc(I->first)+1;
+    if (I->Dep->Node->getOpcode() == ISD::CopyToReg)
+      Cycle = closestSucc(I->Dep)+1;
     if (Cycle > MaxCycle)
       MaxCycle = Cycle;
   }
@@ -602,14 +602,14 @@ 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->second) continue;  // ignore chain preds
-    if (I->first->Node->getOpcode() != ISD::CopyFromReg)
+    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->second) continue;  // ignore chain succs
-    if (I->first->Node->getOpcode() != ISD::CopyToReg)
+    if (I->isCtrl) continue;  // ignore chain succs
+    if (I->Dep->Node->getOpcode() != ISD::CopyToReg)
       Scratches += 10;
   }
   return Scratches;
@@ -691,7 +691,7 @@ static void isReachable(SUnit *SU, SUnit *TargetSU,
 
   for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); I != E;
        ++I)
-    isReachable(I->first, TargetSU, Visited, Reached);
+    isReachable(I->Dep, TargetSU, Visited, Reached);
 }
 
 static bool isReachable(SUnit *SU, SUnit *TargetSU) {
@@ -744,8 +744,8 @@ void BURegReductionPriorityQueue<SF>::AddPseudoTwoAddrDeps() {
         if (!DUSU) continue;
         for (SUnit::succ_iterator I = DUSU->Succs.begin(),E = DUSU->Succs.end();
              I != E; ++I) {
-          if (I->second) continue;
-          SUnit *SuccSU = I->first;
+          if (I->isCtrl) continue;
+          SUnit *SuccSU = I->Dep;
           if (SuccSU != SU &&
               (!canClobber(SuccSU, DUSU) ||
                (!SU->isCommutable && SuccSU->isCommutable))){
@@ -776,13 +776,13 @@ CalcNodeSethiUllmanNumber(const SUnit *SU) {
   unsigned Extra = 0;
   for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
        I != E; ++I) {
-    if (I->second) continue;  // ignore chain preds
-    SUnit *PredSU = I->first;
+    if (I->isCtrl) continue;  // ignore chain preds
+    SUnit *PredSU = I->Dep;
     unsigned PredSethiUllman = CalcNodeSethiUllmanNumber(PredSU);
     if (PredSethiUllman > SethiUllmanNumber) {
       SethiUllmanNumber = PredSethiUllman;
       Extra = 0;
-    } else if (PredSethiUllman == SethiUllmanNumber && !I->second)
+    } else if (PredSethiUllman == SethiUllmanNumber && !I->isCtrl)
       Extra++;
   }
 
@@ -808,10 +808,10 @@ static unsigned SumOfUnscheduledPredsOfSuccs(const SUnit *SU) {
   unsigned Sum = 0;
   for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
        I != E; ++I) {
-    SUnit *SuccSU = I->first;
+    SUnit *SuccSU = I->Dep;
     for (SUnit::const_pred_iterator II = SuccSU->Preds.begin(),
          EE = SuccSU->Preds.end(); II != EE; ++II) {
-      SUnit *PredSU = II->first;
+      SUnit *PredSU = II->Dep;
       if (!PredSU->isScheduled)
         Sum++;
     }
@@ -899,13 +899,13 @@ CalcNodeSethiUllmanNumber(const SUnit *SU) {
     int Extra = 0;
     for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
          I != E; ++I) {
-      if (I->second) continue;  // ignore chain preds
-      SUnit *PredSU = I->first;
+      if (I->isCtrl) continue;  // ignore chain preds
+      SUnit *PredSU = I->Dep;
       unsigned PredSethiUllman = CalcNodeSethiUllmanNumber(PredSU);
       if (PredSethiUllman > SethiUllmanNumber) {
         SethiUllmanNumber = PredSethiUllman;
         Extra = 0;
-      } else if (PredSethiUllman == SethiUllmanNumber && !I->second)
+      } else if (PredSethiUllman == SethiUllmanNumber && !I->isCtrl)
         Extra++;
     }
 
index d03439b4c44273b4d76f49016b67d44f01147cbc..73902b870b995a45df7c0ec682caf3e8c93a82af 100644 (file)
@@ -264,7 +264,7 @@ namespace llvm {
     /// edge, override this method.
     template<typename EdgeIter>
     static std::string getEdgeAttributes(const void *Node, EdgeIter EI) {
-      if (EI.isChain())
+      if (EI.isCtrlDep())
         return "color=blue,style=dashed";
       return "";
     }