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