LLVM API Documentation

ScheduleDAGFast.cpp

Go to the documentation of this file.
00001 //===----- ScheduleDAGFast.cpp - Fast poor list scheduler -----------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This implements a fast scheduler.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #define DEBUG_TYPE "pre-RA-sched"
00015 #include "llvm/CodeGen/ScheduleDAGSDNodes.h"
00016 #include "llvm/CodeGen/SchedulerRegistry.h"
00017 #include "llvm/CodeGen/SelectionDAGISel.h"
00018 #include "llvm/Target/TargetRegisterInfo.h"
00019 #include "llvm/Target/TargetData.h"
00020 #include "llvm/Target/TargetInstrInfo.h"
00021 #include "llvm/Support/Debug.h"
00022 #include "llvm/Support/Compiler.h"
00023 #include "llvm/ADT/SmallSet.h"
00024 #include "llvm/ADT/Statistic.h"
00025 #include "llvm/ADT/STLExtras.h"
00026 #include "llvm/Support/CommandLine.h"
00027 using namespace llvm;
00028 
00029 STATISTIC(NumUnfolds,    "Number of nodes unfolded");
00030 STATISTIC(NumDups,       "Number of duplicated nodes");
00031 STATISTIC(NumPRCopies,   "Number of physical copies");
00032 
00033 static RegisterScheduler
00034   fastDAGScheduler("fast", "Fast suboptimal list scheduling",
00035                    createFastDAGScheduler);
00036 
00037 namespace {
00038   /// FastPriorityQueue - A degenerate priority queue that considers
00039   /// all nodes to have the same priority.
00040   ///
00041   struct VISIBILITY_HIDDEN FastPriorityQueue {
00042     SmallVector<SUnit *, 16> Queue;
00043 
00044     bool empty() const { return Queue.empty(); }
00045     
00046     void push(SUnit *U) {
00047       Queue.push_back(U);
00048     }
00049 
00050     SUnit *pop() {
00051       if (empty()) return NULL;
00052       SUnit *V = Queue.back();
00053       Queue.pop_back();
00054       return V;
00055     }
00056   };
00057 
00058 //===----------------------------------------------------------------------===//
00059 /// ScheduleDAGFast - The actual "fast" list scheduler implementation.
00060 ///
00061 class VISIBILITY_HIDDEN ScheduleDAGFast : public ScheduleDAGSDNodes {
00062 private:
00063   /// AvailableQueue - The priority queue to use for the available SUnits.
00064   FastPriorityQueue AvailableQueue;
00065 
00066   /// LiveRegDefs - A set of physical registers and their definition
00067   /// that are "live". These nodes must be scheduled before any other nodes that
00068   /// modifies the registers can be scheduled.
00069   unsigned NumLiveRegs;
00070   std::vector<SUnit*> LiveRegDefs;
00071   std::vector<unsigned> LiveRegCycles;
00072 
00073 public:
00074   ScheduleDAGFast(MachineFunction &mf)
00075     : ScheduleDAGSDNodes(mf) {}
00076 
00077   void Schedule();
00078 
00079   /// AddPred - adds a predecessor edge to SUnit SU.
00080   /// This returns true if this is a new predecessor.
00081   void AddPred(SUnit *SU, const SDep &D) {
00082     SU->addPred(D);
00083   }
00084 
00085   /// RemovePred - removes a predecessor edge from SUnit SU.
00086   /// This returns true if an edge was removed.
00087   void RemovePred(SUnit *SU, const SDep &D) {
00088     SU->removePred(D);
00089   }
00090 
00091 private:
00092   void ReleasePred(SUnit *SU, SDep *PredEdge);
00093   void ScheduleNodeBottomUp(SUnit*, unsigned);
00094   SUnit *CopyAndMoveSuccessors(SUnit*);
00095   void InsertCopiesAndMoveSuccs(SUnit*, unsigned,
00096                                 const TargetRegisterClass*,
00097                                 const TargetRegisterClass*,
00098                                 SmallVector<SUnit*, 2>&);
00099   bool DelayForLiveRegsBottomUp(SUnit*, SmallVector<unsigned, 4>&);
00100   void ListScheduleBottomUp();
00101 
00102   /// ForceUnitLatencies - The fast scheduler doesn't care about real latencies.
00103   bool ForceUnitLatencies() const { return true; }
00104 };
00105 }  // end anonymous namespace
00106 
00107 
00108 /// Schedule - Schedule the DAG using list scheduling.
00109 void ScheduleDAGFast::Schedule() {
00110   DOUT << "********** List Scheduling **********\n";
00111 
00112   NumLiveRegs = 0;
00113   LiveRegDefs.resize(TRI->getNumRegs(), NULL);  
00114   LiveRegCycles.resize(TRI->getNumRegs(), 0);
00115 
00116   // Build the scheduling graph.
00117   BuildSchedGraph();
00118 
00119   DEBUG(for (unsigned su = 0, e = SUnits.size(); su != e; ++su)
00120           SUnits[su].dumpAll(this));
00121 
00122   // Execute the actual scheduling loop.
00123   ListScheduleBottomUp();
00124 }
00125 
00126 //===----------------------------------------------------------------------===//
00127 //  Bottom-Up Scheduling
00128 //===----------------------------------------------------------------------===//
00129 
00130 /// ReleasePred - Decrement the NumSuccsLeft count of a predecessor. Add it to
00131 /// the AvailableQueue if the count reaches zero. Also update its cycle bound.
00132 void ScheduleDAGFast::ReleasePred(SUnit *SU, SDep *PredEdge) {
00133   SUnit *PredSU = PredEdge->getSUnit();
00134   --PredSU->NumSuccsLeft;
00135   
00136 #ifndef NDEBUG
00137   if (PredSU->NumSuccsLeft < 0) {
00138     cerr << "*** Scheduling failed! ***\n";
00139     PredSU->dump(this);
00140     cerr << " has been released too many times!\n";
00141     assert(0);
00142   }
00143 #endif
00144   
00145   if (PredSU->NumSuccsLeft == 0) {
00146     PredSU->isAvailable = true;
00147     AvailableQueue.push(PredSU);
00148   }
00149 }
00150 
00151 /// ScheduleNodeBottomUp - Add the node to the schedule. Decrement the pending
00152 /// count of its predecessors. If a predecessor pending count is zero, add it to
00153 /// the Available queue.
00154 void ScheduleDAGFast::ScheduleNodeBottomUp(SUnit *SU, unsigned CurCycle) {
00155   DOUT << "*** Scheduling [" << CurCycle << "]: ";
00156   DEBUG(SU->dump(this));
00157 
00158   assert(CurCycle >= SU->getHeight() && "Node scheduled below its height!");
00159   SU->setHeightToAtLeast(CurCycle);
00160   Sequence.push_back(SU);
00161 
00162   // Bottom up: release predecessors
00163   for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
00164        I != E; ++I) {
00165     ReleasePred(SU, &*I);
00166     if (I->isAssignedRegDep()) {
00167       // This is a physical register dependency and it's impossible or
00168       // expensive to copy the register. Make sure nothing that can 
00169       // clobber the register is scheduled between the predecessor and
00170       // this node.
00171       if (!LiveRegDefs[I->getReg()]) {
00172         ++NumLiveRegs;
00173         LiveRegDefs[I->getReg()] = I->getSUnit();
00174         LiveRegCycles[I->getReg()] = CurCycle;
00175       }
00176     }
00177   }
00178 
00179   // Release all the implicit physical register defs that are live.
00180   for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
00181        I != E; ++I) {
00182     if (I->isAssignedRegDep()) {
00183       if (LiveRegCycles[I->getReg()] == I->getSUnit()->getHeight()) {
00184         assert(NumLiveRegs > 0 && "NumLiveRegs is already zero!");
00185         assert(LiveRegDefs[I->getReg()] == SU &&
00186                "Physical register dependency violated?");
00187         --NumLiveRegs;
00188         LiveRegDefs[I->getReg()] = NULL;
00189         LiveRegCycles[I->getReg()] = 0;
00190       }
00191     }
00192   }
00193 
00194   SU->isScheduled = true;
00195 }
00196 
00197 /// CopyAndMoveSuccessors - Clone the specified node and move its scheduled
00198 /// successors to the newly created node.
00199 SUnit *ScheduleDAGFast::CopyAndMoveSuccessors(SUnit *SU) {
00200   if (SU->getNode()->getFlaggedNode())
00201     return NULL;
00202 
00203   SDNode *N = SU->getNode();
00204   if (!N)
00205     return NULL;
00206 
00207   SUnit *NewSU;
00208   bool TryUnfold = false;
00209   for (unsigned i = 0, e = N->getNumValues(); i != e; ++i) {
00210     MVT VT = N->getValueType(i);
00211     if (VT == MVT::Flag)
00212       return NULL;
00213     else if (VT == MVT::Other)
00214       TryUnfold = true;
00215   }
00216   for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
00217     const SDValue &Op = N->getOperand(i);
00218     MVT VT = Op.getNode()->getValueType(Op.getResNo());
00219     if (VT == MVT::Flag)
00220       return NULL;
00221   }
00222 
00223   if (TryUnfold) {
00224     SmallVector<SDNode*, 2> NewNodes;
00225     if (!TII->unfoldMemoryOperand(*DAG, N, NewNodes))
00226       return NULL;
00227 
00228     DOUT << "Unfolding SU # " << SU->NodeNum << "\n";
00229     assert(NewNodes.size() == 2 && "Expected a load folding node!");
00230 
00231     N = NewNodes[1];
00232     SDNode *LoadNode = NewNodes[0];
00233     unsigned NumVals = N->getNumValues();
00234     unsigned OldNumVals = SU->getNode()->getNumValues();
00235     for (unsigned i = 0; i != NumVals; ++i)
00236       DAG->ReplaceAllUsesOfValueWith(SDValue(SU->getNode(), i), SDValue(N, i));
00237     DAG->ReplaceAllUsesOfValueWith(SDValue(SU->getNode(), OldNumVals-1),
00238                                    SDValue(LoadNode, 1));
00239 
00240     SUnit *NewSU = NewSUnit(N);
00241     assert(N->getNodeId() == -1 && "Node already inserted!");
00242     N->setNodeId(NewSU->NodeNum);
00243       
00244     const TargetInstrDesc &TID = TII->get(N->getMachineOpcode());
00245     for (unsigned i = 0; i != TID.getNumOperands(); ++i) {
00246       if (TID.getOperandConstraint(i, TOI::TIED_TO) != -1) {
00247         NewSU->isTwoAddress = true;
00248         break;
00249       }
00250     }
00251     if (TID.isCommutable())
00252       NewSU->isCommutable = true;
00253 
00254     // LoadNode may already exist. This can happen when there is another
00255     // load from the same location and producing the same type of value
00256     // but it has different alignment or volatileness.
00257     bool isNewLoad = true;
00258     SUnit *LoadSU;
00259     if (LoadNode->getNodeId() != -1) {
00260       LoadSU = &SUnits[LoadNode->getNodeId()];
00261       isNewLoad = false;
00262     } else {
00263       LoadSU = NewSUnit(LoadNode);
00264       LoadNode->setNodeId(LoadSU->NodeNum);
00265     }
00266 
00267     SDep ChainPred;
00268     SmallVector<SDep, 4> ChainSuccs;
00269     SmallVector<SDep, 4> LoadPreds;
00270     SmallVector<SDep, 4> NodePreds;
00271     SmallVector<SDep, 4> NodeSuccs;
00272     for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
00273          I != E; ++I) {
00274       if (I->isCtrl())
00275         ChainPred = *I;
00276       else if (I->getSUnit()->getNode() &&
00277                I->getSUnit()->getNode()->isOperandOf(LoadNode))
00278         LoadPreds.push_back(*I);
00279       else
00280         NodePreds.push_back(*I);
00281     }
00282     for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
00283          I != E; ++I) {
00284       if (I->isCtrl())
00285         ChainSuccs.push_back(*I);
00286       else
00287         NodeSuccs.push_back(*I);
00288     }
00289 
00290     if (ChainPred.getSUnit()) {
00291       RemovePred(SU, ChainPred);
00292       if (isNewLoad)
00293         AddPred(LoadSU, ChainPred);
00294     }
00295     for (unsigned i = 0, e = LoadPreds.size(); i != e; ++i) {
00296       const SDep &Pred = LoadPreds[i];
00297       RemovePred(SU, Pred);
00298       if (isNewLoad) {
00299         AddPred(LoadSU, Pred);
00300       }
00301     }
00302     for (unsigned i = 0, e = NodePreds.size(); i != e; ++i) {
00303       const SDep &Pred = NodePreds[i];
00304       RemovePred(SU, Pred);
00305       AddPred(NewSU, Pred);
00306     }
00307     for (unsigned i = 0, e = NodeSuccs.size(); i != e; ++i) {
00308       SDep D = NodeSuccs[i];
00309       SUnit *SuccDep = D.getSUnit();
00310       D.setSUnit(SU);
00311       RemovePred(SuccDep, D);
00312       D.setSUnit(NewSU);
00313       AddPred(SuccDep, D);
00314     }
00315     for (unsigned i = 0, e = ChainSuccs.size(); i != e; ++i) {
00316       SDep D = ChainSuccs[i];
00317       SUnit *SuccDep = D.getSUnit();
00318       D.setSUnit(SU);
00319       RemovePred(SuccDep, D);
00320       if (isNewLoad) {
00321         D.setSUnit(LoadSU);
00322         AddPred(SuccDep, D);
00323       }
00324     } 
00325     if (isNewLoad) {
00326       AddPred(NewSU, SDep(LoadSU, SDep::Order, LoadSU->Latency));
00327     }
00328 
00329     ++NumUnfolds;
00330 
00331     if (NewSU->NumSuccsLeft == 0) {
00332       NewSU->isAvailable = true;
00333       return NewSU;
00334     }
00335     SU = NewSU;
00336   }
00337 
00338   DOUT << "Duplicating SU # " << SU->NodeNum << "\n";
00339   NewSU = Clone(SU);
00340 
00341   // New SUnit has the exact same predecessors.
00342   for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
00343        I != E; ++I)
00344     if (!I->isArtificial())
00345       AddPred(NewSU, *I);
00346 
00347   // Only copy scheduled successors. Cut them from old node's successor
00348   // list and move them over.
00349   SmallVector<std::pair<SUnit *, SDep>, 4> DelDeps;
00350   for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
00351        I != E; ++I) {
00352     if (I->isArtificial())
00353       continue;
00354     SUnit *SuccSU = I->getSUnit();
00355     if (SuccSU->isScheduled) {
00356       SDep D = *I;
00357       D.setSUnit(NewSU);
00358       AddPred(SuccSU, D);
00359       D.setSUnit(SU);
00360       DelDeps.push_back(std::make_pair(SuccSU, D));
00361     }
00362   }
00363   for (unsigned i = 0, e = DelDeps.size(); i != e; ++i)
00364     RemovePred(DelDeps[i].first, DelDeps[i].second);
00365 
00366   ++NumDups;
00367   return NewSU;
00368 }
00369 
00370 /// InsertCopiesAndMoveSuccs - Insert register copies and move all
00371 /// scheduled successors of the given SUnit to the last copy.
00372 void ScheduleDAGFast::InsertCopiesAndMoveSuccs(SUnit *SU, unsigned Reg,
00373                                               const TargetRegisterClass *DestRC,
00374                                               const TargetRegisterClass *SrcRC,
00375                                                SmallVector<SUnit*, 2> &Copies) {
00376   SUnit *CopyFromSU = NewSUnit(static_cast<SDNode *>(NULL));
00377   CopyFromSU->CopySrcRC = SrcRC;
00378   CopyFromSU->CopyDstRC = DestRC;
00379 
00380   SUnit *CopyToSU = NewSUnit(static_cast<SDNode *>(NULL));
00381   CopyToSU->CopySrcRC = DestRC;
00382   CopyToSU->CopyDstRC = SrcRC;
00383 
00384   // Only copy scheduled successors. Cut them from old node's successor
00385   // list and move them over.
00386   SmallVector<std::pair<SUnit *, SDep>, 4> DelDeps;
00387   for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
00388        I != E; ++I) {
00389     if (I->isArtificial())
00390       continue;
00391     SUnit *SuccSU = I->getSUnit();
00392     if (SuccSU->isScheduled) {
00393       SDep D = *I;
00394       D.setSUnit(CopyToSU);
00395       AddPred(SuccSU, D);
00396       DelDeps.push_back(std::make_pair(SuccSU, *I));
00397     }
00398   }
00399   for (unsigned i = 0, e = DelDeps.size(); i != e; ++i) {
00400     RemovePred(DelDeps[i].first, DelDeps[i].second);
00401   }
00402 
00403   AddPred(CopyFromSU, SDep(SU, SDep::Data, SU->Latency, Reg));
00404   AddPred(CopyToSU, SDep(CopyFromSU, SDep::Data, CopyFromSU->Latency, 0));
00405 
00406   Copies.push_back(CopyFromSU);
00407   Copies.push_back(CopyToSU);
00408 
00409   ++NumPRCopies;
00410 }
00411 
00412 /// getPhysicalRegisterVT - Returns the ValueType of the physical register
00413 /// definition of the specified node.
00414 /// FIXME: Move to SelectionDAG?
00415 static MVT getPhysicalRegisterVT(SDNode *N, unsigned Reg,
00416                                  const TargetInstrInfo *TII) {
00417   const TargetInstrDesc &TID = TII->get(N->getMachineOpcode());
00418   assert(TID.ImplicitDefs && "Physical reg def must be in implicit def list!");
00419   unsigned NumRes = TID.getNumDefs();
00420   for (const unsigned *ImpDef = TID.getImplicitDefs(); *ImpDef; ++ImpDef) {
00421     if (Reg == *ImpDef)
00422       break;
00423     ++NumRes;
00424   }
00425   return N->getValueType(NumRes);
00426 }
00427 
00428 /// DelayForLiveRegsBottomUp - Returns true if it is necessary to delay
00429 /// scheduling of the given node to satisfy live physical register dependencies.
00430 /// If the specific node is the last one that's available to schedule, do
00431 /// whatever is necessary (i.e. backtracking or cloning) to make it possible.
00432 bool ScheduleDAGFast::DelayForLiveRegsBottomUp(SUnit *SU,
00433                                                SmallVector<unsigned, 4> &LRegs){
00434   if (NumLiveRegs == 0)
00435     return false;
00436 
00437   SmallSet<unsigned, 4> RegAdded;
00438   // If this node would clobber any "live" register, then it's not ready.
00439   for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
00440        I != E; ++I) {
00441     if (I->isAssignedRegDep()) {
00442       unsigned Reg = I->getReg();
00443       if (LiveRegDefs[Reg] && LiveRegDefs[Reg] != I->getSUnit()) {
00444         if (RegAdded.insert(Reg))
00445           LRegs.push_back(Reg);
00446       }
00447       for (const unsigned *Alias = TRI->getAliasSet(Reg);
00448            *Alias; ++Alias)
00449         if (LiveRegDefs[*Alias] && LiveRegDefs[*Alias] != I->getSUnit()) {
00450           if (RegAdded.insert(*Alias))
00451             LRegs.push_back(*Alias);
00452         }
00453     }
00454   }
00455 
00456   for (SDNode *Node = SU->getNode(); Node; Node = Node->getFlaggedNode()) {
00457     if (!Node->isMachineOpcode())
00458       continue;
00459     const TargetInstrDesc &TID = TII->get(Node->getMachineOpcode());
00460     if (!TID.ImplicitDefs)
00461       continue;
00462     for (const unsigned *Reg = TID.ImplicitDefs; *Reg; ++Reg) {
00463       if (LiveRegDefs[*Reg] && LiveRegDefs[*Reg] != SU) {
00464         if (RegAdded.insert(*Reg))
00465           LRegs.push_back(*Reg);
00466       }
00467       for (const unsigned *Alias = TRI->getAliasSet(*Reg);
00468            *Alias; ++Alias)
00469         if (LiveRegDefs[*Alias] && LiveRegDefs[*Alias] != SU) {
00470           if (RegAdded.insert(*Alias))
00471             LRegs.push_back(*Alias);
00472         }
00473     }
00474   }
00475   return !LRegs.empty();
00476 }
00477 
00478 
00479 /// ListScheduleBottomUp - The main loop of list scheduling for bottom-up
00480 /// schedulers.
00481 void ScheduleDAGFast::ListScheduleBottomUp() {
00482   unsigned CurCycle = 0;
00483   // Add root to Available queue.
00484   if (!SUnits.empty()) {
00485     SUnit *RootSU = &SUnits[DAG->getRoot().getNode()->getNodeId()];
00486     assert(RootSU->Succs.empty() && "Graph root shouldn't have successors!");
00487     RootSU->isAvailable = true;
00488     AvailableQueue.push(RootSU);
00489   }
00490 
00491   // While Available queue is not empty, grab the node with the highest
00492   // priority. If it is not ready put it back.  Schedule the node.
00493   SmallVector<SUnit*, 4> NotReady;
00494   DenseMap<SUnit*, SmallVector<unsigned, 4> > LRegsMap;
00495   Sequence.reserve(SUnits.size());
00496   while (!AvailableQueue.empty()) {
00497     bool Delayed = false;
00498     LRegsMap.clear();
00499     SUnit *CurSU = AvailableQueue.pop();
00500     while (CurSU) {
00501       SmallVector<unsigned, 4> LRegs;
00502       if (!DelayForLiveRegsBottomUp(CurSU, LRegs))
00503         break;
00504       Delayed = true;
00505       LRegsMap.insert(std::make_pair(CurSU, LRegs));
00506 
00507       CurSU->isPending = true;  // This SU is not in AvailableQueue right now.
00508       NotReady.push_back(CurSU);
00509       CurSU = AvailableQueue.pop();
00510     }
00511 
00512     // All candidates are delayed due to live physical reg dependencies.
00513     // Try code duplication or inserting cross class copies
00514     // to resolve it.
00515     if (Delayed && !CurSU) {
00516       if (!CurSU) {
00517         // Try duplicating the nodes that produces these
00518         // "expensive to copy" values to break the dependency. In case even
00519         // that doesn't work, insert cross class copies.
00520         SUnit *TrySU = NotReady[0];
00521         SmallVector<unsigned, 4> &LRegs = LRegsMap[TrySU];
00522         assert(LRegs.size() == 1 && "Can't handle this yet!");
00523         unsigned Reg = LRegs[0];
00524         SUnit *LRDef = LiveRegDefs[Reg];
00525         MVT VT = getPhysicalRegisterVT(LRDef->getNode(), Reg, TII);
00526         const TargetRegisterClass *RC =
00527           TRI->getPhysicalRegisterRegClass(Reg, VT);
00528         const TargetRegisterClass *DestRC = TRI->getCrossCopyRegClass(RC);
00529 
00530         // If cross copy register class is null, then it must be possible copy
00531         // the value directly. Do not try duplicate the def.
00532         SUnit *NewDef = 0;
00533         if (DestRC)
00534           NewDef = CopyAndMoveSuccessors(LRDef);
00535         else
00536           DestRC = RC;
00537         if (!NewDef) {
00538           // Issue copies, these can be expensive cross register class copies.
00539           SmallVector<SUnit*, 2> Copies;
00540           InsertCopiesAndMoveSuccs(LRDef, Reg, DestRC, RC, Copies);
00541           DOUT << "Adding an edge from SU # " << TrySU->NodeNum
00542                << " to SU #" << Copies.front()->NodeNum << "\n";
00543           AddPred(TrySU, SDep(Copies.front(), SDep::Order, /*Latency=*/1,
00544                               /*Reg=*/0, /*isNormalMemory=*/false,
00545                               /*isMustAlias=*/false, /*isArtificial=*/true));
00546           NewDef = Copies.back();
00547         }
00548 
00549         DOUT << "Adding an edge from SU # " << NewDef->NodeNum
00550              << " to SU #" << TrySU->NodeNum << "\n";
00551         LiveRegDefs[Reg] = NewDef;
00552         AddPred(NewDef, SDep(TrySU, SDep::Order, /*Latency=*/1,
00553                              /*Reg=*/0, /*isNormalMemory=*/false,
00554                              /*isMustAlias=*/false, /*isArtificial=*/true));
00555         TrySU->isAvailable = false;
00556         CurSU = NewDef;
00557       }
00558 
00559       if (!CurSU) {
00560         assert(false && "Unable to resolve live physical register dependencies!");
00561         abort();
00562       }
00563     }
00564 
00565     // Add the nodes that aren't ready back onto the available list.
00566     for (unsigned i = 0, e = NotReady.size(); i != e; ++i) {
00567       NotReady[i]->isPending = false;
00568       // May no longer be available due to backtracking.
00569       if (NotReady[i]->isAvailable)
00570         AvailableQueue.push(NotReady[i]);
00571     }
00572     NotReady.clear();
00573 
00574     if (CurSU)
00575       ScheduleNodeBottomUp(CurSU, CurCycle);
00576     ++CurCycle;
00577   }
00578 
00579   // Reverse the order if it is bottom up.
00580   std::reverse(Sequence.begin(), Sequence.end());
00581   
00582   
00583 #ifndef NDEBUG
00584   // Verify that all SUnits were scheduled.
00585   bool AnyNotSched = false;
00586   unsigned DeadNodes = 0;
00587   unsigned Noops = 0;
00588   for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
00589     if (!SUnits[i].isScheduled) {
00590       if (SUnits[i].NumPreds == 0 && SUnits[i].NumSuccs == 0) {
00591         ++DeadNodes;
00592         continue;
00593       }
00594       if (!AnyNotSched)
00595         cerr << "*** List scheduling failed! ***\n";
00596       SUnits[i].dump(this);
00597       cerr << "has not been scheduled!\n";
00598       AnyNotSched = true;
00599     }
00600     if (SUnits[i].NumSuccsLeft != 0) {
00601       if (!AnyNotSched)
00602         cerr << "*** List scheduling failed! ***\n";
00603       SUnits[i].dump(this);
00604       cerr << "has successors left!\n";
00605       AnyNotSched = true;
00606     }
00607   }
00608   for (unsigned i = 0, e = Sequence.size(); i != e; ++i)
00609     if (!Sequence[i])
00610       ++Noops;
00611   assert(!AnyNotSched);
00612   assert(Sequence.size() + DeadNodes - Noops == SUnits.size() &&
00613          "The number of nodes scheduled doesn't match the expected number!");
00614 #endif
00615 }
00616 
00617 //===----------------------------------------------------------------------===//
00618 //                         Public Constructor Functions
00619 //===----------------------------------------------------------------------===//
00620 
00621 llvm::ScheduleDAG* llvm::createFastDAGScheduler(SelectionDAGISel *IS, bool) {
00622   return new ScheduleDAGFast(*IS->MF);
00623 }