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