70ad94957133e99ad5f62fd3658eb6f57f72d267
[oota-llvm.git] / lib / CodeGen / ScheduleDAG.cpp
1 //===---- ScheduleDAG.cpp - Implement the ScheduleDAG class ---------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This implements the ScheduleDAG class, which is a base class used by
11 // scheduling implementation classes.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #define DEBUG_TYPE "pre-RA-sched"
16 #include "llvm/CodeGen/ScheduleDAG.h"
17 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
18 #include "llvm/CodeGen/SelectionDAGNodes.h"
19 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Support/raw_ostream.h"
22 #include "llvm/Target/TargetInstrInfo.h"
23 #include "llvm/Target/TargetMachine.h"
24 #include "llvm/Target/TargetRegisterInfo.h"
25 #include <climits>
26 using namespace llvm;
27
28 #ifndef NDEBUG
29 static cl::opt<bool> StressSchedOpt(
30   "stress-sched", cl::Hidden, cl::init(false),
31   cl::desc("Stress test instruction scheduling"));
32 #endif
33
34 void SchedulingPriorityQueue::anchor() { }
35
36 ScheduleDAG::ScheduleDAG(MachineFunction &mf)
37   : TM(mf.getTarget()),
38     TII(TM.getInstrInfo()),
39     TRI(TM.getRegisterInfo()),
40     MF(mf), MRI(mf.getRegInfo()),
41     EntrySU(), ExitSU() {
42 #ifndef NDEBUG
43   StressSched = StressSchedOpt;
44 #endif
45 }
46
47 ScheduleDAG::~ScheduleDAG() {}
48
49 /// Clear the DAG state (e.g. between scheduling regions).
50 void ScheduleDAG::clearDAG() {
51   SUnits.clear();
52   EntrySU = SUnit();
53   ExitSU = SUnit();
54 }
55
56 /// getInstrDesc helper to handle SDNodes.
57 const MCInstrDesc *ScheduleDAG::getNodeDesc(const SDNode *Node) const {
58   if (!Node || !Node->isMachineOpcode()) return NULL;
59   return &TII->get(Node->getMachineOpcode());
60 }
61
62 /// addPred - This adds the specified edge as a pred of the current node if
63 /// not already.  It also adds the current node as a successor of the
64 /// specified node.
65 bool SUnit::addPred(const SDep &D, bool Required) {
66   // If this node already has this depenence, don't add a redundant one.
67   for (SmallVector<SDep, 4>::iterator I = Preds.begin(), E = Preds.end();
68        I != E; ++I) {
69     // Zero-latency weak edges may be added purely for heuristic ordering. Don't
70     // add them if another kind of edge already exists.
71     if (!Required && I->getSUnit() == D.getSUnit())
72       return false;
73     if (I->overlaps(D)) {
74       // Extend the latency if needed. Equivalent to removePred(I) + addPred(D).
75       if (I->getLatency() < D.getLatency()) {
76         SUnit *PredSU = I->getSUnit();
77         // Find the corresponding successor in N.
78         SDep ForwardD = *I;
79         ForwardD.setSUnit(this);
80         for (SmallVector<SDep, 4>::iterator II = PredSU->Succs.begin(),
81                EE = PredSU->Succs.end(); II != EE; ++II) {
82           if (*II == ForwardD) {
83             II->setLatency(D.getLatency());
84             break;
85           }
86         }
87         I->setLatency(D.getLatency());
88       }
89       return false;
90     }
91   }
92   // Now add a corresponding succ to N.
93   SDep P = D;
94   P.setSUnit(this);
95   SUnit *N = D.getSUnit();
96   // Update the bookkeeping.
97   if (D.getKind() == SDep::Data) {
98     assert(NumPreds < UINT_MAX && "NumPreds will overflow!");
99     assert(N->NumSuccs < UINT_MAX && "NumSuccs will overflow!");
100     ++NumPreds;
101     ++N->NumSuccs;
102   }
103   if (!N->isScheduled) {
104     if (D.isWeak()) {
105       ++WeakPredsLeft;
106     }
107     else {
108       assert(NumPredsLeft < UINT_MAX && "NumPredsLeft will overflow!");
109       ++NumPredsLeft;
110     }
111   }
112   if (!isScheduled) {
113     if (D.isWeak()) {
114       ++N->WeakSuccsLeft;
115     }
116     else {
117       assert(N->NumSuccsLeft < UINT_MAX && "NumSuccsLeft will overflow!");
118       ++N->NumSuccsLeft;
119     }
120   }
121   Preds.push_back(D);
122   N->Succs.push_back(P);
123   if (P.getLatency() != 0) {
124     this->setDepthDirty();
125     N->setHeightDirty();
126   }
127   return true;
128 }
129
130 /// removePred - This removes the specified edge as a pred of the current
131 /// node if it exists.  It also removes the current node as a successor of
132 /// the specified node.
133 void SUnit::removePred(const SDep &D) {
134   // Find the matching predecessor.
135   for (SmallVector<SDep, 4>::iterator I = Preds.begin(), E = Preds.end();
136        I != E; ++I)
137     if (*I == D) {
138       bool FoundSucc = false;
139       // Find the corresponding successor in N.
140       SDep P = D;
141       P.setSUnit(this);
142       SUnit *N = D.getSUnit();
143       for (SmallVector<SDep, 4>::iterator II = N->Succs.begin(),
144              EE = N->Succs.end(); II != EE; ++II)
145         if (*II == P) {
146           FoundSucc = true;
147           N->Succs.erase(II);
148           break;
149         }
150       assert(FoundSucc && "Mismatching preds / succs lists!");
151       (void)FoundSucc;
152       Preds.erase(I);
153       // Update the bookkeeping.
154       if (P.getKind() == SDep::Data) {
155         assert(NumPreds > 0 && "NumPreds will underflow!");
156         assert(N->NumSuccs > 0 && "NumSuccs will underflow!");
157         --NumPreds;
158         --N->NumSuccs;
159       }
160       if (!N->isScheduled) {
161         if (D.isWeak())
162           --WeakPredsLeft;
163         else {
164           assert(NumPredsLeft > 0 && "NumPredsLeft will underflow!");
165           --NumPredsLeft;
166         }
167       }
168       if (!isScheduled) {
169         if (D.isWeak())
170           --N->WeakSuccsLeft;
171         else {
172           assert(N->NumSuccsLeft > 0 && "NumSuccsLeft will underflow!");
173           --N->NumSuccsLeft;
174         }
175       }
176       if (P.getLatency() != 0) {
177         this->setDepthDirty();
178         N->setHeightDirty();
179       }
180       return;
181     }
182 }
183
184 void SUnit::setDepthDirty() {
185   if (!isDepthCurrent) return;
186   SmallVector<SUnit*, 8> WorkList;
187   WorkList.push_back(this);
188   do {
189     SUnit *SU = WorkList.pop_back_val();
190     SU->isDepthCurrent = false;
191     for (SUnit::const_succ_iterator I = SU->Succs.begin(),
192          E = SU->Succs.end(); I != E; ++I) {
193       SUnit *SuccSU = I->getSUnit();
194       if (SuccSU->isDepthCurrent)
195         WorkList.push_back(SuccSU);
196     }
197   } while (!WorkList.empty());
198 }
199
200 void SUnit::setHeightDirty() {
201   if (!isHeightCurrent) return;
202   SmallVector<SUnit*, 8> WorkList;
203   WorkList.push_back(this);
204   do {
205     SUnit *SU = WorkList.pop_back_val();
206     SU->isHeightCurrent = false;
207     for (SUnit::const_pred_iterator I = SU->Preds.begin(),
208          E = SU->Preds.end(); I != E; ++I) {
209       SUnit *PredSU = I->getSUnit();
210       if (PredSU->isHeightCurrent)
211         WorkList.push_back(PredSU);
212     }
213   } while (!WorkList.empty());
214 }
215
216 /// setDepthToAtLeast - Update this node's successors to reflect the
217 /// fact that this node's depth just increased.
218 ///
219 void SUnit::setDepthToAtLeast(unsigned NewDepth) {
220   if (NewDepth <= getDepth())
221     return;
222   setDepthDirty();
223   Depth = NewDepth;
224   isDepthCurrent = true;
225 }
226
227 /// setHeightToAtLeast - Update this node's predecessors to reflect the
228 /// fact that this node's height just increased.
229 ///
230 void SUnit::setHeightToAtLeast(unsigned NewHeight) {
231   if (NewHeight <= getHeight())
232     return;
233   setHeightDirty();
234   Height = NewHeight;
235   isHeightCurrent = true;
236 }
237
238 /// ComputeDepth - Calculate the maximal path from the node to the exit.
239 ///
240 void SUnit::ComputeDepth() {
241   SmallVector<SUnit*, 8> WorkList;
242   WorkList.push_back(this);
243   do {
244     SUnit *Cur = WorkList.back();
245
246     bool Done = true;
247     unsigned MaxPredDepth = 0;
248     for (SUnit::const_pred_iterator I = Cur->Preds.begin(),
249          E = Cur->Preds.end(); I != E; ++I) {
250       SUnit *PredSU = I->getSUnit();
251       if (PredSU->isDepthCurrent)
252         MaxPredDepth = std::max(MaxPredDepth,
253                                 PredSU->Depth + I->getLatency());
254       else {
255         Done = false;
256         WorkList.push_back(PredSU);
257       }
258     }
259
260     if (Done) {
261       WorkList.pop_back();
262       if (MaxPredDepth != Cur->Depth) {
263         Cur->setDepthDirty();
264         Cur->Depth = MaxPredDepth;
265       }
266       Cur->isDepthCurrent = true;
267     }
268   } while (!WorkList.empty());
269 }
270
271 /// ComputeHeight - Calculate the maximal path from the node to the entry.
272 ///
273 void SUnit::ComputeHeight() {
274   SmallVector<SUnit*, 8> WorkList;
275   WorkList.push_back(this);
276   do {
277     SUnit *Cur = WorkList.back();
278
279     bool Done = true;
280     unsigned MaxSuccHeight = 0;
281     for (SUnit::const_succ_iterator I = Cur->Succs.begin(),
282          E = Cur->Succs.end(); I != E; ++I) {
283       SUnit *SuccSU = I->getSUnit();
284       if (SuccSU->isHeightCurrent)
285         MaxSuccHeight = std::max(MaxSuccHeight,
286                                  SuccSU->Height + I->getLatency());
287       else {
288         Done = false;
289         WorkList.push_back(SuccSU);
290       }
291     }
292
293     if (Done) {
294       WorkList.pop_back();
295       if (MaxSuccHeight != Cur->Height) {
296         Cur->setHeightDirty();
297         Cur->Height = MaxSuccHeight;
298       }
299       Cur->isHeightCurrent = true;
300     }
301   } while (!WorkList.empty());
302 }
303
304 void SUnit::biasCriticalPath() {
305   if (NumPreds < 2)
306     return;
307
308   SUnit::pred_iterator BestI = Preds.begin();
309   unsigned MaxDepth = BestI->getSUnit()->getDepth();
310   for (SUnit::pred_iterator
311          I = llvm::next(BestI), E = Preds.end(); I != E; ++I) {
312     if (I->getKind() == SDep::Data && I->getSUnit()->getDepth() > MaxDepth)
313       BestI = I;
314   }
315   if (BestI != Preds.begin())
316     std::swap(*Preds.begin(), *BestI);
317 }
318
319 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
320 /// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
321 /// a group of nodes flagged together.
322 void SUnit::dump(const ScheduleDAG *G) const {
323   dbgs() << "SU(" << NodeNum << "): ";
324   G->dumpNode(this);
325 }
326
327 void SUnit::dumpAll(const ScheduleDAG *G) const {
328   dump(G);
329
330   dbgs() << "  # preds left       : " << NumPredsLeft << "\n";
331   dbgs() << "  # succs left       : " << NumSuccsLeft << "\n";
332   if (WeakPredsLeft)
333     dbgs() << "  # weak preds left  : " << WeakPredsLeft << "\n";
334   if (WeakSuccsLeft)
335     dbgs() << "  # weak succs left  : " << WeakSuccsLeft << "\n";
336   dbgs() << "  # rdefs left       : " << NumRegDefsLeft << "\n";
337   dbgs() << "  Latency            : " << Latency << "\n";
338   dbgs() << "  Depth              : " << Depth << "\n";
339   dbgs() << "  Height             : " << Height << "\n";
340
341   if (Preds.size() != 0) {
342     dbgs() << "  Predecessors:\n";
343     for (SUnit::const_succ_iterator I = Preds.begin(), E = Preds.end();
344          I != E; ++I) {
345       dbgs() << "   ";
346       switch (I->getKind()) {
347       case SDep::Data:        dbgs() << "val "; break;
348       case SDep::Anti:        dbgs() << "anti"; break;
349       case SDep::Output:      dbgs() << "out "; break;
350       case SDep::Order:       dbgs() << "ch  "; break;
351       }
352       dbgs() << "SU(" << I->getSUnit()->NodeNum << ")";
353       if (I->isArtificial())
354         dbgs() << " *";
355       dbgs() << ": Latency=" << I->getLatency();
356       if (I->isAssignedRegDep())
357         dbgs() << " Reg=" << PrintReg(I->getReg(), G->TRI);
358       dbgs() << "\n";
359     }
360   }
361   if (Succs.size() != 0) {
362     dbgs() << "  Successors:\n";
363     for (SUnit::const_succ_iterator I = Succs.begin(), E = Succs.end();
364          I != E; ++I) {
365       dbgs() << "   ";
366       switch (I->getKind()) {
367       case SDep::Data:        dbgs() << "val "; break;
368       case SDep::Anti:        dbgs() << "anti"; break;
369       case SDep::Output:      dbgs() << "out "; break;
370       case SDep::Order:       dbgs() << "ch  "; break;
371       }
372       dbgs() << "SU(" << I->getSUnit()->NodeNum << ")";
373       if (I->isArtificial())
374         dbgs() << " *";
375       dbgs() << ": Latency=" << I->getLatency();
376       dbgs() << "\n";
377     }
378   }
379   dbgs() << "\n";
380 }
381 #endif
382
383 #ifndef NDEBUG
384 /// VerifyScheduledDAG - Verify that all SUnits were scheduled and that
385 /// their state is consistent. Return the number of scheduled nodes.
386 ///
387 unsigned ScheduleDAG::VerifyScheduledDAG(bool isBottomUp) {
388   bool AnyNotSched = false;
389   unsigned DeadNodes = 0;
390   for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
391     if (!SUnits[i].isScheduled) {
392       if (SUnits[i].NumPreds == 0 && SUnits[i].NumSuccs == 0) {
393         ++DeadNodes;
394         continue;
395       }
396       if (!AnyNotSched)
397         dbgs() << "*** Scheduling failed! ***\n";
398       SUnits[i].dump(this);
399       dbgs() << "has not been scheduled!\n";
400       AnyNotSched = true;
401     }
402     if (SUnits[i].isScheduled &&
403         (isBottomUp ? SUnits[i].getHeight() : SUnits[i].getDepth()) >
404           unsigned(INT_MAX)) {
405       if (!AnyNotSched)
406         dbgs() << "*** Scheduling failed! ***\n";
407       SUnits[i].dump(this);
408       dbgs() << "has an unexpected "
409            << (isBottomUp ? "Height" : "Depth") << " value!\n";
410       AnyNotSched = true;
411     }
412     if (isBottomUp) {
413       if (SUnits[i].NumSuccsLeft != 0) {
414         if (!AnyNotSched)
415           dbgs() << "*** Scheduling failed! ***\n";
416         SUnits[i].dump(this);
417         dbgs() << "has successors left!\n";
418         AnyNotSched = true;
419       }
420     } else {
421       if (SUnits[i].NumPredsLeft != 0) {
422         if (!AnyNotSched)
423           dbgs() << "*** Scheduling failed! ***\n";
424         SUnits[i].dump(this);
425         dbgs() << "has predecessors left!\n";
426         AnyNotSched = true;
427       }
428     }
429   }
430   assert(!AnyNotSched);
431   return SUnits.size() - DeadNodes;
432 }
433 #endif
434
435 /// InitDAGTopologicalSorting - create the initial topological
436 /// ordering from the DAG to be scheduled.
437 ///
438 /// The idea of the algorithm is taken from
439 /// "Online algorithms for managing the topological order of
440 /// a directed acyclic graph" by David J. Pearce and Paul H.J. Kelly
441 /// This is the MNR algorithm, which was first introduced by
442 /// A. Marchetti-Spaccamela, U. Nanni and H. Rohnert in
443 /// "Maintaining a topological order under edge insertions".
444 ///
445 /// Short description of the algorithm:
446 ///
447 /// Topological ordering, ord, of a DAG maps each node to a topological
448 /// index so that for all edges X->Y it is the case that ord(X) < ord(Y).
449 ///
450 /// This means that if there is a path from the node X to the node Z,
451 /// then ord(X) < ord(Z).
452 ///
453 /// This property can be used to check for reachability of nodes:
454 /// if Z is reachable from X, then an insertion of the edge Z->X would
455 /// create a cycle.
456 ///
457 /// The algorithm first computes a topological ordering for the DAG by
458 /// initializing the Index2Node and Node2Index arrays and then tries to keep
459 /// the ordering up-to-date after edge insertions by reordering the DAG.
460 ///
461 /// On insertion of the edge X->Y, the algorithm first marks by calling DFS
462 /// the nodes reachable from Y, and then shifts them using Shift to lie
463 /// immediately after X in Index2Node.
464 void ScheduleDAGTopologicalSort::InitDAGTopologicalSorting() {
465   unsigned DAGSize = SUnits.size();
466   std::vector<SUnit*> WorkList;
467   WorkList.reserve(DAGSize);
468
469   Index2Node.resize(DAGSize);
470   Node2Index.resize(DAGSize);
471
472   // Initialize the data structures.
473   if (ExitSU)
474     WorkList.push_back(ExitSU);
475   for (unsigned i = 0, e = DAGSize; i != e; ++i) {
476     SUnit *SU = &SUnits[i];
477     int NodeNum = SU->NodeNum;
478     unsigned Degree = SU->Succs.size();
479     // Temporarily use the Node2Index array as scratch space for degree counts.
480     Node2Index[NodeNum] = Degree;
481
482     // Is it a node without dependencies?
483     if (Degree == 0) {
484       assert(SU->Succs.empty() && "SUnit should have no successors");
485       // Collect leaf nodes.
486       WorkList.push_back(SU);
487     }
488   }
489
490   int Id = DAGSize;
491   while (!WorkList.empty()) {
492     SUnit *SU = WorkList.back();
493     WorkList.pop_back();
494     if (SU->NodeNum < DAGSize)
495       Allocate(SU->NodeNum, --Id);
496     for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
497          I != E; ++I) {
498       SUnit *SU = I->getSUnit();
499       if (SU->NodeNum < DAGSize && !--Node2Index[SU->NodeNum])
500         // If all dependencies of the node are processed already,
501         // then the node can be computed now.
502         WorkList.push_back(SU);
503     }
504   }
505
506   Visited.resize(DAGSize);
507
508 #ifndef NDEBUG
509   // Check correctness of the ordering
510   for (unsigned i = 0, e = DAGSize; i != e; ++i) {
511     SUnit *SU = &SUnits[i];
512     for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
513          I != E; ++I) {
514       assert(Node2Index[SU->NodeNum] > Node2Index[I->getSUnit()->NodeNum] &&
515       "Wrong topological sorting");
516     }
517   }
518 #endif
519 }
520
521 /// AddPred - Updates the topological ordering to accommodate an edge
522 /// to be added from SUnit X to SUnit Y.
523 void ScheduleDAGTopologicalSort::AddPred(SUnit *Y, SUnit *X) {
524   int UpperBound, LowerBound;
525   LowerBound = Node2Index[Y->NodeNum];
526   UpperBound = Node2Index[X->NodeNum];
527   bool HasLoop = false;
528   // Is Ord(X) < Ord(Y) ?
529   if (LowerBound < UpperBound) {
530     // Update the topological order.
531     Visited.reset();
532     DFS(Y, UpperBound, HasLoop);
533     assert(!HasLoop && "Inserted edge creates a loop!");
534     // Recompute topological indexes.
535     Shift(Visited, LowerBound, UpperBound);
536   }
537 }
538
539 /// RemovePred - Updates the topological ordering to accommodate an
540 /// an edge to be removed from the specified node N from the predecessors
541 /// of the current node M.
542 void ScheduleDAGTopologicalSort::RemovePred(SUnit *M, SUnit *N) {
543   // InitDAGTopologicalSorting();
544 }
545
546 /// DFS - Make a DFS traversal to mark all nodes reachable from SU and mark
547 /// all nodes affected by the edge insertion. These nodes will later get new
548 /// topological indexes by means of the Shift method.
549 void ScheduleDAGTopologicalSort::DFS(const SUnit *SU, int UpperBound,
550                                      bool &HasLoop) {
551   std::vector<const SUnit*> WorkList;
552   WorkList.reserve(SUnits.size());
553
554   WorkList.push_back(SU);
555   do {
556     SU = WorkList.back();
557     WorkList.pop_back();
558     Visited.set(SU->NodeNum);
559     for (int I = SU->Succs.size()-1; I >= 0; --I) {
560       unsigned s = SU->Succs[I].getSUnit()->NodeNum;
561       // Edges to non-SUnits are allowed but ignored (e.g. ExitSU).
562       if (s >= Node2Index.size())
563         continue;
564       if (Node2Index[s] == UpperBound) {
565         HasLoop = true;
566         return;
567       }
568       // Visit successors if not already and in affected region.
569       if (!Visited.test(s) && Node2Index[s] < UpperBound) {
570         WorkList.push_back(SU->Succs[I].getSUnit());
571       }
572     }
573   } while (!WorkList.empty());
574 }
575
576 /// Shift - Renumber the nodes so that the topological ordering is
577 /// preserved.
578 void ScheduleDAGTopologicalSort::Shift(BitVector& Visited, int LowerBound,
579                                        int UpperBound) {
580   std::vector<int> L;
581   int shift = 0;
582   int i;
583
584   for (i = LowerBound; i <= UpperBound; ++i) {
585     // w is node at topological index i.
586     int w = Index2Node[i];
587     if (Visited.test(w)) {
588       // Unmark.
589       Visited.reset(w);
590       L.push_back(w);
591       shift = shift + 1;
592     } else {
593       Allocate(w, i - shift);
594     }
595   }
596
597   for (unsigned j = 0; j < L.size(); ++j) {
598     Allocate(L[j], i - shift);
599     i = i + 1;
600   }
601 }
602
603
604 /// WillCreateCycle - Returns true if adding an edge to TargetSU from SU will
605 /// create a cycle. If so, it is not safe to call AddPred(TargetSU, SU).
606 bool ScheduleDAGTopologicalSort::WillCreateCycle(SUnit *TargetSU, SUnit *SU) {
607   // Is SU reachable from TargetSU via successor edges?
608   if (IsReachable(SU, TargetSU))
609     return true;
610   for (SUnit::pred_iterator
611          I = TargetSU->Preds.begin(), E = TargetSU->Preds.end(); I != E; ++I)
612     if (I->isAssignedRegDep() &&
613         IsReachable(SU, I->getSUnit()))
614       return true;
615   return false;
616 }
617
618 /// IsReachable - Checks if SU is reachable from TargetSU.
619 bool ScheduleDAGTopologicalSort::IsReachable(const SUnit *SU,
620                                              const SUnit *TargetSU) {
621   // If insertion of the edge SU->TargetSU would create a cycle
622   // then there is a path from TargetSU to SU.
623   int UpperBound, LowerBound;
624   LowerBound = Node2Index[TargetSU->NodeNum];
625   UpperBound = Node2Index[SU->NodeNum];
626   bool HasLoop = false;
627   // Is Ord(TargetSU) < Ord(SU) ?
628   if (LowerBound < UpperBound) {
629     Visited.reset();
630     // There may be a path from TargetSU to SU. Check for it.
631     DFS(TargetSU, UpperBound, HasLoop);
632   }
633   return HasLoop;
634 }
635
636 /// Allocate - assign the topological index to the node n.
637 void ScheduleDAGTopologicalSort::Allocate(int n, int index) {
638   Node2Index[n] = index;
639   Index2Node[index] = n;
640 }
641
642 ScheduleDAGTopologicalSort::
643 ScheduleDAGTopologicalSort(std::vector<SUnit> &sunits, SUnit *exitsu)
644   : SUnits(sunits), ExitSU(exitsu) {}
645
646 ScheduleHazardRecognizer::~ScheduleHazardRecognizer() {}