Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 1 | //===---- ScheduleDAGList.cpp - Implement a list scheduler for isel DAG ---===// |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 10 | // This implements a top-down list scheduler, using standard algorithms. |
| 11 | // The basic approach uses a priority queue of available nodes to schedule. |
| 12 | // One at a time, nodes are taken from the priority queue (thus in priority |
| 13 | // order), checked for legality to schedule, and emitted if legal. |
Chris Lattner | 01aa752 | 2006-03-06 17:58:04 +0000 | [diff] [blame] | 14 | // |
| 15 | // Nodes may not be legal to schedule either due to structural hazards (e.g. |
| 16 | // pipeline or resource constraints) or because an input to the instruction has |
| 17 | // not completed execution. |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 18 | // |
| 19 | //===----------------------------------------------------------------------===// |
| 20 | |
Dale Johannesen | 2182f06 | 2007-07-13 17:13:54 +0000 | [diff] [blame] | 21 | #define DEBUG_TYPE "pre-RA-sched" |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/ScheduleDAG.h" |
Jim Laskey | 29e635d | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/SchedulerRegistry.h" |
Jim Laskey | 03593f7 | 2006-08-01 18:29:48 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/SelectionDAGISel.h" |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetRegisterInfo.h" |
Owen Anderson | 8c2c1e9 | 2006-05-12 06:33:49 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetData.h" |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetMachine.h" |
| 28 | #include "llvm/Target/TargetInstrInfo.h" |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Debug.h" |
Chris Lattner | 3d27be1 | 2006-08-27 12:54:02 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Compiler.h" |
Dan Gohman | 0d8a61e | 2008-06-23 23:40:09 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/PriorityQueue.h" |
Chris Lattner | fa5e1c9 | 2006-03-05 23:13:56 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/Statistic.h" |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 33 | #include <climits> |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 34 | using namespace llvm; |
| 35 | |
Chris Lattner | aee775a | 2006-12-19 22:41:21 +0000 | [diff] [blame] | 36 | STATISTIC(NumNoops , "Number of noops inserted"); |
| 37 | STATISTIC(NumStalls, "Number of pipeline stalls"); |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 38 | |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 39 | static RegisterScheduler |
Dan Gohman | 9c4b7d5 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 40 | tdListDAGScheduler("list-td", "Top-down list scheduler", |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 41 | createTDListDAGScheduler); |
| 42 | |
Chris Lattner | af5e26c | 2006-03-08 04:37:58 +0000 | [diff] [blame] | 43 | namespace { |
Chris Lattner | 9e95acc | 2006-03-09 06:37:29 +0000 | [diff] [blame] | 44 | //===----------------------------------------------------------------------===// |
| 45 | /// ScheduleDAGList - The actual list scheduler implementation. This supports |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 46 | /// top-down scheduling. |
Chris Lattner | 9e95acc | 2006-03-09 06:37:29 +0000 | [diff] [blame] | 47 | /// |
Chris Lattner | e097e6f | 2006-06-28 22:17:39 +0000 | [diff] [blame] | 48 | class VISIBILITY_HIDDEN ScheduleDAGList : public ScheduleDAG { |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 49 | private: |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 50 | /// AvailableQueue - The priority queue to use for the available SUnits. |
| 51 | /// |
| 52 | SchedulingPriorityQueue *AvailableQueue; |
Chris Lattner | 9df6475 | 2006-03-09 06:35:14 +0000 | [diff] [blame] | 53 | |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 54 | /// PendingQueue - This contains all of the instructions whose operands have |
| 55 | /// been issued, but their results are not ready yet (due to the latency of |
| 56 | /// the operation). Once the operands becomes available, the instruction is |
| 57 | /// added to the AvailableQueue. This keeps track of each SUnit and the |
| 58 | /// number of cycles left to execute before the operation is available. |
| 59 | std::vector<std::pair<unsigned, SUnit*> > PendingQueue; |
Evan Cheng | 9add880 | 2006-05-04 19:16:39 +0000 | [diff] [blame] | 60 | |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 61 | /// HazardRec - The hazard recognizer to use. |
Chris Lattner | 543832d | 2006-03-08 04:25:59 +0000 | [diff] [blame] | 62 | HazardRecognizer *HazardRec; |
Evan Cheng | 9add880 | 2006-05-04 19:16:39 +0000 | [diff] [blame] | 63 | |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 64 | public: |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 65 | ScheduleDAGList(SelectionDAG *dag, MachineBasicBlock *bb, |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 66 | const TargetMachine &tm, |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 67 | SchedulingPriorityQueue *availqueue, |
Chris Lattner | 543832d | 2006-03-08 04:25:59 +0000 | [diff] [blame] | 68 | HazardRecognizer *HR) |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 69 | : ScheduleDAG(dag, bb, tm), |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 70 | AvailableQueue(availqueue), HazardRec(HR) { |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 71 | } |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 72 | |
| 73 | ~ScheduleDAGList() { |
Chris Lattner | 543832d | 2006-03-08 04:25:59 +0000 | [diff] [blame] | 74 | delete HazardRec; |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 75 | delete AvailableQueue; |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 76 | } |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 77 | |
| 78 | void Schedule(); |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 79 | |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 80 | private: |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 81 | void ReleaseSucc(SUnit *SuccSU, bool isChain); |
Chris Lattner | 063086b | 2006-03-11 22:34:41 +0000 | [diff] [blame] | 82 | void ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle); |
Chris Lattner | 399bee2 | 2006-03-09 06:48:37 +0000 | [diff] [blame] | 83 | void ListScheduleTopDown(); |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 84 | }; |
Chris Lattner | af5e26c | 2006-03-08 04:37:58 +0000 | [diff] [blame] | 85 | } // end anonymous namespace |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 86 | |
Chris Lattner | 47639db | 2006-03-06 00:22:00 +0000 | [diff] [blame] | 87 | HazardRecognizer::~HazardRecognizer() {} |
| 88 | |
Evan Cheng | c4c339c | 2006-01-26 00:30:29 +0000 | [diff] [blame] | 89 | |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 90 | /// Schedule - Schedule the DAG using list scheduling. |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 91 | void ScheduleDAGList::Schedule() { |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 92 | DOUT << "********** List Scheduling **********\n"; |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 93 | |
| 94 | // Build scheduling units. |
| 95 | BuildSchedUnits(); |
Evan Cheng | 7d69389 | 2006-05-09 07:13:34 +0000 | [diff] [blame] | 96 | |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 97 | AvailableQueue->initNodes(SUnits); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 98 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 99 | ListScheduleTopDown(); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 100 | |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 101 | AvailableQueue->releaseState(); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | //===----------------------------------------------------------------------===// |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 105 | // Top-Down Scheduling |
| 106 | //===----------------------------------------------------------------------===// |
| 107 | |
| 108 | /// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 109 | /// the PendingQueue if the count reaches zero. |
| 110 | void ScheduleDAGList::ReleaseSucc(SUnit *SuccSU, bool isChain) { |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 111 | SuccSU->NumPredsLeft--; |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 112 | |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 113 | assert(SuccSU->NumPredsLeft >= 0 && |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 114 | "List scheduling internal error"); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 115 | |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 116 | if (SuccSU->NumPredsLeft == 0) { |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 117 | // Compute how many cycles it will be before this actually becomes |
| 118 | // available. This is the max of the start time of all predecessors plus |
| 119 | // their latencies. |
| 120 | unsigned AvailableCycle = 0; |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 121 | for (SUnit::pred_iterator I = SuccSU->Preds.begin(), |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 122 | E = SuccSU->Preds.end(); I != E; ++I) { |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 123 | // If this is a token edge, we don't need to wait for the latency of the |
| 124 | // preceeding instruction (e.g. a long-latency load) unless there is also |
| 125 | // some other data dependence. |
Evan Cheng | 0effc3a | 2007-09-19 01:38:40 +0000 | [diff] [blame] | 126 | SUnit &Pred = *I->Dep; |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 127 | unsigned PredDoneCycle = Pred.Cycle; |
Evan Cheng | 0effc3a | 2007-09-19 01:38:40 +0000 | [diff] [blame] | 128 | if (!I->isCtrl) |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 129 | PredDoneCycle += Pred.Latency; |
| 130 | else if (Pred.Latency) |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 131 | PredDoneCycle += 1; |
Chris Lattner | 86a9b60 | 2006-03-12 03:52:09 +0000 | [diff] [blame] | 132 | |
| 133 | AvailableCycle = std::max(AvailableCycle, PredDoneCycle); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | PendingQueue.push_back(std::make_pair(AvailableCycle, SuccSU)); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
| 140 | /// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending |
| 141 | /// count of its successors. If a successor pending count is zero, add it to |
| 142 | /// the Available queue. |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 143 | void ScheduleDAGList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) { |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 144 | DOUT << "*** Scheduling [" << CurCycle << "]: "; |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 145 | DEBUG(SU->dump(DAG)); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 146 | |
| 147 | Sequence.push_back(SU); |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 148 | SU->Cycle = CurCycle; |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 149 | |
| 150 | // Bottom up: release successors. |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 151 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 152 | I != E; ++I) |
Evan Cheng | 0effc3a | 2007-09-19 01:38:40 +0000 | [diff] [blame] | 153 | ReleaseSucc(I->Dep, I->isCtrl); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 156 | /// ListScheduleTopDown - The main loop of list scheduling for top-down |
| 157 | /// schedulers. |
Chris Lattner | 399bee2 | 2006-03-09 06:48:37 +0000 | [diff] [blame] | 158 | void ScheduleDAGList::ListScheduleTopDown() { |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 159 | unsigned CurCycle = 0; |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 160 | |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 161 | // All leaves to Available queue. |
Chris Lattner | 42e2026 | 2006-03-08 04:54:34 +0000 | [diff] [blame] | 162 | for (unsigned i = 0, e = SUnits.size(); i != e; ++i) { |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 163 | // It is available if it has no predecessors. |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 164 | if (SUnits[i].Preds.empty()) { |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 165 | AvailableQueue->push(&SUnits[i]); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 166 | SUnits[i].isAvailable = SUnits[i].isPending = true; |
| 167 | } |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | // While Available queue is not empty, grab the node with the highest |
| 171 | // priority. If it is not ready put it back. Schedule the node. |
| 172 | std::vector<SUnit*> NotReady; |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 173 | Sequence.reserve(SUnits.size()); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 174 | while (!AvailableQueue->empty() || !PendingQueue.empty()) { |
| 175 | // Check to see if any of the pending instructions are ready to issue. If |
| 176 | // so, add them to the available queue. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 177 | for (unsigned i = 0, e = PendingQueue.size(); i != e; ++i) { |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 178 | if (PendingQueue[i].first == CurCycle) { |
| 179 | AvailableQueue->push(PendingQueue[i].second); |
| 180 | PendingQueue[i].second->isAvailable = true; |
| 181 | PendingQueue[i] = PendingQueue.back(); |
| 182 | PendingQueue.pop_back(); |
| 183 | --i; --e; |
| 184 | } else { |
| 185 | assert(PendingQueue[i].first > CurCycle && "Negative latency?"); |
| 186 | } |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 187 | } |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 188 | |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 189 | // If there are no instructions available, don't try to issue anything, and |
| 190 | // don't advance the hazard recognizer. |
| 191 | if (AvailableQueue->empty()) { |
| 192 | ++CurCycle; |
| 193 | continue; |
| 194 | } |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 195 | |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 196 | SUnit *FoundSUnit = 0; |
| 197 | SDNode *FoundNode = 0; |
| 198 | |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 199 | bool HasNoopHazards = false; |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 200 | while (!AvailableQueue->empty()) { |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 201 | SUnit *CurSUnit = AvailableQueue->pop(); |
Chris Lattner | 0c801bd | 2006-03-07 05:40:43 +0000 | [diff] [blame] | 202 | |
| 203 | // Get the node represented by this SUnit. |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame^] | 204 | FoundNode = CurSUnit->getNode(); |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 205 | |
Chris Lattner | 0c801bd | 2006-03-07 05:40:43 +0000 | [diff] [blame] | 206 | // If this is a pseudo op, like copyfromreg, look to see if there is a |
| 207 | // real target node flagged to it. If so, use the target node. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 208 | for (unsigned i = 0, e = CurSUnit->FlaggedNodes.size(); |
Dan Gohman | 1705968 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 209 | !FoundNode->isMachineOpcode() && i != e; ++i) |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 210 | FoundNode = CurSUnit->FlaggedNodes[i]; |
Chris Lattner | 0c801bd | 2006-03-07 05:40:43 +0000 | [diff] [blame] | 211 | |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 212 | HazardRecognizer::HazardType HT = HazardRec->getHazardType(FoundNode); |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 213 | if (HT == HazardRecognizer::NoHazard) { |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 214 | FoundSUnit = CurSUnit; |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 215 | break; |
| 216 | } |
| 217 | |
| 218 | // Remember if this is a noop hazard. |
| 219 | HasNoopHazards |= HT == HazardRecognizer::NoopHazard; |
| 220 | |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 221 | NotReady.push_back(CurSUnit); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 222 | } |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 223 | |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 224 | // Add the nodes that aren't ready back onto the available list. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 225 | if (!NotReady.empty()) { |
| 226 | AvailableQueue->push_all(NotReady); |
| 227 | NotReady.clear(); |
| 228 | } |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 229 | |
| 230 | // If we found a node to schedule, do it now. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 231 | if (FoundSUnit) { |
| 232 | ScheduleNodeTopDown(FoundSUnit, CurCycle); |
| 233 | HazardRec->EmitInstruction(FoundNode); |
| 234 | FoundSUnit->isScheduled = true; |
| 235 | AvailableQueue->ScheduledNode(FoundSUnit); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 236 | |
| 237 | // If this is a pseudo-op node, we don't want to increment the current |
| 238 | // cycle. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 239 | if (FoundSUnit->Latency) // Don't increment CurCycle for pseudo-ops! |
| 240 | ++CurCycle; |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 241 | } else if (!HasNoopHazards) { |
| 242 | // Otherwise, we have a pipeline stall, but no other problem, just advance |
| 243 | // the current cycle and try again. |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 244 | DOUT << "*** Advancing cycle, no work to do\n"; |
Chris Lattner | 543832d | 2006-03-08 04:25:59 +0000 | [diff] [blame] | 245 | HazardRec->AdvanceCycle(); |
Chris Lattner | fa5e1c9 | 2006-03-05 23:13:56 +0000 | [diff] [blame] | 246 | ++NumStalls; |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 247 | ++CurCycle; |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 248 | } else { |
| 249 | // Otherwise, we have no instructions to issue and we have instructions |
| 250 | // that will fault if we don't do this right. This is the case for |
| 251 | // processors without pipeline interlocks and other cases. |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 252 | DOUT << "*** Emitting noop\n"; |
Chris Lattner | 543832d | 2006-03-08 04:25:59 +0000 | [diff] [blame] | 253 | HazardRec->EmitNoop(); |
Chris Lattner | 00b52ea | 2006-03-05 23:59:20 +0000 | [diff] [blame] | 254 | Sequence.push_back(0); // NULL SUnit* -> noop |
Chris Lattner | fa5e1c9 | 2006-03-05 23:13:56 +0000 | [diff] [blame] | 255 | ++NumNoops; |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 256 | ++CurCycle; |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 257 | } |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | #ifndef NDEBUG |
| 261 | // Verify that all SUnits were scheduled. |
| 262 | bool AnyNotSched = false; |
Chris Lattner | 42e2026 | 2006-03-08 04:54:34 +0000 | [diff] [blame] | 263 | for (unsigned i = 0, e = SUnits.size(); i != e; ++i) { |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 264 | if (SUnits[i].NumPredsLeft != 0) { |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 265 | if (!AnyNotSched) |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 266 | cerr << "*** List scheduling failed! ***\n"; |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 267 | SUnits[i].dump(DAG); |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 268 | cerr << "has not been scheduled!\n"; |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 269 | AnyNotSched = true; |
| 270 | } |
| 271 | } |
| 272 | assert(!AnyNotSched); |
| 273 | #endif |
| 274 | } |
| 275 | |
Chris Lattner | 9df6475 | 2006-03-09 06:35:14 +0000 | [diff] [blame] | 276 | //===----------------------------------------------------------------------===// |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 277 | // LatencyPriorityQueue Implementation |
| 278 | //===----------------------------------------------------------------------===// |
| 279 | // |
| 280 | // This is a SchedulingPriorityQueue that schedules using latency information to |
| 281 | // reduce the length of the critical path through the basic block. |
| 282 | // |
| 283 | namespace { |
| 284 | class LatencyPriorityQueue; |
| 285 | |
| 286 | /// Sorting functions for the Available queue. |
| 287 | struct latency_sort : public std::binary_function<SUnit*, SUnit*, bool> { |
| 288 | LatencyPriorityQueue *PQ; |
| 289 | latency_sort(LatencyPriorityQueue *pq) : PQ(pq) {} |
| 290 | latency_sort(const latency_sort &RHS) : PQ(RHS.PQ) {} |
| 291 | |
| 292 | bool operator()(const SUnit* left, const SUnit* right) const; |
| 293 | }; |
| 294 | } // end anonymous namespace |
| 295 | |
| 296 | namespace { |
| 297 | class LatencyPriorityQueue : public SchedulingPriorityQueue { |
| 298 | // SUnits - The SUnits for the current graph. |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 299 | std::vector<SUnit> *SUnits; |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 300 | |
| 301 | // Latencies - The latency (max of latency from this node to the bb exit) |
| 302 | // for each node. |
| 303 | std::vector<int> Latencies; |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 304 | |
| 305 | /// NumNodesSolelyBlocking - This vector contains, for every node in the |
| 306 | /// Queue, the number of nodes that the node is the sole unscheduled |
| 307 | /// predecessor for. This is used as a tie-breaker heuristic for better |
| 308 | /// mobility. |
| 309 | std::vector<unsigned> NumNodesSolelyBlocking; |
| 310 | |
Dan Gohman | 0d8a61e | 2008-06-23 23:40:09 +0000 | [diff] [blame] | 311 | PriorityQueue<SUnit*, std::vector<SUnit*>, latency_sort> Queue; |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 312 | public: |
| 313 | LatencyPriorityQueue() : Queue(latency_sort(this)) { |
| 314 | } |
| 315 | |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 316 | void initNodes(std::vector<SUnit> &sunits) { |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 317 | SUnits = &sunits; |
| 318 | // Calculate node priorities. |
| 319 | CalculatePriorities(); |
| 320 | } |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 321 | |
| 322 | void addNode(const SUnit *SU) { |
| 323 | Latencies.resize(SUnits->size(), -1); |
| 324 | NumNodesSolelyBlocking.resize(SUnits->size(), 0); |
| 325 | CalcLatency(*SU); |
| 326 | } |
| 327 | |
| 328 | void updateNode(const SUnit *SU) { |
| 329 | Latencies[SU->NodeNum] = -1; |
| 330 | CalcLatency(*SU); |
| 331 | } |
| 332 | |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 333 | void releaseState() { |
| 334 | SUnits = 0; |
| 335 | Latencies.clear(); |
| 336 | } |
| 337 | |
| 338 | unsigned getLatency(unsigned NodeNum) const { |
| 339 | assert(NodeNum < Latencies.size()); |
| 340 | return Latencies[NodeNum]; |
| 341 | } |
| 342 | |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 343 | unsigned getNumSolelyBlockNodes(unsigned NodeNum) const { |
| 344 | assert(NodeNum < NumNodesSolelyBlocking.size()); |
| 345 | return NumNodesSolelyBlocking[NodeNum]; |
| 346 | } |
| 347 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 348 | unsigned size() const { return Queue.size(); } |
| 349 | |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 350 | bool empty() const { return Queue.empty(); } |
| 351 | |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 352 | virtual void push(SUnit *U) { |
| 353 | push_impl(U); |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 354 | } |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 355 | void push_impl(SUnit *U); |
| 356 | |
Chris Lattner | 25e2556 | 2006-03-10 04:32:49 +0000 | [diff] [blame] | 357 | void push_all(const std::vector<SUnit *> &Nodes) { |
| 358 | for (unsigned i = 0, e = Nodes.size(); i != e; ++i) |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 359 | push_impl(Nodes[i]); |
Chris Lattner | 25e2556 | 2006-03-10 04:32:49 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 362 | SUnit *pop() { |
Evan Cheng | 61e9f0d | 2006-05-30 18:04:34 +0000 | [diff] [blame] | 363 | if (empty()) return NULL; |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 364 | SUnit *V = Queue.top(); |
| 365 | Queue.pop(); |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 366 | return V; |
| 367 | } |
Evan Cheng | 7d69389 | 2006-05-09 07:13:34 +0000 | [diff] [blame] | 368 | |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 369 | void remove(SUnit *SU) { |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 370 | assert(!Queue.empty() && "Not in queue!"); |
Dan Gohman | 0d8a61e | 2008-06-23 23:40:09 +0000 | [diff] [blame] | 371 | Queue.erase_one(SU); |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 372 | } |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 373 | |
| 374 | // ScheduledNode - As nodes are scheduled, we look to see if there are any |
| 375 | // successor nodes that have a single unscheduled predecessor. If so, that |
| 376 | // single predecessor has a higher priority, since scheduling it will make |
| 377 | // the node available. |
| 378 | void ScheduledNode(SUnit *Node); |
| 379 | |
| 380 | private: |
| 381 | void CalculatePriorities(); |
| 382 | int CalcLatency(const SUnit &SU); |
| 383 | void AdjustPriorityOfUnscheduledPreds(SUnit *SU); |
| 384 | SUnit *getSingleUnscheduledPred(SUnit *SU); |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 385 | }; |
| 386 | } |
| 387 | |
| 388 | bool latency_sort::operator()(const SUnit *LHS, const SUnit *RHS) const { |
| 389 | unsigned LHSNum = LHS->NodeNum; |
| 390 | unsigned RHSNum = RHS->NodeNum; |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 391 | |
| 392 | // The most important heuristic is scheduling the critical path. |
| 393 | unsigned LHSLatency = PQ->getLatency(LHSNum); |
| 394 | unsigned RHSLatency = PQ->getLatency(RHSNum); |
| 395 | if (LHSLatency < RHSLatency) return true; |
| 396 | if (LHSLatency > RHSLatency) return false; |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 397 | |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 398 | // After that, if two nodes have identical latencies, look to see if one will |
| 399 | // unblock more other nodes than the other. |
| 400 | unsigned LHSBlocked = PQ->getNumSolelyBlockNodes(LHSNum); |
| 401 | unsigned RHSBlocked = PQ->getNumSolelyBlockNodes(RHSNum); |
| 402 | if (LHSBlocked < RHSBlocked) return true; |
| 403 | if (LHSBlocked > RHSBlocked) return false; |
| 404 | |
| 405 | // Finally, just to provide a stable ordering, use the node number as a |
| 406 | // deciding factor. |
| 407 | return LHSNum < RHSNum; |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | |
| 411 | /// CalcNodePriority - Calculate the maximal path from the node to the exit. |
| 412 | /// |
| 413 | int LatencyPriorityQueue::CalcLatency(const SUnit &SU) { |
| 414 | int &Latency = Latencies[SU.NodeNum]; |
| 415 | if (Latency != -1) |
| 416 | return Latency; |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 417 | |
Evan Cheng | 04c4471 | 2007-10-15 21:33:22 +0000 | [diff] [blame] | 418 | std::vector<const SUnit*> WorkList; |
| 419 | WorkList.push_back(&SU); |
| 420 | while (!WorkList.empty()) { |
| 421 | const SUnit *Cur = WorkList.back(); |
| 422 | bool AllDone = true; |
| 423 | int MaxSuccLatency = 0; |
| 424 | for (SUnit::const_succ_iterator I = Cur->Succs.begin(),E = Cur->Succs.end(); |
| 425 | I != E; ++I) { |
| 426 | int SuccLatency = Latencies[I->Dep->NodeNum]; |
| 427 | if (SuccLatency == -1) { |
| 428 | AllDone = false; |
| 429 | WorkList.push_back(I->Dep); |
| 430 | } else { |
| 431 | MaxSuccLatency = std::max(MaxSuccLatency, SuccLatency); |
| 432 | } |
| 433 | } |
| 434 | if (AllDone) { |
| 435 | Latencies[Cur->NodeNum] = MaxSuccLatency + Cur->Latency; |
| 436 | WorkList.pop_back(); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | return Latency; |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | /// CalculatePriorities - Calculate priorities of all scheduling units. |
| 444 | void LatencyPriorityQueue::CalculatePriorities() { |
| 445 | Latencies.assign(SUnits->size(), -1); |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 446 | NumNodesSolelyBlocking.assign(SUnits->size(), 0); |
Evan Cheng | 04c4471 | 2007-10-15 21:33:22 +0000 | [diff] [blame] | 447 | |
| 448 | // For each node, calculate the maximal path from the node to the exit. |
| 449 | std::vector<std::pair<const SUnit*, unsigned> > WorkList; |
| 450 | for (unsigned i = 0, e = SUnits->size(); i != e; ++i) { |
| 451 | const SUnit *SU = &(*SUnits)[i]; |
Dan Gohman | 70de4cb | 2008-01-29 13:02:09 +0000 | [diff] [blame] | 452 | if (SU->Succs.empty()) |
Evan Cheng | 04c4471 | 2007-10-15 21:33:22 +0000 | [diff] [blame] | 453 | WorkList.push_back(std::make_pair(SU, 0U)); |
| 454 | } |
| 455 | |
| 456 | while (!WorkList.empty()) { |
| 457 | const SUnit *SU = WorkList.back().first; |
| 458 | unsigned SuccLat = WorkList.back().second; |
| 459 | WorkList.pop_back(); |
| 460 | int &Latency = Latencies[SU->NodeNum]; |
| 461 | if (Latency == -1 || (SU->Latency + SuccLat) > (unsigned)Latency) { |
| 462 | Latency = SU->Latency + SuccLat; |
| 463 | for (SUnit::const_pred_iterator I = SU->Preds.begin(),E = SU->Preds.end(); |
| 464 | I != E; ++I) |
| 465 | WorkList.push_back(std::make_pair(I->Dep, Latency)); |
| 466 | } |
| 467 | } |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 468 | } |
| 469 | |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 470 | /// getSingleUnscheduledPred - If there is exactly one unscheduled predecessor |
| 471 | /// of SU, return it, otherwise return null. |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 472 | SUnit *LatencyPriorityQueue::getSingleUnscheduledPred(SUnit *SU) { |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 473 | SUnit *OnlyAvailablePred = 0; |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 474 | for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end(); |
| 475 | I != E; ++I) { |
Evan Cheng | 0effc3a | 2007-09-19 01:38:40 +0000 | [diff] [blame] | 476 | SUnit &Pred = *I->Dep; |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 477 | if (!Pred.isScheduled) { |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 478 | // We found an available, but not scheduled, predecessor. If it's the |
| 479 | // only one we have found, keep track of it... otherwise give up. |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 480 | if (OnlyAvailablePred && OnlyAvailablePred != &Pred) |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 481 | return 0; |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 482 | OnlyAvailablePred = &Pred; |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 483 | } |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 484 | } |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 485 | |
| 486 | return OnlyAvailablePred; |
| 487 | } |
| 488 | |
| 489 | void LatencyPriorityQueue::push_impl(SUnit *SU) { |
| 490 | // Look at all of the successors of this node. Count the number of nodes that |
| 491 | // this node is the sole unscheduled node for. |
| 492 | unsigned NumNodesBlocking = 0; |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 493 | for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 494 | I != E; ++I) |
Evan Cheng | 0effc3a | 2007-09-19 01:38:40 +0000 | [diff] [blame] | 495 | if (getSingleUnscheduledPred(I->Dep) == SU) |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 496 | ++NumNodesBlocking; |
Chris Lattner | 578d8fc | 2006-03-11 22:24:20 +0000 | [diff] [blame] | 497 | NumNodesSolelyBlocking[SU->NodeNum] = NumNodesBlocking; |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 498 | |
| 499 | Queue.push(SU); |
| 500 | } |
| 501 | |
| 502 | |
| 503 | // ScheduledNode - As nodes are scheduled, we look to see if there are any |
| 504 | // successor nodes that have a single unscheduled predecessor. If so, that |
| 505 | // single predecessor has a higher priority, since scheduling it will make |
| 506 | // the node available. |
| 507 | void LatencyPriorityQueue::ScheduledNode(SUnit *SU) { |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 508 | for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 509 | I != E; ++I) |
Evan Cheng | 0effc3a | 2007-09-19 01:38:40 +0000 | [diff] [blame] | 510 | AdjustPriorityOfUnscheduledPreds(I->Dep); |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /// AdjustPriorityOfUnscheduledPreds - One of the predecessors of SU was just |
| 514 | /// scheduled. If SU is not itself available, then there is at least one |
| 515 | /// predecessor node that has not been scheduled yet. If SU has exactly ONE |
| 516 | /// unscheduled predecessor, we want to increase its priority: it getting |
| 517 | /// scheduled will make this node available, so it is better than some other |
| 518 | /// node of the same priority that will not make a node available. |
| 519 | void LatencyPriorityQueue::AdjustPriorityOfUnscheduledPreds(SUnit *SU) { |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 520 | if (SU->isPending) return; // All preds scheduled. |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 521 | |
| 522 | SUnit *OnlyAvailablePred = getSingleUnscheduledPred(SU); |
| 523 | if (OnlyAvailablePred == 0 || !OnlyAvailablePred->isAvailable) return; |
| 524 | |
| 525 | // Okay, we found a single predecessor that is available, but not scheduled. |
| 526 | // Since it is available, it must be in the priority queue. First remove it. |
Evan Cheng | 5924bf7 | 2007-09-25 01:54:36 +0000 | [diff] [blame] | 527 | remove(OnlyAvailablePred); |
Chris Lattner | 349e9dd | 2006-03-10 05:51:05 +0000 | [diff] [blame] | 528 | |
| 529 | // Reinsert the node into the priority queue, which recomputes its |
| 530 | // NumNodesSolelyBlocking value. |
| 531 | push(OnlyAvailablePred); |
| 532 | } |
| 533 | |
Chris Lattner | 9df6475 | 2006-03-09 06:35:14 +0000 | [diff] [blame] | 534 | |
| 535 | //===----------------------------------------------------------------------===// |
| 536 | // Public Constructor Functions |
| 537 | //===----------------------------------------------------------------------===// |
| 538 | |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 539 | /// createTDListDAGScheduler - This creates a top-down list scheduler with a |
| 540 | /// new hazard recognizer. This scheduler takes ownership of the hazard |
| 541 | /// recognizer and deletes it when done. |
Jim Laskey | 03593f7 | 2006-08-01 18:29:48 +0000 | [diff] [blame] | 542 | ScheduleDAG* llvm::createTDListDAGScheduler(SelectionDAGISel *IS, |
| 543 | SelectionDAG *DAG, |
Dan Gohman | 5499e89 | 2008-11-11 17:50:47 +0000 | [diff] [blame] | 544 | const TargetMachine *TM, |
Evan Cheng | 2c97731 | 2008-07-01 18:05:03 +0000 | [diff] [blame] | 545 | MachineBasicBlock *BB, bool Fast) { |
Dan Gohman | 5a390b9 | 2008-11-13 21:21:28 +0000 | [diff] [blame] | 546 | return new ScheduleDAGList(DAG, BB, *TM, |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 547 | new LatencyPriorityQueue(), |
Jim Laskey | 03593f7 | 2006-08-01 18:29:48 +0000 | [diff] [blame] | 548 | IS->CreateTargetHazardRecognizer()); |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 549 | } |