blob: 6d6b9c7c0f0c95b476b9d335d8abca393260d063 [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
Dan Gohman96c2ad22008-11-13 21:21:28 +000023ScheduleDAG::ScheduleDAG(SelectionDAG *dag, MachineBasicBlock *bb,
Chris Lattner1b989192007-12-31 04:13:23 +000024 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();
Dan Gohmanfa603902008-11-11 21:31:56 +000027 MF = BB->getParent();
Evan Cheng19da42d2008-04-03 16:36:07 +000028 TRI = TM.getRegisterInfo();
Dan Gohmanfa603902008-11-11 21:31:56 +000029 TLI = TM.getTargetLowering();
30 ConstPool = MF->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) {
Dan Gohmanf26ca4b2008-11-13 21:36:12 +000061 SUnit *SU = NewSUnit(Old->getNode());
Dan Gohmanab162912008-06-21 15:52:51 +000062 SU->OrigNode = Old->OrigNode;
Evan Cheng93f143e2007-09-25 01:54:36 +000063 SU->Latency = Old->Latency;
64 SU->isTwoAddress = Old->isTwoAddress;
65 SU->isCommutable = Old->isCommutable;
Evan Chengba597da2007-09-28 22:32:30 +000066 SU->hasPhysRegDefs = Old->hasPhysRegDefs;
Evan Cheng93f143e2007-09-25 01:54:36 +000067 return SU;
68}
69
Evan Chengdd3f8b92007-10-05 01:39:18 +000070
Dan Gohmanf17a25c2007-07-18 16:29:46 +000071/// BuildSchedUnits - Build SUnits from the selection dag that we are input.
72/// This SUnit graph is similar to the SelectionDAG, but represents flagged
73/// together nodes with a single SUnit.
74void ScheduleDAG::BuildSchedUnits() {
75 // Reserve entries in the vector for each of the SUnits we are creating. This
76 // ensure that reallocation of the vector won't happen, so SUnit*'s won't get
77 // invalidated.
Dan Gohman96c2ad22008-11-13 21:21:28 +000078 SUnits.reserve(DAG->allnodes_size());
Dan Gohmanf17a25c2007-07-18 16:29:46 +000079
Dan Gohman018d7b72008-06-21 19:18:17 +000080 // During scheduling, the NodeId field of SDNode is used to map SDNodes
81 // to their associated SUnits by holding SUnits table indices. A value
82 // of -1 means the SDNode does not yet have an associated SUnit.
Dan Gohman96c2ad22008-11-13 21:21:28 +000083 for (SelectionDAG::allnodes_iterator NI = DAG->allnodes_begin(),
84 E = DAG->allnodes_end(); NI != E; ++NI)
Dan Gohman018d7b72008-06-21 19:18:17 +000085 NI->setNodeId(-1);
86
Dan Gohman96c2ad22008-11-13 21:21:28 +000087 for (SelectionDAG::allnodes_iterator NI = DAG->allnodes_begin(),
88 E = DAG->allnodes_end(); NI != E; ++NI) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000089 if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate.
90 continue;
91
92 // If this node has already been processed, stop now.
Dan Gohman018d7b72008-06-21 19:18:17 +000093 if (NI->getNodeId() != -1) continue;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000094
95 SUnit *NodeSUnit = NewSUnit(NI);
96
97 // See if anything is flagged to this node, if so, add them to flagged
98 // nodes. Nodes can have at most one flag input and one flag output. Flags
99 // are required the be the last operand and result of a node.
100
Dan Gohman40ae0f02008-11-13 23:24:17 +0000101 // Scan up to find flagged preds.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000102 SDNode *N = NI;
103 if (N->getNumOperands() &&
104 N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Flag) {
105 do {
Gabor Greif1c80d112008-08-28 21:40:38 +0000106 N = N->getOperand(N->getNumOperands()-1).getNode();
Dan Gohman018d7b72008-06-21 19:18:17 +0000107 assert(N->getNodeId() == -1 && "Node already inserted!");
108 N->setNodeId(NodeSUnit->NodeNum);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000109 } while (N->getNumOperands() &&
110 N->getOperand(N->getNumOperands()-1).getValueType()== MVT::Flag);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000111 }
112
Dan Gohman40ae0f02008-11-13 23:24:17 +0000113 // Scan down to find any flagged succs.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000114 N = NI;
115 while (N->getValueType(N->getNumValues()-1) == MVT::Flag) {
Dan Gohman8181bd12008-07-27 21:46:04 +0000116 SDValue FlagVal(N, N->getNumValues()-1);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000117
118 // There are either zero or one users of the Flag result.
119 bool HasFlagUse = false;
120 for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end();
121 UI != E; ++UI)
Dan Gohman0c97f1d2008-07-27 20:43:25 +0000122 if (FlagVal.isOperandOf(*UI)) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000123 HasFlagUse = true;
Dan Gohman018d7b72008-06-21 19:18:17 +0000124 assert(N->getNodeId() == -1 && "Node already inserted!");
125 N->setNodeId(NodeSUnit->NodeNum);
Dan Gohman0c97f1d2008-07-27 20:43:25 +0000126 N = *UI;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000127 break;
128 }
129 if (!HasFlagUse) break;
130 }
131
Dan Gohman40ae0f02008-11-13 23:24:17 +0000132 // If there are flag operands involved, N is now the bottom-most node
133 // of the sequence of nodes that are flagged together.
134 // Update the SUnit.
Dan Gohmanf26ca4b2008-11-13 21:36:12 +0000135 NodeSUnit->setNode(N);
Dan Gohman018d7b72008-06-21 19:18:17 +0000136 assert(N->getNodeId() == -1 && "Node already inserted!");
137 N->setNodeId(NodeSUnit->NodeNum);
Evan Chengdd3f8b92007-10-05 01:39:18 +0000138
139 ComputeLatency(NodeSUnit);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000140 }
141
142 // Pass 2: add the preds, succs, etc.
143 for (unsigned su = 0, e = SUnits.size(); su != e; ++su) {
144 SUnit *SU = &SUnits[su];
Dan Gohmanf26ca4b2008-11-13 21:36:12 +0000145 SDNode *MainNode = SU->getNode();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000146
Dan Gohmanbd68c792008-07-17 19:10:17 +0000147 if (MainNode->isMachineOpcode()) {
148 unsigned Opc = MainNode->getMachineOpcode();
Chris Lattner5b930372008-01-07 07:27:27 +0000149 const TargetInstrDesc &TID = TII->get(Opc);
Chris Lattner0c2a4f32008-01-07 03:13:06 +0000150 for (unsigned i = 0; i != TID.getNumOperands(); ++i) {
Evan Cheng93f143e2007-09-25 01:54:36 +0000151 if (TID.getOperandConstraint(i, TOI::TIED_TO) != -1) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000152 SU->isTwoAddress = true;
153 break;
154 }
155 }
Chris Lattnerd8529ab2008-01-07 06:42:05 +0000156 if (TID.isCommutable())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000157 SU->isCommutable = true;
158 }
159
160 // Find all predecessors and successors of the group.
Dan Gohman40ae0f02008-11-13 23:24:17 +0000161 for (SDNode *N = SU->getNode(); N; N = N->getFlaggedNode()) {
Dan Gohmanbd68c792008-07-17 19:10:17 +0000162 if (N->isMachineOpcode() &&
163 TII->get(N->getMachineOpcode()).getImplicitDefs() &&
164 CountResults(N) > TII->get(N->getMachineOpcode()).getNumDefs())
Evan Chengba597da2007-09-28 22:32:30 +0000165 SU->hasPhysRegDefs = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000166
167 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
Gabor Greif1c80d112008-08-28 21:40:38 +0000168 SDNode *OpN = N->getOperand(i).getNode();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169 if (isPassiveNode(OpN)) continue; // Not scheduled.
Dan Gohman018d7b72008-06-21 19:18:17 +0000170 SUnit *OpSU = &SUnits[OpN->getNodeId()];
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000171 assert(OpSU && "Node has no SUnit!");
172 if (OpSU == SU) continue; // In the same group.
173
Duncan Sands92c43912008-06-06 12:08:01 +0000174 MVT OpVT = N->getOperand(i).getValueType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000175 assert(OpVT != MVT::Flag && "Flagged nodes should be in same sunit!");
176 bool isChain = OpVT == MVT::Other;
Evan Cheng93f143e2007-09-25 01:54:36 +0000177
178 unsigned PhysReg = 0;
179 int Cost = 1;
180 // Determine if this is a physical register dependency.
Dan Gohman1e57df32008-02-10 18:45:23 +0000181 CheckForPhysRegDependency(OpN, N, i, TRI, TII, PhysReg, Cost);
Evan Cheng93f143e2007-09-25 01:54:36 +0000182 SU->addPred(OpSU, isChain, false, PhysReg, Cost);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000183 }
184 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000185 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000186}
187
Evan Chengdd3f8b92007-10-05 01:39:18 +0000188void ScheduleDAG::ComputeLatency(SUnit *SU) {
189 const InstrItineraryData &InstrItins = TM.getInstrItineraryData();
190
191 // Compute the latency for the node. We use the sum of the latencies for
192 // all nodes flagged together into this SUnit.
193 if (InstrItins.isEmpty()) {
194 // No latency information.
195 SU->Latency = 1;
Evan Chengf2639ba2008-07-02 09:23:51 +0000196 return;
197 }
198
199 SU->Latency = 0;
Dan Gohman40ae0f02008-11-13 23:24:17 +0000200 for (SDNode *N = SU->getNode(); N; N = N->getFlaggedNode()) {
201 if (N->isMachineOpcode()) {
202 unsigned SchedClass = TII->get(N->getMachineOpcode()).getSchedClass();
Dan Gohman12300e12008-03-25 21:45:14 +0000203 const InstrStage *S = InstrItins.begin(SchedClass);
204 const InstrStage *E = InstrItins.end(SchedClass);
Evan Chengdd3f8b92007-10-05 01:39:18 +0000205 for (; S != E; ++S)
206 SU->Latency += S->Cycles;
207 }
Evan Chengdd3f8b92007-10-05 01:39:18 +0000208 }
209}
210
Roman Levenstein1db9b822008-03-04 11:19:43 +0000211/// CalculateDepths - compute depths using algorithms for the longest
212/// paths in the DAG
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213void ScheduleDAG::CalculateDepths() {
Roman Levenstein1db9b822008-03-04 11:19:43 +0000214 unsigned DAGSize = SUnits.size();
Roman Levenstein1db9b822008-03-04 11:19:43 +0000215 std::vector<SUnit*> WorkList;
216 WorkList.reserve(DAGSize);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217
Roman Levenstein1db9b822008-03-04 11:19:43 +0000218 // Initialize the data structures
219 for (unsigned i = 0, e = DAGSize; i != e; ++i) {
220 SUnit *SU = &SUnits[i];
Roman Levenstein1db9b822008-03-04 11:19:43 +0000221 unsigned Degree = SU->Preds.size();
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000222 // Temporarily use the Depth field as scratch space for the degree count.
223 SU->Depth = Degree;
Roman Levenstein1db9b822008-03-04 11:19:43 +0000224
225 // Is it a node without dependencies?
226 if (Degree == 0) {
227 assert(SU->Preds.empty() && "SUnit should have no predecessors");
228 // Collect leaf nodes
229 WorkList.push_back(SU);
230 }
231 }
232
233 // Process nodes in the topological order
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234 while (!WorkList.empty()) {
Roman Levenstein1db9b822008-03-04 11:19:43 +0000235 SUnit *SU = WorkList.back();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000236 WorkList.pop_back();
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000237 unsigned SUDepth = 0;
Roman Levenstein1db9b822008-03-04 11:19:43 +0000238
239 // Use dynamic programming:
240 // When current node is being processed, all of its dependencies
241 // are already processed.
242 // So, just iterate over all predecessors and take the longest path
243 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
244 I != E; ++I) {
245 unsigned PredDepth = I->Dep->Depth;
246 if (PredDepth+1 > SUDepth) {
247 SUDepth = PredDepth + 1;
248 }
249 }
250
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000251 SU->Depth = SUDepth;
252
253 // Update degrees of all nodes depending on current SUnit
Roman Levenstein1db9b822008-03-04 11:19:43 +0000254 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
255 I != E; ++I) {
256 SUnit *SU = I->Dep;
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000257 if (!--SU->Depth)
Roman Levenstein1db9b822008-03-04 11:19:43 +0000258 // If all dependencies of the node are processed already,
259 // then the longest path for the node can be computed now
260 WorkList.push_back(SU);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000261 }
262 }
263}
264
Roman Levenstein1db9b822008-03-04 11:19:43 +0000265/// CalculateHeights - compute heights using algorithms for the longest
266/// paths in the DAG
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000267void ScheduleDAG::CalculateHeights() {
Roman Levenstein1db9b822008-03-04 11:19:43 +0000268 unsigned DAGSize = SUnits.size();
Roman Levenstein1db9b822008-03-04 11:19:43 +0000269 std::vector<SUnit*> WorkList;
270 WorkList.reserve(DAGSize);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000271
Roman Levenstein1db9b822008-03-04 11:19:43 +0000272 // Initialize the data structures
273 for (unsigned i = 0, e = DAGSize; i != e; ++i) {
274 SUnit *SU = &SUnits[i];
Roman Levenstein1db9b822008-03-04 11:19:43 +0000275 unsigned Degree = SU->Succs.size();
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000276 // Temporarily use the Height field as scratch space for the degree count.
277 SU->Height = Degree;
Roman Levenstein1db9b822008-03-04 11:19:43 +0000278
279 // Is it a node without dependencies?
280 if (Degree == 0) {
281 assert(SU->Succs.empty() && "Something wrong");
282 assert(WorkList.empty() && "Should be empty");
283 // Collect leaf nodes
284 WorkList.push_back(SU);
285 }
286 }
287
288 // Process nodes in the topological order
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000289 while (!WorkList.empty()) {
Roman Levenstein1db9b822008-03-04 11:19:43 +0000290 SUnit *SU = WorkList.back();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000291 WorkList.pop_back();
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000292 unsigned SUHeight = 0;
Roman Levenstein1db9b822008-03-04 11:19:43 +0000293
294 // Use dynamic programming:
295 // When current node is being processed, all of its dependencies
296 // are already processed.
297 // So, just iterate over all successors and take the longest path
298 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
299 I != E; ++I) {
300 unsigned SuccHeight = I->Dep->Height;
301 if (SuccHeight+1 > SUHeight) {
302 SUHeight = SuccHeight + 1;
303 }
304 }
305
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000306 SU->Height = SUHeight;
307
308 // Update degrees of all nodes depending on current SUnit
Roman Levenstein1db9b822008-03-04 11:19:43 +0000309 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
310 I != E; ++I) {
311 SUnit *SU = I->Dep;
Dan Gohman4c43d5a2008-08-27 16:27:25 +0000312 if (!--SU->Height)
Roman Levenstein1db9b822008-03-04 11:19:43 +0000313 // If all dependencies of the node are processed already,
314 // then the longest path for the node can be computed now
315 WorkList.push_back(SU);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000316 }
317 }
318}
319
320/// CountResults - The results of target nodes have register or immediate
321/// operands first, then an optional chain, and optional flag operands (which do
Dan Gohman0256f1e2008-02-11 19:00:03 +0000322/// not go into the resulting MachineInstr).
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000323unsigned ScheduleDAG::CountResults(SDNode *Node) {
324 unsigned N = Node->getNumValues();
325 while (N && Node->getValueType(N - 1) == MVT::Flag)
326 --N;
327 if (N && Node->getValueType(N - 1) == MVT::Other)
328 --N; // Skip over chain result.
329 return N;
330}
331
Dan Gohman12a9c082008-02-06 22:27:42 +0000332/// CountOperands - The inputs to target nodes have any actual inputs first,
Dan Gohmance256462008-02-16 00:36:48 +0000333/// followed by special operands that describe memory references, then an
Dan Gohmanf175ade2008-10-25 17:51:24 +0000334/// optional chain operand, then an optional flag operand. Compute the number
335/// of actual operands that will go into the resulting MachineInstr.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000336unsigned ScheduleDAG::CountOperands(SDNode *Node) {
Dan Gohmance256462008-02-16 00:36:48 +0000337 unsigned N = ComputeMemOperandsEnd(Node);
Gabor Greif1c80d112008-08-28 21:40:38 +0000338 while (N && isa<MemOperandSDNode>(Node->getOperand(N - 1).getNode()))
Dan Gohman1fad9e62008-04-07 19:35:22 +0000339 --N; // Ignore MEMOPERAND nodes
Dan Gohman12a9c082008-02-06 22:27:42 +0000340 return N;
341}
342
Dan Gohmance256462008-02-16 00:36:48 +0000343/// ComputeMemOperandsEnd - Find the index one past the last MemOperandSDNode
344/// operand
345unsigned ScheduleDAG::ComputeMemOperandsEnd(SDNode *Node) {
Dan Gohman12a9c082008-02-06 22:27:42 +0000346 unsigned N = Node->getNumOperands();
347 while (N && Node->getOperand(N - 1).getValueType() == MVT::Flag)
348 --N;
349 if (N && Node->getOperand(N - 1).getValueType() == MVT::Other)
350 --N; // Ignore chain if it exists.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000351 return N;
352}
353
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354
355/// dump - dump the schedule.
356void ScheduleDAG::dumpSchedule() const {
357 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
358 if (SUnit *SU = Sequence[i])
Dan Gohman96c2ad22008-11-13 21:21:28 +0000359 SU->dump(DAG);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360 else
361 cerr << "**** NOOP ****\n";
362 }
363}
364
365
366/// Run - perform scheduling.
367///
Dan Gohman368a08b2008-07-14 18:19:29 +0000368void ScheduleDAG::Run() {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000369 Schedule();
Dan Gohman368a08b2008-07-14 18:19:29 +0000370
371 DOUT << "*** Final schedule ***\n";
372 DEBUG(dumpSchedule());
373 DOUT << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000374}
375
376/// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
377/// a group of nodes flagged together.
378void SUnit::dump(const SelectionDAG *G) const {
379 cerr << "SU(" << NodeNum << "): ";
Dan Gohman40ae0f02008-11-13 23:24:17 +0000380 if (getNode())
381 getNode()->dump(G);
Evan Cheng5ec4b762007-09-26 21:36:17 +0000382 else
383 cerr << "CROSS RC COPY ";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000384 cerr << "\n";
Dan Gohman40ae0f02008-11-13 23:24:17 +0000385 SmallVector<SDNode *, 4> FlaggedNodes;
386 for (SDNode *N = getNode()->getFlaggedNode(); N; N = N->getFlaggedNode())
387 FlaggedNodes.push_back(N);
388 while (!FlaggedNodes.empty()) {
389 cerr << " ";
390 FlaggedNodes.back()->dump(G);
391 cerr << "\n";
392 FlaggedNodes.pop_back();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000393 }
394}
395
396void SUnit::dumpAll(const SelectionDAG *G) const {
397 dump(G);
398
399 cerr << " # preds left : " << NumPredsLeft << "\n";
400 cerr << " # succs left : " << NumSuccsLeft << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000401 cerr << " Latency : " << Latency << "\n";
402 cerr << " Depth : " << Depth << "\n";
403 cerr << " Height : " << Height << "\n";
404
405 if (Preds.size() != 0) {
406 cerr << " Predecessors:\n";
407 for (SUnit::const_succ_iterator I = Preds.begin(), E = Preds.end();
408 I != E; ++I) {
Evan Chenge7959472007-09-19 01:38:40 +0000409 if (I->isCtrl)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000410 cerr << " ch #";
411 else
412 cerr << " val #";
Evan Cheng93f143e2007-09-25 01:54:36 +0000413 cerr << I->Dep << " - SU(" << I->Dep->NodeNum << ")";
414 if (I->isSpecial)
415 cerr << " *";
416 cerr << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000417 }
418 }
419 if (Succs.size() != 0) {
420 cerr << " Successors:\n";
421 for (SUnit::const_succ_iterator I = Succs.begin(), E = Succs.end();
422 I != E; ++I) {
Evan Chenge7959472007-09-19 01:38:40 +0000423 if (I->isCtrl)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000424 cerr << " ch #";
425 else
426 cerr << " val #";
Evan Cheng93f143e2007-09-25 01:54:36 +0000427 cerr << I->Dep << " - SU(" << I->Dep->NodeNum << ")";
428 if (I->isSpecial)
429 cerr << " *";
430 cerr << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000431 }
432 }
433 cerr << "\n";
434}