1 //===----- ScheduleDAGRRList.cpp - Reg pressure reduction list scheduler --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This implements bottom-up and top-down register pressure reduction list
11 // schedulers, using standard algorithms. The basic approach uses a priority
12 // queue of available nodes to schedule. One at a time, nodes are taken from
13 // the priority queue (thus in priority order), checked for legality to
14 // schedule, and emitted if legal.
16 //===----------------------------------------------------------------------===//
18 #define DEBUG_TYPE "pre-RA-sched"
19 #include "llvm/CodeGen/ScheduleDAGSDNodes.h"
20 #include "llvm/CodeGen/SchedulerRegistry.h"
21 #include "llvm/Target/TargetRegisterInfo.h"
22 #include "llvm/Target/TargetData.h"
23 #include "llvm/Target/TargetMachine.h"
24 #include "llvm/Target/TargetInstrInfo.h"
25 #include "llvm/Support/Debug.h"
26 #include "llvm/Support/Compiler.h"
27 #include "llvm/ADT/BitVector.h"
28 #include "llvm/ADT/PriorityQueue.h"
29 #include "llvm/ADT/SmallPtrSet.h"
30 #include "llvm/ADT/SmallSet.h"
31 #include "llvm/ADT/Statistic.h"
32 #include "llvm/ADT/STLExtras.h"
34 #include "llvm/Support/CommandLine.h"
37 STATISTIC(NumBacktracks, "Number of times scheduler backtracked");
38 STATISTIC(NumUnfolds, "Number of nodes unfolded");
39 STATISTIC(NumDups, "Number of duplicated nodes");
40 STATISTIC(NumCCCopies, "Number of cross class copies");
42 static RegisterScheduler
43 burrListDAGScheduler("list-burr",
44 "Bottom-up register reduction list scheduling",
45 createBURRListDAGScheduler);
46 static RegisterScheduler
47 tdrListrDAGScheduler("list-tdrr",
48 "Top-down register reduction list scheduling",
49 createTDRRListDAGScheduler);
52 //===----------------------------------------------------------------------===//
53 /// ScheduleDAGRRList - The actual register reduction list scheduler
54 /// implementation. This supports both top-down and bottom-up scheduling.
56 class VISIBILITY_HIDDEN ScheduleDAGRRList : public ScheduleDAGSDNodes {
58 /// isBottomUp - This is true if the scheduling problem is bottom-up, false if
62 /// AvailableQueue - The priority queue to use for the available SUnits.
63 SchedulingPriorityQueue *AvailableQueue;
65 /// LiveRegDefs - A set of physical registers and their definition
66 /// that are "live". These nodes must be scheduled before any other nodes that
67 /// modifies the registers can be scheduled.
69 std::vector<SUnit*> LiveRegDefs;
70 std::vector<unsigned> LiveRegCycles;
72 /// Topo - A topological ordering for SUnits which permits fast IsReachable
73 /// and similar queries.
74 ScheduleDAGTopologicalSort Topo;
77 ScheduleDAGRRList(SelectionDAG *dag, MachineBasicBlock *bb,
78 const TargetMachine &tm, bool isbottomup,
79 SchedulingPriorityQueue *availqueue)
80 : ScheduleDAGSDNodes(dag, bb, tm), isBottomUp(isbottomup),
81 AvailableQueue(availqueue), Topo(SUnits) {
84 ~ScheduleDAGRRList() {
85 delete AvailableQueue;
90 /// IsReachable - Checks if SU is reachable from TargetSU.
91 bool IsReachable(const SUnit *SU, const SUnit *TargetSU) {
92 return Topo.IsReachable(SU, TargetSU);
95 /// willCreateCycle - Returns true if adding an edge from SU to TargetSU will
97 bool WillCreateCycle(SUnit *SU, SUnit *TargetSU) {
98 return Topo.WillCreateCycle(SU, TargetSU);
101 /// AddPred - adds a predecessor edge to SUnit SU.
102 /// This returns true if this is a new predecessor.
103 /// Updates the topological ordering if required.
104 void AddPred(SUnit *SU, const SDep &D) {
105 Topo.AddPred(SU, D.getSUnit());
109 /// RemovePred - removes a predecessor edge from SUnit SU.
110 /// This returns true if an edge was removed.
111 /// Updates the topological ordering if required.
112 void RemovePred(SUnit *SU, const SDep &D) {
113 Topo.RemovePred(SU, D.getSUnit());
118 void ReleasePred(SUnit *SU, SDep *PredEdge);
119 void ReleaseSucc(SUnit *SU, SDep *SuccEdge);
120 void CapturePred(SDep *PredEdge);
121 void ScheduleNodeBottomUp(SUnit*, unsigned);
122 void ScheduleNodeTopDown(SUnit*, unsigned);
123 void UnscheduleNodeBottomUp(SUnit*);
124 void BacktrackBottomUp(SUnit*, unsigned, unsigned&);
125 SUnit *CopyAndMoveSuccessors(SUnit*);
126 void InsertCCCopiesAndMoveSuccs(SUnit*, unsigned,
127 const TargetRegisterClass*,
128 const TargetRegisterClass*,
129 SmallVector<SUnit*, 2>&);
130 bool DelayForLiveRegsBottomUp(SUnit*, SmallVector<unsigned, 4>&);
131 void ListScheduleTopDown();
132 void ListScheduleBottomUp();
133 void CommuteNodesToReducePressure();
136 /// CreateNewSUnit - Creates a new SUnit and returns a pointer to it.
137 /// Updates the topological ordering if required.
138 SUnit *CreateNewSUnit(SDNode *N) {
139 unsigned NumSUnits = SUnits.size();
140 SUnit *NewNode = NewSUnit(N);
141 // Update the topological ordering.
142 if (NewNode->NodeNum >= NumSUnits)
143 Topo.InitDAGTopologicalSorting();
147 /// CreateClone - Creates a new SUnit from an existing one.
148 /// Updates the topological ordering if required.
149 SUnit *CreateClone(SUnit *N) {
150 unsigned NumSUnits = SUnits.size();
151 SUnit *NewNode = Clone(N);
152 // Update the topological ordering.
153 if (NewNode->NodeNum >= NumSUnits)
154 Topo.InitDAGTopologicalSorting();
158 /// ForceUnitLatencies - Return true, since register-pressure-reducing
159 /// scheduling doesn't need actual latency information.
160 bool ForceUnitLatencies() const { return true; }
162 } // end anonymous namespace
165 /// Schedule - Schedule the DAG using list scheduling.
166 void ScheduleDAGRRList::Schedule() {
167 DOUT << "********** List Scheduling **********\n";
170 LiveRegDefs.resize(TRI->getNumRegs(), NULL);
171 LiveRegCycles.resize(TRI->getNumRegs(), 0);
173 // Build the scheduling graph.
176 DEBUG(for (unsigned su = 0, e = SUnits.size(); su != e; ++su)
177 SUnits[su].dumpAll(this));
178 Topo.InitDAGTopologicalSorting();
180 AvailableQueue->initNodes(SUnits);
182 // Execute the actual scheduling loop Top-Down or Bottom-Up as appropriate.
184 ListScheduleBottomUp();
186 ListScheduleTopDown();
188 AvailableQueue->releaseState();
191 //===----------------------------------------------------------------------===//
192 // Bottom-Up Scheduling
193 //===----------------------------------------------------------------------===//
195 /// ReleasePred - Decrement the NumSuccsLeft count of a predecessor. Add it to
196 /// the AvailableQueue if the count reaches zero. Also update its cycle bound.
197 void ScheduleDAGRRList::ReleasePred(SUnit *SU, SDep *PredEdge) {
198 SUnit *PredSU = PredEdge->getSUnit();
199 --PredSU->NumSuccsLeft;
202 if (PredSU->NumSuccsLeft < 0) {
203 cerr << "*** Scheduling failed! ***\n";
205 cerr << " has been released too many times!\n";
210 if (PredSU->NumSuccsLeft == 0) {
211 PredSU->isAvailable = true;
212 AvailableQueue->push(PredSU);
216 /// ScheduleNodeBottomUp - Add the node to the schedule. Decrement the pending
217 /// count of its predecessors. If a predecessor pending count is zero, add it to
218 /// the Available queue.
219 void ScheduleDAGRRList::ScheduleNodeBottomUp(SUnit *SU, unsigned CurCycle) {
220 DOUT << "*** Scheduling [" << CurCycle << "]: ";
221 DEBUG(SU->dump(this));
223 assert(CurCycle >= SU->getHeight() && "Node scheduled below its height!");
224 SU->setHeightToAtLeast(CurCycle);
225 Sequence.push_back(SU);
227 // Bottom up: release predecessors
228 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
230 ReleasePred(SU, &*I);
231 if (I->isAssignedRegDep()) {
232 // This is a physical register dependency and it's impossible or
233 // expensive to copy the register. Make sure nothing that can
234 // clobber the register is scheduled between the predecessor and
236 if (!LiveRegDefs[I->getReg()]) {
238 LiveRegDefs[I->getReg()] = I->getSUnit();
239 LiveRegCycles[I->getReg()] = CurCycle;
244 // Release all the implicit physical register defs that are live.
245 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
247 if (I->isAssignedRegDep()) {
248 if (LiveRegCycles[I->getReg()] == I->getSUnit()->getHeight()) {
249 assert(NumLiveRegs > 0 && "NumLiveRegs is already zero!");
250 assert(LiveRegDefs[I->getReg()] == SU &&
251 "Physical register dependency violated?");
253 LiveRegDefs[I->getReg()] = NULL;
254 LiveRegCycles[I->getReg()] = 0;
259 SU->isScheduled = true;
260 AvailableQueue->ScheduledNode(SU);
263 /// CapturePred - This does the opposite of ReleasePred. Since SU is being
264 /// unscheduled, incrcease the succ left count of its predecessors. Remove
265 /// them from AvailableQueue if necessary.
266 void ScheduleDAGRRList::CapturePred(SDep *PredEdge) {
267 SUnit *PredSU = PredEdge->getSUnit();
268 if (PredSU->isAvailable) {
269 PredSU->isAvailable = false;
270 if (!PredSU->isPending)
271 AvailableQueue->remove(PredSU);
274 ++PredSU->NumSuccsLeft;
277 /// UnscheduleNodeBottomUp - Remove the node from the schedule, update its and
278 /// its predecessor states to reflect the change.
279 void ScheduleDAGRRList::UnscheduleNodeBottomUp(SUnit *SU) {
280 DOUT << "*** Unscheduling [" << SU->getHeight() << "]: ";
281 DEBUG(SU->dump(this));
283 AvailableQueue->UnscheduledNode(SU);
285 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
288 if (I->isAssignedRegDep() && SU->getHeight() == LiveRegCycles[I->getReg()]) {
289 assert(NumLiveRegs > 0 && "NumLiveRegs is already zero!");
290 assert(LiveRegDefs[I->getReg()] == I->getSUnit() &&
291 "Physical register dependency violated?");
293 LiveRegDefs[I->getReg()] = NULL;
294 LiveRegCycles[I->getReg()] = 0;
298 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
300 if (I->isAssignedRegDep()) {
301 if (!LiveRegDefs[I->getReg()]) {
302 LiveRegDefs[I->getReg()] = SU;
305 if (I->getSUnit()->getHeight() < LiveRegCycles[I->getReg()])
306 LiveRegCycles[I->getReg()] = I->getSUnit()->getHeight();
310 SU->setHeightDirty();
311 SU->isScheduled = false;
312 SU->isAvailable = true;
313 AvailableQueue->push(SU);
316 /// BacktrackBottomUp - Backtrack scheduling to a previous cycle specified in
317 /// BTCycle in order to schedule a specific node. Returns the last unscheduled
318 /// SUnit. Also returns if a successor is unscheduled in the process.
319 void ScheduleDAGRRList::BacktrackBottomUp(SUnit *SU, unsigned BtCycle,
320 unsigned &CurCycle) {
322 while (CurCycle > BtCycle) {
323 OldSU = Sequence.back();
325 if (SU->isSucc(OldSU))
326 // Don't try to remove SU from AvailableQueue.
327 SU->isAvailable = false;
328 UnscheduleNodeBottomUp(OldSU);
333 if (SU->isSucc(OldSU)) {
334 assert(false && "Something is wrong!");
341 /// CopyAndMoveSuccessors - Clone the specified node and move its scheduled
342 /// successors to the newly created node.
343 SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) {
344 if (SU->getNode()->getFlaggedNode())
347 SDNode *N = SU->getNode();
352 bool TryUnfold = false;
353 for (unsigned i = 0, e = N->getNumValues(); i != e; ++i) {
354 MVT VT = N->getValueType(i);
357 else if (VT == MVT::Other)
360 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
361 const SDValue &Op = N->getOperand(i);
362 MVT VT = Op.getNode()->getValueType(Op.getResNo());
368 SmallVector<SDNode*, 2> NewNodes;
369 if (!TII->unfoldMemoryOperand(*DAG, N, NewNodes))
372 DOUT << "Unfolding SU # " << SU->NodeNum << "\n";
373 assert(NewNodes.size() == 2 && "Expected a load folding node!");
376 SDNode *LoadNode = NewNodes[0];
377 unsigned NumVals = N->getNumValues();
378 unsigned OldNumVals = SU->getNode()->getNumValues();
379 for (unsigned i = 0; i != NumVals; ++i)
380 DAG->ReplaceAllUsesOfValueWith(SDValue(SU->getNode(), i), SDValue(N, i));
381 DAG->ReplaceAllUsesOfValueWith(SDValue(SU->getNode(), OldNumVals-1),
382 SDValue(LoadNode, 1));
384 // LoadNode may already exist. This can happen when there is another
385 // load from the same location and producing the same type of value
386 // but it has different alignment or volatileness.
387 bool isNewLoad = true;
389 if (LoadNode->getNodeId() != -1) {
390 LoadSU = &SUnits[LoadNode->getNodeId()];
393 LoadSU = CreateNewSUnit(LoadNode);
394 LoadNode->setNodeId(LoadSU->NodeNum);
395 ComputeLatency(LoadSU);
398 SUnit *NewSU = CreateNewSUnit(N);
399 assert(N->getNodeId() == -1 && "Node already inserted!");
400 N->setNodeId(NewSU->NodeNum);
402 const TargetInstrDesc &TID = TII->get(N->getMachineOpcode());
403 for (unsigned i = 0; i != TID.getNumOperands(); ++i) {
404 if (TID.getOperandConstraint(i, TOI::TIED_TO) != -1) {
405 NewSU->isTwoAddress = true;
409 if (TID.isCommutable())
410 NewSU->isCommutable = true;
411 ComputeLatency(NewSU);
414 SmallVector<SDep, 4> ChainSuccs;
415 SmallVector<SDep, 4> LoadPreds;
416 SmallVector<SDep, 4> NodePreds;
417 SmallVector<SDep, 4> NodeSuccs;
418 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
422 else if (I->getSUnit()->getNode() &&
423 I->getSUnit()->getNode()->isOperandOf(LoadNode))
424 LoadPreds.push_back(*I);
426 NodePreds.push_back(*I);
428 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
431 ChainSuccs.push_back(*I);
433 NodeSuccs.push_back(*I);
436 if (ChainPred.getSUnit()) {
437 RemovePred(SU, ChainPred);
439 AddPred(LoadSU, ChainPred);
441 for (unsigned i = 0, e = LoadPreds.size(); i != e; ++i) {
442 const SDep &Pred = LoadPreds[i];
443 RemovePred(SU, Pred);
445 AddPred(LoadSU, Pred);
448 for (unsigned i = 0, e = NodePreds.size(); i != e; ++i) {
449 const SDep &Pred = NodePreds[i];
450 RemovePred(SU, Pred);
451 AddPred(NewSU, Pred);
453 for (unsigned i = 0, e = NodeSuccs.size(); i != e; ++i) {
454 SDep D = NodeSuccs[i];
455 SUnit *SuccDep = D.getSUnit();
457 RemovePred(SuccDep, D);
461 for (unsigned i = 0, e = ChainSuccs.size(); i != e; ++i) {
462 SDep D = ChainSuccs[i];
463 SUnit *SuccDep = D.getSUnit();
465 RemovePred(SuccDep, D);
472 AddPred(NewSU, SDep(LoadSU, SDep::Order, LoadSU->Latency));
476 AvailableQueue->addNode(LoadSU);
477 AvailableQueue->addNode(NewSU);
481 if (NewSU->NumSuccsLeft == 0) {
482 NewSU->isAvailable = true;
488 DOUT << "Duplicating SU # " << SU->NodeNum << "\n";
489 NewSU = CreateClone(SU);
491 // New SUnit has the exact same predecessors.
492 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
494 if (!I->isArtificial())
497 // Only copy scheduled successors. Cut them from old node's successor
498 // list and move them over.
499 SmallVector<std::pair<SUnit *, SDep>, 4> DelDeps;
500 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
502 if (I->isArtificial())
504 SUnit *SuccSU = I->getSUnit();
505 if (SuccSU->isScheduled) {
510 DelDeps.push_back(std::make_pair(SuccSU, D));
513 for (unsigned i = 0, e = DelDeps.size(); i != e; ++i)
514 RemovePred(DelDeps[i].first, DelDeps[i].second);
516 AvailableQueue->updateNode(SU);
517 AvailableQueue->addNode(NewSU);
523 /// InsertCCCopiesAndMoveSuccs - Insert expensive cross register class copies
524 /// and move all scheduled successors of the given SUnit to the last copy.
525 void ScheduleDAGRRList::InsertCCCopiesAndMoveSuccs(SUnit *SU, unsigned Reg,
526 const TargetRegisterClass *DestRC,
527 const TargetRegisterClass *SrcRC,
528 SmallVector<SUnit*, 2> &Copies) {
529 SUnit *CopyFromSU = CreateNewSUnit(NULL);
530 CopyFromSU->CopySrcRC = SrcRC;
531 CopyFromSU->CopyDstRC = DestRC;
533 SUnit *CopyToSU = CreateNewSUnit(NULL);
534 CopyToSU->CopySrcRC = DestRC;
535 CopyToSU->CopyDstRC = SrcRC;
537 // Only copy scheduled successors. Cut them from old node's successor
538 // list and move them over.
539 SmallVector<std::pair<SUnit *, SDep>, 4> DelDeps;
540 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
542 if (I->isArtificial())
544 SUnit *SuccSU = I->getSUnit();
545 if (SuccSU->isScheduled) {
547 D.setSUnit(CopyToSU);
549 DelDeps.push_back(std::make_pair(SuccSU, *I));
552 for (unsigned i = 0, e = DelDeps.size(); i != e; ++i) {
553 RemovePred(DelDeps[i].first, DelDeps[i].second);
556 AddPred(CopyFromSU, SDep(SU, SDep::Data, SU->Latency, Reg));
557 AddPred(CopyToSU, SDep(CopyFromSU, SDep::Data, CopyFromSU->Latency, 0));
559 AvailableQueue->updateNode(SU);
560 AvailableQueue->addNode(CopyFromSU);
561 AvailableQueue->addNode(CopyToSU);
562 Copies.push_back(CopyFromSU);
563 Copies.push_back(CopyToSU);
568 /// getPhysicalRegisterVT - Returns the ValueType of the physical register
569 /// definition of the specified node.
570 /// FIXME: Move to SelectionDAG?
571 static MVT getPhysicalRegisterVT(SDNode *N, unsigned Reg,
572 const TargetInstrInfo *TII) {
573 const TargetInstrDesc &TID = TII->get(N->getMachineOpcode());
574 assert(TID.ImplicitDefs && "Physical reg def must be in implicit def list!");
575 unsigned NumRes = TID.getNumDefs();
576 for (const unsigned *ImpDef = TID.getImplicitDefs(); *ImpDef; ++ImpDef) {
581 return N->getValueType(NumRes);
584 /// DelayForLiveRegsBottomUp - Returns true if it is necessary to delay
585 /// scheduling of the given node to satisfy live physical register dependencies.
586 /// If the specific node is the last one that's available to schedule, do
587 /// whatever is necessary (i.e. backtracking or cloning) to make it possible.
588 bool ScheduleDAGRRList::DelayForLiveRegsBottomUp(SUnit *SU,
589 SmallVector<unsigned, 4> &LRegs){
590 if (NumLiveRegs == 0)
593 SmallSet<unsigned, 4> RegAdded;
594 // If this node would clobber any "live" register, then it's not ready.
595 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
597 if (I->isAssignedRegDep()) {
598 unsigned Reg = I->getReg();
599 if (LiveRegDefs[Reg] && LiveRegDefs[Reg] != I->getSUnit()) {
600 if (RegAdded.insert(Reg))
601 LRegs.push_back(Reg);
603 for (const unsigned *Alias = TRI->getAliasSet(Reg);
605 if (LiveRegDefs[*Alias] && LiveRegDefs[*Alias] != I->getSUnit()) {
606 if (RegAdded.insert(*Alias))
607 LRegs.push_back(*Alias);
612 for (SDNode *Node = SU->getNode(); Node; Node = Node->getFlaggedNode()) {
613 if (!Node->isMachineOpcode())
615 const TargetInstrDesc &TID = TII->get(Node->getMachineOpcode());
616 if (!TID.ImplicitDefs)
618 for (const unsigned *Reg = TID.ImplicitDefs; *Reg; ++Reg) {
619 if (LiveRegDefs[*Reg] && LiveRegDefs[*Reg] != SU) {
620 if (RegAdded.insert(*Reg))
621 LRegs.push_back(*Reg);
623 for (const unsigned *Alias = TRI->getAliasSet(*Reg);
625 if (LiveRegDefs[*Alias] && LiveRegDefs[*Alias] != SU) {
626 if (RegAdded.insert(*Alias))
627 LRegs.push_back(*Alias);
631 return !LRegs.empty();
635 /// ListScheduleBottomUp - The main loop of list scheduling for bottom-up
637 void ScheduleDAGRRList::ListScheduleBottomUp() {
638 unsigned CurCycle = 0;
639 // Add root to Available queue.
640 if (!SUnits.empty()) {
641 SUnit *RootSU = &SUnits[DAG->getRoot().getNode()->getNodeId()];
642 assert(RootSU->Succs.empty() && "Graph root shouldn't have successors!");
643 RootSU->isAvailable = true;
644 AvailableQueue->push(RootSU);
647 // While Available queue is not empty, grab the node with the highest
648 // priority. If it is not ready put it back. Schedule the node.
649 SmallVector<SUnit*, 4> NotReady;
650 DenseMap<SUnit*, SmallVector<unsigned, 4> > LRegsMap;
651 Sequence.reserve(SUnits.size());
652 while (!AvailableQueue->empty()) {
653 bool Delayed = false;
655 SUnit *CurSU = AvailableQueue->pop();
657 SmallVector<unsigned, 4> LRegs;
658 if (!DelayForLiveRegsBottomUp(CurSU, LRegs))
661 LRegsMap.insert(std::make_pair(CurSU, LRegs));
663 CurSU->isPending = true; // This SU is not in AvailableQueue right now.
664 NotReady.push_back(CurSU);
665 CurSU = AvailableQueue->pop();
668 // All candidates are delayed due to live physical reg dependencies.
669 // Try backtracking, code duplication, or inserting cross class copies
671 if (Delayed && !CurSU) {
672 for (unsigned i = 0, e = NotReady.size(); i != e; ++i) {
673 SUnit *TrySU = NotReady[i];
674 SmallVector<unsigned, 4> &LRegs = LRegsMap[TrySU];
676 // Try unscheduling up to the point where it's safe to schedule
678 unsigned LiveCycle = CurCycle;
679 for (unsigned j = 0, ee = LRegs.size(); j != ee; ++j) {
680 unsigned Reg = LRegs[j];
681 unsigned LCycle = LiveRegCycles[Reg];
682 LiveCycle = std::min(LiveCycle, LCycle);
684 SUnit *OldSU = Sequence[LiveCycle];
685 if (!WillCreateCycle(TrySU, OldSU)) {
686 BacktrackBottomUp(TrySU, LiveCycle, CurCycle);
687 // Force the current node to be scheduled before the node that
688 // requires the physical reg dep.
689 if (OldSU->isAvailable) {
690 OldSU->isAvailable = false;
691 AvailableQueue->remove(OldSU);
693 AddPred(TrySU, SDep(OldSU, SDep::Order, /*Latency=*/1,
694 /*Reg=*/0, /*isNormalMemory=*/false,
695 /*isMustAlias=*/false, /*isArtificial=*/true));
696 // If one or more successors has been unscheduled, then the current
697 // node is no longer avaialable. Schedule a successor that's now
698 // available instead.
699 if (!TrySU->isAvailable)
700 CurSU = AvailableQueue->pop();
703 TrySU->isPending = false;
704 NotReady.erase(NotReady.begin()+i);
711 // Can't backtrack. Try duplicating the nodes that produces these
712 // "expensive to copy" values to break the dependency. In case even
713 // that doesn't work, insert cross class copies.
714 SUnit *TrySU = NotReady[0];
715 SmallVector<unsigned, 4> &LRegs = LRegsMap[TrySU];
716 assert(LRegs.size() == 1 && "Can't handle this yet!");
717 unsigned Reg = LRegs[0];
718 SUnit *LRDef = LiveRegDefs[Reg];
719 SUnit *NewDef = CopyAndMoveSuccessors(LRDef);
721 // Issue expensive cross register class copies.
722 MVT VT = getPhysicalRegisterVT(LRDef->getNode(), Reg, TII);
723 const TargetRegisterClass *RC =
724 TRI->getPhysicalRegisterRegClass(Reg, VT);
725 const TargetRegisterClass *DestRC = TRI->getCrossCopyRegClass(RC);
727 assert(false && "Don't know how to copy this physical register!");
730 SmallVector<SUnit*, 2> Copies;
731 InsertCCCopiesAndMoveSuccs(LRDef, Reg, DestRC, RC, Copies);
732 DOUT << "Adding an edge from SU # " << TrySU->NodeNum
733 << " to SU #" << Copies.front()->NodeNum << "\n";
734 AddPred(TrySU, SDep(Copies.front(), SDep::Order, /*Latency=*/1,
735 /*Reg=*/0, /*isMustAlias=*/false,
736 /*isArtificial=*/true));
737 NewDef = Copies.back();
740 DOUT << "Adding an edge from SU # " << NewDef->NodeNum
741 << " to SU #" << TrySU->NodeNum << "\n";
742 LiveRegDefs[Reg] = NewDef;
743 AddPred(NewDef, SDep(TrySU, SDep::Order, /*Latency=*/1,
744 /*Reg=*/0, /*isMustAlias=*/false,
745 /*isArtificial=*/true));
746 TrySU->isAvailable = false;
751 assert(false && "Unable to resolve live physical register dependencies!");
756 // Add the nodes that aren't ready back onto the available list.
757 for (unsigned i = 0, e = NotReady.size(); i != e; ++i) {
758 NotReady[i]->isPending = false;
759 // May no longer be available due to backtracking.
760 if (NotReady[i]->isAvailable)
761 AvailableQueue->push(NotReady[i]);
766 ScheduleNodeBottomUp(CurSU, CurCycle);
770 // Reverse the order if it is bottom up.
771 std::reverse(Sequence.begin(), Sequence.end());
774 VerifySchedule(isBottomUp);
778 //===----------------------------------------------------------------------===//
779 // Top-Down Scheduling
780 //===----------------------------------------------------------------------===//
782 /// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to
783 /// the AvailableQueue if the count reaches zero. Also update its cycle bound.
784 void ScheduleDAGRRList::ReleaseSucc(SUnit *SU, SDep *SuccEdge) {
785 SUnit *SuccSU = SuccEdge->getSUnit();
786 --SuccSU->NumPredsLeft;
789 if (SuccSU->NumPredsLeft < 0) {
790 cerr << "*** Scheduling failed! ***\n";
792 cerr << " has been released too many times!\n";
797 if (SuccSU->NumPredsLeft == 0) {
798 SuccSU->isAvailable = true;
799 AvailableQueue->push(SuccSU);
803 /// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending
804 /// count of its successors. If a successor pending count is zero, add it to
805 /// the Available queue.
806 void ScheduleDAGRRList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) {
807 DOUT << "*** Scheduling [" << CurCycle << "]: ";
808 DEBUG(SU->dump(this));
810 assert(CurCycle >= SU->getDepth() && "Node scheduled above its depth!");
811 SU->setDepthToAtLeast(CurCycle);
812 Sequence.push_back(SU);
814 // Top down: release successors
815 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
817 ReleaseSucc(SU, &*I);
819 SU->isScheduled = true;
820 AvailableQueue->ScheduledNode(SU);
823 /// ListScheduleTopDown - The main loop of list scheduling for top-down
825 void ScheduleDAGRRList::ListScheduleTopDown() {
826 unsigned CurCycle = 0;
828 // All leaves to Available queue.
829 for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
830 // It is available if it has no predecessors.
831 if (SUnits[i].Preds.empty()) {
832 AvailableQueue->push(&SUnits[i]);
833 SUnits[i].isAvailable = true;
837 // While Available queue is not empty, grab the node with the highest
838 // priority. If it is not ready put it back. Schedule the node.
839 Sequence.reserve(SUnits.size());
840 while (!AvailableQueue->empty()) {
841 SUnit *CurSU = AvailableQueue->pop();
844 ScheduleNodeTopDown(CurSU, CurCycle);
849 VerifySchedule(isBottomUp);
854 //===----------------------------------------------------------------------===//
855 // RegReductionPriorityQueue Implementation
856 //===----------------------------------------------------------------------===//
858 // This is a SchedulingPriorityQueue that schedules using Sethi Ullman numbers
859 // to reduce register pressure.
863 class RegReductionPriorityQueue;
865 /// Sorting functions for the Available queue.
866 struct bu_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> {
867 RegReductionPriorityQueue<bu_ls_rr_sort> *SPQ;
868 bu_ls_rr_sort(RegReductionPriorityQueue<bu_ls_rr_sort> *spq) : SPQ(spq) {}
869 bu_ls_rr_sort(const bu_ls_rr_sort &RHS) : SPQ(RHS.SPQ) {}
871 bool operator()(const SUnit* left, const SUnit* right) const;
874 struct td_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> {
875 RegReductionPriorityQueue<td_ls_rr_sort> *SPQ;
876 td_ls_rr_sort(RegReductionPriorityQueue<td_ls_rr_sort> *spq) : SPQ(spq) {}
877 td_ls_rr_sort(const td_ls_rr_sort &RHS) : SPQ(RHS.SPQ) {}
879 bool operator()(const SUnit* left, const SUnit* right) const;
881 } // end anonymous namespace
883 static inline bool isCopyFromLiveIn(const SUnit *SU) {
884 SDNode *N = SU->getNode();
885 return N && N->getOpcode() == ISD::CopyFromReg &&
886 N->getOperand(N->getNumOperands()-1).getValueType() != MVT::Flag;
889 /// CalcNodeSethiUllmanNumber - Compute Sethi Ullman number.
890 /// Smaller number is the higher priority.
892 CalcNodeSethiUllmanNumber(const SUnit *SU, std::vector<unsigned> &SUNumbers) {
893 unsigned &SethiUllmanNumber = SUNumbers[SU->NodeNum];
894 if (SethiUllmanNumber != 0)
895 return SethiUllmanNumber;
898 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
900 if (I->isCtrl()) continue; // ignore chain preds
901 SUnit *PredSU = I->getSUnit();
902 unsigned PredSethiUllman = CalcNodeSethiUllmanNumber(PredSU, SUNumbers);
903 if (PredSethiUllman > SethiUllmanNumber) {
904 SethiUllmanNumber = PredSethiUllman;
906 } else if (PredSethiUllman == SethiUllmanNumber && !I->isCtrl())
910 SethiUllmanNumber += Extra;
912 if (SethiUllmanNumber == 0)
913 SethiUllmanNumber = 1;
915 return SethiUllmanNumber;
920 class VISIBILITY_HIDDEN RegReductionPriorityQueue
921 : public SchedulingPriorityQueue {
922 PriorityQueue<SUnit*, std::vector<SUnit*>, SF> Queue;
923 unsigned currentQueueId;
926 // SUnits - The SUnits for the current graph.
927 std::vector<SUnit> *SUnits;
929 const TargetInstrInfo *TII;
930 const TargetRegisterInfo *TRI;
931 ScheduleDAGRRList *scheduleDAG;
933 // SethiUllmanNumbers - The SethiUllman number for each node.
934 std::vector<unsigned> SethiUllmanNumbers;
937 RegReductionPriorityQueue(const TargetInstrInfo *tii,
938 const TargetRegisterInfo *tri) :
939 Queue(SF(this)), currentQueueId(0),
940 TII(tii), TRI(tri), scheduleDAG(NULL) {}
942 void initNodes(std::vector<SUnit> &sunits) {
944 // Add pseudo dependency edges for two-address nodes.
945 AddPseudoTwoAddrDeps();
946 // Calculate node priorities.
947 CalculateSethiUllmanNumbers();
950 void addNode(const SUnit *SU) {
951 unsigned SUSize = SethiUllmanNumbers.size();
952 if (SUnits->size() > SUSize)
953 SethiUllmanNumbers.resize(SUSize*2, 0);
954 CalcNodeSethiUllmanNumber(SU, SethiUllmanNumbers);
957 void updateNode(const SUnit *SU) {
958 SethiUllmanNumbers[SU->NodeNum] = 0;
959 CalcNodeSethiUllmanNumber(SU, SethiUllmanNumbers);
962 void releaseState() {
964 SethiUllmanNumbers.clear();
967 unsigned getNodePriority(const SUnit *SU) const {
968 assert(SU->NodeNum < SethiUllmanNumbers.size());
969 unsigned Opc = SU->getNode() ? SU->getNode()->getOpcode() : 0;
970 if (Opc == ISD::CopyFromReg && !isCopyFromLiveIn(SU))
971 // CopyFromReg should be close to its def because it restricts
972 // allocation choices. But if it is a livein then perhaps we want it
973 // closer to its uses so it can be coalesced.
975 else if (Opc == ISD::TokenFactor || Opc == ISD::CopyToReg)
976 // CopyToReg should be close to its uses to facilitate coalescing and
979 else if (Opc == TargetInstrInfo::EXTRACT_SUBREG ||
980 Opc == TargetInstrInfo::INSERT_SUBREG)
981 // EXTRACT_SUBREG / INSERT_SUBREG should be close to its use to
982 // facilitate coalescing.
984 else if (SU->NumSuccs == 0)
985 // If SU does not have a use, i.e. it doesn't produce a value that would
986 // be consumed (e.g. store), then it terminates a chain of computation.
987 // Give it a large SethiUllman number so it will be scheduled right
988 // before its predecessors that it doesn't lengthen their live ranges.
990 else if (SU->NumPreds == 0)
991 // If SU does not have a def, schedule it close to its uses because it
992 // does not lengthen any live ranges.
995 return SethiUllmanNumbers[SU->NodeNum];
998 unsigned size() const { return Queue.size(); }
1000 bool empty() const { return Queue.empty(); }
1002 void push(SUnit *U) {
1003 assert(!U->NodeQueueId && "Node in the queue already");
1004 U->NodeQueueId = ++currentQueueId;
1008 void push_all(const std::vector<SUnit *> &Nodes) {
1009 for (unsigned i = 0, e = Nodes.size(); i != e; ++i)
1014 if (empty()) return NULL;
1015 SUnit *V = Queue.top();
1021 void remove(SUnit *SU) {
1022 assert(!Queue.empty() && "Queue is empty!");
1023 assert(SU->NodeQueueId != 0 && "Not in queue!");
1024 Queue.erase_one(SU);
1025 SU->NodeQueueId = 0;
1028 void setScheduleDAG(ScheduleDAGRRList *scheduleDag) {
1029 scheduleDAG = scheduleDag;
1033 bool canClobber(const SUnit *SU, const SUnit *Op);
1034 void AddPseudoTwoAddrDeps();
1035 void CalculateSethiUllmanNumbers();
1038 typedef RegReductionPriorityQueue<bu_ls_rr_sort>
1039 BURegReductionPriorityQueue;
1041 typedef RegReductionPriorityQueue<td_ls_rr_sort>
1042 TDRegReductionPriorityQueue;
1045 /// closestSucc - Returns the scheduled cycle of the successor which is
1046 /// closet to the current cycle.
1047 static unsigned closestSucc(const SUnit *SU) {
1048 unsigned MaxHeight = 0;
1049 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
1051 unsigned Height = I->getSUnit()->getHeight();
1052 // If there are bunch of CopyToRegs stacked up, they should be considered
1053 // to be at the same position.
1054 if (I->getSUnit()->getNode() &&
1055 I->getSUnit()->getNode()->getOpcode() == ISD::CopyToReg)
1056 Height = closestSucc(I->getSUnit())+1;
1057 if (Height > MaxHeight)
1063 /// calcMaxScratches - Returns an cost estimate of the worse case requirement
1064 /// for scratch registers. Live-in operands and live-out results don't count
1065 /// since they are "fixed".
1066 static unsigned calcMaxScratches(const SUnit *SU) {
1067 unsigned Scratches = 0;
1068 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
1070 if (I->isCtrl()) continue; // ignore chain preds
1071 if (!I->getSUnit()->getNode() ||
1072 I->getSUnit()->getNode()->getOpcode() != ISD::CopyFromReg)
1075 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
1077 if (I->isCtrl()) continue; // ignore chain succs
1078 if (!I->getSUnit()->getNode() ||
1079 I->getSUnit()->getNode()->getOpcode() != ISD::CopyToReg)
1086 bool bu_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const {
1087 unsigned LPriority = SPQ->getNodePriority(left);
1088 unsigned RPriority = SPQ->getNodePriority(right);
1089 if (LPriority != RPriority)
1090 return LPriority > RPriority;
1092 // Try schedule def + use closer when Sethi-Ullman numbers are the same.
1097 // and the following instructions are both ready.
1101 // Then schedule t2 = op first.
1108 // This creates more short live intervals.
1109 unsigned LDist = closestSucc(left);
1110 unsigned RDist = closestSucc(right);
1112 return LDist < RDist;
1114 // Intuitively, it's good to push down instructions whose results are
1115 // liveout so their long live ranges won't conflict with other values
1116 // which are needed inside the BB. Further prioritize liveout instructions
1117 // by the number of operands which are calculated within the BB.
1118 unsigned LScratch = calcMaxScratches(left);
1119 unsigned RScratch = calcMaxScratches(right);
1120 if (LScratch != RScratch)
1121 return LScratch > RScratch;
1123 if (left->getHeight() != right->getHeight())
1124 return left->getHeight() > right->getHeight();
1126 if (left->getDepth() != right->getDepth())
1127 return left->getDepth() < right->getDepth();
1129 assert(left->NodeQueueId && right->NodeQueueId &&
1130 "NodeQueueId cannot be zero");
1131 return (left->NodeQueueId > right->NodeQueueId);
1136 RegReductionPriorityQueue<SF>::canClobber(const SUnit *SU, const SUnit *Op) {
1137 if (SU->isTwoAddress) {
1138 unsigned Opc = SU->getNode()->getMachineOpcode();
1139 const TargetInstrDesc &TID = TII->get(Opc);
1140 unsigned NumRes = TID.getNumDefs();
1141 unsigned NumOps = TID.getNumOperands() - NumRes;
1142 for (unsigned i = 0; i != NumOps; ++i) {
1143 if (TID.getOperandConstraint(i+NumRes, TOI::TIED_TO) != -1) {
1144 SDNode *DU = SU->getNode()->getOperand(i).getNode();
1145 if (DU->getNodeId() != -1 &&
1146 Op->OrigNode == &(*SUnits)[DU->getNodeId()])
1155 /// hasCopyToRegUse - Return true if SU has a value successor that is a
1157 static bool hasCopyToRegUse(const SUnit *SU) {
1158 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
1160 if (I->isCtrl()) continue;
1161 const SUnit *SuccSU = I->getSUnit();
1162 if (SuccSU->getNode() && SuccSU->getNode()->getOpcode() == ISD::CopyToReg)
1168 /// canClobberPhysRegDefs - True if SU would clobber one of SuccSU's
1169 /// physical register defs.
1170 static bool canClobberPhysRegDefs(const SUnit *SuccSU, const SUnit *SU,
1171 const TargetInstrInfo *TII,
1172 const TargetRegisterInfo *TRI) {
1173 SDNode *N = SuccSU->getNode();
1174 unsigned NumDefs = TII->get(N->getMachineOpcode()).getNumDefs();
1175 const unsigned *ImpDefs = TII->get(N->getMachineOpcode()).getImplicitDefs();
1176 assert(ImpDefs && "Caller should check hasPhysRegDefs");
1177 const unsigned *SUImpDefs =
1178 TII->get(SU->getNode()->getMachineOpcode()).getImplicitDefs();
1181 for (unsigned i = NumDefs, e = N->getNumValues(); i != e; ++i) {
1182 MVT VT = N->getValueType(i);
1183 if (VT == MVT::Flag || VT == MVT::Other)
1185 if (!N->hasAnyUseOfValue(i))
1187 unsigned Reg = ImpDefs[i - NumDefs];
1188 for (;*SUImpDefs; ++SUImpDefs) {
1189 unsigned SUReg = *SUImpDefs;
1190 if (TRI->regsOverlap(Reg, SUReg))
1197 /// AddPseudoTwoAddrDeps - If two nodes share an operand and one of them uses
1198 /// it as a def&use operand. Add a pseudo control edge from it to the other
1199 /// node (if it won't create a cycle) so the two-address one will be scheduled
1200 /// first (lower in the schedule). If both nodes are two-address, favor the
1201 /// one that has a CopyToReg use (more likely to be a loop induction update).
1202 /// If both are two-address, but one is commutable while the other is not
1203 /// commutable, favor the one that's not commutable.
1205 void RegReductionPriorityQueue<SF>::AddPseudoTwoAddrDeps() {
1206 for (unsigned i = 0, e = SUnits->size(); i != e; ++i) {
1207 SUnit *SU = &(*SUnits)[i];
1208 if (!SU->isTwoAddress)
1211 SDNode *Node = SU->getNode();
1212 if (!Node || !Node->isMachineOpcode() || SU->getNode()->getFlaggedNode())
1215 unsigned Opc = Node->getMachineOpcode();
1216 const TargetInstrDesc &TID = TII->get(Opc);
1217 unsigned NumRes = TID.getNumDefs();
1218 unsigned NumOps = TID.getNumOperands() - NumRes;
1219 for (unsigned j = 0; j != NumOps; ++j) {
1220 if (TID.getOperandConstraint(j+NumRes, TOI::TIED_TO) == -1)
1222 SDNode *DU = SU->getNode()->getOperand(j).getNode();
1223 if (DU->getNodeId() == -1)
1225 const SUnit *DUSU = &(*SUnits)[DU->getNodeId()];
1226 if (!DUSU) continue;
1227 for (SUnit::const_succ_iterator I = DUSU->Succs.begin(),
1228 E = DUSU->Succs.end(); I != E; ++I) {
1229 if (I->isCtrl()) continue;
1230 SUnit *SuccSU = I->getSUnit();
1233 // Be conservative. Ignore if nodes aren't at roughly the same
1234 // depth and height.
1235 if (SuccSU->getHeight() < SU->getHeight() &&
1236 (SU->getHeight() - SuccSU->getHeight()) > 1)
1238 if (!SuccSU->getNode() || !SuccSU->getNode()->isMachineOpcode())
1240 // Don't constrain nodes with physical register defs if the
1241 // predecessor can clobber them.
1242 if (SuccSU->hasPhysRegDefs) {
1243 if (canClobberPhysRegDefs(SuccSU, SU, TII, TRI))
1246 // Don't constraint extract_subreg / insert_subreg these may be
1247 // coalesced away. We don't them close to their uses.
1248 unsigned SuccOpc = SuccSU->getNode()->getMachineOpcode();
1249 if (SuccOpc == TargetInstrInfo::EXTRACT_SUBREG ||
1250 SuccOpc == TargetInstrInfo::INSERT_SUBREG)
1252 if ((!canClobber(SuccSU, DUSU) ||
1253 (hasCopyToRegUse(SU) && !hasCopyToRegUse(SuccSU)) ||
1254 (!SU->isCommutable && SuccSU->isCommutable)) &&
1255 !scheduleDAG->IsReachable(SuccSU, SU)) {
1256 DOUT << "Adding a pseudo-two-addr edge from SU # " << SU->NodeNum
1257 << " to SU #" << SuccSU->NodeNum << "\n";
1258 scheduleDAG->AddPred(SU, SDep(SuccSU, SDep::Order, /*Latency=*/1,
1259 /*Reg=*/0, /*isMustAlias=*/false,
1260 /*isArtificial=*/true));
1267 /// CalculateSethiUllmanNumbers - Calculate Sethi-Ullman numbers of all
1268 /// scheduling units.
1270 void RegReductionPriorityQueue<SF>::CalculateSethiUllmanNumbers() {
1271 SethiUllmanNumbers.assign(SUnits->size(), 0);
1273 for (unsigned i = 0, e = SUnits->size(); i != e; ++i)
1274 CalcNodeSethiUllmanNumber(&(*SUnits)[i], SethiUllmanNumbers);
1277 /// LimitedSumOfUnscheduledPredsOfSuccs - Compute the sum of the unscheduled
1278 /// predecessors of the successors of the SUnit SU. Stop when the provided
1279 /// limit is exceeded.
1280 static unsigned LimitedSumOfUnscheduledPredsOfSuccs(const SUnit *SU,
1283 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
1285 const SUnit *SuccSU = I->getSUnit();
1286 for (SUnit::const_pred_iterator II = SuccSU->Preds.begin(),
1287 EE = SuccSU->Preds.end(); II != EE; ++II) {
1288 SUnit *PredSU = II->getSUnit();
1289 if (!PredSU->isScheduled)
1299 bool td_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const {
1300 unsigned LPriority = SPQ->getNodePriority(left);
1301 unsigned RPriority = SPQ->getNodePriority(right);
1302 bool LIsTarget = left->getNode() && left->getNode()->isMachineOpcode();
1303 bool RIsTarget = right->getNode() && right->getNode()->isMachineOpcode();
1304 bool LIsFloater = LIsTarget && left->NumPreds == 0;
1305 bool RIsFloater = RIsTarget && right->NumPreds == 0;
1306 unsigned LBonus = (LimitedSumOfUnscheduledPredsOfSuccs(left,1) == 1) ? 2 : 0;
1307 unsigned RBonus = (LimitedSumOfUnscheduledPredsOfSuccs(right,1) == 1) ? 2 : 0;
1309 if (left->NumSuccs == 0 && right->NumSuccs != 0)
1311 else if (left->NumSuccs != 0 && right->NumSuccs == 0)
1318 if (left->NumSuccs == 1)
1320 if (right->NumSuccs == 1)
1323 if (LPriority+LBonus != RPriority+RBonus)
1324 return LPriority+LBonus < RPriority+RBonus;
1326 if (left->getDepth() != right->getDepth())
1327 return left->getDepth() < right->getDepth();
1329 if (left->NumSuccsLeft != right->NumSuccsLeft)
1330 return left->NumSuccsLeft > right->NumSuccsLeft;
1332 assert(left->NodeQueueId && right->NodeQueueId &&
1333 "NodeQueueId cannot be zero");
1334 return (left->NodeQueueId > right->NodeQueueId);
1337 //===----------------------------------------------------------------------===//
1338 // Public Constructor Functions
1339 //===----------------------------------------------------------------------===//
1341 llvm::ScheduleDAG* llvm::createBURRListDAGScheduler(SelectionDAGISel *IS,
1343 const TargetMachine *TM,
1344 MachineBasicBlock *BB,
1346 const TargetInstrInfo *TII = TM->getInstrInfo();
1347 const TargetRegisterInfo *TRI = TM->getRegisterInfo();
1349 BURegReductionPriorityQueue *PQ = new BURegReductionPriorityQueue(TII, TRI);
1351 ScheduleDAGRRList *SD =
1352 new ScheduleDAGRRList(DAG, BB, *TM, true, PQ);
1353 PQ->setScheduleDAG(SD);
1357 llvm::ScheduleDAG* llvm::createTDRRListDAGScheduler(SelectionDAGISel *IS,
1359 const TargetMachine *TM,
1360 MachineBasicBlock *BB,
1362 const TargetInstrInfo *TII = TM->getInstrInfo();
1363 const TargetRegisterInfo *TRI = TM->getRegisterInfo();
1365 TDRegReductionPriorityQueue *PQ = new TDRegReductionPriorityQueue(TII, TRI);
1367 ScheduleDAGRRList *SD = new ScheduleDAGRRList(DAG, BB, *TM, false, PQ);
1368 PQ->setScheduleDAG(SD);