blob: 6fc4e11b53c6d08f077c7eb38654fc464536394e [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===---- ScheduleDAG.cpp - Implement the ScheduleDAG class ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
Dan Gohmane39d9902008-07-11 22:39:58 +000010// This implements the ScheduleDAG class, which is a base class used by
11// scheduling implementation classes.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000012//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "pre-RA-sched"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000016#include "llvm/CodeGen/ScheduleDAG.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000017#include "llvm/Target/TargetMachine.h"
18#include "llvm/Target/TargetInstrInfo.h"
Dan Gohmanc3861152008-09-03 16:01:59 +000019#include "llvm/Target/TargetRegisterInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020#include "llvm/Support/Debug.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021using namespace llvm;
22
Chris Lattner1b989192007-12-31 04:13:23 +000023ScheduleDAG::ScheduleDAG(SelectionDAG &dag, MachineBasicBlock *bb,
24 const TargetMachine &tm)
Evan Cheng8725a112008-03-12 22:19:41 +000025 : DAG(dag), BB(bb), TM(tm), MRI(BB->getParent()->getRegInfo()) {
Evan Cheng19da42d2008-04-03 16:36:07 +000026 TII = TM.getInstrInfo();
27 MF = &DAG.getMachineFunction();
28 TRI = TM.getRegisterInfo();
29 TLI = &DAG.getTargetLoweringInfo();
30 ConstPool = BB->getParent()->getConstantPool();
Chris Lattner1b989192007-12-31 04:13:23 +000031}
Evan Cheng93f143e2007-09-25 01:54:36 +000032
Evan Cheng93f143e2007-09-25 01:54:36 +000033/// CheckForPhysRegDependency - Check if the dependency between def and use of
34/// a specified operand is a physical register dependency. If so, returns the
35/// register and the cost of copying the register.
Dan Gohman0c97f1d2008-07-27 20:43:25 +000036static void CheckForPhysRegDependency(SDNode *Def, SDNode *User, unsigned Op,
Dan Gohman1e57df32008-02-10 18:45:23 +000037 const TargetRegisterInfo *TRI,
Evan Cheng93f143e2007-09-25 01:54:36 +000038 const TargetInstrInfo *TII,
39 unsigned &PhysReg, int &Cost) {
Dan Gohman0c97f1d2008-07-27 20:43:25 +000040 if (Op != 2 || User->getOpcode() != ISD::CopyToReg)
Evan Cheng93f143e2007-09-25 01:54:36 +000041 return;
42
Dan Gohman0c97f1d2008-07-27 20:43:25 +000043 unsigned Reg = cast<RegisterSDNode>(User->getOperand(1))->getReg();
Dan Gohman1e57df32008-02-10 18:45:23 +000044 if (TargetRegisterInfo::isVirtualRegister(Reg))
Evan Cheng93f143e2007-09-25 01:54:36 +000045 return;
46
Gabor Greif46bf5472008-08-26 22:36:50 +000047 unsigned ResNo = User->getOperand(2).getResNo();
Dan Gohmanbd68c792008-07-17 19:10:17 +000048 if (Def->isMachineOpcode()) {
49 const TargetInstrDesc &II = TII->get(Def->getMachineOpcode());
Chris Lattner0c2a4f32008-01-07 03:13:06 +000050 if (ResNo >= II.getNumDefs() &&
51 II.ImplicitDefs[ResNo - II.getNumDefs()] == Reg) {
Evan Cheng93f143e2007-09-25 01:54:36 +000052 PhysReg = Reg;
53 const TargetRegisterClass *RC =
Evan Cheng14cc83f2008-03-11 07:19:34 +000054 TRI->getPhysicalRegisterRegClass(Reg, Def->getValueType(ResNo));
Evan Cheng93f143e2007-09-25 01:54:36 +000055 Cost = RC->getCopyCost();
56 }
57 }
58}
59
60SUnit *ScheduleDAG::Clone(SUnit *Old) {
61 SUnit *SU = NewSUnit(Old->Node);
Dan Gohmanab162912008-06-21 15:52:51 +000062 SU->OrigNode = Old->OrigNode;
Dan Gohmanb100d802008-03-10 23:48:14 +000063 SU->FlaggedNodes = Old->FlaggedNodes;
Evan Cheng93f143e2007-09-25 01:54:36 +000064 SU->Latency = Old->Latency;
65 SU->isTwoAddress = Old->isTwoAddress;
66 SU->isCommutable = Old->isCommutable;
Evan Chengba597da2007-09-28 22:32:30 +000067 SU->hasPhysRegDefs = Old->hasPhysRegDefs;
Evan Cheng93f143e2007-09-25 01:54:36 +000068 return SU;
69}
70
Evan Chengdd3f8b92007-10-05 01:39:18 +000071
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072/// BuildSchedUnits - Build SUnits from the selection dag that we are input.
73/// This SUnit graph is similar to the SelectionDAG, but represents flagged
74/// together nodes with a single SUnit.
75void ScheduleDAG::BuildSchedUnits() {
76 // Reserve entries in the vector for each of the SUnits we are creating. This
77 // ensure that reallocation of the vector won't happen, so SUnit*'s won't get
78 // invalidated.
Dan Gohman17495de2008-06-20 17:15:19 +000079 SUnits.reserve(DAG.allnodes_size());
Dan Gohmanf17a25c2007-07-18 16:29:46 +000080
Dan Gohman018d7b72008-06-21 19:18:17 +000081 // During scheduling, the NodeId field of SDNode is used to map SDNodes
82 // to their associated SUnits by holding SUnits table indices. A value
83 // of -1 means the SDNode does not yet have an associated SUnit.
84 for (SelectionDAG::allnodes_iterator NI = DAG.allnodes_begin(),
85 E = DAG.allnodes_end(); NI != E; ++NI)
86 NI->setNodeId(-1);
87
Dan Gohmanf17a25c2007-07-18 16:29:46 +000088 for (SelectionDAG::allnodes_iterator NI = DAG.allnodes_begin(),
89 E = DAG.allnodes_end(); NI != E; ++NI) {
90 if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate.
91 continue;
92
93 // If this node has already been processed, stop now.
Dan Gohman018d7b72008-06-21 19:18:17 +000094 if (NI->getNodeId() != -1) continue;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000095
96 SUnit *NodeSUnit = NewSUnit(NI);
97
98 // See if anything is flagged to this node, if so, add them to flagged
99 // nodes. Nodes can have at most one flag input and one flag output. Flags
100 // are required the be the last operand and result of a node.
101
102 // Scan up, adding flagged preds to FlaggedNodes.
103 SDNode *N = NI;
104 if (N->getNumOperands() &&
105 N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Flag) {
106 do {
Gabor Greif1c80d112008-08-28 21:40:38 +0000107 N = N->getOperand(N->getNumOperands()-1).getNode();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000108 NodeSUnit->FlaggedNodes.push_back(N);
Dan Gohman018d7b72008-06-21 19:18:17 +0000109 assert(N->getNodeId() == -1 && "Node already inserted!");
110 N->setNodeId(NodeSUnit->NodeNum);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000111 } while (N->getNumOperands() &&
112 N->getOperand(N->getNumOperands()-1).getValueType()== MVT::Flag);
113 std::reverse(NodeSUnit->FlaggedNodes.begin(),
114 NodeSUnit->FlaggedNodes.end());
115 }
116
117 // Scan down, adding this node and any flagged succs to FlaggedNodes if they
118 // have a user of the flag operand.
119 N = NI;
120 while (N->getValueType(N->getNumValues()-1) == MVT::Flag) {
Dan Gohman8181bd12008-07-27 21:46:04 +0000121 SDValue FlagVal(N, N->getNumValues()-1);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000122
123 // There are either zero or one users of the Flag result.
124 bool HasFlagUse = false;
125 for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end();
126 UI != E; ++UI)
Dan Gohman0c97f1d2008-07-27 20:43:25 +0000127 if (FlagVal.isOperandOf(*UI)) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000128 HasFlagUse = true;
129 NodeSUnit->FlaggedNodes.push_back(N);
Dan Gohman018d7b72008-06-21 19:18:17 +0000130 assert(N->getNodeId() == -1 && "Node already inserted!");
131 N->setNodeId(NodeSUnit->NodeNum);
Dan Gohman0c97f1d2008-07-27 20:43:25 +0000132 N = *UI;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000133 break;
134 }
135 if (!HasFlagUse) break;
136 }
137
138 // Now all flagged nodes are in FlaggedNodes and N is the bottom-most node.
139 // Update the SUnit
140 NodeSUnit->Node = N;
Dan Gohman018d7b72008-06-21 19:18:17 +0000141 assert(N->getNodeId() == -1 && "Node already inserted!");
142 N->setNodeId(NodeSUnit->NodeNum);
Evan Chengdd3f8b92007-10-05 01:39:18 +0000143
144 ComputeLatency(NodeSUnit);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000145 }
146
147 // Pass 2: add the preds, succs, etc.
148 for (unsigned su = 0, e = SUnits.size(); su != e; ++su) {
149 SUnit *SU = &SUnits[su];
150 SDNode *MainNode = SU->Node;
151
Dan Gohmanbd68c792008-07-17 19:10:17 +0000152 if (MainNode->isMachineOpcode()) {
153 unsigned Opc = MainNode->getMachineOpcode();
Chris Lattner5b930372008-01-07 07:27:27 +0000154 const TargetInstrDesc &TID = TII->get(Opc);
Chris Lattner0c2a4f32008-01-07 03:13:06 +0000155 for (unsigned i = 0; i != TID.getNumOperands(); ++i) {
Evan Cheng93f143e2007-09-25 01:54:36 +0000156 if (TID.getOperandConstraint(i, TOI::TIED_TO) != -1) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000157 SU->isTwoAddress = true;
158 break;
159 }
160 }
Chris Lattnerd8529ab2008-01-07 06:42:05 +0000161 if (TID.isCommutable())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000162 SU->isCommutable = true;
163 }
164
165 // Find all predecessors and successors of the group.
166 // Temporarily add N to make code simpler.
167 SU->FlaggedNodes.push_back(MainNode);
168
169 for (unsigned n = 0, e = SU->FlaggedNodes.size(); n != e; ++n) {
170 SDNode *N = SU->FlaggedNodes[n];
Dan Gohmanbd68c792008-07-17 19:10:17 +0000171 if (N->isMachineOpcode() &&
172 TII->get(N->getMachineOpcode()).getImplicitDefs() &&
173 CountResults(N) > TII->get(N->getMachineOpcode()).getNumDefs())
Evan Chengba597da2007-09-28 22:32:30 +0000174 SU->hasPhysRegDefs = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000175
176 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
Gabor Greif1c80d112008-08-28 21:40:38 +0000177 SDNode *OpN = N->getOperand(i).getNode();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000178 if (isPassiveNode(OpN)) continue; // Not scheduled.
Dan Gohman018d7b72008-06-21 19:18:17 +0000179 SUnit *OpSU = &SUnits[OpN->getNodeId()];
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000180 assert(OpSU && "Node has no SUnit!");
181 if (OpSU == SU) continue; // In the same group.
182
Duncan Sands92c43912008-06-06 12:08:01 +0000183 MVT OpVT = N->getOperand(i).getValueType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184 assert(OpVT != MVT::Flag && "Flagged nodes should be in same sunit!");
185 bool isChain = OpVT == MVT::Other;
Evan Cheng93f143e2007-09-25 01:54:36 +0000186
187 unsigned PhysReg = 0;
188 int Cost = 1;
189 // Determine if this is a physical register dependency.
Dan Gohman1e57df32008-02-10 18:45:23 +0000190 CheckForPhysRegDependency(OpN, N, i, TRI, TII, PhysReg, Cost);
Evan Cheng93f143e2007-09-25 01:54:36 +0000191 SU->addPred(OpSU, isChain, false, PhysReg, Cost);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000192 }
193 }
194
195 // Remove MainNode from FlaggedNodes again.
196 SU->FlaggedNodes.pop_back();
197 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000198}
199
Evan Chengdd3f8b92007-10-05 01:39:18 +0000200void ScheduleDAG::ComputeLatency(SUnit *SU) {
201 const InstrItineraryData &InstrItins = TM.getInstrItineraryData();
202
203 // Compute the latency for the node. We use the sum of the latencies for
204 // all nodes flagged together into this SUnit.
205 if (InstrItins.isEmpty()) {
206 // No latency information.
207 SU->Latency = 1;
Evan Chengf2639ba2008-07-02 09:23:51 +0000208 return;
209 }
210
211 SU->Latency = 0;
Dan Gohmanbd68c792008-07-17 19:10:17 +0000212 if (SU->Node->isMachineOpcode()) {
213 unsigned SchedClass = TII->get(SU->Node->getMachineOpcode()).getSchedClass();
Evan Chengf2639ba2008-07-02 09:23:51 +0000214 const InstrStage *S = InstrItins.begin(SchedClass);
215 const InstrStage *E = InstrItins.end(SchedClass);
216 for (; S != E; ++S)
217 SU->Latency += S->Cycles;
218 }
219 for (unsigned i = 0, e = SU->FlaggedNodes.size(); i != e; ++i) {
220 SDNode *FNode = SU->FlaggedNodes[i];
Dan Gohmanbd68c792008-07-17 19:10:17 +0000221 if (FNode->isMachineOpcode()) {
222 unsigned SchedClass = TII->get(FNode->getMachineOpcode()).getSchedClass();
Dan Gohman12300e12008-03-25 21:45:14 +0000223 const InstrStage *S = InstrItins.begin(SchedClass);
224 const InstrStage *E = InstrItins.end(SchedClass);
Evan Chengdd3f8b92007-10-05 01:39:18 +0000225 for (; S != E; ++S)
226 SU->Latency += S->Cycles;
227 }
Evan Chengdd3f8b92007-10-05 01:39:18 +0000228 }
229}
230
Roman Levenstein1db9b822008-03-04 11:19:43 +0000231/// CalculateDepths - compute depths using algorithms for the longest
232/// paths in the DAG
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000233void ScheduleDAG::CalculateDepths() {
Roman Levenstein1db9b822008-03-04 11:19:43 +0000234 unsigned DAGSize = SUnits.size();
Roman Levenstein1db9b822008-03-04 11:19:43 +0000235 std::vector<SUnit*> WorkList;
236 WorkList.reserve(DAGSize);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000237
Roman Levenstein1db9b822008-03-04 11:19:43 +0000238 // Initialize the data structures
239 for (unsigned i = 0, e = DAGSize; i != e; ++i) {
240 SUnit *SU = &SUnits[i];
Roman Levenstein1db9b822008-03-04 11:19:43 +0000241 unsigned Degree = SU->Preds.size();
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000242 // Temporarily use the Depth field as scratch space for the degree count.
243 SU->Depth = Degree;
Roman Levenstein1db9b822008-03-04 11:19:43 +0000244
245 // Is it a node without dependencies?
246 if (Degree == 0) {
247 assert(SU->Preds.empty() && "SUnit should have no predecessors");
248 // Collect leaf nodes
249 WorkList.push_back(SU);
250 }
251 }
252
253 // Process nodes in the topological order
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000254 while (!WorkList.empty()) {
Roman Levenstein1db9b822008-03-04 11:19:43 +0000255 SUnit *SU = WorkList.back();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000256 WorkList.pop_back();
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000257 unsigned SUDepth = 0;
Roman Levenstein1db9b822008-03-04 11:19:43 +0000258
259 // Use dynamic programming:
260 // When current node is being processed, all of its dependencies
261 // are already processed.
262 // So, just iterate over all predecessors and take the longest path
263 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
264 I != E; ++I) {
265 unsigned PredDepth = I->Dep->Depth;
266 if (PredDepth+1 > SUDepth) {
267 SUDepth = PredDepth + 1;
268 }
269 }
270
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000271 SU->Depth = SUDepth;
272
273 // Update degrees of all nodes depending on current SUnit
Roman Levenstein1db9b822008-03-04 11:19:43 +0000274 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
275 I != E; ++I) {
276 SUnit *SU = I->Dep;
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000277 if (!--SU->Depth)
Roman Levenstein1db9b822008-03-04 11:19:43 +0000278 // If all dependencies of the node are processed already,
279 // then the longest path for the node can be computed now
280 WorkList.push_back(SU);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000281 }
282 }
283}
284
Roman Levenstein1db9b822008-03-04 11:19:43 +0000285/// CalculateHeights - compute heights using algorithms for the longest
286/// paths in the DAG
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000287void ScheduleDAG::CalculateHeights() {
Roman Levenstein1db9b822008-03-04 11:19:43 +0000288 unsigned DAGSize = SUnits.size();
Roman Levenstein1db9b822008-03-04 11:19:43 +0000289 std::vector<SUnit*> WorkList;
290 WorkList.reserve(DAGSize);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000291
Roman Levenstein1db9b822008-03-04 11:19:43 +0000292 // Initialize the data structures
293 for (unsigned i = 0, e = DAGSize; i != e; ++i) {
294 SUnit *SU = &SUnits[i];
Roman Levenstein1db9b822008-03-04 11:19:43 +0000295 unsigned Degree = SU->Succs.size();
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000296 // Temporarily use the Height field as scratch space for the degree count.
297 SU->Height = Degree;
Roman Levenstein1db9b822008-03-04 11:19:43 +0000298
299 // Is it a node without dependencies?
300 if (Degree == 0) {
301 assert(SU->Succs.empty() && "Something wrong");
302 assert(WorkList.empty() && "Should be empty");
303 // Collect leaf nodes
304 WorkList.push_back(SU);
305 }
306 }
307
308 // Process nodes in the topological order
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000309 while (!WorkList.empty()) {
Roman Levenstein1db9b822008-03-04 11:19:43 +0000310 SUnit *SU = WorkList.back();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000311 WorkList.pop_back();
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000312 unsigned SUHeight = 0;
Roman Levenstein1db9b822008-03-04 11:19:43 +0000313
314 // Use dynamic programming:
315 // When current node is being processed, all of its dependencies
316 // are already processed.
317 // So, just iterate over all successors and take the longest path
318 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
319 I != E; ++I) {
320 unsigned SuccHeight = I->Dep->Height;
321 if (SuccHeight+1 > SUHeight) {
322 SUHeight = SuccHeight + 1;
323 }
324 }
325
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000326 SU->Height = SUHeight;
327
328 // Update degrees of all nodes depending on current SUnit
Roman Levenstein1db9b822008-03-04 11:19:43 +0000329 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
330 I != E; ++I) {
331 SUnit *SU = I->Dep;
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000332 if (!--SU->Height)
Roman Levenstein1db9b822008-03-04 11:19:43 +0000333 // If all dependencies of the node are processed already,
334 // then the longest path for the node can be computed now
335 WorkList.push_back(SU);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000336 }
337 }
338}
339
340/// CountResults - The results of target nodes have register or immediate
341/// operands first, then an optional chain, and optional flag operands (which do
Dan Gohman0256f1e2008-02-11 19:00:03 +0000342/// not go into the resulting MachineInstr).
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343unsigned ScheduleDAG::CountResults(SDNode *Node) {
344 unsigned N = Node->getNumValues();
345 while (N && Node->getValueType(N - 1) == MVT::Flag)
346 --N;
347 if (N && Node->getValueType(N - 1) == MVT::Other)
348 --N; // Skip over chain result.
349 return N;
350}
351
Dan Gohman12a9c082008-02-06 22:27:42 +0000352/// CountOperands - The inputs to target nodes have any actual inputs first,
Dan Gohmance256462008-02-16 00:36:48 +0000353/// followed by special operands that describe memory references, then an
354/// optional chain operand, then flag operands. Compute the number of
355/// actual operands that will go into the resulting MachineInstr.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356unsigned ScheduleDAG::CountOperands(SDNode *Node) {
Dan Gohmance256462008-02-16 00:36:48 +0000357 unsigned N = ComputeMemOperandsEnd(Node);
Gabor Greif1c80d112008-08-28 21:40:38 +0000358 while (N && isa<MemOperandSDNode>(Node->getOperand(N - 1).getNode()))
Dan Gohman1fad9e62008-04-07 19:35:22 +0000359 --N; // Ignore MEMOPERAND nodes
Dan Gohman12a9c082008-02-06 22:27:42 +0000360 return N;
361}
362
Dan Gohmance256462008-02-16 00:36:48 +0000363/// ComputeMemOperandsEnd - Find the index one past the last MemOperandSDNode
364/// operand
365unsigned ScheduleDAG::ComputeMemOperandsEnd(SDNode *Node) {
Dan Gohman12a9c082008-02-06 22:27:42 +0000366 unsigned N = Node->getNumOperands();
367 while (N && Node->getOperand(N - 1).getValueType() == MVT::Flag)
368 --N;
369 if (N && Node->getOperand(N - 1).getValueType() == MVT::Other)
370 --N; // Ignore chain if it exists.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000371 return N;
372}
373
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000374
375/// dump - dump the schedule.
376void ScheduleDAG::dumpSchedule() const {
377 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
378 if (SUnit *SU = Sequence[i])
379 SU->dump(&DAG);
380 else
381 cerr << "**** NOOP ****\n";
382 }
383}
384
385
386/// Run - perform scheduling.
387///
Dan Gohman368a08b2008-07-14 18:19:29 +0000388void ScheduleDAG::Run() {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389 Schedule();
Dan Gohman368a08b2008-07-14 18:19:29 +0000390
391 DOUT << "*** Final schedule ***\n";
392 DEBUG(dumpSchedule());
393 DOUT << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394}
395
396/// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
397/// a group of nodes flagged together.
398void SUnit::dump(const SelectionDAG *G) const {
399 cerr << "SU(" << NodeNum << "): ";
Evan Cheng5ec4b762007-09-26 21:36:17 +0000400 if (Node)
401 Node->dump(G);
402 else
403 cerr << "CROSS RC COPY ";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000404 cerr << "\n";
405 if (FlaggedNodes.size() != 0) {
406 for (unsigned i = 0, e = FlaggedNodes.size(); i != e; i++) {
407 cerr << " ";
408 FlaggedNodes[i]->dump(G);
409 cerr << "\n";
410 }
411 }
412}
413
414void SUnit::dumpAll(const SelectionDAG *G) const {
415 dump(G);
416
417 cerr << " # preds left : " << NumPredsLeft << "\n";
418 cerr << " # succs left : " << NumSuccsLeft << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000419 cerr << " Latency : " << Latency << "\n";
420 cerr << " Depth : " << Depth << "\n";
421 cerr << " Height : " << Height << "\n";
422
423 if (Preds.size() != 0) {
424 cerr << " Predecessors:\n";
425 for (SUnit::const_succ_iterator I = Preds.begin(), E = Preds.end();
426 I != E; ++I) {
Evan Chenge7959472007-09-19 01:38:40 +0000427 if (I->isCtrl)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428 cerr << " ch #";
429 else
430 cerr << " val #";
Evan Cheng93f143e2007-09-25 01:54:36 +0000431 cerr << I->Dep << " - SU(" << I->Dep->NodeNum << ")";
432 if (I->isSpecial)
433 cerr << " *";
434 cerr << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000435 }
436 }
437 if (Succs.size() != 0) {
438 cerr << " Successors:\n";
439 for (SUnit::const_succ_iterator I = Succs.begin(), E = Succs.end();
440 I != E; ++I) {
Evan Chenge7959472007-09-19 01:38:40 +0000441 if (I->isCtrl)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000442 cerr << " ch #";
443 else
444 cerr << " val #";
Evan Cheng93f143e2007-09-25 01:54:36 +0000445 cerr << I->Dep << " - SU(" << I->Dep->NodeNum << ")";
446 if (I->isSpecial)
447 cerr << " *";
448 cerr << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000449 }
450 }
451 cerr << "\n";
452}