blob: f881737f9991fcd69dfd48f43fdcaef6979f742c [file] [log] [blame]
Evan Chengd38c22b2006-05-11 23:55:42 +00001//===----- ScheduleDAGList.cpp - Reg pressure reduction list scheduler ----===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chengd38c22b2006-05-11 23:55:42 +00007//
8//===----------------------------------------------------------------------===//
9//
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.
15//
16//===----------------------------------------------------------------------===//
17
Dale Johannesen2182f062007-07-13 17:13:54 +000018#define DEBUG_TYPE "pre-RA-sched"
Evan Chengd38c22b2006-05-11 23:55:42 +000019#include "llvm/CodeGen/ScheduleDAG.h"
Jim Laskey29e635d2006-08-02 12:30:23 +000020#include "llvm/CodeGen/SchedulerRegistry.h"
Dan Gohman3a4be0f2008-02-10 18:45:23 +000021#include "llvm/Target/TargetRegisterInfo.h"
Owen Anderson8c2c1e92006-05-12 06:33:49 +000022#include "llvm/Target/TargetData.h"
Evan Chengd38c22b2006-05-11 23:55:42 +000023#include "llvm/Target/TargetMachine.h"
24#include "llvm/Target/TargetInstrInfo.h"
25#include "llvm/Support/Debug.h"
Chris Lattner3d27be12006-08-27 12:54:02 +000026#include "llvm/Support/Compiler.h"
Dan Gohmana4db3352008-06-21 18:35:25 +000027#include "llvm/ADT/BitVector.h"
28#include "llvm/ADT/PriorityQueue.h"
Evan Chenge6f92252007-09-27 18:46:06 +000029#include "llvm/ADT/SmallPtrSet.h"
Evan Cheng5924bf72007-09-25 01:54:36 +000030#include "llvm/ADT/SmallSet.h"
Evan Chengd38c22b2006-05-11 23:55:42 +000031#include "llvm/ADT/Statistic.h"
Roman Levenstein6b371142008-04-29 09:07:59 +000032#include "llvm/ADT/STLExtras.h"
Evan Chengd38c22b2006-05-11 23:55:42 +000033#include <climits>
Evan Chengd38c22b2006-05-11 23:55:42 +000034#include "llvm/Support/CommandLine.h"
35using namespace llvm;
36
Dan Gohmanfd227e92008-03-25 17:10:29 +000037STATISTIC(NumBacktracks, "Number of times scheduler backtracked");
Evan Cheng79e97132007-10-05 01:39:18 +000038STATISTIC(NumUnfolds, "Number of nodes unfolded");
Evan Cheng1ec79b42007-09-27 07:09:03 +000039STATISTIC(NumDups, "Number of duplicated nodes");
40STATISTIC(NumCCCopies, "Number of cross class copies");
41
Jim Laskey95eda5b2006-08-01 14:21:23 +000042static RegisterScheduler
43 burrListDAGScheduler("list-burr",
44 " Bottom-up register reduction list scheduling",
45 createBURRListDAGScheduler);
46static RegisterScheduler
47 tdrListrDAGScheduler("list-tdrr",
48 " Top-down register reduction list scheduling",
49 createTDRRListDAGScheduler);
50
Evan Chengd38c22b2006-05-11 23:55:42 +000051namespace {
Evan Chengd38c22b2006-05-11 23:55:42 +000052//===----------------------------------------------------------------------===//
53/// ScheduleDAGRRList - The actual register reduction list scheduler
54/// implementation. This supports both top-down and bottom-up scheduling.
55///
Chris Lattnere097e6f2006-06-28 22:17:39 +000056class VISIBILITY_HIDDEN ScheduleDAGRRList : public ScheduleDAG {
Evan Chengd38c22b2006-05-11 23:55:42 +000057private:
58 /// isBottomUp - This is true if the scheduling problem is bottom-up, false if
59 /// it is top-down.
60 bool isBottomUp;
Evan Cheng2c977312008-07-01 18:05:03 +000061
62 bool Fast;
Evan Chengd38c22b2006-05-11 23:55:42 +000063
64 /// AvailableQueue - The priority queue to use for the available SUnits.
Evan Chengd38c22b2006-05-11 23:55:42 +000065 SchedulingPriorityQueue *AvailableQueue;
66
Evan Cheng5924bf72007-09-25 01:54:36 +000067 /// LiveRegs / LiveRegDefs - A set of physical registers and their definition
68 /// that are "live". These nodes must be scheduled before any other nodes that
69 /// modifies the registers can be scheduled.
70 SmallSet<unsigned, 4> LiveRegs;
71 std::vector<SUnit*> LiveRegDefs;
72 std::vector<unsigned> LiveRegCycles;
73
Evan Chengd38c22b2006-05-11 23:55:42 +000074public:
75 ScheduleDAGRRList(SelectionDAG &dag, MachineBasicBlock *bb,
Evan Cheng2c977312008-07-01 18:05:03 +000076 const TargetMachine &tm, bool isbottomup, bool f,
77 SchedulingPriorityQueue *availqueue)
78 : ScheduleDAG(dag, bb, tm), isBottomUp(isbottomup), Fast(f),
Evan Chengd38c22b2006-05-11 23:55:42 +000079 AvailableQueue(availqueue) {
80 }
81
82 ~ScheduleDAGRRList() {
83 delete AvailableQueue;
84 }
85
86 void Schedule();
87
Roman Levenstein733a4d62008-03-26 11:23:38 +000088 /// IsReachable - Checks if SU is reachable from TargetSU.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +000089 bool IsReachable(SUnit *SU, SUnit *TargetSU);
90
91 /// willCreateCycle - Returns true if adding an edge from SU to TargetSU will
92 /// create a cycle.
93 bool WillCreateCycle(SUnit *SU, SUnit *TargetSU);
94
95 /// AddPred - This adds the specified node X as a predecessor of
96 /// the current node Y if not already.
Roman Levenstein733a4d62008-03-26 11:23:38 +000097 /// This returns true if this is a new predecessor.
98 /// Updates the topological ordering if required.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +000099 bool AddPred(SUnit *Y, SUnit *X, bool isCtrl, bool isSpecial,
Roman Levenstein733a4d62008-03-26 11:23:38 +0000100 unsigned PhyReg = 0, int Cost = 1);
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000101
Roman Levenstein733a4d62008-03-26 11:23:38 +0000102 /// RemovePred - This removes the specified node N from the predecessors of
103 /// the current node M. Updates the topological ordering if required.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000104 bool RemovePred(SUnit *M, SUnit *N, bool isCtrl, bool isSpecial);
105
Evan Chengd38c22b2006-05-11 23:55:42 +0000106private:
Evan Cheng8e136a92007-09-26 21:36:17 +0000107 void ReleasePred(SUnit*, bool, unsigned);
108 void ReleaseSucc(SUnit*, bool isChain, unsigned);
109 void CapturePred(SUnit*, SUnit*, bool);
110 void ScheduleNodeBottomUp(SUnit*, unsigned);
111 void ScheduleNodeTopDown(SUnit*, unsigned);
112 void UnscheduleNodeBottomUp(SUnit*);
113 void BacktrackBottomUp(SUnit*, unsigned, unsigned&);
114 SUnit *CopyAndMoveSuccessors(SUnit*);
Evan Cheng1ec79b42007-09-27 07:09:03 +0000115 void InsertCCCopiesAndMoveSuccs(SUnit*, unsigned,
Evan Cheng8e136a92007-09-26 21:36:17 +0000116 const TargetRegisterClass*,
Evan Cheng1ec79b42007-09-27 07:09:03 +0000117 const TargetRegisterClass*,
118 SmallVector<SUnit*, 2>&);
119 bool DelayForLiveRegsBottomUp(SUnit*, SmallVector<unsigned, 4>&);
Evan Chengd38c22b2006-05-11 23:55:42 +0000120 void ListScheduleTopDown();
121 void ListScheduleBottomUp();
Evan Chengafed73e2006-05-12 01:58:24 +0000122 void CommuteNodesToReducePressure();
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000123
124
125 /// CreateNewSUnit - Creates a new SUnit and returns a pointer to it.
Roman Levenstein733a4d62008-03-26 11:23:38 +0000126 /// Updates the topological ordering if required.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000127 SUnit *CreateNewSUnit(SDNode *N) {
128 SUnit *NewNode = NewSUnit(N);
Roman Levenstein733a4d62008-03-26 11:23:38 +0000129 // Update the topological ordering.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000130 if (NewNode->NodeNum >= Node2Index.size())
131 InitDAGTopologicalSorting();
132 return NewNode;
133 }
134
Roman Levenstein733a4d62008-03-26 11:23:38 +0000135 /// CreateClone - Creates a new SUnit from an existing one.
136 /// Updates the topological ordering if required.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000137 SUnit *CreateClone(SUnit *N) {
138 SUnit *NewNode = Clone(N);
Roman Levenstein733a4d62008-03-26 11:23:38 +0000139 // Update the topological ordering.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000140 if (NewNode->NodeNum >= Node2Index.size())
141 InitDAGTopologicalSorting();
142 return NewNode;
143 }
144
145 /// Functions for preserving the topological ordering
146 /// even after dynamic insertions of new edges.
Roman Levenstein733a4d62008-03-26 11:23:38 +0000147 /// This allows a very fast implementation of IsReachable.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000148
Roman Levenstein733a4d62008-03-26 11:23:38 +0000149 /// InitDAGTopologicalSorting - create the initial topological
150 /// ordering from the DAG to be scheduled.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000151 void InitDAGTopologicalSorting();
152
153 /// DFS - make a DFS traversal and mark all nodes affected by the
Roman Levenstein733a4d62008-03-26 11:23:38 +0000154 /// edge insertion. These nodes will later get new topological indexes
155 /// by means of the Shift method.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000156 void DFS(SUnit *SU, int UpperBound, bool& HasLoop);
157
158 /// Shift - reassign topological indexes for the nodes in the DAG
Roman Levenstein733a4d62008-03-26 11:23:38 +0000159 /// to preserve the topological ordering.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000160 void Shift(BitVector& Visited, int LowerBound, int UpperBound);
161
Roman Levenstein733a4d62008-03-26 11:23:38 +0000162 /// Allocate - assign the topological index to the node n.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000163 void Allocate(int n, int index);
164
Roman Levenstein733a4d62008-03-26 11:23:38 +0000165 /// Index2Node - Maps topological index to the node number.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000166 std::vector<int> Index2Node;
Roman Levenstein733a4d62008-03-26 11:23:38 +0000167 /// Node2Index - Maps the node number to its topological index.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000168 std::vector<int> Node2Index;
Roman Levenstein733a4d62008-03-26 11:23:38 +0000169 /// Visited - a set of nodes visited during a DFS traversal.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000170 BitVector Visited;
Evan Chengd38c22b2006-05-11 23:55:42 +0000171};
172} // end anonymous namespace
173
174
175/// Schedule - Schedule the DAG using list scheduling.
176void ScheduleDAGRRList::Schedule() {
Bill Wendling22e978a2006-12-07 20:04:42 +0000177 DOUT << "********** List Scheduling **********\n";
Evan Cheng5924bf72007-09-25 01:54:36 +0000178
Dan Gohman3a4be0f2008-02-10 18:45:23 +0000179 LiveRegDefs.resize(TRI->getNumRegs(), NULL);
180 LiveRegCycles.resize(TRI->getNumRegs(), 0);
Evan Cheng5924bf72007-09-25 01:54:36 +0000181
Evan Chengd38c22b2006-05-11 23:55:42 +0000182 // Build scheduling units.
183 BuildSchedUnits();
184
Evan Chengd38c22b2006-05-11 23:55:42 +0000185 DEBUG(for (unsigned su = 0, e = SUnits.size(); su != e; ++su)
Chris Lattnerd86418a2006-08-17 00:09:56 +0000186 SUnits[su].dumpAll(&DAG));
Evan Cheng2c977312008-07-01 18:05:03 +0000187 if (!Fast) {
188 CalculateDepths();
189 CalculateHeights();
190 }
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000191 InitDAGTopologicalSorting();
Evan Chengd38c22b2006-05-11 23:55:42 +0000192
Dan Gohman46520a22008-06-21 19:18:17 +0000193 AvailableQueue->initNodes(SUnits);
Dan Gohman54a187e2007-08-20 19:28:38 +0000194
Evan Chengd38c22b2006-05-11 23:55:42 +0000195 // Execute the actual scheduling loop Top-Down or Bottom-Up as appropriate.
196 if (isBottomUp)
197 ListScheduleBottomUp();
198 else
199 ListScheduleTopDown();
200
201 AvailableQueue->releaseState();
Evan Cheng2c977312008-07-01 18:05:03 +0000202
203 if (!Fast)
204 CommuteNodesToReducePressure();
Evan Chengd38c22b2006-05-11 23:55:42 +0000205
Bill Wendling22e978a2006-12-07 20:04:42 +0000206 DOUT << "*** Final schedule ***\n";
Evan Chengd38c22b2006-05-11 23:55:42 +0000207 DEBUG(dumpSchedule());
Bill Wendling22e978a2006-12-07 20:04:42 +0000208 DOUT << "\n";
Evan Chengd38c22b2006-05-11 23:55:42 +0000209
210 // Emit in scheduled order
211 EmitSchedule();
212}
213
Evan Chengfd2c5dd2006-11-04 09:44:31 +0000214/// CommuteNodesToReducePressure - If a node is two-address and commutable, and
Evan Chengafed73e2006-05-12 01:58:24 +0000215/// it is not the last use of its first operand, add it to the CommuteSet if
216/// possible. It will be commuted when it is translated to a MI.
217void ScheduleDAGRRList::CommuteNodesToReducePressure() {
Evan Chenge3c44192007-06-22 01:35:51 +0000218 SmallPtrSet<SUnit*, 4> OperandSeen;
Dan Gohman4370f262008-04-15 01:22:18 +0000219 for (unsigned i = Sequence.size(); i != 0; ) {
220 --i;
Evan Chengafed73e2006-05-12 01:58:24 +0000221 SUnit *SU = Sequence[i];
Evan Cheng8e136a92007-09-26 21:36:17 +0000222 if (!SU || !SU->Node) continue;
Evan Chengfd2c5dd2006-11-04 09:44:31 +0000223 if (SU->isCommutable) {
224 unsigned Opc = SU->Node->getTargetOpcode();
Chris Lattner03ad8852008-01-07 07:27:27 +0000225 const TargetInstrDesc &TID = TII->get(Opc);
Chris Lattnerfd2e3382008-01-07 06:47:00 +0000226 unsigned NumRes = TID.getNumDefs();
Dan Gohman0340d1e2008-02-15 20:50:13 +0000227 unsigned NumOps = TID.getNumOperands() - NumRes;
Evan Chengfd2c5dd2006-11-04 09:44:31 +0000228 for (unsigned j = 0; j != NumOps; ++j) {
Chris Lattnerfd2e3382008-01-07 06:47:00 +0000229 if (TID.getOperandConstraint(j+NumRes, TOI::TIED_TO) == -1)
Evan Chengfd2c5dd2006-11-04 09:44:31 +0000230 continue;
231
232 SDNode *OpN = SU->Node->getOperand(j).Val;
Dan Gohman46520a22008-06-21 19:18:17 +0000233 SUnit *OpSU = isPassiveNode(OpN) ? NULL : &SUnits[OpN->getNodeId()];
Evan Chengfd2c5dd2006-11-04 09:44:31 +0000234 if (OpSU && OperandSeen.count(OpSU) == 1) {
235 // Ok, so SU is not the last use of OpSU, but SU is two-address so
236 // it will clobber OpSU. Try to commute SU if no other source operands
237 // are live below.
238 bool DoCommute = true;
239 for (unsigned k = 0; k < NumOps; ++k) {
240 if (k != j) {
241 OpN = SU->Node->getOperand(k).Val;
Dan Gohman46520a22008-06-21 19:18:17 +0000242 OpSU = isPassiveNode(OpN) ? NULL : &SUnits[OpN->getNodeId()];
Evan Chengfd2c5dd2006-11-04 09:44:31 +0000243 if (OpSU && OperandSeen.count(OpSU) == 1) {
244 DoCommute = false;
245 break;
246 }
247 }
Evan Chengafed73e2006-05-12 01:58:24 +0000248 }
Evan Chengfd2c5dd2006-11-04 09:44:31 +0000249 if (DoCommute)
250 CommuteSet.insert(SU->Node);
Evan Chengafed73e2006-05-12 01:58:24 +0000251 }
Evan Chengfd2c5dd2006-11-04 09:44:31 +0000252
253 // Only look at the first use&def node for now.
254 break;
Evan Chengafed73e2006-05-12 01:58:24 +0000255 }
256 }
257
Chris Lattnerd86418a2006-08-17 00:09:56 +0000258 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
259 I != E; ++I) {
Evan Cheng0effc3a2007-09-19 01:38:40 +0000260 if (!I->isCtrl)
Dan Gohmane6e13482008-06-21 15:52:51 +0000261 OperandSeen.insert(I->Dep->OrigNode);
Evan Chengafed73e2006-05-12 01:58:24 +0000262 }
263 }
264}
Evan Chengd38c22b2006-05-11 23:55:42 +0000265
266//===----------------------------------------------------------------------===//
267// Bottom-Up Scheduling
268//===----------------------------------------------------------------------===//
269
Evan Chengd38c22b2006-05-11 23:55:42 +0000270/// ReleasePred - Decrement the NumSuccsLeft count of a predecessor. Add it to
Dan Gohman54a187e2007-08-20 19:28:38 +0000271/// the AvailableQueue if the count reaches zero. Also update its cycle bound.
Evan Chengd38c22b2006-05-11 23:55:42 +0000272void ScheduleDAGRRList::ReleasePred(SUnit *PredSU, bool isChain,
273 unsigned CurCycle) {
274 // FIXME: the distance between two nodes is not always == the predecessor's
275 // latency. For example, the reader can very well read the register written
276 // by the predecessor later than the issue cycle. It also depends on the
277 // interrupt model (drain vs. freeze).
278 PredSU->CycleBound = std::max(PredSU->CycleBound, CurCycle + PredSU->Latency);
279
Evan Cheng038dcc52007-09-28 19:24:24 +0000280 --PredSU->NumSuccsLeft;
Evan Chengd38c22b2006-05-11 23:55:42 +0000281
282#ifndef NDEBUG
Evan Cheng038dcc52007-09-28 19:24:24 +0000283 if (PredSU->NumSuccsLeft < 0) {
Bill Wendling22e978a2006-12-07 20:04:42 +0000284 cerr << "*** List scheduling failed! ***\n";
Evan Chengd38c22b2006-05-11 23:55:42 +0000285 PredSU->dump(&DAG);
Bill Wendling22e978a2006-12-07 20:04:42 +0000286 cerr << " has been released too many times!\n";
Evan Chengd38c22b2006-05-11 23:55:42 +0000287 assert(0);
288 }
289#endif
290
Evan Cheng038dcc52007-09-28 19:24:24 +0000291 if (PredSU->NumSuccsLeft == 0) {
Dan Gohman4370f262008-04-15 01:22:18 +0000292 PredSU->isAvailable = true;
293 AvailableQueue->push(PredSU);
Evan Chengd38c22b2006-05-11 23:55:42 +0000294 }
295}
296
297/// ScheduleNodeBottomUp - Add the node to the schedule. Decrement the pending
298/// count of its predecessors. If a predecessor pending count is zero, add it to
299/// the Available queue.
Evan Chengd12c97d2006-05-30 18:05:39 +0000300void ScheduleDAGRRList::ScheduleNodeBottomUp(SUnit *SU, unsigned CurCycle) {
Bill Wendling22e978a2006-12-07 20:04:42 +0000301 DOUT << "*** Scheduling [" << CurCycle << "]: ";
Evan Chengd38c22b2006-05-11 23:55:42 +0000302 DEBUG(SU->dump(&DAG));
303 SU->Cycle = CurCycle;
304
305 AvailableQueue->ScheduledNode(SU);
Evan Chengd38c22b2006-05-11 23:55:42 +0000306
307 // Bottom up: release predecessors
Chris Lattnerd86418a2006-08-17 00:09:56 +0000308 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
Evan Cheng5924bf72007-09-25 01:54:36 +0000309 I != E; ++I) {
Evan Cheng0effc3a2007-09-19 01:38:40 +0000310 ReleasePred(I->Dep, I->isCtrl, CurCycle);
Evan Cheng5924bf72007-09-25 01:54:36 +0000311 if (I->Cost < 0) {
312 // This is a physical register dependency and it's impossible or
313 // expensive to copy the register. Make sure nothing that can
314 // clobber the register is scheduled between the predecessor and
315 // this node.
316 if (LiveRegs.insert(I->Reg)) {
317 LiveRegDefs[I->Reg] = I->Dep;
318 LiveRegCycles[I->Reg] = CurCycle;
319 }
320 }
321 }
322
323 // Release all the implicit physical register defs that are live.
324 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
325 I != E; ++I) {
326 if (I->Cost < 0) {
327 if (LiveRegCycles[I->Reg] == I->Dep->Cycle) {
328 LiveRegs.erase(I->Reg);
329 assert(LiveRegDefs[I->Reg] == SU &&
330 "Physical register dependency violated?");
331 LiveRegDefs[I->Reg] = NULL;
332 LiveRegCycles[I->Reg] = 0;
333 }
334 }
335 }
336
Evan Chengd38c22b2006-05-11 23:55:42 +0000337 SU->isScheduled = true;
Evan Chengd38c22b2006-05-11 23:55:42 +0000338}
339
Evan Cheng5924bf72007-09-25 01:54:36 +0000340/// CapturePred - This does the opposite of ReleasePred. Since SU is being
341/// unscheduled, incrcease the succ left count of its predecessors. Remove
342/// them from AvailableQueue if necessary.
Roman Levenstein6b371142008-04-29 09:07:59 +0000343void ScheduleDAGRRList::CapturePred(SUnit *PredSU, SUnit *SU, bool isChain) {
344 unsigned CycleBound = 0;
Evan Cheng5924bf72007-09-25 01:54:36 +0000345 for (SUnit::succ_iterator I = PredSU->Succs.begin(), E = PredSU->Succs.end();
346 I != E; ++I) {
347 if (I->Dep == SU)
348 continue;
Roman Levenstein6b371142008-04-29 09:07:59 +0000349 CycleBound = std::max(CycleBound,
350 I->Dep->Cycle + PredSU->Latency);
Evan Cheng5924bf72007-09-25 01:54:36 +0000351 }
352
353 if (PredSU->isAvailable) {
354 PredSU->isAvailable = false;
355 if (!PredSU->isPending)
356 AvailableQueue->remove(PredSU);
357 }
358
Roman Levenstein6b371142008-04-29 09:07:59 +0000359 PredSU->CycleBound = CycleBound;
Evan Cheng038dcc52007-09-28 19:24:24 +0000360 ++PredSU->NumSuccsLeft;
Evan Cheng5924bf72007-09-25 01:54:36 +0000361}
362
363/// UnscheduleNodeBottomUp - Remove the node from the schedule, update its and
364/// its predecessor states to reflect the change.
365void ScheduleDAGRRList::UnscheduleNodeBottomUp(SUnit *SU) {
366 DOUT << "*** Unscheduling [" << SU->Cycle << "]: ";
367 DEBUG(SU->dump(&DAG));
368
369 AvailableQueue->UnscheduledNode(SU);
370
371 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
372 I != E; ++I) {
373 CapturePred(I->Dep, SU, I->isCtrl);
374 if (I->Cost < 0 && SU->Cycle == LiveRegCycles[I->Reg]) {
375 LiveRegs.erase(I->Reg);
376 assert(LiveRegDefs[I->Reg] == I->Dep &&
377 "Physical register dependency violated?");
378 LiveRegDefs[I->Reg] = NULL;
379 LiveRegCycles[I->Reg] = 0;
380 }
381 }
382
383 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
384 I != E; ++I) {
385 if (I->Cost < 0) {
386 if (LiveRegs.insert(I->Reg)) {
387 assert(!LiveRegDefs[I->Reg] &&
388 "Physical register dependency violated?");
389 LiveRegDefs[I->Reg] = SU;
390 }
391 if (I->Dep->Cycle < LiveRegCycles[I->Reg])
392 LiveRegCycles[I->Reg] = I->Dep->Cycle;
393 }
394 }
395
396 SU->Cycle = 0;
397 SU->isScheduled = false;
398 SU->isAvailable = true;
399 AvailableQueue->push(SU);
400}
401
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000402/// IsReachable - Checks if SU is reachable from TargetSU.
403bool ScheduleDAGRRList::IsReachable(SUnit *SU, SUnit *TargetSU) {
Roman Levenstein733a4d62008-03-26 11:23:38 +0000404 // If insertion of the edge SU->TargetSU would create a cycle
405 // then there is a path from TargetSU to SU.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000406 int UpperBound, LowerBound;
407 LowerBound = Node2Index[TargetSU->NodeNum];
408 UpperBound = Node2Index[SU->NodeNum];
409 bool HasLoop = false;
410 // Is Ord(TargetSU) < Ord(SU) ?
411 if (LowerBound < UpperBound) {
412 Visited.reset();
413 // There may be a path from TargetSU to SU. Check for it.
414 DFS(TargetSU, UpperBound, HasLoop);
Evan Chengcfd5f822007-09-27 00:25:29 +0000415 }
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000416 return HasLoop;
Evan Chengcfd5f822007-09-27 00:25:29 +0000417}
418
Roman Levenstein733a4d62008-03-26 11:23:38 +0000419/// Allocate - assign the topological index to the node n.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000420inline void ScheduleDAGRRList::Allocate(int n, int index) {
421 Node2Index[n] = index;
422 Index2Node[index] = n;
Evan Chengcfd5f822007-09-27 00:25:29 +0000423}
424
Roman Levenstein733a4d62008-03-26 11:23:38 +0000425/// InitDAGTopologicalSorting - create the initial topological
426/// ordering from the DAG to be scheduled.
Evan Cheng2c977312008-07-01 18:05:03 +0000427
428/// The idea of the algorithm is taken from
429/// "Online algorithms for managing the topological order of
430/// a directed acyclic graph" by David J. Pearce and Paul H.J. Kelly
431/// This is the MNR algorithm, which was first introduced by
432/// A. Marchetti-Spaccamela, U. Nanni and H. Rohnert in
433/// "Maintaining a topological order under edge insertions".
434///
435/// Short description of the algorithm:
436///
437/// Topological ordering, ord, of a DAG maps each node to a topological
438/// index so that for all edges X->Y it is the case that ord(X) < ord(Y).
439///
440/// This means that if there is a path from the node X to the node Z,
441/// then ord(X) < ord(Z).
442///
443/// This property can be used to check for reachability of nodes:
444/// if Z is reachable from X, then an insertion of the edge Z->X would
445/// create a cycle.
446///
447/// The algorithm first computes a topological ordering for the DAG by
448/// initializing the Index2Node and Node2Index arrays and then tries to keep
449/// the ordering up-to-date after edge insertions by reordering the DAG.
450///
451/// On insertion of the edge X->Y, the algorithm first marks by calling DFS
452/// the nodes reachable from Y, and then shifts them using Shift to lie
453/// immediately after X in Index2Node.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000454void ScheduleDAGRRList::InitDAGTopologicalSorting() {
455 unsigned DAGSize = SUnits.size();
456 std::vector<unsigned> InDegree(DAGSize);
457 std::vector<SUnit*> WorkList;
458 WorkList.reserve(DAGSize);
459 std::vector<SUnit*> TopOrder;
460 TopOrder.reserve(DAGSize);
461
Roman Levenstein733a4d62008-03-26 11:23:38 +0000462 // Initialize the data structures.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000463 for (unsigned i = 0, e = DAGSize; i != e; ++i) {
464 SUnit *SU = &SUnits[i];
465 int NodeNum = SU->NodeNum;
466 unsigned Degree = SU->Succs.size();
467 InDegree[NodeNum] = Degree;
468
469 // Is it a node without dependencies?
470 if (Degree == 0) {
471 assert(SU->Succs.empty() && "SUnit should have no successors");
Roman Levenstein733a4d62008-03-26 11:23:38 +0000472 // Collect leaf nodes.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000473 WorkList.push_back(SU);
474 }
475 }
476
477 while (!WorkList.empty()) {
478 SUnit *SU = WorkList.back();
479 WorkList.pop_back();
480 TopOrder.push_back(SU);
481 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
482 I != E; ++I) {
483 SUnit *SU = I->Dep;
484 if (!--InDegree[SU->NodeNum])
485 // If all dependencies of the node are processed already,
Roman Levenstein733a4d62008-03-26 11:23:38 +0000486 // then the node can be computed now.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000487 WorkList.push_back(SU);
488 }
489 }
490
491 // Second pass, assign the actual topological order as node ids.
492 int Id = 0;
493
494 Index2Node.clear();
495 Node2Index.clear();
496 Index2Node.resize(DAGSize);
497 Node2Index.resize(DAGSize);
498 Visited.resize(DAGSize);
499
500 for (std::vector<SUnit*>::reverse_iterator TI = TopOrder.rbegin(),
501 TE = TopOrder.rend();TI != TE; ++TI) {
502 Allocate((*TI)->NodeNum, Id);
503 Id++;
504 }
505
506#ifndef NDEBUG
507 // Check correctness of the ordering
508 for (unsigned i = 0, e = DAGSize; i != e; ++i) {
509 SUnit *SU = &SUnits[i];
510 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
511 I != E; ++I) {
512 assert(Node2Index[SU->NodeNum] > Node2Index[I->Dep->NodeNum] &&
513 "Wrong topological sorting");
514 }
515 }
516#endif
517}
518
Roman Levenstein733a4d62008-03-26 11:23:38 +0000519/// AddPred - adds an edge from SUnit X to SUnit Y.
520/// Updates the topological ordering if required.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000521bool ScheduleDAGRRList::AddPred(SUnit *Y, SUnit *X, bool isCtrl, bool isSpecial,
522 unsigned PhyReg, int Cost) {
523 int UpperBound, LowerBound;
524 LowerBound = Node2Index[Y->NodeNum];
525 UpperBound = Node2Index[X->NodeNum];
526 bool HasLoop = false;
527 // Is Ord(X) < Ord(Y) ?
528 if (LowerBound < UpperBound) {
Roman Levenstein733a4d62008-03-26 11:23:38 +0000529 // Update the topological order.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000530 Visited.reset();
531 DFS(Y, UpperBound, HasLoop);
532 assert(!HasLoop && "Inserted edge creates a loop!");
Roman Levenstein733a4d62008-03-26 11:23:38 +0000533 // Recompute topological indexes.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000534 Shift(Visited, LowerBound, UpperBound);
535 }
Roman Levenstein733a4d62008-03-26 11:23:38 +0000536 // Now really insert the edge.
537 return Y->addPred(X, isCtrl, isSpecial, PhyReg, Cost);
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000538}
539
Roman Levenstein733a4d62008-03-26 11:23:38 +0000540/// RemovePred - This removes the specified node N from the predecessors of
541/// the current node M. Updates the topological ordering if required.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000542bool ScheduleDAGRRList::RemovePred(SUnit *M, SUnit *N,
543 bool isCtrl, bool isSpecial) {
544 // InitDAGTopologicalSorting();
545 return M->removePred(N, isCtrl, isSpecial);
546}
547
Roman Levenstein733a4d62008-03-26 11:23:38 +0000548/// DFS - Make a DFS traversal to mark all nodes reachable from SU and mark
549/// all nodes affected by the edge insertion. These nodes will later get new
550/// topological indexes by means of the Shift method.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000551void ScheduleDAGRRList::DFS(SUnit *SU, int UpperBound, bool& HasLoop) {
552 std::vector<SUnit*> WorkList;
553 WorkList.reserve(SUnits.size());
554
555 WorkList.push_back(SU);
556 while (!WorkList.empty()) {
557 SU = WorkList.back();
558 WorkList.pop_back();
559 Visited.set(SU->NodeNum);
560 for (int I = SU->Succs.size()-1; I >= 0; --I) {
561 int s = SU->Succs[I].Dep->NodeNum;
562 if (Node2Index[s] == UpperBound) {
563 HasLoop = true;
564 return;
565 }
Roman Levenstein733a4d62008-03-26 11:23:38 +0000566 // Visit successors if not already and in affected region.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000567 if (!Visited.test(s) && Node2Index[s] < UpperBound) {
568 WorkList.push_back(SU->Succs[I].Dep);
569 }
570 }
571 }
572}
573
Roman Levenstein733a4d62008-03-26 11:23:38 +0000574/// Shift - Renumber the nodes so that the topological ordering is
575/// preserved.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000576void ScheduleDAGRRList::Shift(BitVector& Visited, int LowerBound,
577 int UpperBound) {
578 std::vector<int> L;
579 int shift = 0;
580 int i;
581
582 for (i = LowerBound; i <= UpperBound; ++i) {
Roman Levenstein733a4d62008-03-26 11:23:38 +0000583 // w is node at topological index i.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000584 int w = Index2Node[i];
585 if (Visited.test(w)) {
Roman Levenstein733a4d62008-03-26 11:23:38 +0000586 // Unmark.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000587 Visited.reset(w);
588 L.push_back(w);
589 shift = shift + 1;
590 } else {
591 Allocate(w, i - shift);
592 }
593 }
594
595 for (unsigned j = 0; j < L.size(); ++j) {
596 Allocate(L[j], i - shift);
597 i = i + 1;
598 }
599}
600
601
Dan Gohmanfd227e92008-03-25 17:10:29 +0000602/// WillCreateCycle - Returns true if adding an edge from SU to TargetSU will
Evan Chengcfd5f822007-09-27 00:25:29 +0000603/// create a cycle.
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000604bool ScheduleDAGRRList::WillCreateCycle(SUnit *SU, SUnit *TargetSU) {
605 if (IsReachable(TargetSU, SU))
Evan Chengcfd5f822007-09-27 00:25:29 +0000606 return true;
607 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
608 I != E; ++I)
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000609 if (I->Cost < 0 && IsReachable(TargetSU, I->Dep))
Evan Chengcfd5f822007-09-27 00:25:29 +0000610 return true;
611 return false;
612}
613
Evan Cheng8e136a92007-09-26 21:36:17 +0000614/// BacktrackBottomUp - Backtrack scheduling to a previous cycle specified in
Evan Cheng5924bf72007-09-25 01:54:36 +0000615/// BTCycle in order to schedule a specific node. Returns the last unscheduled
616/// SUnit. Also returns if a successor is unscheduled in the process.
Evan Cheng8e136a92007-09-26 21:36:17 +0000617void ScheduleDAGRRList::BacktrackBottomUp(SUnit *SU, unsigned BtCycle,
618 unsigned &CurCycle) {
Evan Cheng5924bf72007-09-25 01:54:36 +0000619 SUnit *OldSU = NULL;
Evan Cheng8e136a92007-09-26 21:36:17 +0000620 while (CurCycle > BtCycle) {
Evan Cheng5924bf72007-09-25 01:54:36 +0000621 OldSU = Sequence.back();
622 Sequence.pop_back();
623 if (SU->isSucc(OldSU))
Evan Cheng8e136a92007-09-26 21:36:17 +0000624 // Don't try to remove SU from AvailableQueue.
625 SU->isAvailable = false;
Evan Cheng5924bf72007-09-25 01:54:36 +0000626 UnscheduleNodeBottomUp(OldSU);
627 --CurCycle;
628 }
629
630
631 if (SU->isSucc(OldSU)) {
632 assert(false && "Something is wrong!");
633 abort();
634 }
Evan Cheng1ec79b42007-09-27 07:09:03 +0000635
636 ++NumBacktracks;
Evan Cheng5924bf72007-09-25 01:54:36 +0000637}
638
Evan Cheng5924bf72007-09-25 01:54:36 +0000639/// CopyAndMoveSuccessors - Clone the specified node and move its scheduled
640/// successors to the newly created node.
641SUnit *ScheduleDAGRRList::CopyAndMoveSuccessors(SUnit *SU) {
Evan Cheng79e97132007-10-05 01:39:18 +0000642 if (SU->FlaggedNodes.size())
643 return NULL;
Evan Cheng8e136a92007-09-26 21:36:17 +0000644
Evan Cheng79e97132007-10-05 01:39:18 +0000645 SDNode *N = SU->Node;
646 if (!N)
647 return NULL;
648
649 SUnit *NewSU;
Evan Cheng79e97132007-10-05 01:39:18 +0000650 bool TryUnfold = false;
Evan Cheng84d0ebc2007-10-05 01:42:35 +0000651 for (unsigned i = 0, e = N->getNumValues(); i != e; ++i) {
Duncan Sands13237ac2008-06-06 12:08:01 +0000652 MVT VT = N->getValueType(i);
Evan Cheng84d0ebc2007-10-05 01:42:35 +0000653 if (VT == MVT::Flag)
654 return NULL;
655 else if (VT == MVT::Other)
656 TryUnfold = true;
657 }
Evan Cheng79e97132007-10-05 01:39:18 +0000658 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
659 const SDOperand &Op = N->getOperand(i);
Duncan Sands13237ac2008-06-06 12:08:01 +0000660 MVT VT = Op.Val->getValueType(Op.ResNo);
Evan Cheng79e97132007-10-05 01:39:18 +0000661 if (VT == MVT::Flag)
662 return NULL;
Evan Cheng79e97132007-10-05 01:39:18 +0000663 }
664
665 if (TryUnfold) {
Dan Gohmane6e13482008-06-21 15:52:51 +0000666 SmallVector<SDNode*, 2> NewNodes;
Owen Anderson0ec92e92008-01-07 01:35:56 +0000667 if (!TII->unfoldMemoryOperand(DAG, N, NewNodes))
Evan Cheng79e97132007-10-05 01:39:18 +0000668 return NULL;
669
670 DOUT << "Unfolding SU # " << SU->NodeNum << "\n";
671 assert(NewNodes.size() == 2 && "Expected a load folding node!");
672
673 N = NewNodes[1];
674 SDNode *LoadNode = NewNodes[0];
Evan Cheng79e97132007-10-05 01:39:18 +0000675 unsigned NumVals = N->getNumValues();
676 unsigned OldNumVals = SU->Node->getNumValues();
677 for (unsigned i = 0; i != NumVals; ++i)
Chris Lattner3cfb56d2007-10-15 06:10:22 +0000678 DAG.ReplaceAllUsesOfValueWith(SDOperand(SU->Node, i), SDOperand(N, i));
Evan Cheng79e97132007-10-05 01:39:18 +0000679 DAG.ReplaceAllUsesOfValueWith(SDOperand(SU->Node, OldNumVals-1),
Chris Lattner3cfb56d2007-10-15 06:10:22 +0000680 SDOperand(LoadNode, 1));
Evan Cheng79e97132007-10-05 01:39:18 +0000681
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000682 SUnit *NewSU = CreateNewSUnit(N);
Dan Gohman46520a22008-06-21 19:18:17 +0000683 assert(N->getNodeId() == -1 && "Node already inserted!");
684 N->setNodeId(NewSU->NodeNum);
Dan Gohmane6e13482008-06-21 15:52:51 +0000685
Chris Lattner03ad8852008-01-07 07:27:27 +0000686 const TargetInstrDesc &TID = TII->get(N->getTargetOpcode());
Dan Gohman856c0122008-02-16 00:25:40 +0000687 for (unsigned i = 0; i != TID.getNumOperands(); ++i) {
Chris Lattnerfd2e3382008-01-07 06:47:00 +0000688 if (TID.getOperandConstraint(i, TOI::TIED_TO) != -1) {
Evan Cheng79e97132007-10-05 01:39:18 +0000689 NewSU->isTwoAddress = true;
690 break;
691 }
692 }
Chris Lattnerfd2e3382008-01-07 06:47:00 +0000693 if (TID.isCommutable())
Evan Cheng79e97132007-10-05 01:39:18 +0000694 NewSU->isCommutable = true;
Evan Cheng79e97132007-10-05 01:39:18 +0000695 // FIXME: Calculate height / depth and propagate the changes?
Evan Cheng91e0fc92007-12-18 08:42:10 +0000696 NewSU->Depth = SU->Depth;
697 NewSU->Height = SU->Height;
Evan Cheng79e97132007-10-05 01:39:18 +0000698 ComputeLatency(NewSU);
699
Evan Cheng91e0fc92007-12-18 08:42:10 +0000700 // LoadNode may already exist. This can happen when there is another
701 // load from the same location and producing the same type of value
702 // but it has different alignment or volatileness.
703 bool isNewLoad = true;
704 SUnit *LoadSU;
Dan Gohman46520a22008-06-21 19:18:17 +0000705 if (LoadNode->getNodeId() != -1) {
706 LoadSU = &SUnits[LoadNode->getNodeId()];
Evan Cheng91e0fc92007-12-18 08:42:10 +0000707 isNewLoad = false;
708 } else {
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000709 LoadSU = CreateNewSUnit(LoadNode);
Dan Gohman46520a22008-06-21 19:18:17 +0000710 LoadNode->setNodeId(LoadSU->NodeNum);
Evan Cheng91e0fc92007-12-18 08:42:10 +0000711
712 LoadSU->Depth = SU->Depth;
713 LoadSU->Height = SU->Height;
714 ComputeLatency(LoadSU);
715 }
716
Evan Cheng79e97132007-10-05 01:39:18 +0000717 SUnit *ChainPred = NULL;
718 SmallVector<SDep, 4> ChainSuccs;
719 SmallVector<SDep, 4> LoadPreds;
720 SmallVector<SDep, 4> NodePreds;
721 SmallVector<SDep, 4> NodeSuccs;
722 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
723 I != E; ++I) {
724 if (I->isCtrl)
725 ChainPred = I->Dep;
Evan Cheng567d2e52008-03-04 00:41:45 +0000726 else if (I->Dep->Node && I->Dep->Node->isOperandOf(LoadNode))
Evan Cheng79e97132007-10-05 01:39:18 +0000727 LoadPreds.push_back(SDep(I->Dep, I->Reg, I->Cost, false, false));
728 else
729 NodePreds.push_back(SDep(I->Dep, I->Reg, I->Cost, false, false));
730 }
731 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
732 I != E; ++I) {
733 if (I->isCtrl)
734 ChainSuccs.push_back(SDep(I->Dep, I->Reg, I->Cost,
735 I->isCtrl, I->isSpecial));
736 else
737 NodeSuccs.push_back(SDep(I->Dep, I->Reg, I->Cost,
738 I->isCtrl, I->isSpecial));
739 }
740
Dan Gohman4370f262008-04-15 01:22:18 +0000741 if (ChainPred) {
742 RemovePred(SU, ChainPred, true, false);
743 if (isNewLoad)
744 AddPred(LoadSU, ChainPred, true, false);
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000745 }
Evan Cheng79e97132007-10-05 01:39:18 +0000746 for (unsigned i = 0, e = LoadPreds.size(); i != e; ++i) {
747 SDep *Pred = &LoadPreds[i];
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000748 RemovePred(SU, Pred->Dep, Pred->isCtrl, Pred->isSpecial);
749 if (isNewLoad) {
750 AddPred(LoadSU, Pred->Dep, Pred->isCtrl, Pred->isSpecial,
Roman Levenstein733a4d62008-03-26 11:23:38 +0000751 Pred->Reg, Pred->Cost);
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000752 }
Evan Cheng79e97132007-10-05 01:39:18 +0000753 }
754 for (unsigned i = 0, e = NodePreds.size(); i != e; ++i) {
755 SDep *Pred = &NodePreds[i];
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000756 RemovePred(SU, Pred->Dep, Pred->isCtrl, Pred->isSpecial);
757 AddPred(NewSU, Pred->Dep, Pred->isCtrl, Pred->isSpecial,
Roman Levenstein733a4d62008-03-26 11:23:38 +0000758 Pred->Reg, Pred->Cost);
Evan Cheng79e97132007-10-05 01:39:18 +0000759 }
760 for (unsigned i = 0, e = NodeSuccs.size(); i != e; ++i) {
761 SDep *Succ = &NodeSuccs[i];
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000762 RemovePred(Succ->Dep, SU, Succ->isCtrl, Succ->isSpecial);
763 AddPred(Succ->Dep, NewSU, Succ->isCtrl, Succ->isSpecial,
Roman Levenstein733a4d62008-03-26 11:23:38 +0000764 Succ->Reg, Succ->Cost);
Evan Cheng79e97132007-10-05 01:39:18 +0000765 }
766 for (unsigned i = 0, e = ChainSuccs.size(); i != e; ++i) {
767 SDep *Succ = &ChainSuccs[i];
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000768 RemovePred(Succ->Dep, SU, Succ->isCtrl, Succ->isSpecial);
769 if (isNewLoad) {
770 AddPred(Succ->Dep, LoadSU, Succ->isCtrl, Succ->isSpecial,
Roman Levenstein733a4d62008-03-26 11:23:38 +0000771 Succ->Reg, Succ->Cost);
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000772 }
Evan Cheng79e97132007-10-05 01:39:18 +0000773 }
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000774 if (isNewLoad) {
775 AddPred(NewSU, LoadSU, false, false);
776 }
Evan Cheng79e97132007-10-05 01:39:18 +0000777
Evan Cheng91e0fc92007-12-18 08:42:10 +0000778 if (isNewLoad)
779 AvailableQueue->addNode(LoadSU);
Evan Cheng79e97132007-10-05 01:39:18 +0000780 AvailableQueue->addNode(NewSU);
781
782 ++NumUnfolds;
783
784 if (NewSU->NumSuccsLeft == 0) {
785 NewSU->isAvailable = true;
786 return NewSU;
Evan Cheng91e0fc92007-12-18 08:42:10 +0000787 }
788 SU = NewSU;
Evan Cheng79e97132007-10-05 01:39:18 +0000789 }
790
791 DOUT << "Duplicating SU # " << SU->NodeNum << "\n";
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000792 NewSU = CreateClone(SU);
Evan Cheng5924bf72007-09-25 01:54:36 +0000793
794 // New SUnit has the exact same predecessors.
795 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
796 I != E; ++I)
797 if (!I->isSpecial) {
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000798 AddPred(NewSU, I->Dep, I->isCtrl, false, I->Reg, I->Cost);
Evan Cheng5924bf72007-09-25 01:54:36 +0000799 NewSU->Depth = std::max(NewSU->Depth, I->Dep->Depth+1);
800 }
801
802 // Only copy scheduled successors. Cut them from old node's successor
803 // list and move them over.
Evan Chengbde499b2007-09-27 07:29:27 +0000804 SmallVector<std::pair<SUnit*, bool>, 4> DelDeps;
Evan Cheng5924bf72007-09-25 01:54:36 +0000805 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
806 I != E; ++I) {
807 if (I->isSpecial)
808 continue;
Evan Cheng5924bf72007-09-25 01:54:36 +0000809 if (I->Dep->isScheduled) {
Evan Chengbde499b2007-09-27 07:29:27 +0000810 NewSU->Height = std::max(NewSU->Height, I->Dep->Height+1);
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000811 AddPred(I->Dep, NewSU, I->isCtrl, false, I->Reg, I->Cost);
Evan Chengbde499b2007-09-27 07:29:27 +0000812 DelDeps.push_back(std::make_pair(I->Dep, I->isCtrl));
Evan Cheng5924bf72007-09-25 01:54:36 +0000813 }
814 }
815 for (unsigned i = 0, e = DelDeps.size(); i != e; ++i) {
Evan Chengbde499b2007-09-27 07:29:27 +0000816 SUnit *Succ = DelDeps[i].first;
817 bool isCtrl = DelDeps[i].second;
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000818 RemovePred(Succ, SU, isCtrl, false);
Evan Cheng5924bf72007-09-25 01:54:36 +0000819 }
820
821 AvailableQueue->updateNode(SU);
822 AvailableQueue->addNode(NewSU);
823
Evan Cheng1ec79b42007-09-27 07:09:03 +0000824 ++NumDups;
Evan Cheng5924bf72007-09-25 01:54:36 +0000825 return NewSU;
826}
827
Evan Cheng1ec79b42007-09-27 07:09:03 +0000828/// InsertCCCopiesAndMoveSuccs - Insert expensive cross register class copies
829/// and move all scheduled successors of the given SUnit to the last copy.
830void ScheduleDAGRRList::InsertCCCopiesAndMoveSuccs(SUnit *SU, unsigned Reg,
831 const TargetRegisterClass *DestRC,
832 const TargetRegisterClass *SrcRC,
833 SmallVector<SUnit*, 2> &Copies) {
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000834 SUnit *CopyFromSU = CreateNewSUnit(NULL);
Evan Cheng8e136a92007-09-26 21:36:17 +0000835 CopyFromSU->CopySrcRC = SrcRC;
836 CopyFromSU->CopyDstRC = DestRC;
837 CopyFromSU->Depth = SU->Depth;
838 CopyFromSU->Height = SU->Height;
839
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000840 SUnit *CopyToSU = CreateNewSUnit(NULL);
Evan Cheng8e136a92007-09-26 21:36:17 +0000841 CopyToSU->CopySrcRC = DestRC;
842 CopyToSU->CopyDstRC = SrcRC;
843
844 // Only copy scheduled successors. Cut them from old node's successor
845 // list and move them over.
Evan Chengbde499b2007-09-27 07:29:27 +0000846 SmallVector<std::pair<SUnit*, bool>, 4> DelDeps;
Evan Cheng8e136a92007-09-26 21:36:17 +0000847 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
848 I != E; ++I) {
849 if (I->isSpecial)
850 continue;
Evan Cheng8e136a92007-09-26 21:36:17 +0000851 if (I->Dep->isScheduled) {
Evan Chengbde499b2007-09-27 07:29:27 +0000852 CopyToSU->Height = std::max(CopyToSU->Height, I->Dep->Height+1);
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000853 AddPred(I->Dep, CopyToSU, I->isCtrl, false, I->Reg, I->Cost);
Evan Chengbde499b2007-09-27 07:29:27 +0000854 DelDeps.push_back(std::make_pair(I->Dep, I->isCtrl));
Evan Cheng8e136a92007-09-26 21:36:17 +0000855 }
856 }
857 for (unsigned i = 0, e = DelDeps.size(); i != e; ++i) {
Evan Chengbde499b2007-09-27 07:29:27 +0000858 SUnit *Succ = DelDeps[i].first;
859 bool isCtrl = DelDeps[i].second;
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000860 RemovePred(Succ, SU, isCtrl, false);
Evan Cheng8e136a92007-09-26 21:36:17 +0000861 }
862
Roman Levenstein7e71b4b2008-03-26 09:18:09 +0000863 AddPred(CopyFromSU, SU, false, false, Reg, -1);
864 AddPred(CopyToSU, CopyFromSU, false, false, Reg, 1);
Evan Cheng8e136a92007-09-26 21:36:17 +0000865
866 AvailableQueue->updateNode(SU);
867 AvailableQueue->addNode(CopyFromSU);
868 AvailableQueue->addNode(CopyToSU);
Evan Cheng1ec79b42007-09-27 07:09:03 +0000869 Copies.push_back(CopyFromSU);
870 Copies.push_back(CopyToSU);
Evan Cheng8e136a92007-09-26 21:36:17 +0000871
Evan Cheng1ec79b42007-09-27 07:09:03 +0000872 ++NumCCCopies;
Evan Cheng8e136a92007-09-26 21:36:17 +0000873}
874
875/// getPhysicalRegisterVT - Returns the ValueType of the physical register
876/// definition of the specified node.
877/// FIXME: Move to SelectionDAG?
Duncan Sands13237ac2008-06-06 12:08:01 +0000878static MVT getPhysicalRegisterVT(SDNode *N, unsigned Reg,
879 const TargetInstrInfo *TII) {
Chris Lattner03ad8852008-01-07 07:27:27 +0000880 const TargetInstrDesc &TID = TII->get(N->getTargetOpcode());
Evan Cheng8e136a92007-09-26 21:36:17 +0000881 assert(TID.ImplicitDefs && "Physical reg def must be in implicit def list!");
Chris Lattnerb0d06b42008-01-07 03:13:06 +0000882 unsigned NumRes = TID.getNumDefs();
883 for (const unsigned *ImpDef = TID.getImplicitDefs(); *ImpDef; ++ImpDef) {
Evan Cheng8e136a92007-09-26 21:36:17 +0000884 if (Reg == *ImpDef)
885 break;
886 ++NumRes;
887 }
888 return N->getValueType(NumRes);
889}
890
Evan Cheng5924bf72007-09-25 01:54:36 +0000891/// DelayForLiveRegsBottomUp - Returns true if it is necessary to delay
892/// scheduling of the given node to satisfy live physical register dependencies.
893/// If the specific node is the last one that's available to schedule, do
894/// whatever is necessary (i.e. backtracking or cloning) to make it possible.
Evan Cheng1ec79b42007-09-27 07:09:03 +0000895bool ScheduleDAGRRList::DelayForLiveRegsBottomUp(SUnit *SU,
896 SmallVector<unsigned, 4> &LRegs){
Evan Cheng5924bf72007-09-25 01:54:36 +0000897 if (LiveRegs.empty())
898 return false;
899
Evan Chenge6f92252007-09-27 18:46:06 +0000900 SmallSet<unsigned, 4> RegAdded;
Evan Cheng5924bf72007-09-25 01:54:36 +0000901 // If this node would clobber any "live" register, then it's not ready.
Evan Cheng5924bf72007-09-25 01:54:36 +0000902 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
903 I != E; ++I) {
904 if (I->Cost < 0) {
905 unsigned Reg = I->Reg;
Evan Chenge6f92252007-09-27 18:46:06 +0000906 if (LiveRegs.count(Reg) && LiveRegDefs[Reg] != I->Dep) {
907 if (RegAdded.insert(Reg))
908 LRegs.push_back(Reg);
909 }
Dan Gohman3a4be0f2008-02-10 18:45:23 +0000910 for (const unsigned *Alias = TRI->getAliasSet(Reg);
Evan Cheng5924bf72007-09-25 01:54:36 +0000911 *Alias; ++Alias)
Evan Chenge6f92252007-09-27 18:46:06 +0000912 if (LiveRegs.count(*Alias) && LiveRegDefs[*Alias] != I->Dep) {
913 if (RegAdded.insert(*Alias))
914 LRegs.push_back(*Alias);
915 }
Evan Cheng5924bf72007-09-25 01:54:36 +0000916 }
917 }
918
919 for (unsigned i = 0, e = SU->FlaggedNodes.size()+1; i != e; ++i) {
920 SDNode *Node = (i == 0) ? SU->Node : SU->FlaggedNodes[i-1];
Evan Cheng8e136a92007-09-26 21:36:17 +0000921 if (!Node || !Node->isTargetOpcode())
Evan Cheng5924bf72007-09-25 01:54:36 +0000922 continue;
Chris Lattner03ad8852008-01-07 07:27:27 +0000923 const TargetInstrDesc &TID = TII->get(Node->getTargetOpcode());
Evan Cheng5924bf72007-09-25 01:54:36 +0000924 if (!TID.ImplicitDefs)
925 continue;
926 for (const unsigned *Reg = TID.ImplicitDefs; *Reg; ++Reg) {
Evan Chenge6f92252007-09-27 18:46:06 +0000927 if (LiveRegs.count(*Reg) && LiveRegDefs[*Reg] != SU) {
928 if (RegAdded.insert(*Reg))
929 LRegs.push_back(*Reg);
930 }
Dan Gohman3a4be0f2008-02-10 18:45:23 +0000931 for (const unsigned *Alias = TRI->getAliasSet(*Reg);
Evan Cheng5924bf72007-09-25 01:54:36 +0000932 *Alias; ++Alias)
Evan Chenge6f92252007-09-27 18:46:06 +0000933 if (LiveRegs.count(*Alias) && LiveRegDefs[*Alias] != SU) {
934 if (RegAdded.insert(*Alias))
935 LRegs.push_back(*Alias);
936 }
Evan Cheng5924bf72007-09-25 01:54:36 +0000937 }
938 }
Evan Cheng5924bf72007-09-25 01:54:36 +0000939 return !LRegs.empty();
Evan Chengd38c22b2006-05-11 23:55:42 +0000940}
941
Evan Cheng1ec79b42007-09-27 07:09:03 +0000942
Evan Chengd38c22b2006-05-11 23:55:42 +0000943/// ListScheduleBottomUp - The main loop of list scheduling for bottom-up
944/// schedulers.
945void ScheduleDAGRRList::ListScheduleBottomUp() {
946 unsigned CurCycle = 0;
947 // Add root to Available queue.
Dan Gohman4370f262008-04-15 01:22:18 +0000948 if (!SUnits.empty()) {
Dan Gohman46520a22008-06-21 19:18:17 +0000949 SUnit *RootSU = &SUnits[DAG.getRoot().Val->getNodeId()];
Dan Gohman4370f262008-04-15 01:22:18 +0000950 assert(RootSU->Succs.empty() && "Graph root shouldn't have successors!");
951 RootSU->isAvailable = true;
952 AvailableQueue->push(RootSU);
953 }
Evan Chengd38c22b2006-05-11 23:55:42 +0000954
955 // While Available queue is not empty, grab the node with the highest
Dan Gohman54a187e2007-08-20 19:28:38 +0000956 // priority. If it is not ready put it back. Schedule the node.
Evan Cheng5924bf72007-09-25 01:54:36 +0000957 SmallVector<SUnit*, 4> NotReady;
Dan Gohmanfa63cc42008-06-23 21:15:00 +0000958 DenseMap<SUnit*, SmallVector<unsigned, 4> > LRegsMap;
Dan Gohmane6e13482008-06-21 15:52:51 +0000959 Sequence.reserve(SUnits.size());
Evan Chengd38c22b2006-05-11 23:55:42 +0000960 while (!AvailableQueue->empty()) {
Evan Cheng1ec79b42007-09-27 07:09:03 +0000961 bool Delayed = false;
Dan Gohmanfa63cc42008-06-23 21:15:00 +0000962 LRegsMap.clear();
Evan Cheng5924bf72007-09-25 01:54:36 +0000963 SUnit *CurSU = AvailableQueue->pop();
964 while (CurSU) {
Evan Cheng1ec79b42007-09-27 07:09:03 +0000965 if (CurSU->CycleBound <= CurCycle) {
966 SmallVector<unsigned, 4> LRegs;
967 if (!DelayForLiveRegsBottomUp(CurSU, LRegs))
Evan Cheng5924bf72007-09-25 01:54:36 +0000968 break;
Evan Cheng1ec79b42007-09-27 07:09:03 +0000969 Delayed = true;
970 LRegsMap.insert(std::make_pair(CurSU, LRegs));
Evan Cheng5924bf72007-09-25 01:54:36 +0000971 }
Evan Cheng1ec79b42007-09-27 07:09:03 +0000972
973 CurSU->isPending = true; // This SU is not in AvailableQueue right now.
974 NotReady.push_back(CurSU);
Evan Cheng5924bf72007-09-25 01:54:36 +0000975 CurSU = AvailableQueue->pop();
Evan Chengd38c22b2006-05-11 23:55:42 +0000976 }
Evan Cheng1ec79b42007-09-27 07:09:03 +0000977
978 // All candidates are delayed due to live physical reg dependencies.
979 // Try backtracking, code duplication, or inserting cross class copies
980 // to resolve it.
981 if (Delayed && !CurSU) {
982 for (unsigned i = 0, e = NotReady.size(); i != e; ++i) {
983 SUnit *TrySU = NotReady[i];
984 SmallVector<unsigned, 4> &LRegs = LRegsMap[TrySU];
985
986 // Try unscheduling up to the point where it's safe to schedule
987 // this node.
988 unsigned LiveCycle = CurCycle;
989 for (unsigned j = 0, ee = LRegs.size(); j != ee; ++j) {
990 unsigned Reg = LRegs[j];
991 unsigned LCycle = LiveRegCycles[Reg];
992 LiveCycle = std::min(LiveCycle, LCycle);
993 }
994 SUnit *OldSU = Sequence[LiveCycle];
995 if (!WillCreateCycle(TrySU, OldSU)) {
996 BacktrackBottomUp(TrySU, LiveCycle, CurCycle);
997 // Force the current node to be scheduled before the node that
998 // requires the physical reg dep.
999 if (OldSU->isAvailable) {
1000 OldSU->isAvailable = false;
1001 AvailableQueue->remove(OldSU);
1002 }
Roman Levenstein7e71b4b2008-03-26 09:18:09 +00001003 AddPred(TrySU, OldSU, true, true);
Evan Cheng1ec79b42007-09-27 07:09:03 +00001004 // If one or more successors has been unscheduled, then the current
1005 // node is no longer avaialable. Schedule a successor that's now
1006 // available instead.
1007 if (!TrySU->isAvailable)
1008 CurSU = AvailableQueue->pop();
1009 else {
1010 CurSU = TrySU;
1011 TrySU->isPending = false;
1012 NotReady.erase(NotReady.begin()+i);
1013 }
1014 break;
1015 }
1016 }
1017
1018 if (!CurSU) {
Dan Gohmanfd227e92008-03-25 17:10:29 +00001019 // Can't backtrack. Try duplicating the nodes that produces these
Evan Cheng1ec79b42007-09-27 07:09:03 +00001020 // "expensive to copy" values to break the dependency. In case even
1021 // that doesn't work, insert cross class copies.
1022 SUnit *TrySU = NotReady[0];
1023 SmallVector<unsigned, 4> &LRegs = LRegsMap[TrySU];
1024 assert(LRegs.size() == 1 && "Can't handle this yet!");
1025 unsigned Reg = LRegs[0];
1026 SUnit *LRDef = LiveRegDefs[Reg];
Evan Cheng79e97132007-10-05 01:39:18 +00001027 SUnit *NewDef = CopyAndMoveSuccessors(LRDef);
1028 if (!NewDef) {
Evan Cheng1ec79b42007-09-27 07:09:03 +00001029 // Issue expensive cross register class copies.
Duncan Sands13237ac2008-06-06 12:08:01 +00001030 MVT VT = getPhysicalRegisterVT(LRDef->Node, Reg, TII);
Evan Cheng1ec79b42007-09-27 07:09:03 +00001031 const TargetRegisterClass *RC =
Evan Chenge88a6252008-03-11 07:19:34 +00001032 TRI->getPhysicalRegisterRegClass(Reg, VT);
Dan Gohman3a4be0f2008-02-10 18:45:23 +00001033 const TargetRegisterClass *DestRC = TRI->getCrossCopyRegClass(RC);
Evan Cheng1ec79b42007-09-27 07:09:03 +00001034 if (!DestRC) {
1035 assert(false && "Don't know how to copy this physical register!");
1036 abort();
1037 }
1038 SmallVector<SUnit*, 2> Copies;
1039 InsertCCCopiesAndMoveSuccs(LRDef, Reg, DestRC, RC, Copies);
1040 DOUT << "Adding an edge from SU # " << TrySU->NodeNum
1041 << " to SU #" << Copies.front()->NodeNum << "\n";
Roman Levenstein7e71b4b2008-03-26 09:18:09 +00001042 AddPred(TrySU, Copies.front(), true, true);
Evan Cheng1ec79b42007-09-27 07:09:03 +00001043 NewDef = Copies.back();
1044 }
1045
1046 DOUT << "Adding an edge from SU # " << NewDef->NodeNum
1047 << " to SU #" << TrySU->NodeNum << "\n";
1048 LiveRegDefs[Reg] = NewDef;
Roman Levenstein7e71b4b2008-03-26 09:18:09 +00001049 AddPred(NewDef, TrySU, true, true);
Evan Cheng1ec79b42007-09-27 07:09:03 +00001050 TrySU->isAvailable = false;
1051 CurSU = NewDef;
1052 }
1053
1054 if (!CurSU) {
1055 assert(false && "Unable to resolve live physical register dependencies!");
1056 abort();
1057 }
1058 }
1059
Evan Chengd38c22b2006-05-11 23:55:42 +00001060 // Add the nodes that aren't ready back onto the available list.
Evan Cheng5924bf72007-09-25 01:54:36 +00001061 for (unsigned i = 0, e = NotReady.size(); i != e; ++i) {
1062 NotReady[i]->isPending = false;
Evan Cheng1ec79b42007-09-27 07:09:03 +00001063 // May no longer be available due to backtracking.
Evan Cheng5924bf72007-09-25 01:54:36 +00001064 if (NotReady[i]->isAvailable)
1065 AvailableQueue->push(NotReady[i]);
1066 }
Evan Chengd38c22b2006-05-11 23:55:42 +00001067 NotReady.clear();
1068
Evan Cheng5924bf72007-09-25 01:54:36 +00001069 if (!CurSU)
1070 Sequence.push_back(0);
1071 else {
1072 ScheduleNodeBottomUp(CurSU, CurCycle);
1073 Sequence.push_back(CurSU);
1074 }
1075 ++CurCycle;
Evan Chengd38c22b2006-05-11 23:55:42 +00001076 }
1077
Evan Chengd38c22b2006-05-11 23:55:42 +00001078 // Reverse the order if it is bottom up.
1079 std::reverse(Sequence.begin(), Sequence.end());
1080
1081
1082#ifndef NDEBUG
1083 // Verify that all SUnits were scheduled.
1084 bool AnyNotSched = false;
Dan Gohman4370f262008-04-15 01:22:18 +00001085 unsigned DeadNodes = 0;
Dan Gohman82b66732008-04-15 22:40:14 +00001086 unsigned Noops = 0;
Evan Chengd38c22b2006-05-11 23:55:42 +00001087 for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
Dan Gohman4370f262008-04-15 01:22:18 +00001088 if (!SUnits[i].isScheduled) {
1089 if (SUnits[i].NumPreds == 0 && SUnits[i].NumSuccs == 0) {
1090 ++DeadNodes;
1091 continue;
1092 }
Evan Chengd38c22b2006-05-11 23:55:42 +00001093 if (!AnyNotSched)
Bill Wendling22e978a2006-12-07 20:04:42 +00001094 cerr << "*** List scheduling failed! ***\n";
Evan Chengd38c22b2006-05-11 23:55:42 +00001095 SUnits[i].dump(&DAG);
Bill Wendling22e978a2006-12-07 20:04:42 +00001096 cerr << "has not been scheduled!\n";
Evan Chengd38c22b2006-05-11 23:55:42 +00001097 AnyNotSched = true;
1098 }
Dan Gohman4370f262008-04-15 01:22:18 +00001099 if (SUnits[i].NumSuccsLeft != 0) {
1100 if (!AnyNotSched)
1101 cerr << "*** List scheduling failed! ***\n";
1102 SUnits[i].dump(&DAG);
1103 cerr << "has successors left!\n";
1104 AnyNotSched = true;
1105 }
Evan Chengd38c22b2006-05-11 23:55:42 +00001106 }
Dan Gohman82b66732008-04-15 22:40:14 +00001107 for (unsigned i = 0, e = Sequence.size(); i != e; ++i)
1108 if (!Sequence[i])
1109 ++Noops;
Evan Chengd38c22b2006-05-11 23:55:42 +00001110 assert(!AnyNotSched);
Dan Gohman82b66732008-04-15 22:40:14 +00001111 assert(Sequence.size() + DeadNodes - Noops == SUnits.size() &&
Dan Gohman4370f262008-04-15 01:22:18 +00001112 "The number of nodes scheduled doesn't match the expected number!");
Evan Chengd38c22b2006-05-11 23:55:42 +00001113#endif
1114}
1115
1116//===----------------------------------------------------------------------===//
1117// Top-Down Scheduling
1118//===----------------------------------------------------------------------===//
1119
1120/// ReleaseSucc - Decrement the NumPredsLeft count of a successor. Add it to
Dan Gohman54a187e2007-08-20 19:28:38 +00001121/// the AvailableQueue if the count reaches zero. Also update its cycle bound.
Evan Chengd38c22b2006-05-11 23:55:42 +00001122void ScheduleDAGRRList::ReleaseSucc(SUnit *SuccSU, bool isChain,
1123 unsigned CurCycle) {
1124 // FIXME: the distance between two nodes is not always == the predecessor's
1125 // latency. For example, the reader can very well read the register written
1126 // by the predecessor later than the issue cycle. It also depends on the
1127 // interrupt model (drain vs. freeze).
1128 SuccSU->CycleBound = std::max(SuccSU->CycleBound, CurCycle + SuccSU->Latency);
1129
Evan Cheng038dcc52007-09-28 19:24:24 +00001130 --SuccSU->NumPredsLeft;
Evan Chengd38c22b2006-05-11 23:55:42 +00001131
1132#ifndef NDEBUG
Evan Cheng038dcc52007-09-28 19:24:24 +00001133 if (SuccSU->NumPredsLeft < 0) {
Bill Wendling22e978a2006-12-07 20:04:42 +00001134 cerr << "*** List scheduling failed! ***\n";
Evan Chengd38c22b2006-05-11 23:55:42 +00001135 SuccSU->dump(&DAG);
Bill Wendling22e978a2006-12-07 20:04:42 +00001136 cerr << " has been released too many times!\n";
Evan Chengd38c22b2006-05-11 23:55:42 +00001137 assert(0);
1138 }
1139#endif
1140
Evan Cheng038dcc52007-09-28 19:24:24 +00001141 if (SuccSU->NumPredsLeft == 0) {
Evan Chengd38c22b2006-05-11 23:55:42 +00001142 SuccSU->isAvailable = true;
1143 AvailableQueue->push(SuccSU);
1144 }
1145}
1146
1147
1148/// ScheduleNodeTopDown - Add the node to the schedule. Decrement the pending
1149/// count of its successors. If a successor pending count is zero, add it to
1150/// the Available queue.
Evan Chengd12c97d2006-05-30 18:05:39 +00001151void ScheduleDAGRRList::ScheduleNodeTopDown(SUnit *SU, unsigned CurCycle) {
Bill Wendling22e978a2006-12-07 20:04:42 +00001152 DOUT << "*** Scheduling [" << CurCycle << "]: ";
Evan Chengd38c22b2006-05-11 23:55:42 +00001153 DEBUG(SU->dump(&DAG));
1154 SU->Cycle = CurCycle;
1155
1156 AvailableQueue->ScheduledNode(SU);
Evan Chengd38c22b2006-05-11 23:55:42 +00001157
1158 // Top down: release successors
Chris Lattnerd86418a2006-08-17 00:09:56 +00001159 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
1160 I != E; ++I)
Evan Cheng0effc3a2007-09-19 01:38:40 +00001161 ReleaseSucc(I->Dep, I->isCtrl, CurCycle);
Evan Chengd38c22b2006-05-11 23:55:42 +00001162 SU->isScheduled = true;
Evan Chengd38c22b2006-05-11 23:55:42 +00001163}
1164
Dan Gohman54a187e2007-08-20 19:28:38 +00001165/// ListScheduleTopDown - The main loop of list scheduling for top-down
1166/// schedulers.
Evan Chengd38c22b2006-05-11 23:55:42 +00001167void ScheduleDAGRRList::ListScheduleTopDown() {
1168 unsigned CurCycle = 0;
Evan Chengd38c22b2006-05-11 23:55:42 +00001169
1170 // All leaves to Available queue.
1171 for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
1172 // It is available if it has no predecessors.
Dan Gohman4370f262008-04-15 01:22:18 +00001173 if (SUnits[i].Preds.empty()) {
Evan Chengd38c22b2006-05-11 23:55:42 +00001174 AvailableQueue->push(&SUnits[i]);
1175 SUnits[i].isAvailable = true;
1176 }
1177 }
1178
Evan Chengd38c22b2006-05-11 23:55:42 +00001179 // While Available queue is not empty, grab the node with the highest
Dan Gohman54a187e2007-08-20 19:28:38 +00001180 // priority. If it is not ready put it back. Schedule the node.
Evan Chengd38c22b2006-05-11 23:55:42 +00001181 std::vector<SUnit*> NotReady;
Dan Gohmane6e13482008-06-21 15:52:51 +00001182 Sequence.reserve(SUnits.size());
Evan Chengd38c22b2006-05-11 23:55:42 +00001183 while (!AvailableQueue->empty()) {
Evan Cheng5924bf72007-09-25 01:54:36 +00001184 SUnit *CurSU = AvailableQueue->pop();
1185 while (CurSU && CurSU->CycleBound > CurCycle) {
1186 NotReady.push_back(CurSU);
1187 CurSU = AvailableQueue->pop();
Evan Chengd38c22b2006-05-11 23:55:42 +00001188 }
1189
1190 // Add the nodes that aren't ready back onto the available list.
1191 AvailableQueue->push_all(NotReady);
1192 NotReady.clear();
1193
Evan Cheng5924bf72007-09-25 01:54:36 +00001194 if (!CurSU)
1195 Sequence.push_back(0);
1196 else {
1197 ScheduleNodeTopDown(CurSU, CurCycle);
1198 Sequence.push_back(CurSU);
1199 }
Dan Gohman4370f262008-04-15 01:22:18 +00001200 ++CurCycle;
Evan Chengd38c22b2006-05-11 23:55:42 +00001201 }
1202
1203
1204#ifndef NDEBUG
1205 // Verify that all SUnits were scheduled.
1206 bool AnyNotSched = false;
Dan Gohman4370f262008-04-15 01:22:18 +00001207 unsigned DeadNodes = 0;
Dan Gohman82b66732008-04-15 22:40:14 +00001208 unsigned Noops = 0;
Evan Chengd38c22b2006-05-11 23:55:42 +00001209 for (unsigned i = 0, e = SUnits.size(); i != e; ++i) {
1210 if (!SUnits[i].isScheduled) {
Dan Gohman4370f262008-04-15 01:22:18 +00001211 if (SUnits[i].NumPreds == 0 && SUnits[i].NumSuccs == 0) {
1212 ++DeadNodes;
1213 continue;
1214 }
Evan Chengd38c22b2006-05-11 23:55:42 +00001215 if (!AnyNotSched)
Bill Wendling22e978a2006-12-07 20:04:42 +00001216 cerr << "*** List scheduling failed! ***\n";
Evan Chengd38c22b2006-05-11 23:55:42 +00001217 SUnits[i].dump(&DAG);
Bill Wendling22e978a2006-12-07 20:04:42 +00001218 cerr << "has not been scheduled!\n";
Evan Chengd38c22b2006-05-11 23:55:42 +00001219 AnyNotSched = true;
1220 }
Dan Gohman4370f262008-04-15 01:22:18 +00001221 if (SUnits[i].NumPredsLeft != 0) {
1222 if (!AnyNotSched)
1223 cerr << "*** List scheduling failed! ***\n";
1224 SUnits[i].dump(&DAG);
1225 cerr << "has predecessors left!\n";
1226 AnyNotSched = true;
1227 }
Evan Chengd38c22b2006-05-11 23:55:42 +00001228 }
Dan Gohman82b66732008-04-15 22:40:14 +00001229 for (unsigned i = 0, e = Sequence.size(); i != e; ++i)
1230 if (!Sequence[i])
1231 ++Noops;
Evan Chengd38c22b2006-05-11 23:55:42 +00001232 assert(!AnyNotSched);
Dan Gohman82b66732008-04-15 22:40:14 +00001233 assert(Sequence.size() + DeadNodes - Noops == SUnits.size() &&
Dan Gohman4370f262008-04-15 01:22:18 +00001234 "The number of nodes scheduled doesn't match the expected number!");
Evan Chengd38c22b2006-05-11 23:55:42 +00001235#endif
1236}
1237
1238
1239
1240//===----------------------------------------------------------------------===//
1241// RegReductionPriorityQueue Implementation
1242//===----------------------------------------------------------------------===//
1243//
1244// This is a SchedulingPriorityQueue that schedules using Sethi Ullman numbers
1245// to reduce register pressure.
1246//
1247namespace {
1248 template<class SF>
1249 class RegReductionPriorityQueue;
1250
1251 /// Sorting functions for the Available queue.
1252 struct bu_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> {
1253 RegReductionPriorityQueue<bu_ls_rr_sort> *SPQ;
1254 bu_ls_rr_sort(RegReductionPriorityQueue<bu_ls_rr_sort> *spq) : SPQ(spq) {}
1255 bu_ls_rr_sort(const bu_ls_rr_sort &RHS) : SPQ(RHS.SPQ) {}
1256
1257 bool operator()(const SUnit* left, const SUnit* right) const;
1258 };
1259
1260 struct td_ls_rr_sort : public std::binary_function<SUnit*, SUnit*, bool> {
1261 RegReductionPriorityQueue<td_ls_rr_sort> *SPQ;
1262 td_ls_rr_sort(RegReductionPriorityQueue<td_ls_rr_sort> *spq) : SPQ(spq) {}
1263 td_ls_rr_sort(const td_ls_rr_sort &RHS) : SPQ(RHS.SPQ) {}
1264
1265 bool operator()(const SUnit* left, const SUnit* right) const;
1266 };
1267} // end anonymous namespace
1268
Evan Cheng961bbd32007-01-08 23:50:38 +00001269static inline bool isCopyFromLiveIn(const SUnit *SU) {
1270 SDNode *N = SU->Node;
Evan Cheng8e136a92007-09-26 21:36:17 +00001271 return N && N->getOpcode() == ISD::CopyFromReg &&
Evan Cheng961bbd32007-01-08 23:50:38 +00001272 N->getOperand(N->getNumOperands()-1).getValueType() != MVT::Flag;
1273}
1274
Evan Chengd38c22b2006-05-11 23:55:42 +00001275namespace {
1276 template<class SF>
Chris Lattner996795b2006-06-28 23:17:24 +00001277 class VISIBILITY_HIDDEN RegReductionPriorityQueue
1278 : public SchedulingPriorityQueue {
Dan Gohmana4db3352008-06-21 18:35:25 +00001279 PriorityQueue<SUnit*, std::vector<SUnit*>, SF> Queue;
Roman Levenstein6b371142008-04-29 09:07:59 +00001280 unsigned currentQueueId;
Evan Chengd38c22b2006-05-11 23:55:42 +00001281
1282 public:
1283 RegReductionPriorityQueue() :
Roman Levenstein6b371142008-04-29 09:07:59 +00001284 Queue(SF(this)), currentQueueId(0) {}
Evan Chengd38c22b2006-05-11 23:55:42 +00001285
Dan Gohman46520a22008-06-21 19:18:17 +00001286 virtual void initNodes(std::vector<SUnit> &sunits) {}
Evan Cheng5924bf72007-09-25 01:54:36 +00001287
1288 virtual void addNode(const SUnit *SU) {}
1289
1290 virtual void updateNode(const SUnit *SU) {}
1291
Evan Chengd38c22b2006-05-11 23:55:42 +00001292 virtual void releaseState() {}
1293
Evan Cheng6730f032007-01-08 23:55:53 +00001294 virtual unsigned getNodePriority(const SUnit *SU) const {
Evan Chengd38c22b2006-05-11 23:55:42 +00001295 return 0;
1296 }
1297
Evan Cheng5924bf72007-09-25 01:54:36 +00001298 unsigned size() const { return Queue.size(); }
1299
Evan Chengd38c22b2006-05-11 23:55:42 +00001300 bool empty() const { return Queue.empty(); }
1301
1302 void push(SUnit *U) {
Roman Levenstein6b371142008-04-29 09:07:59 +00001303 assert(!U->NodeQueueId && "Node in the queue already");
1304 U->NodeQueueId = ++currentQueueId;
Dan Gohmana4db3352008-06-21 18:35:25 +00001305 Queue.push(U);
Evan Chengd38c22b2006-05-11 23:55:42 +00001306 }
Roman Levenstein6b371142008-04-29 09:07:59 +00001307
Evan Chengd38c22b2006-05-11 23:55:42 +00001308 void push_all(const std::vector<SUnit *> &Nodes) {
1309 for (unsigned i = 0, e = Nodes.size(); i != e; ++i)
Roman Levenstein6b371142008-04-29 09:07:59 +00001310 push(Nodes[i]);
Evan Chengd38c22b2006-05-11 23:55:42 +00001311 }
1312
1313 SUnit *pop() {
Evan Chengd12c97d2006-05-30 18:05:39 +00001314 if (empty()) return NULL;
Dan Gohmana4db3352008-06-21 18:35:25 +00001315 SUnit *V = Queue.top();
1316 Queue.pop();
Roman Levenstein6b371142008-04-29 09:07:59 +00001317 V->NodeQueueId = 0;
Evan Chengd38c22b2006-05-11 23:55:42 +00001318 return V;
1319 }
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001320
Evan Cheng5924bf72007-09-25 01:54:36 +00001321 void remove(SUnit *SU) {
Roman Levenstein6b371142008-04-29 09:07:59 +00001322 assert(!Queue.empty() && "Queue is empty!");
Dan Gohmana4db3352008-06-21 18:35:25 +00001323 assert(SU->NodeQueueId != 0 && "Not in queue!");
1324 Queue.erase_one(SU);
Roman Levenstein6b371142008-04-29 09:07:59 +00001325 SU->NodeQueueId = 0;
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001326 }
Evan Chengd38c22b2006-05-11 23:55:42 +00001327 };
1328
Chris Lattner996795b2006-06-28 23:17:24 +00001329 class VISIBILITY_HIDDEN BURegReductionPriorityQueue
Dan Gohman4b49be12008-06-21 01:08:22 +00001330 : public RegReductionPriorityQueue<bu_ls_rr_sort> {
Evan Chengd38c22b2006-05-11 23:55:42 +00001331 // SUnits - The SUnits for the current graph.
1332 const std::vector<SUnit> *SUnits;
1333
1334 // SethiUllmanNumbers - The SethiUllman number for each node.
Evan Cheng961bbd32007-01-08 23:50:38 +00001335 std::vector<unsigned> SethiUllmanNumbers;
Evan Chengd38c22b2006-05-11 23:55:42 +00001336
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001337 const TargetInstrInfo *TII;
Dan Gohman3a4be0f2008-02-10 18:45:23 +00001338 const TargetRegisterInfo *TRI;
Roman Levenstein7e71b4b2008-03-26 09:18:09 +00001339 ScheduleDAGRRList *scheduleDAG;
Evan Cheng2c977312008-07-01 18:05:03 +00001340
1341 bool Fast;
Evan Chengd38c22b2006-05-11 23:55:42 +00001342 public:
Evan Chengf9891412007-12-20 09:25:31 +00001343 explicit BURegReductionPriorityQueue(const TargetInstrInfo *tii,
Evan Cheng2c977312008-07-01 18:05:03 +00001344 const TargetRegisterInfo *tri,
1345 bool f)
1346 : TII(tii), TRI(tri), scheduleDAG(NULL), Fast(f) {}
Evan Chengd38c22b2006-05-11 23:55:42 +00001347
Dan Gohman46520a22008-06-21 19:18:17 +00001348 void initNodes(std::vector<SUnit> &sunits) {
Evan Chengd38c22b2006-05-11 23:55:42 +00001349 SUnits = &sunits;
1350 // Add pseudo dependency edges for two-address nodes.
Evan Cheng2c977312008-07-01 18:05:03 +00001351 if (!Fast)
1352 AddPseudoTwoAddrDeps();
Evan Chengd38c22b2006-05-11 23:55:42 +00001353 // Calculate node priorities.
Evan Cheng6730f032007-01-08 23:55:53 +00001354 CalculateSethiUllmanNumbers();
Evan Chengd38c22b2006-05-11 23:55:42 +00001355 }
1356
Evan Cheng5924bf72007-09-25 01:54:36 +00001357 void addNode(const SUnit *SU) {
1358 SethiUllmanNumbers.resize(SUnits->size(), 0);
1359 CalcNodeSethiUllmanNumber(SU);
1360 }
1361
1362 void updateNode(const SUnit *SU) {
1363 SethiUllmanNumbers[SU->NodeNum] = 0;
1364 CalcNodeSethiUllmanNumber(SU);
1365 }
1366
Evan Chengd38c22b2006-05-11 23:55:42 +00001367 void releaseState() {
1368 SUnits = 0;
1369 SethiUllmanNumbers.clear();
1370 }
1371
Evan Cheng6730f032007-01-08 23:55:53 +00001372 unsigned getNodePriority(const SUnit *SU) const {
Evan Cheng961bbd32007-01-08 23:50:38 +00001373 assert(SU->NodeNum < SethiUllmanNumbers.size());
Evan Cheng8e136a92007-09-26 21:36:17 +00001374 unsigned Opc = SU->Node ? SU->Node->getOpcode() : 0;
Evan Cheng961bbd32007-01-08 23:50:38 +00001375 if (Opc == ISD::CopyFromReg && !isCopyFromLiveIn(SU))
1376 // CopyFromReg should be close to its def because it restricts
1377 // allocation choices. But if it is a livein then perhaps we want it
1378 // closer to its uses so it can be coalesced.
1379 return 0xffff;
1380 else if (Opc == ISD::TokenFactor || Opc == ISD::CopyToReg)
1381 // CopyToReg should be close to its uses to facilitate coalescing and
1382 // avoid spilling.
1383 return 0;
Evan Chengaa2d6ef2007-10-12 08:50:34 +00001384 else if (Opc == TargetInstrInfo::EXTRACT_SUBREG ||
1385 Opc == TargetInstrInfo::INSERT_SUBREG)
1386 // EXTRACT_SUBREG / INSERT_SUBREG should be close to its use to
1387 // facilitate coalescing.
1388 return 0;
Evan Cheng961bbd32007-01-08 23:50:38 +00001389 else if (SU->NumSuccs == 0)
1390 // If SU does not have a use, i.e. it doesn't produce a value that would
1391 // be consumed (e.g. store), then it terminates a chain of computation.
1392 // Give it a large SethiUllman number so it will be scheduled right
1393 // before its predecessors that it doesn't lengthen their live ranges.
1394 return 0xffff;
1395 else if (SU->NumPreds == 0)
1396 // If SU does not have a def, schedule it close to its uses because it
1397 // does not lengthen any live ranges.
1398 return 0;
1399 else
1400 return SethiUllmanNumbers[SU->NodeNum];
Evan Chengd38c22b2006-05-11 23:55:42 +00001401 }
1402
Roman Levenstein7e71b4b2008-03-26 09:18:09 +00001403 void setScheduleDAG(ScheduleDAGRRList *scheduleDag) {
1404 scheduleDAG = scheduleDag;
1405 }
1406
Evan Chengd38c22b2006-05-11 23:55:42 +00001407 private:
Evan Cheng73bdf042008-03-01 00:39:47 +00001408 bool canClobber(const SUnit *SU, const SUnit *Op);
Evan Chengd38c22b2006-05-11 23:55:42 +00001409 void AddPseudoTwoAddrDeps();
Evan Cheng6730f032007-01-08 23:55:53 +00001410 void CalculateSethiUllmanNumbers();
1411 unsigned CalcNodeSethiUllmanNumber(const SUnit *SU);
Evan Chengd38c22b2006-05-11 23:55:42 +00001412 };
1413
1414
Dan Gohman54a187e2007-08-20 19:28:38 +00001415 class VISIBILITY_HIDDEN TDRegReductionPriorityQueue
Dan Gohman4b49be12008-06-21 01:08:22 +00001416 : public RegReductionPriorityQueue<td_ls_rr_sort> {
Evan Chengd38c22b2006-05-11 23:55:42 +00001417 // SUnits - The SUnits for the current graph.
1418 const std::vector<SUnit> *SUnits;
1419
1420 // SethiUllmanNumbers - The SethiUllman number for each node.
Evan Cheng961bbd32007-01-08 23:50:38 +00001421 std::vector<unsigned> SethiUllmanNumbers;
Evan Chengd38c22b2006-05-11 23:55:42 +00001422
1423 public:
1424 TDRegReductionPriorityQueue() {}
1425
Dan Gohman46520a22008-06-21 19:18:17 +00001426 void initNodes(std::vector<SUnit> &sunits) {
Evan Chengd38c22b2006-05-11 23:55:42 +00001427 SUnits = &sunits;
1428 // Calculate node priorities.
Evan Cheng6730f032007-01-08 23:55:53 +00001429 CalculateSethiUllmanNumbers();
Evan Chengd38c22b2006-05-11 23:55:42 +00001430 }
1431
Evan Cheng5924bf72007-09-25 01:54:36 +00001432 void addNode(const SUnit *SU) {
1433 SethiUllmanNumbers.resize(SUnits->size(), 0);
1434 CalcNodeSethiUllmanNumber(SU);
1435 }
1436
1437 void updateNode(const SUnit *SU) {
1438 SethiUllmanNumbers[SU->NodeNum] = 0;
1439 CalcNodeSethiUllmanNumber(SU);
1440 }
1441
Evan Chengd38c22b2006-05-11 23:55:42 +00001442 void releaseState() {
1443 SUnits = 0;
1444 SethiUllmanNumbers.clear();
1445 }
1446
Evan Cheng6730f032007-01-08 23:55:53 +00001447 unsigned getNodePriority(const SUnit *SU) const {
Evan Cheng961bbd32007-01-08 23:50:38 +00001448 assert(SU->NodeNum < SethiUllmanNumbers.size());
1449 return SethiUllmanNumbers[SU->NodeNum];
Evan Chengd38c22b2006-05-11 23:55:42 +00001450 }
1451
1452 private:
Evan Cheng6730f032007-01-08 23:55:53 +00001453 void CalculateSethiUllmanNumbers();
1454 unsigned CalcNodeSethiUllmanNumber(const SUnit *SU);
Evan Chengd38c22b2006-05-11 23:55:42 +00001455 };
1456}
1457
Evan Chengb9e3db62007-03-14 22:43:40 +00001458/// closestSucc - Returns the scheduled cycle of the successor which is
1459/// closet to the current cycle.
Evan Cheng28748552007-03-13 23:25:11 +00001460static unsigned closestSucc(const SUnit *SU) {
1461 unsigned MaxCycle = 0;
1462 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
Evan Chengb9e3db62007-03-14 22:43:40 +00001463 I != E; ++I) {
Evan Cheng0effc3a2007-09-19 01:38:40 +00001464 unsigned Cycle = I->Dep->Cycle;
Evan Chengb9e3db62007-03-14 22:43:40 +00001465 // If there are bunch of CopyToRegs stacked up, they should be considered
1466 // to be at the same position.
Evan Cheng8e136a92007-09-26 21:36:17 +00001467 if (I->Dep->Node && I->Dep->Node->getOpcode() == ISD::CopyToReg)
Evan Cheng0effc3a2007-09-19 01:38:40 +00001468 Cycle = closestSucc(I->Dep)+1;
Evan Chengb9e3db62007-03-14 22:43:40 +00001469 if (Cycle > MaxCycle)
1470 MaxCycle = Cycle;
1471 }
Evan Cheng28748552007-03-13 23:25:11 +00001472 return MaxCycle;
1473}
1474
Evan Cheng61bc51e2007-12-20 02:22:36 +00001475/// calcMaxScratches - Returns an cost estimate of the worse case requirement
1476/// for scratch registers. Live-in operands and live-out results don't count
1477/// since they are "fixed".
1478static unsigned calcMaxScratches(const SUnit *SU) {
1479 unsigned Scratches = 0;
1480 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
1481 I != E; ++I) {
1482 if (I->isCtrl) continue; // ignore chain preds
Evan Cheng0e400d42008-01-09 23:01:55 +00001483 if (!I->Dep->Node || I->Dep->Node->getOpcode() != ISD::CopyFromReg)
Evan Cheng61bc51e2007-12-20 02:22:36 +00001484 Scratches++;
1485 }
1486 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
1487 I != E; ++I) {
1488 if (I->isCtrl) continue; // ignore chain succs
Evan Cheng0e400d42008-01-09 23:01:55 +00001489 if (!I->Dep->Node || I->Dep->Node->getOpcode() != ISD::CopyToReg)
Evan Cheng61bc51e2007-12-20 02:22:36 +00001490 Scratches += 10;
1491 }
1492 return Scratches;
1493}
1494
Evan Chengd38c22b2006-05-11 23:55:42 +00001495// Bottom up
1496bool bu_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const {
Evan Cheng99f2f792006-05-13 08:22:24 +00001497
Evan Cheng6730f032007-01-08 23:55:53 +00001498 unsigned LPriority = SPQ->getNodePriority(left);
1499 unsigned RPriority = SPQ->getNodePriority(right);
Evan Cheng73bdf042008-03-01 00:39:47 +00001500 if (LPriority != RPriority)
1501 return LPriority > RPriority;
1502
1503 // Try schedule def + use closer when Sethi-Ullman numbers are the same.
1504 // e.g.
1505 // t1 = op t2, c1
1506 // t3 = op t4, c2
1507 //
1508 // and the following instructions are both ready.
1509 // t2 = op c3
1510 // t4 = op c4
1511 //
1512 // Then schedule t2 = op first.
1513 // i.e.
1514 // t4 = op c4
1515 // t2 = op c3
1516 // t1 = op t2, c1
1517 // t3 = op t4, c2
1518 //
1519 // This creates more short live intervals.
1520 unsigned LDist = closestSucc(left);
1521 unsigned RDist = closestSucc(right);
1522 if (LDist != RDist)
1523 return LDist < RDist;
1524
1525 // Intuitively, it's good to push down instructions whose results are
1526 // liveout so their long live ranges won't conflict with other values
1527 // which are needed inside the BB. Further prioritize liveout instructions
1528 // by the number of operands which are calculated within the BB.
1529 unsigned LScratch = calcMaxScratches(left);
1530 unsigned RScratch = calcMaxScratches(right);
1531 if (LScratch != RScratch)
1532 return LScratch > RScratch;
1533
1534 if (left->Height != right->Height)
1535 return left->Height > right->Height;
1536
1537 if (left->Depth != right->Depth)
1538 return left->Depth < right->Depth;
1539
1540 if (left->CycleBound != right->CycleBound)
1541 return left->CycleBound > right->CycleBound;
1542
Roman Levenstein6b371142008-04-29 09:07:59 +00001543 assert(left->NodeQueueId && right->NodeQueueId &&
1544 "NodeQueueId cannot be zero");
1545 return (left->NodeQueueId > right->NodeQueueId);
Evan Chengd38c22b2006-05-11 23:55:42 +00001546}
1547
Dan Gohman4b49be12008-06-21 01:08:22 +00001548bool
1549BURegReductionPriorityQueue::canClobber(const SUnit *SU, const SUnit *Op) {
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001550 if (SU->isTwoAddress) {
1551 unsigned Opc = SU->Node->getTargetOpcode();
Chris Lattner03ad8852008-01-07 07:27:27 +00001552 const TargetInstrDesc &TID = TII->get(Opc);
Chris Lattnerfd2e3382008-01-07 06:47:00 +00001553 unsigned NumRes = TID.getNumDefs();
Dan Gohman0340d1e2008-02-15 20:50:13 +00001554 unsigned NumOps = TID.getNumOperands() - NumRes;
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001555 for (unsigned i = 0; i != NumOps; ++i) {
Chris Lattnerfd2e3382008-01-07 06:47:00 +00001556 if (TID.getOperandConstraint(i+NumRes, TOI::TIED_TO) != -1) {
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001557 SDNode *DU = SU->Node->getOperand(i).Val;
Dan Gohman46520a22008-06-21 19:18:17 +00001558 if (DU->getNodeId() != -1 &&
1559 Op->OrigNode == &(*SUnits)[DU->getNodeId()])
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001560 return true;
1561 }
1562 }
Evan Chengd38c22b2006-05-11 23:55:42 +00001563 }
Evan Chengd38c22b2006-05-11 23:55:42 +00001564 return false;
1565}
1566
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001567
Evan Chenga5e595d2007-09-28 22:32:30 +00001568/// hasCopyToRegUse - Return true if SU has a value successor that is a
1569/// CopyToReg node.
1570static bool hasCopyToRegUse(SUnit *SU) {
1571 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
1572 I != E; ++I) {
1573 if (I->isCtrl) continue;
1574 SUnit *SuccSU = I->Dep;
1575 if (SuccSU->Node && SuccSU->Node->getOpcode() == ISD::CopyToReg)
1576 return true;
1577 }
1578 return false;
1579}
1580
Evan Chengf9891412007-12-20 09:25:31 +00001581/// canClobberPhysRegDefs - True if SU would clobber one of SuccSU's
Dan Gohmanea045202008-06-21 22:05:24 +00001582/// physical register defs.
Evan Chengf9891412007-12-20 09:25:31 +00001583static bool canClobberPhysRegDefs(SUnit *SuccSU, SUnit *SU,
1584 const TargetInstrInfo *TII,
Dan Gohman3a4be0f2008-02-10 18:45:23 +00001585 const TargetRegisterInfo *TRI) {
Evan Chengf9891412007-12-20 09:25:31 +00001586 SDNode *N = SuccSU->Node;
Chris Lattnerb0d06b42008-01-07 03:13:06 +00001587 unsigned NumDefs = TII->get(N->getTargetOpcode()).getNumDefs();
1588 const unsigned *ImpDefs = TII->get(N->getTargetOpcode()).getImplicitDefs();
Dan Gohmanea045202008-06-21 22:05:24 +00001589 assert(ImpDefs && "Caller should check hasPhysRegDefs");
Chris Lattnerb0d06b42008-01-07 03:13:06 +00001590 const unsigned *SUImpDefs =
1591 TII->get(SU->Node->getTargetOpcode()).getImplicitDefs();
Evan Chengf9891412007-12-20 09:25:31 +00001592 if (!SUImpDefs)
1593 return false;
1594 for (unsigned i = NumDefs, e = N->getNumValues(); i != e; ++i) {
Duncan Sands13237ac2008-06-06 12:08:01 +00001595 MVT VT = N->getValueType(i);
Evan Chengf9891412007-12-20 09:25:31 +00001596 if (VT == MVT::Flag || VT == MVT::Other)
1597 continue;
1598 unsigned Reg = ImpDefs[i - NumDefs];
1599 for (;*SUImpDefs; ++SUImpDefs) {
1600 unsigned SUReg = *SUImpDefs;
Dan Gohman3a4be0f2008-02-10 18:45:23 +00001601 if (TRI->regsOverlap(Reg, SUReg))
Evan Chengf9891412007-12-20 09:25:31 +00001602 return true;
1603 }
1604 }
1605 return false;
1606}
1607
Evan Chengd38c22b2006-05-11 23:55:42 +00001608/// AddPseudoTwoAddrDeps - If two nodes share an operand and one of them uses
1609/// it as a def&use operand. Add a pseudo control edge from it to the other
1610/// node (if it won't create a cycle) so the two-address one will be scheduled
Evan Chenga5e595d2007-09-28 22:32:30 +00001611/// first (lower in the schedule). If both nodes are two-address, favor the
1612/// one that has a CopyToReg use (more likely to be a loop induction update).
1613/// If both are two-address, but one is commutable while the other is not
1614/// commutable, favor the one that's not commutable.
Dan Gohman4b49be12008-06-21 01:08:22 +00001615void BURegReductionPriorityQueue::AddPseudoTwoAddrDeps() {
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001616 for (unsigned i = 0, e = SUnits->size(); i != e; ++i) {
1617 SUnit *SU = (SUnit *)&((*SUnits)[i]);
1618 if (!SU->isTwoAddress)
1619 continue;
1620
1621 SDNode *Node = SU->Node;
Evan Chenga5e595d2007-09-28 22:32:30 +00001622 if (!Node || !Node->isTargetOpcode() || SU->FlaggedNodes.size() > 0)
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001623 continue;
1624
1625 unsigned Opc = Node->getTargetOpcode();
Chris Lattner03ad8852008-01-07 07:27:27 +00001626 const TargetInstrDesc &TID = TII->get(Opc);
Chris Lattnerfd2e3382008-01-07 06:47:00 +00001627 unsigned NumRes = TID.getNumDefs();
Dan Gohman0340d1e2008-02-15 20:50:13 +00001628 unsigned NumOps = TID.getNumOperands() - NumRes;
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001629 for (unsigned j = 0; j != NumOps; ++j) {
Chris Lattnerfd2e3382008-01-07 06:47:00 +00001630 if (TID.getOperandConstraint(j+NumRes, TOI::TIED_TO) != -1) {
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001631 SDNode *DU = SU->Node->getOperand(j).Val;
Dan Gohman46520a22008-06-21 19:18:17 +00001632 if (DU->getNodeId() == -1)
Evan Cheng1bf166312007-11-09 01:27:11 +00001633 continue;
Dan Gohman46520a22008-06-21 19:18:17 +00001634 const SUnit *DUSU = &(*SUnits)[DU->getNodeId()];
Evan Chengf24d15f2006-11-06 21:33:46 +00001635 if (!DUSU) continue;
Dan Gohman46520a22008-06-21 19:18:17 +00001636 for (SUnit::const_succ_iterator I = DUSU->Succs.begin(),
1637 E = DUSU->Succs.end(); I != E; ++I) {
Evan Cheng0effc3a2007-09-19 01:38:40 +00001638 if (I->isCtrl) continue;
1639 SUnit *SuccSU = I->Dep;
Evan Chengf9891412007-12-20 09:25:31 +00001640 if (SuccSU == SU)
Evan Cheng5924bf72007-09-25 01:54:36 +00001641 continue;
Evan Cheng2dbffa42007-11-06 08:44:59 +00001642 // Be conservative. Ignore if nodes aren't at roughly the same
1643 // depth and height.
1644 if (SuccSU->Height < SU->Height && (SU->Height - SuccSU->Height) > 1)
1645 continue;
Evan Chengaa2d6ef2007-10-12 08:50:34 +00001646 if (!SuccSU->Node || !SuccSU->Node->isTargetOpcode())
1647 continue;
Evan Chengf9891412007-12-20 09:25:31 +00001648 // Don't constrain nodes with physical register defs if the
Dan Gohmancf8827a2008-01-29 12:43:50 +00001649 // predecessor can clobber them.
Evan Chengf9891412007-12-20 09:25:31 +00001650 if (SuccSU->hasPhysRegDefs) {
Dan Gohman3a4be0f2008-02-10 18:45:23 +00001651 if (canClobberPhysRegDefs(SuccSU, SU, TII, TRI))
Evan Chengf9891412007-12-20 09:25:31 +00001652 continue;
1653 }
Evan Chengaa2d6ef2007-10-12 08:50:34 +00001654 // Don't constraint extract_subreg / insert_subreg these may be
1655 // coalesced away. We don't them close to their uses.
1656 unsigned SuccOpc = SuccSU->Node->getTargetOpcode();
1657 if (SuccOpc == TargetInstrInfo::EXTRACT_SUBREG ||
1658 SuccOpc == TargetInstrInfo::INSERT_SUBREG)
1659 continue;
Evan Cheng5924bf72007-09-25 01:54:36 +00001660 if ((!canClobber(SuccSU, DUSU) ||
Evan Chenga5e595d2007-09-28 22:32:30 +00001661 (hasCopyToRegUse(SU) && !hasCopyToRegUse(SuccSU)) ||
Evan Cheng5924bf72007-09-25 01:54:36 +00001662 (!SU->isCommutable && SuccSU->isCommutable)) &&
Roman Levenstein7e71b4b2008-03-26 09:18:09 +00001663 !scheduleDAG->IsReachable(SuccSU, SU)) {
Evan Cheng5924bf72007-09-25 01:54:36 +00001664 DOUT << "Adding an edge from SU # " << SU->NodeNum
1665 << " to SU #" << SuccSU->NodeNum << "\n";
Roman Levenstein7e71b4b2008-03-26 09:18:09 +00001666 scheduleDAG->AddPred(SU, SuccSU, true, true);
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001667 }
1668 }
1669 }
1670 }
1671 }
Evan Chengd38c22b2006-05-11 23:55:42 +00001672}
1673
Evan Cheng6730f032007-01-08 23:55:53 +00001674/// CalcNodeSethiUllmanNumber - Priority is the Sethi Ullman number.
Evan Chengd38c22b2006-05-11 23:55:42 +00001675/// Smaller number is the higher priority.
Dan Gohman4b49be12008-06-21 01:08:22 +00001676unsigned BURegReductionPriorityQueue::
Chris Lattner296a83c2007-02-01 04:55:59 +00001677CalcNodeSethiUllmanNumber(const SUnit *SU) {
Evan Cheng961bbd32007-01-08 23:50:38 +00001678 unsigned &SethiUllmanNumber = SethiUllmanNumbers[SU->NodeNum];
Evan Chengd38c22b2006-05-11 23:55:42 +00001679 if (SethiUllmanNumber != 0)
1680 return SethiUllmanNumber;
1681
Evan Cheng961bbd32007-01-08 23:50:38 +00001682 unsigned Extra = 0;
1683 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
1684 I != E; ++I) {
Evan Cheng0effc3a2007-09-19 01:38:40 +00001685 if (I->isCtrl) continue; // ignore chain preds
1686 SUnit *PredSU = I->Dep;
Evan Cheng6730f032007-01-08 23:55:53 +00001687 unsigned PredSethiUllman = CalcNodeSethiUllmanNumber(PredSU);
Evan Cheng961bbd32007-01-08 23:50:38 +00001688 if (PredSethiUllman > SethiUllmanNumber) {
1689 SethiUllmanNumber = PredSethiUllman;
1690 Extra = 0;
Evan Cheng0effc3a2007-09-19 01:38:40 +00001691 } else if (PredSethiUllman == SethiUllmanNumber && !I->isCtrl)
Evan Cheng5924bf72007-09-25 01:54:36 +00001692 ++Extra;
Evan Chengd38c22b2006-05-11 23:55:42 +00001693 }
Evan Cheng961bbd32007-01-08 23:50:38 +00001694
1695 SethiUllmanNumber += Extra;
1696
1697 if (SethiUllmanNumber == 0)
1698 SethiUllmanNumber = 1;
Evan Chengd38c22b2006-05-11 23:55:42 +00001699
1700 return SethiUllmanNumber;
1701}
1702
Evan Cheng6730f032007-01-08 23:55:53 +00001703/// CalculateSethiUllmanNumbers - Calculate Sethi-Ullman numbers of all
1704/// scheduling units.
Dan Gohman4b49be12008-06-21 01:08:22 +00001705void BURegReductionPriorityQueue::CalculateSethiUllmanNumbers() {
Evan Chengd38c22b2006-05-11 23:55:42 +00001706 SethiUllmanNumbers.assign(SUnits->size(), 0);
1707
1708 for (unsigned i = 0, e = SUnits->size(); i != e; ++i)
Evan Cheng6730f032007-01-08 23:55:53 +00001709 CalcNodeSethiUllmanNumber(&(*SUnits)[i]);
Evan Chengd38c22b2006-05-11 23:55:42 +00001710}
1711
Roman Levenstein30d09512008-03-27 09:44:37 +00001712/// LimitedSumOfUnscheduledPredsOfSuccs - Compute the sum of the unscheduled
Roman Levensteinbc674502008-03-27 09:14:57 +00001713/// predecessors of the successors of the SUnit SU. Stop when the provided
1714/// limit is exceeded.
Roman Levensteinbc674502008-03-27 09:14:57 +00001715static unsigned LimitedSumOfUnscheduledPredsOfSuccs(const SUnit *SU,
1716 unsigned Limit) {
1717 unsigned Sum = 0;
1718 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
1719 I != E; ++I) {
1720 SUnit *SuccSU = I->Dep;
1721 for (SUnit::const_pred_iterator II = SuccSU->Preds.begin(),
1722 EE = SuccSU->Preds.end(); II != EE; ++II) {
1723 SUnit *PredSU = II->Dep;
Evan Cheng16d72072008-03-29 18:34:22 +00001724 if (!PredSU->isScheduled)
1725 if (++Sum > Limit)
1726 return Sum;
Roman Levensteinbc674502008-03-27 09:14:57 +00001727 }
1728 }
1729 return Sum;
1730}
1731
Evan Chengd38c22b2006-05-11 23:55:42 +00001732
1733// Top down
1734bool td_ls_rr_sort::operator()(const SUnit *left, const SUnit *right) const {
Evan Cheng6730f032007-01-08 23:55:53 +00001735 unsigned LPriority = SPQ->getNodePriority(left);
1736 unsigned RPriority = SPQ->getNodePriority(right);
Evan Cheng8e136a92007-09-26 21:36:17 +00001737 bool LIsTarget = left->Node && left->Node->isTargetOpcode();
1738 bool RIsTarget = right->Node && right->Node->isTargetOpcode();
Evan Chengd38c22b2006-05-11 23:55:42 +00001739 bool LIsFloater = LIsTarget && left->NumPreds == 0;
1740 bool RIsFloater = RIsTarget && right->NumPreds == 0;
Roman Levensteinbc674502008-03-27 09:14:57 +00001741 unsigned LBonus = (LimitedSumOfUnscheduledPredsOfSuccs(left,1) == 1) ? 2 : 0;
1742 unsigned RBonus = (LimitedSumOfUnscheduledPredsOfSuccs(right,1) == 1) ? 2 : 0;
Evan Chengd38c22b2006-05-11 23:55:42 +00001743
1744 if (left->NumSuccs == 0 && right->NumSuccs != 0)
1745 return false;
1746 else if (left->NumSuccs != 0 && right->NumSuccs == 0)
1747 return true;
1748
Evan Chengd38c22b2006-05-11 23:55:42 +00001749 if (LIsFloater)
1750 LBonus -= 2;
1751 if (RIsFloater)
1752 RBonus -= 2;
1753 if (left->NumSuccs == 1)
1754 LBonus += 2;
1755 if (right->NumSuccs == 1)
1756 RBonus += 2;
1757
Evan Cheng73bdf042008-03-01 00:39:47 +00001758 if (LPriority+LBonus != RPriority+RBonus)
1759 return LPriority+LBonus < RPriority+RBonus;
Anton Korobeynikov035eaac2008-02-20 11:10:28 +00001760
Evan Cheng73bdf042008-03-01 00:39:47 +00001761 if (left->Depth != right->Depth)
1762 return left->Depth < right->Depth;
1763
1764 if (left->NumSuccsLeft != right->NumSuccsLeft)
1765 return left->NumSuccsLeft > right->NumSuccsLeft;
1766
1767 if (left->CycleBound != right->CycleBound)
1768 return left->CycleBound > right->CycleBound;
1769
Roman Levenstein6b371142008-04-29 09:07:59 +00001770 assert(left->NodeQueueId && right->NodeQueueId &&
1771 "NodeQueueId cannot be zero");
1772 return (left->NodeQueueId > right->NodeQueueId);
Evan Chengd38c22b2006-05-11 23:55:42 +00001773}
1774
Evan Cheng6730f032007-01-08 23:55:53 +00001775/// CalcNodeSethiUllmanNumber - Priority is the Sethi Ullman number.
Evan Chengd38c22b2006-05-11 23:55:42 +00001776/// Smaller number is the higher priority.
Dan Gohman4b49be12008-06-21 01:08:22 +00001777unsigned TDRegReductionPriorityQueue::
Chris Lattner296a83c2007-02-01 04:55:59 +00001778CalcNodeSethiUllmanNumber(const SUnit *SU) {
Evan Cheng961bbd32007-01-08 23:50:38 +00001779 unsigned &SethiUllmanNumber = SethiUllmanNumbers[SU->NodeNum];
Evan Chengd38c22b2006-05-11 23:55:42 +00001780 if (SethiUllmanNumber != 0)
1781 return SethiUllmanNumber;
1782
Evan Cheng8e136a92007-09-26 21:36:17 +00001783 unsigned Opc = SU->Node ? SU->Node->getOpcode() : 0;
Evan Chengd38c22b2006-05-11 23:55:42 +00001784 if (Opc == ISD::TokenFactor || Opc == ISD::CopyToReg)
Evan Cheng961bbd32007-01-08 23:50:38 +00001785 SethiUllmanNumber = 0xffff;
Evan Chengd38c22b2006-05-11 23:55:42 +00001786 else if (SU->NumSuccsLeft == 0)
1787 // If SU does not have a use, i.e. it doesn't produce a value that would
1788 // be consumed (e.g. store), then it terminates a chain of computation.
Chris Lattner296a83c2007-02-01 04:55:59 +00001789 // Give it a small SethiUllman number so it will be scheduled right before
1790 // its predecessors that it doesn't lengthen their live ranges.
Evan Cheng961bbd32007-01-08 23:50:38 +00001791 SethiUllmanNumber = 0;
Evan Chengd38c22b2006-05-11 23:55:42 +00001792 else if (SU->NumPredsLeft == 0 &&
1793 (Opc != ISD::CopyFromReg || isCopyFromLiveIn(SU)))
Evan Cheng961bbd32007-01-08 23:50:38 +00001794 SethiUllmanNumber = 0xffff;
Evan Chengd38c22b2006-05-11 23:55:42 +00001795 else {
1796 int Extra = 0;
Chris Lattnerd86418a2006-08-17 00:09:56 +00001797 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
1798 I != E; ++I) {
Evan Cheng0effc3a2007-09-19 01:38:40 +00001799 if (I->isCtrl) continue; // ignore chain preds
1800 SUnit *PredSU = I->Dep;
Evan Cheng6730f032007-01-08 23:55:53 +00001801 unsigned PredSethiUllman = CalcNodeSethiUllmanNumber(PredSU);
Evan Chengd38c22b2006-05-11 23:55:42 +00001802 if (PredSethiUllman > SethiUllmanNumber) {
1803 SethiUllmanNumber = PredSethiUllman;
1804 Extra = 0;
Evan Cheng0effc3a2007-09-19 01:38:40 +00001805 } else if (PredSethiUllman == SethiUllmanNumber && !I->isCtrl)
Evan Cheng5924bf72007-09-25 01:54:36 +00001806 ++Extra;
Evan Chengd38c22b2006-05-11 23:55:42 +00001807 }
1808
1809 SethiUllmanNumber += Extra;
1810 }
1811
1812 return SethiUllmanNumber;
1813}
1814
Evan Cheng6730f032007-01-08 23:55:53 +00001815/// CalculateSethiUllmanNumbers - Calculate Sethi-Ullman numbers of all
1816/// scheduling units.
Dan Gohman4b49be12008-06-21 01:08:22 +00001817void TDRegReductionPriorityQueue::CalculateSethiUllmanNumbers() {
Evan Chengd38c22b2006-05-11 23:55:42 +00001818 SethiUllmanNumbers.assign(SUnits->size(), 0);
1819
1820 for (unsigned i = 0, e = SUnits->size(); i != e; ++i)
Evan Cheng6730f032007-01-08 23:55:53 +00001821 CalcNodeSethiUllmanNumber(&(*SUnits)[i]);
Evan Chengd38c22b2006-05-11 23:55:42 +00001822}
1823
1824//===----------------------------------------------------------------------===//
1825// Public Constructor Functions
1826//===----------------------------------------------------------------------===//
1827
Jim Laskey03593f72006-08-01 18:29:48 +00001828llvm::ScheduleDAG* llvm::createBURRListDAGScheduler(SelectionDAGISel *IS,
1829 SelectionDAG *DAG,
Evan Cheng2c977312008-07-01 18:05:03 +00001830 MachineBasicBlock *BB,
1831 bool Fast) {
Evan Chengfd2c5dd2006-11-04 09:44:31 +00001832 const TargetInstrInfo *TII = DAG->getTarget().getInstrInfo();
Dan Gohman3a4be0f2008-02-10 18:45:23 +00001833 const TargetRegisterInfo *TRI = DAG->getTarget().getRegisterInfo();
Roman Levenstein7e71b4b2008-03-26 09:18:09 +00001834
Dan Gohman4b49be12008-06-21 01:08:22 +00001835 BURegReductionPriorityQueue *priorityQueue =
Evan Cheng2c977312008-07-01 18:05:03 +00001836 new BURegReductionPriorityQueue(TII, TRI, Fast);
Roman Levenstein7e71b4b2008-03-26 09:18:09 +00001837
1838 ScheduleDAGRRList * scheduleDAG =
Evan Cheng2c977312008-07-01 18:05:03 +00001839 new ScheduleDAGRRList(*DAG, BB, DAG->getTarget(), true, Fast,priorityQueue);
Roman Levenstein7e71b4b2008-03-26 09:18:09 +00001840 priorityQueue->setScheduleDAG(scheduleDAG);
1841 return scheduleDAG;
Evan Chengd38c22b2006-05-11 23:55:42 +00001842}
1843
Jim Laskey03593f72006-08-01 18:29:48 +00001844llvm::ScheduleDAG* llvm::createTDRRListDAGScheduler(SelectionDAGISel *IS,
1845 SelectionDAG *DAG,
Evan Cheng2c977312008-07-01 18:05:03 +00001846 MachineBasicBlock *BB,
1847 bool Fast) {
1848 return new ScheduleDAGRRList(*DAG, BB, DAG->getTarget(), false, Fast,
Dan Gohman4b49be12008-06-21 01:08:22 +00001849 new TDRegReductionPriorityQueue());
Evan Chengd38c22b2006-05-11 23:55:42 +00001850}
1851