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" |
Dan Gohman | 483377c | 2009-02-06 17:22:58 +0000 | [diff] [blame] | 22 | #include "ScheduleDAGSDNodes.h" |
Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/LatencyPriorityQueue.h" |
Dan Gohman | 7e105f0 | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/ScheduleHazardRecognizer.h" |
Jim Laskey | 29e635d | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/SchedulerRegistry.h" |
Jim Laskey | 03593f7 | 2006-08-01 18:29:48 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/SelectionDAGISel.h" |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetRegisterInfo.h" |
Owen Anderson | 8c2c1e9 | 2006-05-12 06:33:49 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetData.h" |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 29 | #include "llvm/Target/TargetInstrInfo.h" |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Debug.h" |
Torok Edwin | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 31 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 4dc3edd | 2009-08-23 06:35:02 +0000 | [diff] [blame] | 32 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | fa5e1c9 | 2006-03-05 23:13:56 +0000 | [diff] [blame] | 33 | #include "llvm/ADT/Statistic.h" |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 34 | #include <climits> |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 35 | using namespace llvm; |
| 36 | |
Chris Lattner | aee775a | 2006-12-19 22:41:21 +0000 | [diff] [blame] | 37 | STATISTIC(NumNoops , "Number of noops inserted"); |
| 38 | STATISTIC(NumStalls, "Number of pipeline stalls"); |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 39 | |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 40 | static RegisterScheduler |
Dan Gohman | 9c4b7d5 | 2008-10-14 20:25:08 +0000 | [diff] [blame] | 41 | tdListDAGScheduler("list-td", "Top-down list scheduler", |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 42 | createTDListDAGScheduler); |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 43 | |
Chris Lattner | af5e26c | 2006-03-08 04:37:58 +0000 | [diff] [blame] | 44 | namespace { |
Chris Lattner | 9e95acc | 2006-03-09 06:37:29 +0000 | [diff] [blame] | 45 | //===----------------------------------------------------------------------===// |
| 46 | /// ScheduleDAGList - The actual list scheduler implementation. This supports |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 47 | /// top-down scheduling. |
Chris Lattner | 9e95acc | 2006-03-09 06:37:29 +0000 | [diff] [blame] | 48 | /// |
Nick Lewycky | 02d5f77 | 2009-10-25 06:33:48 +0000 | [diff] [blame] | 49 | class ScheduleDAGList : public ScheduleDAGSDNodes { |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 50 | private: |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 51 | /// AvailableQueue - The priority queue to use for the available SUnits. |
| 52 | /// |
| 53 | SchedulingPriorityQueue *AvailableQueue; |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 54 | |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 55 | /// PendingQueue - This contains all of the instructions whose operands have |
| 56 | /// been issued, but their results are not ready yet (due to the latency of |
Dan Gohman | fe1748d | 2008-11-18 02:50:01 +0000 | [diff] [blame] | 57 | /// the operation). Once the operands become available, the instruction is |
Dan Gohman | a687fd8 | 2008-11-17 19:45:19 +0000 | [diff] [blame] | 58 | /// added to the AvailableQueue. |
| 59 | std::vector<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. |
Dan Gohman | 7e105f0 | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 62 | ScheduleHazardRecognizer *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 | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 65 | ScheduleDAGList(MachineFunction &mf, |
Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 66 | SchedulingPriorityQueue *availqueue) |
| 67 | : ScheduleDAGSDNodes(mf), AvailableQueue(availqueue) { |
| 68 | |
| 69 | const TargetMachine &tm = mf.getTarget(); |
| 70 | HazardRec = tm.getInstrInfo()->CreateTargetHazardRecognizer(&tm, this); |
| 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: |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 81 | void ReleaseSucc(SUnit *SU, const SDep &D); |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 82 | void ReleaseSuccessors(SUnit *SU); |
Chris Lattner | 063086b | 2006-03-11 22:34:41 +0000 | [diff] [blame] | 83 | void ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle); |
Chris Lattner | 399bee2 | 2006-03-09 06:48:37 +0000 | [diff] [blame] | 84 | void ListScheduleTopDown(); |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 85 | }; |
Chris Lattner | af5e26c | 2006-03-08 04:37:58 +0000 | [diff] [blame] | 86 | } // end anonymous namespace |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 87 | |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 88 | /// Schedule - Schedule the DAG using list scheduling. |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 89 | void ScheduleDAGList::Schedule() { |
David Greene | 6314584 | 2010-01-05 01:24:43 +0000 | [diff] [blame] | 90 | DEBUG(dbgs() << "********** List Scheduling **********\n"); |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 91 | |
Dan Gohman | 04543e7 | 2008-12-23 18:36:58 +0000 | [diff] [blame] | 92 | // Build the scheduling graph. |
Dan Gohman | 918ec53 | 2009-10-09 23:33:48 +0000 | [diff] [blame] | 93 | BuildSchedGraph(NULL); |
Evan Cheng | 7d69389 | 2006-05-09 07:13:34 +0000 | [diff] [blame] | 94 | |
Dan Gohman | 46520a2 | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 95 | AvailableQueue->initNodes(SUnits); |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 96 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 97 | ListScheduleTopDown(); |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 98 | |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 99 | AvailableQueue->releaseState(); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | //===----------------------------------------------------------------------===// |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 103 | // Top-Down Scheduling |
| 104 | //===----------------------------------------------------------------------===// |
| 105 | |
| 106 | /// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 107 | /// the PendingQueue if the count reaches zero. Also update its cycle bound. |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 108 | void ScheduleDAGList::ReleaseSucc(SUnit *SU, const SDep &D) { |
| 109 | SUnit *SuccSU = D.getSUnit(); |
Reid Kleckner | 8ff5c19 | 2009-09-30 20:15:38 +0000 | [diff] [blame] | 110 | |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 111 | #ifndef NDEBUG |
Reid Kleckner | 8ff5c19 | 2009-09-30 20:15:38 +0000 | [diff] [blame] | 112 | if (SuccSU->NumPredsLeft == 0) { |
David Greene | 6314584 | 2010-01-05 01:24:43 +0000 | [diff] [blame] | 113 | dbgs() << "*** Scheduling failed! ***\n"; |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 114 | SuccSU->dump(this); |
David Greene | 6314584 | 2010-01-05 01:24:43 +0000 | [diff] [blame] | 115 | dbgs() << " has been released too many times!\n"; |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 116 | llvm_unreachable(0); |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 117 | } |
| 118 | #endif |
Reid Kleckner | 8ff5c19 | 2009-09-30 20:15:38 +0000 | [diff] [blame] | 119 | --SuccSU->NumPredsLeft; |
| 120 | |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 121 | SuccSU->setDepthToAtLeast(SU->getDepth() + D.getLatency()); |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 122 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 123 | // If all the node's predecessors are scheduled, this node is ready |
| 124 | // to be scheduled. Ignore the special ExitSU node. |
| 125 | if (SuccSU->NumPredsLeft == 0 && SuccSU != &ExitSU) |
Dan Gohman | a687fd8 | 2008-11-17 19:45:19 +0000 | [diff] [blame] | 126 | PendingQueue.push_back(SuccSU); |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | void ScheduleDAGList::ReleaseSuccessors(SUnit *SU) { |
| 130 | // Top down: release successors. |
| 131 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
| 132 | I != E; ++I) { |
| 133 | assert(!I->isAssignedRegDep() && |
| 134 | "The list-td scheduler doesn't yet support physreg dependencies!"); |
| 135 | |
| 136 | ReleaseSucc(SU, *I); |
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) { |
David Greene | 6314584 | 2010-01-05 01:24:43 +0000 | [diff] [blame] | 144 | DEBUG(dbgs() << "*** Scheduling [" << CurCycle << "]: "); |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 145 | DEBUG(SU->dump(this)); |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 146 | |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 147 | Sequence.push_back(SU); |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 148 | assert(CurCycle >= SU->getDepth() && "Node scheduled above its depth!"); |
| 149 | SU->setDepthToAtLeast(CurCycle); |
Dan Gohman | 92a36d7 | 2008-11-17 21:31:02 +0000 | [diff] [blame] | 150 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 151 | ReleaseSuccessors(SU); |
Dan Gohman | 92a36d7 | 2008-11-17 21:31:02 +0000 | [diff] [blame] | 152 | SU->isScheduled = true; |
| 153 | AvailableQueue->ScheduledNode(SU); |
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 | |
Dan Gohman | b954343 | 2009-02-10 23:27:53 +0000 | [diff] [blame] | 161 | // Release any successors of the special Entry node. |
| 162 | ReleaseSuccessors(&EntrySU); |
| 163 | |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 164 | // All leaves to Available queue. |
Chris Lattner | 42e2026 | 2006-03-08 04:54:34 +0000 | [diff] [blame] | 165 | for (unsigned i = 0, e = SUnits.size(); i != e; ++i) { |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 166 | // It is available if it has no predecessors. |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 167 | if (SUnits[i].Preds.empty()) { |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 168 | AvailableQueue->push(&SUnits[i]); |
Dan Gohman | 17c226b | 2008-11-17 16:37:30 +0000 | [diff] [blame] | 169 | SUnits[i].isAvailable = true; |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 170 | } |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 171 | } |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 172 | |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 173 | // While Available queue is not empty, grab the node with the highest |
| 174 | // priority. If it is not ready put it back. Schedule the node. |
| 175 | std::vector<SUnit*> NotReady; |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 176 | Sequence.reserve(SUnits.size()); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 177 | while (!AvailableQueue->empty() || !PendingQueue.empty()) { |
| 178 | // Check to see if any of the pending instructions are ready to issue. If |
| 179 | // so, add them to the available queue. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 180 | for (unsigned i = 0, e = PendingQueue.size(); i != e; ++i) { |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 181 | if (PendingQueue[i]->getDepth() == CurCycle) { |
Dan Gohman | a687fd8 | 2008-11-17 19:45:19 +0000 | [diff] [blame] | 182 | AvailableQueue->push(PendingQueue[i]); |
| 183 | PendingQueue[i]->isAvailable = true; |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 184 | PendingQueue[i] = PendingQueue.back(); |
| 185 | PendingQueue.pop_back(); |
| 186 | --i; --e; |
| 187 | } else { |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 188 | assert(PendingQueue[i]->getDepth() > CurCycle && "Negative latency?"); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 189 | } |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 190 | } |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 191 | |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 192 | // If there are no instructions available, don't try to issue anything, and |
| 193 | // don't advance the hazard recognizer. |
| 194 | if (AvailableQueue->empty()) { |
| 195 | ++CurCycle; |
| 196 | continue; |
| 197 | } |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 198 | |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 199 | SUnit *FoundSUnit = 0; |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 200 | |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 201 | bool HasNoopHazards = false; |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 202 | while (!AvailableQueue->empty()) { |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 203 | SUnit *CurSUnit = AvailableQueue->pop(); |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 204 | |
Dan Gohman | 7e105f0 | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 205 | ScheduleHazardRecognizer::HazardType HT = |
Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 206 | HazardRec->getHazardType(CurSUnit, 0/*no stalls*/); |
Dan Gohman | 7e105f0 | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 207 | if (HT == ScheduleHazardRecognizer::NoHazard) { |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 208 | FoundSUnit = CurSUnit; |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 209 | break; |
| 210 | } |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 211 | |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 212 | // Remember if this is a noop hazard. |
Dan Gohman | 7e105f0 | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 213 | HasNoopHazards |= HT == ScheduleHazardRecognizer::NoopHazard; |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 214 | |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 215 | NotReady.push_back(CurSUnit); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 216 | } |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 217 | |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 218 | // Add the nodes that aren't ready back onto the available list. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 219 | if (!NotReady.empty()) { |
| 220 | AvailableQueue->push_all(NotReady); |
| 221 | NotReady.clear(); |
| 222 | } |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 223 | |
| 224 | // If we found a node to schedule, do it now. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 225 | if (FoundSUnit) { |
| 226 | ScheduleNodeTopDown(FoundSUnit, CurCycle); |
Dan Gohman | 7e105f0 | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 227 | HazardRec->EmitInstruction(FoundSUnit); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 228 | |
| 229 | // If this is a pseudo-op node, we don't want to increment the current |
| 230 | // cycle. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 231 | if (FoundSUnit->Latency) // Don't increment CurCycle for pseudo-ops! |
Andrew Trick | c416ba6 | 2010-12-24 04:28:06 +0000 | [diff] [blame] | 232 | ++CurCycle; |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 233 | } else if (!HasNoopHazards) { |
| 234 | // Otherwise, we have a pipeline stall, but no other problem, just advance |
| 235 | // the current cycle and try again. |
David Greene | 6314584 | 2010-01-05 01:24:43 +0000 | [diff] [blame] | 236 | DEBUG(dbgs() << "*** Advancing cycle, no work to do\n"); |
Chris Lattner | 543832d | 2006-03-08 04:25:59 +0000 | [diff] [blame] | 237 | HazardRec->AdvanceCycle(); |
Chris Lattner | fa5e1c9 | 2006-03-05 23:13:56 +0000 | [diff] [blame] | 238 | ++NumStalls; |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 239 | ++CurCycle; |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 240 | } else { |
| 241 | // Otherwise, we have no instructions to issue and we have instructions |
| 242 | // that will fault if we don't do this right. This is the case for |
| 243 | // processors without pipeline interlocks and other cases. |
David Greene | 6314584 | 2010-01-05 01:24:43 +0000 | [diff] [blame] | 244 | DEBUG(dbgs() << "*** Emitting noop\n"); |
Chris Lattner | 543832d | 2006-03-08 04:25:59 +0000 | [diff] [blame] | 245 | HazardRec->EmitNoop(); |
Dan Gohman | ceac7c3 | 2009-01-16 01:33:36 +0000 | [diff] [blame] | 246 | Sequence.push_back(0); // NULL here means noop |
Chris Lattner | fa5e1c9 | 2006-03-05 23:13:56 +0000 | [diff] [blame] | 247 | ++NumNoops; |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 248 | ++CurCycle; |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 249 | } |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | #ifndef NDEBUG |
Dan Gohman | 4ce15e1 | 2008-11-20 01:26:25 +0000 | [diff] [blame] | 253 | VerifySchedule(/*isBottomUp=*/false); |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 254 | #endif |
| 255 | } |
| 256 | |
Chris Lattner | 9df6475 | 2006-03-09 06:35:14 +0000 | [diff] [blame] | 257 | //===----------------------------------------------------------------------===// |
Chris Lattner | 9df6475 | 2006-03-09 06:35:14 +0000 | [diff] [blame] | 258 | // Public Constructor Functions |
| 259 | //===----------------------------------------------------------------------===// |
| 260 | |
Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 261 | /// createTDListDAGScheduler - This creates a top-down list scheduler. |
Dan Gohman | dfaf646 | 2009-02-11 04:27:20 +0000 | [diff] [blame] | 262 | ScheduleDAGSDNodes * |
Bill Wendling | 026e5d7 | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 263 | llvm::createTDListDAGScheduler(SelectionDAGISel *IS, CodeGenOpt::Level) { |
Andrew Trick | 10ffc2b | 2010-12-24 05:03:26 +0000 | [diff] [blame] | 264 | return new ScheduleDAGList(*IS->MF, new LatencyPriorityQueue()); |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 265 | } |