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 | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/LatencyPriorityQueue.h" |
| 23 | #include "llvm/CodeGen/ScheduleDAGSDNodes.h" |
Jim Laskey | 29e635d | 2006-08-02 12:30:23 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/SchedulerRegistry.h" |
Jim Laskey | 03593f7 | 2006-08-01 18:29:48 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/SelectionDAGISel.h" |
Dan Gohman | 3a4be0f | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetRegisterInfo.h" |
Owen Anderson | 8c2c1e9 | 2006-05-12 06:33:49 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetData.h" |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 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 | /// |
Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 48 | class VISIBILITY_HIDDEN ScheduleDAGList : public ScheduleDAGSDNodes { |
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 |
Dan Gohman | fe1748d | 2008-11-18 02:50:01 +0000 | [diff] [blame] | 56 | /// the operation). Once the operands become available, the instruction is |
Dan Gohman | a687fd8 | 2008-11-17 19:45:19 +0000 | [diff] [blame] | 57 | /// added to the AvailableQueue. |
| 58 | std::vector<SUnit*> PendingQueue; |
Evan Cheng | 9add880 | 2006-05-04 19:16:39 +0000 | [diff] [blame] | 59 | |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 60 | /// HazardRec - The hazard recognizer to use. |
Chris Lattner | 543832d | 2006-03-08 04:25:59 +0000 | [diff] [blame] | 61 | HazardRecognizer *HazardRec; |
Evan Cheng | 9add880 | 2006-05-04 19:16:39 +0000 | [diff] [blame] | 62 | |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 63 | public: |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame^] | 64 | ScheduleDAGList(MachineFunction &mf, |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 65 | SchedulingPriorityQueue *availqueue, |
Chris Lattner | 543832d | 2006-03-08 04:25:59 +0000 | [diff] [blame] | 66 | HazardRecognizer *HR) |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame^] | 67 | : ScheduleDAGSDNodes(mf), |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 68 | AvailableQueue(availqueue), HazardRec(HR) { |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 69 | } |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 70 | |
| 71 | ~ScheduleDAGList() { |
Chris Lattner | 543832d | 2006-03-08 04:25:59 +0000 | [diff] [blame] | 72 | delete HazardRec; |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 73 | delete AvailableQueue; |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 74 | } |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 75 | |
| 76 | void Schedule(); |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 77 | |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 78 | private: |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 79 | void ReleaseSucc(SUnit *SU, const SDep &D); |
Chris Lattner | 063086b | 2006-03-11 22:34:41 +0000 | [diff] [blame] | 80 | void ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle); |
Chris Lattner | 399bee2 | 2006-03-09 06:48:37 +0000 | [diff] [blame] | 81 | void ListScheduleTopDown(); |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 82 | }; |
Chris Lattner | af5e26c | 2006-03-08 04:37:58 +0000 | [diff] [blame] | 83 | } // end anonymous namespace |
Evan Cheng | ab49556 | 2006-01-25 09:14:32 +0000 | [diff] [blame] | 84 | |
Chris Lattner | 47639db | 2006-03-06 00:22:00 +0000 | [diff] [blame] | 85 | HazardRecognizer::~HazardRecognizer() {} |
| 86 | |
Evan Cheng | c4c339c | 2006-01-26 00:30:29 +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() { |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 90 | DOUT << "********** List Scheduling **********\n"; |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 91 | |
Dan Gohman | 04543e7 | 2008-12-23 18:36:58 +0000 | [diff] [blame] | 92 | // Build the scheduling graph. |
| 93 | BuildSchedGraph(); |
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); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 96 | |
Evan Cheng | d38c22b | 2006-05-11 23:55:42 +0000 | [diff] [blame] | 97 | ListScheduleTopDown(); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +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(); |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 110 | --SuccSU->NumPredsLeft; |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 111 | |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 112 | #ifndef NDEBUG |
| 113 | if (SuccSU->NumPredsLeft < 0) { |
| 114 | cerr << "*** Scheduling failed! ***\n"; |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 115 | SuccSU->dump(this); |
Dan Gohman | 5ebdb98 | 2008-11-18 00:38:59 +0000 | [diff] [blame] | 116 | cerr << " has been released too many times!\n"; |
| 117 | assert(0); |
| 118 | } |
| 119 | #endif |
| 120 | |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 121 | SuccSU->setDepthToAtLeast(SU->getDepth() + D.getLatency()); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 122 | |
Evan Cheng | 038dcc5 | 2007-09-28 19:24:24 +0000 | [diff] [blame] | 123 | if (SuccSU->NumPredsLeft == 0) { |
Dan Gohman | a687fd8 | 2008-11-17 19:45:19 +0000 | [diff] [blame] | 124 | PendingQueue.push_back(SuccSU); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
| 128 | /// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending |
| 129 | /// count of its successors. If a successor pending count is zero, add it to |
| 130 | /// the Available queue. |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 131 | void ScheduleDAGList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) { |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 132 | DOUT << "*** Scheduling [" << CurCycle << "]: "; |
Dan Gohman | 22d07b1 | 2008-11-18 02:06:40 +0000 | [diff] [blame] | 133 | DEBUG(SU->dump(this)); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 134 | |
| 135 | Sequence.push_back(SU); |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 136 | assert(CurCycle >= SU->getDepth() && "Node scheduled above its depth!"); |
| 137 | SU->setDepthToAtLeast(CurCycle); |
Dan Gohman | 92a36d7 | 2008-11-17 21:31:02 +0000 | [diff] [blame] | 138 | |
Dan Gohman | 68294c0 | 2008-11-15 00:24:23 +0000 | [diff] [blame] | 139 | // Top down: release successors. |
Chris Lattner | d86418a | 2006-08-17 00:09:56 +0000 | [diff] [blame] | 140 | for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); |
Dan Gohman | 1407484 | 2009-01-13 20:24:13 +0000 | [diff] [blame] | 141 | I != E; ++I) { |
| 142 | assert(!I->isAssignedRegDep() && |
| 143 | "The list-td scheduler doesn't yet support physreg dependencies!"); |
| 144 | |
Dan Gohman | 2d17089 | 2008-12-09 22:54:47 +0000 | [diff] [blame] | 145 | ReleaseSucc(SU, *I); |
Dan Gohman | 1407484 | 2009-01-13 20:24:13 +0000 | [diff] [blame] | 146 | } |
Dan Gohman | 92a36d7 | 2008-11-17 21:31:02 +0000 | [diff] [blame] | 147 | |
| 148 | SU->isScheduled = true; |
| 149 | AvailableQueue->ScheduledNode(SU); |
Chris Lattner | 9995a0c | 2006-03-11 22:28:35 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 152 | /// ListScheduleTopDown - The main loop of list scheduling for top-down |
| 153 | /// schedulers. |
Chris Lattner | 399bee2 | 2006-03-09 06:48:37 +0000 | [diff] [blame] | 154 | void ScheduleDAGList::ListScheduleTopDown() { |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 155 | unsigned CurCycle = 0; |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 156 | |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 157 | // All leaves to Available queue. |
Chris Lattner | 42e2026 | 2006-03-08 04:54:34 +0000 | [diff] [blame] | 158 | for (unsigned i = 0, e = SUnits.size(); i != e; ++i) { |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 159 | // It is available if it has no predecessors. |
Dan Gohman | 4370f26 | 2008-04-15 01:22:18 +0000 | [diff] [blame] | 160 | if (SUnits[i].Preds.empty()) { |
Chris Lattner | 356183d | 2006-03-11 22:44:37 +0000 | [diff] [blame] | 161 | AvailableQueue->push(&SUnits[i]); |
Dan Gohman | 17c226b | 2008-11-17 16:37:30 +0000 | [diff] [blame] | 162 | SUnits[i].isAvailable = true; |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 163 | } |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | // While Available queue is not empty, grab the node with the highest |
| 167 | // priority. If it is not ready put it back. Schedule the node. |
| 168 | std::vector<SUnit*> NotReady; |
Dan Gohman | e6e1348 | 2008-06-21 15:52:51 +0000 | [diff] [blame] | 169 | Sequence.reserve(SUnits.size()); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 170 | while (!AvailableQueue->empty() || !PendingQueue.empty()) { |
| 171 | // Check to see if any of the pending instructions are ready to issue. If |
| 172 | // so, add them to the available queue. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 173 | for (unsigned i = 0, e = PendingQueue.size(); i != e; ++i) { |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 174 | if (PendingQueue[i]->getDepth() == CurCycle) { |
Dan Gohman | a687fd8 | 2008-11-17 19:45:19 +0000 | [diff] [blame] | 175 | AvailableQueue->push(PendingQueue[i]); |
| 176 | PendingQueue[i]->isAvailable = true; |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 177 | PendingQueue[i] = PendingQueue.back(); |
| 178 | PendingQueue.pop_back(); |
| 179 | --i; --e; |
| 180 | } else { |
Dan Gohman | dddc1ac | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 181 | assert(PendingQueue[i]->getDepth() > CurCycle && "Negative latency?"); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 182 | } |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 183 | } |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 184 | |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 185 | // If there are no instructions available, don't try to issue anything, and |
| 186 | // don't advance the hazard recognizer. |
| 187 | if (AvailableQueue->empty()) { |
| 188 | ++CurCycle; |
| 189 | continue; |
| 190 | } |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 191 | |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 192 | SUnit *FoundSUnit = 0; |
| 193 | SDNode *FoundNode = 0; |
| 194 | |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 195 | bool HasNoopHazards = false; |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 196 | while (!AvailableQueue->empty()) { |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 197 | SUnit *CurSUnit = AvailableQueue->pop(); |
Chris Lattner | 0c801bd | 2006-03-07 05:40:43 +0000 | [diff] [blame] | 198 | |
| 199 | // Get the node represented by this SUnit. |
Dan Gohman | 1ddfcba | 2008-11-13 21:36:12 +0000 | [diff] [blame] | 200 | FoundNode = CurSUnit->getNode(); |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 201 | |
Chris Lattner | 0c801bd | 2006-03-07 05:40:43 +0000 | [diff] [blame] | 202 | // If this is a pseudo op, like copyfromreg, look to see if there is a |
| 203 | // real target node flagged to it. If so, use the target node. |
Dan Gohman | 072734e | 2008-11-13 23:24:17 +0000 | [diff] [blame] | 204 | while (!FoundNode->isMachineOpcode()) { |
| 205 | SDNode *N = FoundNode->getFlaggedNode(); |
| 206 | if (!N) break; |
| 207 | FoundNode = N; |
| 208 | } |
Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 209 | |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 210 | HazardRecognizer::HazardType HT = HazardRec->getHazardType(FoundNode); |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 211 | if (HT == HazardRecognizer::NoHazard) { |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 212 | FoundSUnit = CurSUnit; |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 213 | break; |
| 214 | } |
Dan Gohman | 60cb69e | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 215 | |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 216 | // Remember if this is a noop hazard. |
| 217 | HasNoopHazards |= HT == HazardRecognizer::NoopHazard; |
| 218 | |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 219 | NotReady.push_back(CurSUnit); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 220 | } |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 221 | |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 222 | // Add the nodes that aren't ready back onto the available list. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 223 | if (!NotReady.empty()) { |
| 224 | AvailableQueue->push_all(NotReady); |
| 225 | NotReady.clear(); |
| 226 | } |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 227 | |
| 228 | // If we found a node to schedule, do it now. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 229 | if (FoundSUnit) { |
| 230 | ScheduleNodeTopDown(FoundSUnit, CurCycle); |
| 231 | HazardRec->EmitInstruction(FoundNode); |
Chris Lattner | 572003c | 2006-03-12 00:38:57 +0000 | [diff] [blame] | 232 | |
| 233 | // If this is a pseudo-op node, we don't want to increment the current |
| 234 | // cycle. |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 235 | if (FoundSUnit->Latency) // Don't increment CurCycle for pseudo-ops! |
| 236 | ++CurCycle; |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 237 | } else if (!HasNoopHazards) { |
| 238 | // Otherwise, we have a pipeline stall, but no other problem, just advance |
| 239 | // the current cycle and try again. |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 240 | DOUT << "*** Advancing cycle, no work to do\n"; |
Chris Lattner | 543832d | 2006-03-08 04:25:59 +0000 | [diff] [blame] | 241 | HazardRec->AdvanceCycle(); |
Chris Lattner | fa5e1c9 | 2006-03-05 23:13:56 +0000 | [diff] [blame] | 242 | ++NumStalls; |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 243 | ++CurCycle; |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 244 | } else { |
| 245 | // Otherwise, we have no instructions to issue and we have instructions |
| 246 | // that will fault if we don't do this right. This is the case for |
| 247 | // processors without pipeline interlocks and other cases. |
Bill Wendling | 22e978a | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 248 | DOUT << "*** Emitting noop\n"; |
Chris Lattner | 543832d | 2006-03-08 04:25:59 +0000 | [diff] [blame] | 249 | HazardRec->EmitNoop(); |
Chris Lattner | 00b52ea | 2006-03-05 23:59:20 +0000 | [diff] [blame] | 250 | Sequence.push_back(0); // NULL SUnit* -> noop |
Chris Lattner | fa5e1c9 | 2006-03-05 23:13:56 +0000 | [diff] [blame] | 251 | ++NumNoops; |
Chris Lattner | a767dbf | 2006-03-12 09:01:41 +0000 | [diff] [blame] | 252 | ++CurCycle; |
Chris Lattner | e50c092 | 2006-03-05 22:45:01 +0000 | [diff] [blame] | 253 | } |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | #ifndef NDEBUG |
Dan Gohman | 4ce15e1 | 2008-11-20 01:26:25 +0000 | [diff] [blame] | 257 | VerifySchedule(/*isBottomUp=*/false); |
Chris Lattner | 98ecb8e | 2006-03-05 21:10:33 +0000 | [diff] [blame] | 258 | #endif |
| 259 | } |
| 260 | |
Chris Lattner | 9df6475 | 2006-03-09 06:35:14 +0000 | [diff] [blame] | 261 | //===----------------------------------------------------------------------===// |
Chris Lattner | 9df6475 | 2006-03-09 06:35:14 +0000 | [diff] [blame] | 262 | // Public Constructor Functions |
| 263 | //===----------------------------------------------------------------------===// |
| 264 | |
Jim Laskey | 95eda5b | 2006-08-01 14:21:23 +0000 | [diff] [blame] | 265 | /// createTDListDAGScheduler - This creates a top-down list scheduler with a |
| 266 | /// new hazard recognizer. This scheduler takes ownership of the hazard |
| 267 | /// recognizer and deletes it when done. |
Jim Laskey | 03593f7 | 2006-08-01 18:29:48 +0000 | [diff] [blame] | 268 | ScheduleDAG* llvm::createTDListDAGScheduler(SelectionDAGISel *IS, |
Dan Gohman | 619ef48 | 2009-01-15 19:20:50 +0000 | [diff] [blame^] | 269 | bool Fast) { |
| 270 | return new ScheduleDAGList(*IS->MF, |
Chris Lattner | 6398c13 | 2006-03-09 07:38:27 +0000 | [diff] [blame] | 271 | new LatencyPriorityQueue(), |
Jim Laskey | 03593f7 | 2006-08-01 18:29:48 +0000 | [diff] [blame] | 272 | IS->CreateTargetHazardRecognizer()); |
Evan Cheng | 3127234 | 2006-01-23 08:26:10 +0000 | [diff] [blame] | 273 | } |