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 LLVM_DUMP_METHOD
314 void SUnit::print(raw_ostream &OS, const ScheduleDAG *DAG) const {
315   if (this == &DAG->ExitSU)
316     OS << "ExitSU";
317   else if (this == &DAG->EntrySU)
318     OS << "EntrySU";
319   else
320     OS << "SU(" << NodeNum << ")";
321 }
322 
323 /// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
324 /// a group of nodes flagged together.
325 LLVM_DUMP_METHOD void SUnit::dump(const ScheduleDAG *G) const {
326   print(dbgs(), G);
327   dbgs() << ": ";
328   G->dumpNode(this);
329 }
330 
331 LLVM_DUMP_METHOD void SUnit::dumpAll(const ScheduleDAG *G) const {
332   dump(G);
333 
334   dbgs() << "  # preds left       : " << NumPredsLeft << "\n";
335   dbgs() << "  # succs left       : " << NumSuccsLeft << "\n";
336   if (WeakPredsLeft)
337     dbgs() << "  # weak preds left  : " << WeakPredsLeft << "\n";
338   if (WeakSuccsLeft)
339     dbgs() << "  # weak succs left  : " << WeakSuccsLeft << "\n";
340   dbgs() << "  # rdefs left       : " << NumRegDefsLeft << "\n";
341   dbgs() << "  Latency            : " << Latency << "\n";
342   dbgs() << "  Depth              : " << getDepth() << "\n";
343   dbgs() << "  Height             : " << getHeight() << "\n";
344 
345   if (Preds.size() != 0) {
346     dbgs() << "  Predecessors:\n";
347     for (SUnit::const_succ_iterator I = Preds.begin(), E = Preds.end();
348          I != E; ++I) {
349       dbgs() << "   ";
350       switch (I->getKind()) {
351       case SDep::Data:   dbgs() << "data "; break;
352       case SDep::Anti:   dbgs() << "anti "; break;
353       case SDep::Output: dbgs() << "out  "; break;
354       case SDep::Order:  dbgs() << "ord  "; break;
355       }
356       I->getSUnit()->print(dbgs(), G);
357       if (I->isArtificial())
358         dbgs() << " *";
359       dbgs() << ": Latency=" << I->getLatency();
360       if (I->isAssignedRegDep())
361         dbgs() << " Reg=" << PrintReg(I->getReg(), G->TRI);
362       dbgs() << "\n";
363     }
364   }
365   if (Succs.size() != 0) {
366     dbgs() << "  Successors:\n";
367     for (SUnit::const_succ_iterator I = Succs.begin(), E = Succs.end();
368          I != E; ++I) {
369       dbgs() << "   ";
370       switch (I->getKind()) {
371       case SDep::Data:   dbgs() << "data "; break;
372       case SDep::Anti:   dbgs() << "anti "; break;
373       case SDep::Output: dbgs() << "out  "; break;
374       case SDep::Order:  dbgs() << "ord  "; break;
375       }
376       I->getSUnit()->print(dbgs(), G);
377       if (I->isArtificial())
378         dbgs() << " *";
379       dbgs() << ": Latency=" << I->getLatency();
380       if (I->isAssignedRegDep())
381         dbgs() << " Reg=" << PrintReg(I->getReg(), G->TRI);
382       dbgs() << "\n";
383     }
384   }
385 }
386 #endif
387 
388 #ifndef NDEBUG
389 /// VerifyScheduledDAG - Verify that all SUnits were scheduled and that
390 /// their state is consistent. Return the number of scheduled nodes.
391 ///
392 unsigned ScheduleDAG::VerifyScheduledDAG(bool isBottomUp) {
393   bool AnyNotSched = false;
394   unsigned DeadNodes = 0;
395   for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
396     if (!SUnits[i].isScheduled) {
397       if (SUnits[i].NumPreds == 0 && SUnits[i].NumSuccs == 0) {
398         ++DeadNodes;
399         continue;
400       }
401       if (!AnyNotSched)
402         dbgs() << "*** Scheduling failed! ***\n";
403       SUnits[i].dump(this);
404       dbgs() << "has not been scheduled!\n";
405       AnyNotSched = true;
406     }
407     if (SUnits[i].isScheduled &&
408         (isBottomUp ? SUnits[i].getHeight() : SUnits[i].getDepth()) >
409           unsigned(INT_MAX)) {
410       if (!AnyNotSched)
411         dbgs() << "*** Scheduling failed! ***\n";
412       SUnits[i].dump(this);
413       dbgs() << "has an unexpected "
414            << (isBottomUp ? "Height" : "Depth") << " value!\n";
415       AnyNotSched = true;
416     }
417     if (isBottomUp) {
418       if (SUnits[i].NumSuccsLeft != 0) {
419         if (!AnyNotSched)
420           dbgs() << "*** Scheduling failed! ***\n";
421         SUnits[i].dump(this);
422         dbgs() << "has successors left!\n";
423         AnyNotSched = true;
424       }
425     } else {
426       if (SUnits[i].NumPredsLeft != 0) {
427         if (!AnyNotSched)
428           dbgs() << "*** Scheduling failed! ***\n";
429         SUnits[i].dump(this);
430         dbgs() << "has predecessors left!\n";
431         AnyNotSched = true;
432       }
433     }
434   }
435   assert(!AnyNotSched);
436   return SUnits.size() - DeadNodes;
437 }
438 #endif
439 
440 /// InitDAGTopologicalSorting - create the initial topological
441 /// ordering from the DAG to be scheduled.
442 ///
443 /// The idea of the algorithm is taken from
444 /// "Online algorithms for managing the topological order of
445 /// a directed acyclic graph" by David J. Pearce and Paul H.J. Kelly
446 /// This is the MNR algorithm, which was first introduced by
447 /// A. Marchetti-Spaccamela, U. Nanni and H. Rohnert in
448 /// "Maintaining a topological order under edge insertions".
449 ///
450 /// Short description of the algorithm:
451 ///
452 /// Topological ordering, ord, of a DAG maps each node to a topological
453 /// index so that for all edges X->Y it is the case that ord(X) < ord(Y).
454 ///
455 /// This means that if there is a path from the node X to the node Z,
456 /// then ord(X) < ord(Z).
457 ///
458 /// This property can be used to check for reachability of nodes:
459 /// if Z is reachable from X, then an insertion of the edge Z->X would
460 /// create a cycle.
461 ///
462 /// The algorithm first computes a topological ordering for the DAG by
463 /// initializing the Index2Node and Node2Index arrays and then tries to keep
464 /// the ordering up-to-date after edge insertions by reordering the DAG.
465 ///
466 /// On insertion of the edge X->Y, the algorithm first marks by calling DFS
467 /// the nodes reachable from Y, and then shifts them using Shift to lie
468 /// immediately after X in Index2Node.
469 void ScheduleDAGTopologicalSort::InitDAGTopologicalSorting() {
470   unsigned DAGSize = SUnits.size();
471   std::vector<SUnit*> WorkList;
472   WorkList.reserve(DAGSize);
473 
474   Index2Node.resize(DAGSize);
475   Node2Index.resize(DAGSize);
476 
477   // Initialize the data structures.
478   if (ExitSU)
479     WorkList.push_back(ExitSU);
480   for (unsigned i = 0, e = DAGSize; i != e; ++i) {
481     SUnit *SU = &SUnits[i];
482     int NodeNum = SU->NodeNum;
483     unsigned Degree = SU->Succs.size();
484     // Temporarily use the Node2Index array as scratch space for degree counts.
485     Node2Index[NodeNum] = Degree;
486 
487     // Is it a node without dependencies?
488     if (Degree == 0) {
489       assert(SU->Succs.empty() && "SUnit should have no successors");
490       // Collect leaf nodes.
491       WorkList.push_back(SU);
492     }
493   }
494 
495   int Id = DAGSize;
496   while (!WorkList.empty()) {
497     SUnit *SU = WorkList.back();
498     WorkList.pop_back();
499     if (SU->NodeNum < DAGSize)
500       Allocate(SU->NodeNum, --Id);
501     for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
502          I != E; ++I) {
503       SUnit *SU = I->getSUnit();
504       if (SU->NodeNum < DAGSize && !--Node2Index[SU->NodeNum])
505         // If all dependencies of the node are processed already,
506         // then the node can be computed now.
507         WorkList.push_back(SU);
508     }
509   }
510 
511   Visited.resize(DAGSize);
512 
513 #ifndef NDEBUG
514   // Check correctness of the ordering
515   for (unsigned i = 0, e = DAGSize; i != e; ++i) {
516     SUnit *SU = &SUnits[i];
517     for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
518          I != E; ++I) {
519       assert(Node2Index[SU->NodeNum] > Node2Index[I->getSUnit()->NodeNum] &&
520       "Wrong topological sorting");
521     }
522   }
523 #endif
524 }
525 
526 /// AddPred - Updates the topological ordering to accommodate an edge
527 /// to be added from SUnit X to SUnit Y.
528 void ScheduleDAGTopologicalSort::AddPred(SUnit *Y, SUnit *X) {
529   int UpperBound, LowerBound;
530   LowerBound = Node2Index[Y->NodeNum];
531   UpperBound = Node2Index[X->NodeNum];
532   bool HasLoop = false;
533   // Is Ord(X) < Ord(Y) ?
534   if (LowerBound < UpperBound) {
535     // Update the topological order.
536     Visited.reset();
537     DFS(Y, UpperBound, HasLoop);
538     assert(!HasLoop && "Inserted edge creates a loop!");
539     // Recompute topological indexes.
540     Shift(Visited, LowerBound, UpperBound);
541   }
542 }
543 
544 /// RemovePred - Updates the topological ordering to accommodate an
545 /// an edge to be removed from the specified node N from the predecessors
546 /// of the current node M.
547 void ScheduleDAGTopologicalSort::RemovePred(SUnit *M, SUnit *N) {
548   // InitDAGTopologicalSorting();
549 }
550 
551 /// DFS - Make a DFS traversal to mark all nodes reachable from SU and mark
552 /// all nodes affected by the edge insertion. These nodes will later get new
553 /// topological indexes by means of the Shift method.
554 void ScheduleDAGTopologicalSort::DFS(const SUnit *SU, int UpperBound,
555                                      bool &HasLoop) {
556   std::vector<const SUnit*> WorkList;
557   WorkList.reserve(SUnits.size());
558 
559   WorkList.push_back(SU);
560   do {
561     SU = WorkList.back();
562     WorkList.pop_back();
563     Visited.set(SU->NodeNum);
564     for (int I = SU->Succs.size()-1; I >= 0; --I) {
565       unsigned s = SU->Succs[I].getSUnit()->NodeNum;
566       // Edges to non-SUnits are allowed but ignored (e.g. ExitSU).
567       if (s >= Node2Index.size())
568         continue;
569       if (Node2Index[s] == UpperBound) {
570         HasLoop = true;
571         return;
572       }
573       // Visit successors if not already and in affected region.
574       if (!Visited.test(s) && Node2Index[s] < UpperBound) {
575         WorkList.push_back(SU->Succs[I].getSUnit());
576       }
577     }
578   } while (!WorkList.empty());
579 }
580 
581 /// Shift - Renumber the nodes so that the topological ordering is
582 /// preserved.
583 void ScheduleDAGTopologicalSort::Shift(BitVector& Visited, int LowerBound,
584                                        int UpperBound) {
585   std::vector<int> L;
586   int shift = 0;
587   int i;
588 
589   for (i = LowerBound; i <= UpperBound; ++i) {
590     // w is node at topological index i.
591     int w = Index2Node[i];
592     if (Visited.test(w)) {
593       // Unmark.
594       Visited.reset(w);
595       L.push_back(w);
596       shift = shift + 1;
597     } else {
598       Allocate(w, i - shift);
599     }
600   }
601 
602   for (unsigned j = 0; j < L.size(); ++j) {
603     Allocate(L[j], i - shift);
604     i = i + 1;
605   }
606 }
607 
608 
609 /// WillCreateCycle - Returns true if adding an edge to TargetSU from SU will
610 /// create a cycle. If so, it is not safe to call AddPred(TargetSU, SU).
611 bool ScheduleDAGTopologicalSort::WillCreateCycle(SUnit *TargetSU, SUnit *SU) {
612   // Is SU reachable from TargetSU via successor edges?
613   if (IsReachable(SU, TargetSU))
614     return true;
615   for (SUnit::pred_iterator
616          I = TargetSU->Preds.begin(), E = TargetSU->Preds.end(); I != E; ++I)
617     if (I->isAssignedRegDep() &&
618         IsReachable(SU, I->getSUnit()))
619       return true;
620   return false;
621 }
622 
623 /// IsReachable - Checks if SU is reachable from TargetSU.
624 bool ScheduleDAGTopologicalSort::IsReachable(const SUnit *SU,
625                                              const SUnit *TargetSU) {
626   // If insertion of the edge SU->TargetSU would create a cycle
627   // then there is a path from TargetSU to SU.
628   int UpperBound, LowerBound;
629   LowerBound = Node2Index[TargetSU->NodeNum];
630   UpperBound = Node2Index[SU->NodeNum];
631   bool HasLoop = false;
632   // Is Ord(TargetSU) < Ord(SU) ?
633   if (LowerBound < UpperBound) {
634     Visited.reset();
635     // There may be a path from TargetSU to SU. Check for it.
636     DFS(TargetSU, UpperBound, HasLoop);
637   }
638   return HasLoop;
639 }
640 
641 /// Allocate - assign the topological index to the node n.
642 void ScheduleDAGTopologicalSort::Allocate(int n, int index) {
643   Node2Index[n] = index;
644   Index2Node[index] = n;
645 }
646 
647 ScheduleDAGTopologicalSort::
648 ScheduleDAGTopologicalSort(std::vector<SUnit> &sunits, SUnit *exitsu)
649   : SUnits(sunits), ExitSU(exitsu) {}
650 
651 ScheduleHazardRecognizer::~ScheduleHazardRecognizer() {}
652