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