blob: 5b3b28162b5173de627c6159dafc44b74394953b [file] [log] [blame]
Evan Chenga9c20912006-01-21 02:32:06 +00001//===---- ScheduleDAG.cpp - Implement the ScheduleDAG class ---------------===//
Chris Lattnerd32b2362005-08-18 18:45:24 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerd32b2362005-08-18 18:45:24 +00007//
8//===----------------------------------------------------------------------===//
9//
Jim Laskeye6b90fb2005-09-26 21:57:04 +000010// This implements a simple two pass scheduler. The first pass attempts to push
11// backward any lengthy instructions and critical paths. The second pass packs
12// instructions into semi-optimal time slots.
Chris Lattnerd32b2362005-08-18 18:45:24 +000013//
14//===----------------------------------------------------------------------===//
15
Dale Johannesene7e7d0d2007-07-13 17:13:54 +000016#define DEBUG_TYPE "pre-RA-sched"
Nate Begemane1795842008-02-14 08:57:00 +000017#include "llvm/Constants.h"
Reid Spencere5530da2007-01-12 23:31:12 +000018#include "llvm/Type.h"
Chris Lattnerb0d21ef2006-03-08 04:25:59 +000019#include "llvm/CodeGen/ScheduleDAG.h"
Chris Lattner5839bf22005-08-26 17:15:30 +000020#include "llvm/CodeGen/MachineConstantPool.h"
Chris Lattner4ccd4062005-08-19 20:45:43 +000021#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000022#include "llvm/CodeGen/MachineRegisterInfo.h"
Owen Anderson07000c62006-05-12 06:33:49 +000023#include "llvm/Target/TargetData.h"
Chris Lattner2d973e42005-08-18 20:07:59 +000024#include "llvm/Target/TargetMachine.h"
25#include "llvm/Target/TargetInstrInfo.h"
Chris Lattner025c39b2005-08-26 20:54:47 +000026#include "llvm/Target/TargetLowering.h"
Evan Cheng643afa52008-02-28 07:40:24 +000027#include "llvm/ADT/Statistic.h"
Evan Chenge165a782006-05-11 23:55:42 +000028#include "llvm/Support/Debug.h"
Chris Lattner54a30b92006-03-20 01:51:46 +000029#include "llvm/Support/MathExtras.h"
Chris Lattnerd32b2362005-08-18 18:45:24 +000030using namespace llvm;
31
Evan Cheng643afa52008-02-28 07:40:24 +000032STATISTIC(NumCommutes, "Number of instructions commuted");
33
Chris Lattner84bc5422007-12-31 04:13:23 +000034ScheduleDAG::ScheduleDAG(SelectionDAG &dag, MachineBasicBlock *bb,
35 const TargetMachine &tm)
36 : DAG(dag), BB(bb), TM(tm), RegInfo(BB->getParent()->getRegInfo()) {
37 TII = TM.getInstrInfo();
Evan Cheng6b2cf282008-01-30 19:35:32 +000038 MF = &DAG.getMachineFunction();
Dan Gohman6f0d0242008-02-10 18:45:23 +000039 TRI = TM.getRegisterInfo();
Chris Lattner84bc5422007-12-31 04:13:23 +000040 ConstPool = BB->getParent()->getConstantPool();
41}
Evan Chenga6fb1b62007-09-25 01:54:36 +000042
Evan Chenga6fb1b62007-09-25 01:54:36 +000043/// CheckForPhysRegDependency - Check if the dependency between def and use of
44/// a specified operand is a physical register dependency. If so, returns the
45/// register and the cost of copying the register.
46static void CheckForPhysRegDependency(SDNode *Def, SDNode *Use, unsigned Op,
Dan Gohman6f0d0242008-02-10 18:45:23 +000047 const TargetRegisterInfo *TRI,
Evan Chenga6fb1b62007-09-25 01:54:36 +000048 const TargetInstrInfo *TII,
49 unsigned &PhysReg, int &Cost) {
50 if (Op != 2 || Use->getOpcode() != ISD::CopyToReg)
51 return;
52
53 unsigned Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
Dan Gohman6f0d0242008-02-10 18:45:23 +000054 if (TargetRegisterInfo::isVirtualRegister(Reg))
Evan Chenga6fb1b62007-09-25 01:54:36 +000055 return;
56
57 unsigned ResNo = Use->getOperand(2).ResNo;
58 if (Def->isTargetOpcode()) {
Chris Lattner749c6f62008-01-07 07:27:27 +000059 const TargetInstrDesc &II = TII->get(Def->getTargetOpcode());
Chris Lattner349c4952008-01-07 03:13:06 +000060 if (ResNo >= II.getNumDefs() &&
61 II.ImplicitDefs[ResNo - II.getNumDefs()] == Reg) {
Evan Chenga6fb1b62007-09-25 01:54:36 +000062 PhysReg = Reg;
63 const TargetRegisterClass *RC =
Dan Gohman6f0d0242008-02-10 18:45:23 +000064 TRI->getPhysicalRegisterRegClass(Def->getValueType(ResNo), Reg);
Evan Chenga6fb1b62007-09-25 01:54:36 +000065 Cost = RC->getCopyCost();
66 }
67 }
68}
69
70SUnit *ScheduleDAG::Clone(SUnit *Old) {
71 SUnit *SU = NewSUnit(Old->Node);
Dan Gohman45f36ea2008-03-10 23:48:14 +000072 SU->FlaggedNodes = Old->FlaggedNodes;
Evan Chenga6fb1b62007-09-25 01:54:36 +000073 SU->InstanceNo = SUnitMap[Old->Node].size();
74 SU->Latency = Old->Latency;
75 SU->isTwoAddress = Old->isTwoAddress;
76 SU->isCommutable = Old->isCommutable;
Evan Cheng22a52992007-09-28 22:32:30 +000077 SU->hasPhysRegDefs = Old->hasPhysRegDefs;
Evan Chenga6fb1b62007-09-25 01:54:36 +000078 SUnitMap[Old->Node].push_back(SU);
79 return SU;
80}
81
Evan Chengf10c9732007-10-05 01:39:18 +000082
Evan Chenge165a782006-05-11 23:55:42 +000083/// BuildSchedUnits - Build SUnits from the selection dag that we are input.
84/// This SUnit graph is similar to the SelectionDAG, but represents flagged
85/// together nodes with a single SUnit.
86void ScheduleDAG::BuildSchedUnits() {
87 // Reserve entries in the vector for each of the SUnits we are creating. This
88 // ensure that reallocation of the vector won't happen, so SUnit*'s won't get
89 // invalidated.
90 SUnits.reserve(std::distance(DAG.allnodes_begin(), DAG.allnodes_end()));
91
Evan Chenge165a782006-05-11 23:55:42 +000092 for (SelectionDAG::allnodes_iterator NI = DAG.allnodes_begin(),
93 E = DAG.allnodes_end(); NI != E; ++NI) {
94 if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate.
95 continue;
96
97 // If this node has already been processed, stop now.
Evan Chenga6fb1b62007-09-25 01:54:36 +000098 if (SUnitMap[NI].size()) continue;
Evan Chenge165a782006-05-11 23:55:42 +000099
100 SUnit *NodeSUnit = NewSUnit(NI);
101
102 // See if anything is flagged to this node, if so, add them to flagged
103 // nodes. Nodes can have at most one flag input and one flag output. Flags
104 // are required the be the last operand and result of a node.
105
106 // Scan up, adding flagged preds to FlaggedNodes.
107 SDNode *N = NI;
Evan Cheng3b97acd2006-08-07 22:12:12 +0000108 if (N->getNumOperands() &&
109 N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Flag) {
110 do {
111 N = N->getOperand(N->getNumOperands()-1).Val;
112 NodeSUnit->FlaggedNodes.push_back(N);
Evan Chenga6fb1b62007-09-25 01:54:36 +0000113 SUnitMap[N].push_back(NodeSUnit);
Evan Cheng3b97acd2006-08-07 22:12:12 +0000114 } while (N->getNumOperands() &&
115 N->getOperand(N->getNumOperands()-1).getValueType()== MVT::Flag);
116 std::reverse(NodeSUnit->FlaggedNodes.begin(),
117 NodeSUnit->FlaggedNodes.end());
Evan Chenge165a782006-05-11 23:55:42 +0000118 }
119
120 // Scan down, adding this node and any flagged succs to FlaggedNodes if they
121 // have a user of the flag operand.
122 N = NI;
123 while (N->getValueType(N->getNumValues()-1) == MVT::Flag) {
124 SDOperand FlagVal(N, N->getNumValues()-1);
125
126 // There are either zero or one users of the Flag result.
127 bool HasFlagUse = false;
128 for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end();
129 UI != E; ++UI)
Evan Cheng917be682008-03-04 00:41:45 +0000130 if (FlagVal.isOperandOf(*UI)) {
Evan Chenge165a782006-05-11 23:55:42 +0000131 HasFlagUse = true;
132 NodeSUnit->FlaggedNodes.push_back(N);
Evan Chenga6fb1b62007-09-25 01:54:36 +0000133 SUnitMap[N].push_back(NodeSUnit);
Evan Chenge165a782006-05-11 23:55:42 +0000134 N = *UI;
135 break;
136 }
Chris Lattner228a18e2006-08-17 00:09:56 +0000137 if (!HasFlagUse) break;
Evan Chenge165a782006-05-11 23:55:42 +0000138 }
139
140 // Now all flagged nodes are in FlaggedNodes and N is the bottom-most node.
141 // Update the SUnit
142 NodeSUnit->Node = N;
Evan Chenga6fb1b62007-09-25 01:54:36 +0000143 SUnitMap[N].push_back(NodeSUnit);
Evan Chengf10c9732007-10-05 01:39:18 +0000144
145 ComputeLatency(NodeSUnit);
Evan Chenge165a782006-05-11 23:55:42 +0000146 }
147
148 // Pass 2: add the preds, succs, etc.
149 for (unsigned su = 0, e = SUnits.size(); su != e; ++su) {
150 SUnit *SU = &SUnits[su];
151 SDNode *MainNode = SU->Node;
152
153 if (MainNode->isTargetOpcode()) {
154 unsigned Opc = MainNode->getTargetOpcode();
Chris Lattner749c6f62008-01-07 07:27:27 +0000155 const TargetInstrDesc &TID = TII->get(Opc);
Chris Lattner349c4952008-01-07 03:13:06 +0000156 for (unsigned i = 0; i != TID.getNumOperands(); ++i) {
Evan Chenga6fb1b62007-09-25 01:54:36 +0000157 if (TID.getOperandConstraint(i, TOI::TIED_TO) != -1) {
Evan Cheng95f6ede2006-11-04 09:44:31 +0000158 SU->isTwoAddress = true;
159 break;
160 }
161 }
Chris Lattner0ff23962008-01-07 06:42:05 +0000162 if (TID.isCommutable())
Evan Cheng13d41b92006-05-12 01:58:24 +0000163 SU->isCommutable = true;
Evan Chenge165a782006-05-11 23:55:42 +0000164 }
165
166 // Find all predecessors and successors of the group.
167 // Temporarily add N to make code simpler.
168 SU->FlaggedNodes.push_back(MainNode);
169
170 for (unsigned n = 0, e = SU->FlaggedNodes.size(); n != e; ++n) {
171 SDNode *N = SU->FlaggedNodes[n];
Evan Cheng22a52992007-09-28 22:32:30 +0000172 if (N->isTargetOpcode() &&
Chris Lattner349c4952008-01-07 03:13:06 +0000173 TII->get(N->getTargetOpcode()).getImplicitDefs() &&
174 CountResults(N) > TII->get(N->getTargetOpcode()).getNumDefs())
Evan Cheng22a52992007-09-28 22:32:30 +0000175 SU->hasPhysRegDefs = true;
Evan Chenge165a782006-05-11 23:55:42 +0000176
177 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
178 SDNode *OpN = N->getOperand(i).Val;
179 if (isPassiveNode(OpN)) continue; // Not scheduled.
Evan Chenga6fb1b62007-09-25 01:54:36 +0000180 SUnit *OpSU = SUnitMap[OpN].front();
Evan Chenge165a782006-05-11 23:55:42 +0000181 assert(OpSU && "Node has no SUnit!");
182 if (OpSU == SU) continue; // In the same group.
183
184 MVT::ValueType OpVT = N->getOperand(i).getValueType();
185 assert(OpVT != MVT::Flag && "Flagged nodes should be in same sunit!");
186 bool isChain = OpVT == MVT::Other;
Evan Chenga6fb1b62007-09-25 01:54:36 +0000187
188 unsigned PhysReg = 0;
189 int Cost = 1;
190 // Determine if this is a physical register dependency.
Dan Gohman6f0d0242008-02-10 18:45:23 +0000191 CheckForPhysRegDependency(OpN, N, i, TRI, TII, PhysReg, Cost);
Evan Chenga6fb1b62007-09-25 01:54:36 +0000192 SU->addPred(OpSU, isChain, false, PhysReg, Cost);
Evan Chenge165a782006-05-11 23:55:42 +0000193 }
194 }
195
196 // Remove MainNode from FlaggedNodes again.
197 SU->FlaggedNodes.pop_back();
198 }
199
200 return;
201}
202
Evan Chengf10c9732007-10-05 01:39:18 +0000203void ScheduleDAG::ComputeLatency(SUnit *SU) {
204 const InstrItineraryData &InstrItins = TM.getInstrItineraryData();
205
206 // Compute the latency for the node. We use the sum of the latencies for
207 // all nodes flagged together into this SUnit.
208 if (InstrItins.isEmpty()) {
209 // No latency information.
210 SU->Latency = 1;
211 } else {
212 SU->Latency = 0;
213 if (SU->Node->isTargetOpcode()) {
Chris Lattnerba6da5d2008-01-07 02:46:03 +0000214 unsigned SchedClass =
215 TII->get(SU->Node->getTargetOpcode()).getSchedClass();
Evan Chengf10c9732007-10-05 01:39:18 +0000216 InstrStage *S = InstrItins.begin(SchedClass);
217 InstrStage *E = InstrItins.end(SchedClass);
218 for (; S != E; ++S)
219 SU->Latency += S->Cycles;
220 }
221 for (unsigned i = 0, e = SU->FlaggedNodes.size(); i != e; ++i) {
222 SDNode *FNode = SU->FlaggedNodes[i];
223 if (FNode->isTargetOpcode()) {
Chris Lattnerba6da5d2008-01-07 02:46:03 +0000224 unsigned SchedClass =TII->get(FNode->getTargetOpcode()).getSchedClass();
Evan Chengf10c9732007-10-05 01:39:18 +0000225 InstrStage *S = InstrItins.begin(SchedClass);
226 InstrStage *E = InstrItins.end(SchedClass);
227 for (; S != E; ++S)
228 SU->Latency += S->Cycles;
229 }
230 }
231 }
232}
233
Roman Levensteind86449e2008-03-04 11:19:43 +0000234/// CalculateDepths - compute depths using algorithms for the longest
235/// paths in the DAG
Evan Chenge165a782006-05-11 23:55:42 +0000236void ScheduleDAG::CalculateDepths() {
Roman Levensteind86449e2008-03-04 11:19:43 +0000237 unsigned DAGSize = SUnits.size();
238 std::vector<unsigned> InDegree(DAGSize);
239 std::vector<SUnit*> WorkList;
240 WorkList.reserve(DAGSize);
Evan Chenge165a782006-05-11 23:55:42 +0000241
Roman Levensteind86449e2008-03-04 11:19:43 +0000242 // Initialize the data structures
243 for (unsigned i = 0, e = DAGSize; i != e; ++i) {
244 SUnit *SU = &SUnits[i];
245 int NodeNum = SU->NodeNum;
246 unsigned Degree = SU->Preds.size();
247 InDegree[NodeNum] = Degree;
248 SU->Depth = 0;
249
250 // Is it a node without dependencies?
251 if (Degree == 0) {
252 assert(SU->Preds.empty() && "SUnit should have no predecessors");
253 // Collect leaf nodes
254 WorkList.push_back(SU);
255 }
256 }
257
258 // Process nodes in the topological order
Evan Cheng99126282007-07-06 01:37:28 +0000259 while (!WorkList.empty()) {
Roman Levensteind86449e2008-03-04 11:19:43 +0000260 SUnit *SU = WorkList.back();
Evan Cheng99126282007-07-06 01:37:28 +0000261 WorkList.pop_back();
Roman Levensteind86449e2008-03-04 11:19:43 +0000262 unsigned &SUDepth = SU->Depth;
263
264 // Use dynamic programming:
265 // When current node is being processed, all of its dependencies
266 // are already processed.
267 // So, just iterate over all predecessors and take the longest path
268 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
269 I != E; ++I) {
270 unsigned PredDepth = I->Dep->Depth;
271 if (PredDepth+1 > SUDepth) {
272 SUDepth = PredDepth + 1;
273 }
274 }
275
276 // Update InDegrees of all nodes depending on current SUnit
277 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
278 I != E; ++I) {
279 SUnit *SU = I->Dep;
280 if (!--InDegree[SU->NodeNum])
281 // If all dependencies of the node are processed already,
282 // then the longest path for the node can be computed now
283 WorkList.push_back(SU);
Evan Cheng99126282007-07-06 01:37:28 +0000284 }
Evan Cheng626da3d2006-05-12 06:05:18 +0000285 }
Evan Chenge165a782006-05-11 23:55:42 +0000286}
Evan Cheng99126282007-07-06 01:37:28 +0000287
Roman Levensteind86449e2008-03-04 11:19:43 +0000288/// CalculateHeights - compute heights using algorithms for the longest
289/// paths in the DAG
Evan Chenge165a782006-05-11 23:55:42 +0000290void ScheduleDAG::CalculateHeights() {
Roman Levensteind86449e2008-03-04 11:19:43 +0000291 unsigned DAGSize = SUnits.size();
292 std::vector<unsigned> InDegree(DAGSize);
293 std::vector<SUnit*> WorkList;
294 WorkList.reserve(DAGSize);
Evan Cheng99126282007-07-06 01:37:28 +0000295
Roman Levensteind86449e2008-03-04 11:19:43 +0000296 // Initialize the data structures
297 for (unsigned i = 0, e = DAGSize; i != e; ++i) {
298 SUnit *SU = &SUnits[i];
299 int NodeNum = SU->NodeNum;
300 unsigned Degree = SU->Succs.size();
301 InDegree[NodeNum] = Degree;
302 SU->Height = 0;
303
304 // Is it a node without dependencies?
305 if (Degree == 0) {
306 assert(SU->Succs.empty() && "Something wrong");
307 assert(WorkList.empty() && "Should be empty");
308 // Collect leaf nodes
309 WorkList.push_back(SU);
310 }
311 }
312
313 // Process nodes in the topological order
Evan Cheng99126282007-07-06 01:37:28 +0000314 while (!WorkList.empty()) {
Roman Levensteind86449e2008-03-04 11:19:43 +0000315 SUnit *SU = WorkList.back();
Evan Cheng99126282007-07-06 01:37:28 +0000316 WorkList.pop_back();
Roman Levensteind86449e2008-03-04 11:19:43 +0000317 unsigned &SUHeight = SU->Height;
318
319 // Use dynamic programming:
320 // When current node is being processed, all of its dependencies
321 // are already processed.
322 // So, just iterate over all successors and take the longest path
323 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
324 I != E; ++I) {
325 unsigned SuccHeight = I->Dep->Height;
326 if (SuccHeight+1 > SUHeight) {
327 SUHeight = SuccHeight + 1;
328 }
329 }
330
331 // Update InDegrees of all nodes depending on current SUnit
332 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
333 I != E; ++I) {
334 SUnit *SU = I->Dep;
335 if (!--InDegree[SU->NodeNum])
336 // If all dependencies of the node are processed already,
337 // then the longest path for the node can be computed now
338 WorkList.push_back(SU);
Evan Cheng99126282007-07-06 01:37:28 +0000339 }
340 }
Evan Chenge165a782006-05-11 23:55:42 +0000341}
342
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000343/// CountResults - The results of target nodes have register or immediate
344/// operands first, then an optional chain, and optional flag operands (which do
Dan Gohman027ee7e2008-02-11 19:00:03 +0000345/// not go into the resulting MachineInstr).
Evan Cheng95f6ede2006-11-04 09:44:31 +0000346unsigned ScheduleDAG::CountResults(SDNode *Node) {
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000347 unsigned N = Node->getNumValues();
348 while (N && Node->getValueType(N - 1) == MVT::Flag)
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000349 --N;
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000350 if (N && Node->getValueType(N - 1) == MVT::Other)
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000351 --N; // Skip over chain result.
352 return N;
353}
354
Dan Gohman69de1932008-02-06 22:27:42 +0000355/// CountOperands - The inputs to target nodes have any actual inputs first,
Dan Gohman42a77882008-02-16 00:36:48 +0000356/// followed by special operands that describe memory references, then an
357/// optional chain operand, then flag operands. Compute the number of
358/// actual operands that will go into the resulting MachineInstr.
Evan Cheng95f6ede2006-11-04 09:44:31 +0000359unsigned ScheduleDAG::CountOperands(SDNode *Node) {
Dan Gohman42a77882008-02-16 00:36:48 +0000360 unsigned N = ComputeMemOperandsEnd(Node);
Dan Gohmancc20cd52008-02-11 19:00:34 +0000361 while (N && isa<MemOperandSDNode>(Node->getOperand(N - 1).Val))
Dan Gohman69de1932008-02-06 22:27:42 +0000362 --N; // Ignore MemOperand nodes
363 return N;
364}
365
Dan Gohman42a77882008-02-16 00:36:48 +0000366/// ComputeMemOperandsEnd - Find the index one past the last MemOperandSDNode
367/// operand
368unsigned ScheduleDAG::ComputeMemOperandsEnd(SDNode *Node) {
Dan Gohman69de1932008-02-06 22:27:42 +0000369 unsigned N = Node->getNumOperands();
370 while (N && Node->getOperand(N - 1).getValueType() == MVT::Flag)
371 --N;
372 if (N && Node->getOperand(N - 1).getValueType() == MVT::Other)
373 --N; // Ignore chain if it exists.
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000374 return N;
375}
376
Jim Laskey60f09922006-07-21 20:57:35 +0000377static const TargetRegisterClass *getInstrOperandRegClass(
Dan Gohman6f0d0242008-02-10 18:45:23 +0000378 const TargetRegisterInfo *TRI,
Jim Laskey60f09922006-07-21 20:57:35 +0000379 const TargetInstrInfo *TII,
Chris Lattner749c6f62008-01-07 07:27:27 +0000380 const TargetInstrDesc &II,
Jim Laskey60f09922006-07-21 20:57:35 +0000381 unsigned Op) {
Chris Lattner749c6f62008-01-07 07:27:27 +0000382 if (Op >= II.getNumOperands()) {
383 assert(II.isVariadic() && "Invalid operand # of instruction");
Jim Laskey60f09922006-07-21 20:57:35 +0000384 return NULL;
385 }
Chris Lattner749c6f62008-01-07 07:27:27 +0000386 if (II.OpInfo[Op].isLookupPtrRegClass())
Chris Lattner8ca5c672008-01-07 02:39:19 +0000387 return TII->getPointerRegClass();
Dan Gohman6f0d0242008-02-10 18:45:23 +0000388 return TRI->getRegClass(II.OpInfo[Op].RegClass);
Jim Laskey60f09922006-07-21 20:57:35 +0000389}
390
Evan Chenga6fb1b62007-09-25 01:54:36 +0000391void ScheduleDAG::EmitCopyFromReg(SDNode *Node, unsigned ResNo,
392 unsigned InstanceNo, unsigned SrcReg,
Evan Cheng84097472007-08-02 00:28:15 +0000393 DenseMap<SDOperand, unsigned> &VRBaseMap) {
394 unsigned VRBase = 0;
Dan Gohman6f0d0242008-02-10 18:45:23 +0000395 if (TargetRegisterInfo::isVirtualRegister(SrcReg)) {
Evan Cheng84097472007-08-02 00:28:15 +0000396 // Just use the input register directly!
Evan Chenga6fb1b62007-09-25 01:54:36 +0000397 if (InstanceNo > 0)
398 VRBaseMap.erase(SDOperand(Node, ResNo));
Evan Cheng84097472007-08-02 00:28:15 +0000399 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,ResNo),SrcReg));
400 assert(isNew && "Node emitted out of order - early");
401 return;
402 }
403
404 // If the node is only used by a CopyToReg and the dest reg is a vreg, use
405 // the CopyToReg'd destination register instead of creating a new vreg.
Evan Chenga6fb1b62007-09-25 01:54:36 +0000406 bool MatchReg = true;
Evan Cheng84097472007-08-02 00:28:15 +0000407 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
408 UI != E; ++UI) {
409 SDNode *Use = *UI;
Evan Chenga6fb1b62007-09-25 01:54:36 +0000410 bool Match = true;
Evan Cheng84097472007-08-02 00:28:15 +0000411 if (Use->getOpcode() == ISD::CopyToReg &&
412 Use->getOperand(2).Val == Node &&
413 Use->getOperand(2).ResNo == ResNo) {
414 unsigned DestReg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
Dan Gohman6f0d0242008-02-10 18:45:23 +0000415 if (TargetRegisterInfo::isVirtualRegister(DestReg)) {
Evan Cheng84097472007-08-02 00:28:15 +0000416 VRBase = DestReg;
Evan Chenga6fb1b62007-09-25 01:54:36 +0000417 Match = false;
418 } else if (DestReg != SrcReg)
419 Match = false;
420 } else {
421 for (unsigned i = 0, e = Use->getNumOperands(); i != e; ++i) {
422 SDOperand Op = Use->getOperand(i);
Evan Cheng7c07aeb2007-12-14 08:25:15 +0000423 if (Op.Val != Node || Op.ResNo != ResNo)
Evan Chenga6fb1b62007-09-25 01:54:36 +0000424 continue;
425 MVT::ValueType VT = Node->getValueType(Op.ResNo);
426 if (VT != MVT::Other && VT != MVT::Flag)
427 Match = false;
Evan Cheng84097472007-08-02 00:28:15 +0000428 }
429 }
Evan Chenga6fb1b62007-09-25 01:54:36 +0000430 MatchReg &= Match;
431 if (VRBase)
432 break;
Evan Cheng84097472007-08-02 00:28:15 +0000433 }
434
Chris Lattner02b6d252008-03-09 08:49:15 +0000435 const TargetRegisterClass *SrcRC = 0, *DstRC = 0;
436 SrcRC = TRI->getPhysicalRegisterRegClass(Node->getValueType(ResNo), SrcReg);
437
Evan Chenga6fb1b62007-09-25 01:54:36 +0000438 // Figure out the register class to create for the destreg.
Chris Lattner02b6d252008-03-09 08:49:15 +0000439 if (VRBase) {
440 DstRC = RegInfo.getRegClass(VRBase);
441 } else {
442 DstRC = DAG.getTargetLoweringInfo()
443 .getRegClassFor(Node->getValueType(ResNo));
444 }
Evan Chenga6fb1b62007-09-25 01:54:36 +0000445
446 // If all uses are reading from the src physical register and copying the
447 // register is either impossible or very expensive, then don't create a copy.
Chris Lattner02b6d252008-03-09 08:49:15 +0000448 if (MatchReg && SrcRC->getCopyCost() < 0) {
Evan Chenga6fb1b62007-09-25 01:54:36 +0000449 VRBase = SrcReg;
450 } else {
Evan Cheng84097472007-08-02 00:28:15 +0000451 // Create the reg, emit the copy.
Chris Lattner02b6d252008-03-09 08:49:15 +0000452 VRBase = RegInfo.createVirtualRegister(DstRC);
453 TII->copyRegToReg(*BB, BB->end(), VRBase, SrcReg, DstRC, SrcRC);
Evan Cheng84097472007-08-02 00:28:15 +0000454 }
Evan Cheng84097472007-08-02 00:28:15 +0000455
Evan Chenga6fb1b62007-09-25 01:54:36 +0000456 if (InstanceNo > 0)
457 VRBaseMap.erase(SDOperand(Node, ResNo));
Evan Cheng84097472007-08-02 00:28:15 +0000458 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,ResNo), VRBase));
459 assert(isNew && "Node emitted out of order - early");
460}
461
462void ScheduleDAG::CreateVirtualRegisters(SDNode *Node,
463 MachineInstr *MI,
Chris Lattner749c6f62008-01-07 07:27:27 +0000464 const TargetInstrDesc &II,
Evan Cheng84097472007-08-02 00:28:15 +0000465 DenseMap<SDOperand, unsigned> &VRBaseMap) {
Chris Lattner349c4952008-01-07 03:13:06 +0000466 for (unsigned i = 0; i < II.getNumDefs(); ++i) {
Evan Chengaf825c82007-07-10 07:08:32 +0000467 // If the specific node value is only used by a CopyToReg and the dest reg
468 // is a vreg, use the CopyToReg'd destination register instead of creating
469 // a new vreg.
470 unsigned VRBase = 0;
471 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
472 UI != E; ++UI) {
473 SDNode *Use = *UI;
474 if (Use->getOpcode() == ISD::CopyToReg &&
475 Use->getOperand(2).Val == Node &&
476 Use->getOperand(2).ResNo == i) {
477 unsigned Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
Dan Gohman6f0d0242008-02-10 18:45:23 +0000478 if (TargetRegisterInfo::isVirtualRegister(Reg)) {
Evan Chengaf825c82007-07-10 07:08:32 +0000479 VRBase = Reg;
Chris Lattner8019f412007-12-30 00:41:17 +0000480 MI->addOperand(MachineOperand::CreateReg(Reg, true));
Evan Chengaf825c82007-07-10 07:08:32 +0000481 break;
482 }
483 }
484 }
485
Evan Cheng84097472007-08-02 00:28:15 +0000486 // Create the result registers for this node and add the result regs to
487 // the machine instruction.
Evan Chengaf825c82007-07-10 07:08:32 +0000488 if (VRBase == 0) {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000489 const TargetRegisterClass *RC = getInstrOperandRegClass(TRI, TII, II, i);
Evan Chengaf825c82007-07-10 07:08:32 +0000490 assert(RC && "Isn't a register operand!");
Chris Lattner84bc5422007-12-31 04:13:23 +0000491 VRBase = RegInfo.createVirtualRegister(RC);
Chris Lattner8019f412007-12-30 00:41:17 +0000492 MI->addOperand(MachineOperand::CreateReg(VRBase, true));
Evan Chengaf825c82007-07-10 07:08:32 +0000493 }
494
495 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,i), VRBase));
496 assert(isNew && "Node emitted out of order - early");
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000497 }
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000498}
499
Chris Lattnerdf375062006-03-10 07:25:12 +0000500/// getVR - Return the virtual register corresponding to the specified result
501/// of the specified node.
Evan Chengaf825c82007-07-10 07:08:32 +0000502static unsigned getVR(SDOperand Op, DenseMap<SDOperand, unsigned> &VRBaseMap) {
503 DenseMap<SDOperand, unsigned>::iterator I = VRBaseMap.find(Op);
Chris Lattnerdf375062006-03-10 07:25:12 +0000504 assert(I != VRBaseMap.end() && "Node emitted out of order - late");
Evan Chengaf825c82007-07-10 07:08:32 +0000505 return I->second;
Chris Lattnerdf375062006-03-10 07:25:12 +0000506}
507
508
Chris Lattnered18b682006-02-24 18:54:03 +0000509/// AddOperand - Add the specified operand to the specified machine instr. II
510/// specifies the instruction information for the node, and IIOpNum is the
511/// operand number (in the II) that we are adding. IIOpNum and II are used for
512/// assertions only.
513void ScheduleDAG::AddOperand(MachineInstr *MI, SDOperand Op,
514 unsigned IIOpNum,
Chris Lattner749c6f62008-01-07 07:27:27 +0000515 const TargetInstrDesc *II,
Evan Chengaf825c82007-07-10 07:08:32 +0000516 DenseMap<SDOperand, unsigned> &VRBaseMap) {
Chris Lattnered18b682006-02-24 18:54:03 +0000517 if (Op.isTargetOpcode()) {
518 // Note that this case is redundant with the final else block, but we
519 // include it because it is the most common and it makes the logic
520 // simpler here.
521 assert(Op.getValueType() != MVT::Other &&
522 Op.getValueType() != MVT::Flag &&
523 "Chain and flag operands should occur at end of operand list!");
524
525 // Get/emit the operand.
Chris Lattnerdf375062006-03-10 07:25:12 +0000526 unsigned VReg = getVR(Op, VRBaseMap);
Chris Lattner749c6f62008-01-07 07:27:27 +0000527 const TargetInstrDesc &TID = MI->getDesc();
528 bool isOptDef = (IIOpNum < TID.getNumOperands())
529 ? (TID.OpInfo[IIOpNum].isOptionalDef()) : false;
Chris Lattner8019f412007-12-30 00:41:17 +0000530 MI->addOperand(MachineOperand::CreateReg(VReg, isOptDef));
Chris Lattnered18b682006-02-24 18:54:03 +0000531
532 // Verify that it is right.
Dan Gohman6f0d0242008-02-10 18:45:23 +0000533 assert(TargetRegisterInfo::isVirtualRegister(VReg) && "Not a vreg?");
Chris Lattnered18b682006-02-24 18:54:03 +0000534 if (II) {
Jim Laskey60f09922006-07-21 20:57:35 +0000535 const TargetRegisterClass *RC =
Dan Gohman6f0d0242008-02-10 18:45:23 +0000536 getInstrOperandRegClass(TRI, TII, *II, IIOpNum);
Evan Cheng21d03f22006-05-18 20:42:07 +0000537 assert(RC && "Don't have operand info for this instruction!");
Chris Lattner84bc5422007-12-31 04:13:23 +0000538 const TargetRegisterClass *VRC = RegInfo.getRegClass(VReg);
Chris Lattner01528292007-02-15 18:17:56 +0000539 if (VRC != RC) {
540 cerr << "Register class of operand and regclass of use don't agree!\n";
541#ifndef NDEBUG
542 cerr << "Operand = " << IIOpNum << "\n";
Chris Lattner95ad9432007-02-17 06:38:37 +0000543 cerr << "Op->Val = "; Op.Val->dump(&DAG); cerr << "\n";
Chris Lattner01528292007-02-15 18:17:56 +0000544 cerr << "MI = "; MI->print(cerr);
545 cerr << "VReg = " << VReg << "\n";
546 cerr << "VReg RegClass size = " << VRC->getSize()
Chris Lattner5d4a9f72007-02-15 18:19:15 +0000547 << ", align = " << VRC->getAlignment() << "\n";
Chris Lattner01528292007-02-15 18:17:56 +0000548 cerr << "Expected RegClass size = " << RC->getSize()
Chris Lattner5d4a9f72007-02-15 18:19:15 +0000549 << ", align = " << RC->getAlignment() << "\n";
Chris Lattner01528292007-02-15 18:17:56 +0000550#endif
551 cerr << "Fatal error, aborting.\n";
552 abort();
553 }
Chris Lattnered18b682006-02-24 18:54:03 +0000554 }
Chris Lattnerfec65d52007-12-30 00:51:11 +0000555 } else if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
Chris Lattner8019f412007-12-30 00:41:17 +0000556 MI->addOperand(MachineOperand::CreateImm(C->getValue()));
Nate Begemane1795842008-02-14 08:57:00 +0000557 } else if (ConstantFPSDNode *F = dyn_cast<ConstantFPSDNode>(Op)) {
558 const Type *FType = MVT::getTypeForValueType(Op.getValueType());
559 ConstantFP *CFP = ConstantFP::get(FType, F->getValueAPF());
560 MI->addOperand(MachineOperand::CreateFPImm(CFP));
Chris Lattnerfec65d52007-12-30 00:51:11 +0000561 } else if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(Op)) {
Chris Lattner8019f412007-12-30 00:41:17 +0000562 MI->addOperand(MachineOperand::CreateReg(R->getReg(), false));
Chris Lattnerfec65d52007-12-30 00:51:11 +0000563 } else if (GlobalAddressSDNode *TGA = dyn_cast<GlobalAddressSDNode>(Op)) {
564 MI->addOperand(MachineOperand::CreateGA(TGA->getGlobal(),TGA->getOffset()));
565 } else if (BasicBlockSDNode *BB = dyn_cast<BasicBlockSDNode>(Op)) {
566 MI->addOperand(MachineOperand::CreateMBB(BB->getBasicBlock()));
567 } else if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Op)) {
568 MI->addOperand(MachineOperand::CreateFI(FI->getIndex()));
569 } else if (JumpTableSDNode *JT = dyn_cast<JumpTableSDNode>(Op)) {
570 MI->addOperand(MachineOperand::CreateJTI(JT->getIndex()));
571 } else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Op)) {
Evan Cheng404cb4f2006-02-25 09:54:52 +0000572 int Offset = CP->getOffset();
Chris Lattnered18b682006-02-24 18:54:03 +0000573 unsigned Align = CP->getAlignment();
Evan Chengd6594ae2006-09-12 21:00:35 +0000574 const Type *Type = CP->getType();
Chris Lattnered18b682006-02-24 18:54:03 +0000575 // MachineConstantPool wants an explicit alignment.
576 if (Align == 0) {
Evan Chengde268f72007-01-24 07:03:39 +0000577 Align = TM.getTargetData()->getPreferredTypeAlignmentShift(Type);
Evan Chengf6d039a2007-01-22 23:13:55 +0000578 if (Align == 0) {
Reid Spencerac9dcb92007-02-15 03:39:18 +0000579 // Alignment of vector types. FIXME!
Duncan Sands514ab342007-11-01 20:53:16 +0000580 Align = TM.getTargetData()->getABITypeSize(Type);
Evan Chengf6d039a2007-01-22 23:13:55 +0000581 Align = Log2_64(Align);
Chris Lattner54a30b92006-03-20 01:51:46 +0000582 }
Chris Lattnered18b682006-02-24 18:54:03 +0000583 }
584
Evan Chengd6594ae2006-09-12 21:00:35 +0000585 unsigned Idx;
586 if (CP->isMachineConstantPoolEntry())
587 Idx = ConstPool->getConstantPoolIndex(CP->getMachineCPVal(), Align);
588 else
589 Idx = ConstPool->getConstantPoolIndex(CP->getConstVal(), Align);
Chris Lattnerfec65d52007-12-30 00:51:11 +0000590 MI->addOperand(MachineOperand::CreateCPI(Idx, Offset));
591 } else if (ExternalSymbolSDNode *ES = dyn_cast<ExternalSymbolSDNode>(Op)) {
592 MI->addOperand(MachineOperand::CreateES(ES->getSymbol()));
Chris Lattnered18b682006-02-24 18:54:03 +0000593 } else {
594 assert(Op.getValueType() != MVT::Other &&
595 Op.getValueType() != MVT::Flag &&
596 "Chain and flag operands should occur at end of operand list!");
Chris Lattnerdf375062006-03-10 07:25:12 +0000597 unsigned VReg = getVR(Op, VRBaseMap);
Chris Lattner8019f412007-12-30 00:41:17 +0000598 MI->addOperand(MachineOperand::CreateReg(VReg, false));
Chris Lattnered18b682006-02-24 18:54:03 +0000599
Chris Lattner02b6d252008-03-09 08:49:15 +0000600 // Verify that it is right. Note that the reg class of the physreg and the
601 // vreg don't necessarily need to match, but the target copy insertion has
602 // to be able to handle it. This handles things like copies from ST(0) to
603 // an FP vreg on x86.
Dan Gohman6f0d0242008-02-10 18:45:23 +0000604 assert(TargetRegisterInfo::isVirtualRegister(VReg) && "Not a vreg?");
Chris Lattnered18b682006-02-24 18:54:03 +0000605 if (II) {
Chris Lattner02b6d252008-03-09 08:49:15 +0000606 assert(getInstrOperandRegClass(TRI, TII, *II, IIOpNum) &&
607 "Don't have operand info for this instruction!");
Chris Lattnered18b682006-02-24 18:54:03 +0000608 }
609 }
610
611}
612
Dan Gohman69de1932008-02-06 22:27:42 +0000613void ScheduleDAG::AddMemOperand(MachineInstr *MI, const MemOperand &MO) {
614 MI->addMemOperand(MO);
615}
616
Christopher Lambe24f8f12007-07-26 08:12:07 +0000617// Returns the Register Class of a subregister
618static const TargetRegisterClass *getSubRegisterRegClass(
619 const TargetRegisterClass *TRC,
620 unsigned SubIdx) {
621 // Pick the register class of the subregister
Dan Gohman6f0d0242008-02-10 18:45:23 +0000622 TargetRegisterInfo::regclass_iterator I =
623 TRC->subregclasses_begin() + SubIdx-1;
Christopher Lambe24f8f12007-07-26 08:12:07 +0000624 assert(I < TRC->subregclasses_end() &&
625 "Invalid subregister index for register class");
626 return *I;
627}
628
629static const TargetRegisterClass *getSuperregRegisterClass(
630 const TargetRegisterClass *TRC,
631 unsigned SubIdx,
632 MVT::ValueType VT) {
633 // Pick the register class of the superegister for this type
Dan Gohman6f0d0242008-02-10 18:45:23 +0000634 for (TargetRegisterInfo::regclass_iterator I = TRC->superregclasses_begin(),
Christopher Lambe24f8f12007-07-26 08:12:07 +0000635 E = TRC->superregclasses_end(); I != E; ++I)
636 if ((*I)->hasType(VT) && getSubRegisterRegClass(*I, SubIdx) == TRC)
637 return *I;
638 assert(false && "Couldn't find the register class");
639 return 0;
640}
641
642/// EmitSubregNode - Generate machine code for subreg nodes.
643///
644void ScheduleDAG::EmitSubregNode(SDNode *Node,
645 DenseMap<SDOperand, unsigned> &VRBaseMap) {
646 unsigned VRBase = 0;
647 unsigned Opc = Node->getTargetOpcode();
648 if (Opc == TargetInstrInfo::EXTRACT_SUBREG) {
649 // If the node is only used by a CopyToReg and the dest reg is a vreg, use
650 // the CopyToReg'd destination register instead of creating a new vreg.
651 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
652 UI != E; ++UI) {
653 SDNode *Use = *UI;
654 if (Use->getOpcode() == ISD::CopyToReg &&
655 Use->getOperand(2).Val == Node) {
656 unsigned DestReg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
Dan Gohman6f0d0242008-02-10 18:45:23 +0000657 if (TargetRegisterInfo::isVirtualRegister(DestReg)) {
Christopher Lambe24f8f12007-07-26 08:12:07 +0000658 VRBase = DestReg;
659 break;
660 }
661 }
662 }
663
664 unsigned SubIdx = cast<ConstantSDNode>(Node->getOperand(1))->getValue();
665
666 // TODO: If the node is a use of a CopyFromReg from a physical register
667 // fold the extract into the copy now
668
Christopher Lambe24f8f12007-07-26 08:12:07 +0000669 // Create the extract_subreg machine instruction.
670 MachineInstr *MI =
671 new MachineInstr(BB, TII->get(TargetInstrInfo::EXTRACT_SUBREG));
672
673 // Figure out the register class to create for the destreg.
674 unsigned VReg = getVR(Node->getOperand(0), VRBaseMap);
Chris Lattner84bc5422007-12-31 04:13:23 +0000675 const TargetRegisterClass *TRC = RegInfo.getRegClass(VReg);
Christopher Lambe24f8f12007-07-26 08:12:07 +0000676 const TargetRegisterClass *SRC = getSubRegisterRegClass(TRC, SubIdx);
677
678 if (VRBase) {
679 // Grab the destination register
Chris Lattner02b6d252008-03-09 08:49:15 +0000680 const TargetRegisterClass *DRC = RegInfo.getRegClass(VRBase);
Christopher Lamb175e8152008-01-31 07:09:08 +0000681 assert(SRC && DRC && SRC == DRC &&
Christopher Lambe24f8f12007-07-26 08:12:07 +0000682 "Source subregister and destination must have the same class");
683 } else {
684 // Create the reg
Christopher Lamb175e8152008-01-31 07:09:08 +0000685 assert(SRC && "Couldn't find source register class");
Chris Lattner84bc5422007-12-31 04:13:23 +0000686 VRBase = RegInfo.createVirtualRegister(SRC);
Christopher Lambe24f8f12007-07-26 08:12:07 +0000687 }
688
689 // Add def, source, and subreg index
Chris Lattner8019f412007-12-30 00:41:17 +0000690 MI->addOperand(MachineOperand::CreateReg(VRBase, true));
Christopher Lambe24f8f12007-07-26 08:12:07 +0000691 AddOperand(MI, Node->getOperand(0), 0, 0, VRBaseMap);
Chris Lattnerfec65d52007-12-30 00:51:11 +0000692 MI->addOperand(MachineOperand::CreateImm(SubIdx));
Christopher Lambe24f8f12007-07-26 08:12:07 +0000693
694 } else if (Opc == TargetInstrInfo::INSERT_SUBREG) {
Evan Cheng4499e492008-03-10 19:31:26 +0000695 assert((Node->getNumOperands() == 2 || Node->getNumOperands() == 3) &&
Christopher Lambe24f8f12007-07-26 08:12:07 +0000696 "Malformed insert_subreg node");
Evan Cheng4499e492008-03-10 19:31:26 +0000697 bool isUndefInput = (Node->getNumOperands() == 2);
698 unsigned SubReg = 0;
699 unsigned SubIdx = 0;
700
701 if (isUndefInput) {
702 SubReg = getVR(Node->getOperand(0), VRBaseMap);
703 SubIdx = cast<ConstantSDNode>(Node->getOperand(1))->getValue();
704 } else {
705 SubReg = getVR(Node->getOperand(1), VRBaseMap);
706 SubIdx = cast<ConstantSDNode>(Node->getOperand(2))->getValue();
707 }
Christopher Lambe24f8f12007-07-26 08:12:07 +0000708
Chris Lattner534bcfb2007-12-31 04:16:08 +0000709 // TODO: Add tracking info to MachineRegisterInfo of which vregs are subregs
Christopher Lambe24f8f12007-07-26 08:12:07 +0000710 // to allow coalescing in the allocator
711
712 // If the node is only used by a CopyToReg and the dest reg is a vreg, use
713 // the CopyToReg'd destination register instead of creating a new vreg.
714 // If the CopyToReg'd destination register is physical, then fold the
715 // insert into the copy
716 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
717 UI != E; ++UI) {
718 SDNode *Use = *UI;
719 if (Use->getOpcode() == ISD::CopyToReg &&
720 Use->getOperand(2).Val == Node) {
721 unsigned DestReg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
Dan Gohman6f0d0242008-02-10 18:45:23 +0000722 if (TargetRegisterInfo::isVirtualRegister(DestReg)) {
Christopher Lambe24f8f12007-07-26 08:12:07 +0000723 VRBase = DestReg;
724 break;
725 }
726 }
727 }
728
729 // Create the insert_subreg machine instruction.
730 MachineInstr *MI =
731 new MachineInstr(BB, TII->get(TargetInstrInfo::INSERT_SUBREG));
732
733 // Figure out the register class to create for the destreg.
734 const TargetRegisterClass *TRC = 0;
735 if (VRBase) {
Chris Lattner84bc5422007-12-31 04:13:23 +0000736 TRC = RegInfo.getRegClass(VRBase);
Christopher Lambe24f8f12007-07-26 08:12:07 +0000737 } else {
Chris Lattner84bc5422007-12-31 04:13:23 +0000738 TRC = getSuperregRegisterClass(RegInfo.getRegClass(SubReg), SubIdx,
Christopher Lambe24f8f12007-07-26 08:12:07 +0000739 Node->getValueType(0));
740 assert(TRC && "Couldn't determine register class for insert_subreg");
Chris Lattner84bc5422007-12-31 04:13:23 +0000741 VRBase = RegInfo.createVirtualRegister(TRC); // Create the reg
Christopher Lambe24f8f12007-07-26 08:12:07 +0000742 }
743
Chris Lattner8019f412007-12-30 00:41:17 +0000744 MI->addOperand(MachineOperand::CreateReg(VRBase, true));
Evan Cheng4499e492008-03-10 19:31:26 +0000745 AddOperand(MI, Node->getOperand(0), 0, 0, VRBaseMap);
746 if (!isUndefInput)
747 AddOperand(MI, Node->getOperand(1), 0, 0, VRBaseMap);
Chris Lattnerfec65d52007-12-30 00:51:11 +0000748 MI->addOperand(MachineOperand::CreateImm(SubIdx));
Christopher Lambe24f8f12007-07-26 08:12:07 +0000749 } else
750 assert(0 && "Node is not a subreg insert or extract");
751
752 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,0), VRBase));
753 assert(isNew && "Node emitted out of order - early");
754}
755
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000756/// EmitNode - Generate machine code for an node and needed dependencies.
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000757///
Evan Chenga6fb1b62007-09-25 01:54:36 +0000758void ScheduleDAG::EmitNode(SDNode *Node, unsigned InstanceNo,
Evan Chengaf825c82007-07-10 07:08:32 +0000759 DenseMap<SDOperand, unsigned> &VRBaseMap) {
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000760 // If machine instruction
761 if (Node->isTargetOpcode()) {
762 unsigned Opc = Node->getTargetOpcode();
Christopher Lambe24f8f12007-07-26 08:12:07 +0000763
764 // Handle subreg insert/extract specially
765 if (Opc == TargetInstrInfo::EXTRACT_SUBREG ||
766 Opc == TargetInstrInfo::INSERT_SUBREG) {
767 EmitSubregNode(Node, VRBaseMap);
768 return;
769 }
770
Chris Lattner749c6f62008-01-07 07:27:27 +0000771 const TargetInstrDesc &II = TII->get(Opc);
Chris Lattner2d973e42005-08-18 20:07:59 +0000772
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000773 unsigned NumResults = CountResults(Node);
774 unsigned NodeOperands = CountOperands(Node);
Dan Gohman42a77882008-02-16 00:36:48 +0000775 unsigned MemOperandsEnd = ComputeMemOperandsEnd(Node);
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000776 unsigned NumMIOperands = NodeOperands + NumResults;
Chris Lattner349c4952008-01-07 03:13:06 +0000777 bool HasPhysRegOuts = (NumResults > II.getNumDefs()) &&
778 II.getImplicitDefs() != 0;
Chris Lattnerda8abb02005-09-01 18:44:10 +0000779#ifndef NDEBUG
Chris Lattner349c4952008-01-07 03:13:06 +0000780 assert((II.getNumOperands() == NumMIOperands ||
Chris Lattner8f707e12008-01-07 05:19:29 +0000781 HasPhysRegOuts || II.isVariadic()) &&
Chris Lattner2d973e42005-08-18 20:07:59 +0000782 "#operands for dag node doesn't match .td file!");
Chris Lattnerca6aa2f2005-08-19 01:01:34 +0000783#endif
Chris Lattner2d973e42005-08-18 20:07:59 +0000784
785 // Create the new machine instruction.
Evan Chengc0f64ff2006-11-27 23:37:22 +0000786 MachineInstr *MI = new MachineInstr(II);
Chris Lattner2d973e42005-08-18 20:07:59 +0000787
788 // Add result register values for things that are defined by this
789 // instruction.
Evan Chengaf825c82007-07-10 07:08:32 +0000790 if (NumResults)
Evan Cheng84097472007-08-02 00:28:15 +0000791 CreateVirtualRegisters(Node, MI, II, VRBaseMap);
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000792
793 // Emit all of the actual operands of this instruction, adding them to the
794 // instruction as appropriate.
Chris Lattnered18b682006-02-24 18:54:03 +0000795 for (unsigned i = 0; i != NodeOperands; ++i)
Chris Lattner349c4952008-01-07 03:13:06 +0000796 AddOperand(MI, Node->getOperand(i), i+II.getNumDefs(), &II, VRBaseMap);
Evan Cheng13d41b92006-05-12 01:58:24 +0000797
Dan Gohman69de1932008-02-06 22:27:42 +0000798 // Emit all of the memory operands of this instruction
Dan Gohman42a77882008-02-16 00:36:48 +0000799 for (unsigned i = NodeOperands; i != MemOperandsEnd; ++i)
Dan Gohman69de1932008-02-06 22:27:42 +0000800 AddMemOperand(MI, cast<MemOperandSDNode>(Node->getOperand(i))->MO);
801
Evan Cheng13d41b92006-05-12 01:58:24 +0000802 // Commute node if it has been determined to be profitable.
803 if (CommuteSet.count(Node)) {
804 MachineInstr *NewMI = TII->commuteInstruction(MI);
805 if (NewMI == 0)
Bill Wendling832171c2006-12-07 20:04:42 +0000806 DOUT << "Sched: COMMUTING FAILED!\n";
Evan Cheng13d41b92006-05-12 01:58:24 +0000807 else {
Bill Wendling832171c2006-12-07 20:04:42 +0000808 DOUT << "Sched: COMMUTED TO: " << *NewMI;
Evan Cheng4c6f2f92006-05-31 18:03:39 +0000809 if (MI != NewMI) {
810 delete MI;
811 MI = NewMI;
812 }
Evan Cheng643afa52008-02-28 07:40:24 +0000813 ++NumCommutes;
Evan Cheng13d41b92006-05-12 01:58:24 +0000814 }
815 }
816
Evan Cheng1b08bbc2008-02-01 09:10:45 +0000817 if (II.usesCustomDAGSchedInsertionHook())
Evan Cheng6b2cf282008-01-30 19:35:32 +0000818 // Insert this instruction into the basic block using a target
819 // specific inserter which may returns a new basic block.
Evan Chengff9b3732008-01-30 18:18:23 +0000820 BB = DAG.getTargetLoweringInfo().EmitInstrWithCustomInserter(MI, BB);
Evan Cheng6b2cf282008-01-30 19:35:32 +0000821 else
822 BB->push_back(MI);
Evan Cheng84097472007-08-02 00:28:15 +0000823
824 // Additional results must be an physical register def.
825 if (HasPhysRegOuts) {
Chris Lattner349c4952008-01-07 03:13:06 +0000826 for (unsigned i = II.getNumDefs(); i < NumResults; ++i) {
827 unsigned Reg = II.getImplicitDefs()[i - II.getNumDefs()];
Evan Cheng33d55952007-08-02 05:29:38 +0000828 if (Node->hasAnyUseOfValue(i))
Evan Chenga6fb1b62007-09-25 01:54:36 +0000829 EmitCopyFromReg(Node, i, InstanceNo, Reg, VRBaseMap);
Evan Cheng84097472007-08-02 00:28:15 +0000830 }
831 }
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000832 } else {
833 switch (Node->getOpcode()) {
834 default:
Jim Laskey16d42c62006-07-11 18:25:13 +0000835#ifndef NDEBUG
Dan Gohmanb5bec2b2007-06-19 14:13:56 +0000836 Node->dump(&DAG);
Jim Laskey16d42c62006-07-11 18:25:13 +0000837#endif
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000838 assert(0 && "This target-independent node should have been selected!");
839 case ISD::EntryToken: // fall thru
840 case ISD::TokenFactor:
Jim Laskey1ee29252007-01-26 14:34:52 +0000841 case ISD::LABEL:
Evan Chenga844bde2008-02-02 04:07:54 +0000842 case ISD::DECLARE:
Dan Gohman69de1932008-02-06 22:27:42 +0000843 case ISD::SRCVALUE:
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000844 break;
845 case ISD::CopyToReg: {
Chris Lattnerf30e1cf2008-03-09 09:15:31 +0000846 unsigned SrcReg;
847 SDOperand SrcVal = Node->getOperand(2);
848 if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(SrcVal))
849 SrcReg = R->getReg();
Evan Cheng489a87c2007-01-05 20:59:06 +0000850 else
Chris Lattnerf30e1cf2008-03-09 09:15:31 +0000851 SrcReg = getVR(SrcVal, VRBaseMap);
852
Chris Lattnera4176522005-10-30 18:54:27 +0000853 unsigned DestReg = cast<RegisterSDNode>(Node->getOperand(1))->getReg();
Chris Lattnerf30e1cf2008-03-09 09:15:31 +0000854 if (SrcReg == DestReg) // Coalesced away the copy? Ignore.
855 break;
856
857 const TargetRegisterClass *SrcTRC = 0, *DstTRC = 0;
858 // Get the register classes of the src/dst.
859 if (TargetRegisterInfo::isVirtualRegister(SrcReg))
860 SrcTRC = RegInfo.getRegClass(SrcReg);
861 else
862 SrcTRC = TRI->getPhysicalRegisterRegClass(SrcVal.getValueType(),SrcReg);
863
864 if (TargetRegisterInfo::isVirtualRegister(DestReg))
865 DstTRC = RegInfo.getRegClass(DestReg);
866 else
867 DstTRC = TRI->getPhysicalRegisterRegClass(
868 Node->getOperand(1).getValueType(),
869 DestReg);
870 TII->copyRegToReg(*BB, BB->end(), DestReg, SrcReg, DstTRC, SrcTRC);
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000871 break;
872 }
873 case ISD::CopyFromReg: {
874 unsigned SrcReg = cast<RegisterSDNode>(Node->getOperand(1))->getReg();
Evan Chenga6fb1b62007-09-25 01:54:36 +0000875 EmitCopyFromReg(Node, 0, InstanceNo, SrcReg, VRBaseMap);
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000876 break;
877 }
Chris Lattneracc43bf2006-01-26 23:28:04 +0000878 case ISD::INLINEASM: {
879 unsigned NumOps = Node->getNumOperands();
880 if (Node->getOperand(NumOps-1).getValueType() == MVT::Flag)
881 --NumOps; // Ignore the flag operand.
882
883 // Create the inline asm machine instruction.
884 MachineInstr *MI =
Evan Chengc0f64ff2006-11-27 23:37:22 +0000885 new MachineInstr(BB, TII->get(TargetInstrInfo::INLINEASM));
Chris Lattneracc43bf2006-01-26 23:28:04 +0000886
887 // Add the asm string as an external symbol operand.
888 const char *AsmStr =
889 cast<ExternalSymbolSDNode>(Node->getOperand(1))->getSymbol();
Chris Lattnerfec65d52007-12-30 00:51:11 +0000890 MI->addOperand(MachineOperand::CreateES(AsmStr));
Chris Lattneracc43bf2006-01-26 23:28:04 +0000891
892 // Add all of the operand registers to the instruction.
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000893 for (unsigned i = 2; i != NumOps;) {
894 unsigned Flags = cast<ConstantSDNode>(Node->getOperand(i))->getValue();
Chris Lattnerfd6d2822006-02-24 19:18:20 +0000895 unsigned NumVals = Flags >> 3;
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000896
Chris Lattnerfec65d52007-12-30 00:51:11 +0000897 MI->addOperand(MachineOperand::CreateImm(Flags));
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000898 ++i; // Skip the ID value.
899
900 switch (Flags & 7) {
Chris Lattneracc43bf2006-01-26 23:28:04 +0000901 default: assert(0 && "Bad flags!");
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000902 case 1: // Use of register.
Chris Lattnerfd6d2822006-02-24 19:18:20 +0000903 for (; NumVals; --NumVals, ++i) {
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000904 unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
Chris Lattner8019f412007-12-30 00:41:17 +0000905 MI->addOperand(MachineOperand::CreateReg(Reg, false));
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000906 }
Chris Lattnerdc19b702006-02-04 02:26:14 +0000907 break;
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000908 case 2: // Def of register.
Chris Lattnerfd6d2822006-02-24 19:18:20 +0000909 for (; NumVals; --NumVals, ++i) {
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000910 unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
Chris Lattner8019f412007-12-30 00:41:17 +0000911 MI->addOperand(MachineOperand::CreateReg(Reg, true));
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000912 }
Chris Lattnerdc19b702006-02-04 02:26:14 +0000913 break;
Chris Lattnerdc19b702006-02-04 02:26:14 +0000914 case 3: { // Immediate.
Chris Lattner7df31dc2007-08-25 00:53:07 +0000915 for (; NumVals; --NumVals, ++i) {
916 if (ConstantSDNode *CS =
917 dyn_cast<ConstantSDNode>(Node->getOperand(i))) {
Chris Lattner8019f412007-12-30 00:41:17 +0000918 MI->addOperand(MachineOperand::CreateImm(CS->getValue()));
Dale Johanneseneb57ea72007-11-05 21:20:28 +0000919 } else if (GlobalAddressSDNode *GA =
920 dyn_cast<GlobalAddressSDNode>(Node->getOperand(i))) {
Chris Lattnerfec65d52007-12-30 00:51:11 +0000921 MI->addOperand(MachineOperand::CreateGA(GA->getGlobal(),
922 GA->getOffset()));
Dale Johanneseneb57ea72007-11-05 21:20:28 +0000923 } else {
Chris Lattnerfec65d52007-12-30 00:51:11 +0000924 BasicBlockSDNode *BB =cast<BasicBlockSDNode>(Node->getOperand(i));
925 MI->addOperand(MachineOperand::CreateMBB(BB->getBasicBlock()));
Chris Lattner7df31dc2007-08-25 00:53:07 +0000926 }
Chris Lattnerefa46ce2006-10-31 20:01:56 +0000927 }
Chris Lattnerdc19b702006-02-04 02:26:14 +0000928 break;
929 }
Chris Lattnerfd6d2822006-02-24 19:18:20 +0000930 case 4: // Addressing mode.
931 // The addressing mode has been selected, just add all of the
932 // operands to the machine instruction.
933 for (; NumVals; --NumVals, ++i)
Chris Lattnerdf375062006-03-10 07:25:12 +0000934 AddOperand(MI, Node->getOperand(i), 0, 0, VRBaseMap);
Chris Lattnerfd6d2822006-02-24 19:18:20 +0000935 break;
Chris Lattnerdc19b702006-02-04 02:26:14 +0000936 }
Chris Lattneracc43bf2006-01-26 23:28:04 +0000937 }
938 break;
939 }
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000940 }
941 }
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000942}
943
Chris Lattnera93dfcd2006-03-05 23:51:47 +0000944void ScheduleDAG::EmitNoop() {
945 TII->insertNoop(*BB, BB->end());
946}
947
Chris Lattnerd9c4c452008-03-09 07:51:01 +0000948void ScheduleDAG::EmitCrossRCCopy(SUnit *SU,
949 DenseMap<SUnit*, unsigned> &VRBaseMap) {
Evan Cheng42d60272007-09-26 21:36:17 +0000950 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
951 I != E; ++I) {
952 if (I->isCtrl) continue; // ignore chain preds
953 if (!I->Dep->Node) {
954 // Copy to physical register.
955 DenseMap<SUnit*, unsigned>::iterator VRI = VRBaseMap.find(I->Dep);
956 assert(VRI != VRBaseMap.end() && "Node emitted out of order - late");
957 // Find the destination physical register.
958 unsigned Reg = 0;
959 for (SUnit::const_succ_iterator II = SU->Succs.begin(),
960 EE = SU->Succs.end(); II != EE; ++II) {
961 if (I->Reg) {
962 Reg = I->Reg;
963 break;
964 }
965 }
966 assert(I->Reg && "Unknown physical register!");
Owen Andersond10fd972007-12-31 06:32:00 +0000967 TII->copyRegToReg(*BB, BB->end(), Reg, VRI->second,
Evan Cheng42d60272007-09-26 21:36:17 +0000968 SU->CopyDstRC, SU->CopySrcRC);
969 } else {
970 // Copy from physical register.
971 assert(I->Reg && "Unknown physical register!");
Chris Lattner84bc5422007-12-31 04:13:23 +0000972 unsigned VRBase = RegInfo.createVirtualRegister(SU->CopyDstRC);
Evan Cheng42d60272007-09-26 21:36:17 +0000973 bool isNew = VRBaseMap.insert(std::make_pair(SU, VRBase));
974 assert(isNew && "Node emitted out of order - early");
Owen Andersond10fd972007-12-31 06:32:00 +0000975 TII->copyRegToReg(*BB, BB->end(), VRBase, I->Reg,
Evan Cheng42d60272007-09-26 21:36:17 +0000976 SU->CopyDstRC, SU->CopySrcRC);
977 }
978 break;
979 }
980}
981
Evan Chenge165a782006-05-11 23:55:42 +0000982/// EmitSchedule - Emit the machine code in scheduled order.
983void ScheduleDAG::EmitSchedule() {
Chris Lattner96645412006-05-16 06:10:58 +0000984 // If this is the first basic block in the function, and if it has live ins
985 // that need to be copied into vregs, emit the copies into the top of the
986 // block before emitting the code for the block.
Evan Cheng6b2cf282008-01-30 19:35:32 +0000987 if (&MF->front() == BB) {
Chris Lattner84bc5422007-12-31 04:13:23 +0000988 for (MachineRegisterInfo::livein_iterator LI = RegInfo.livein_begin(),
989 E = RegInfo.livein_end(); LI != E; ++LI)
Evan Cheng9efce632007-09-26 06:25:56 +0000990 if (LI->second) {
Chris Lattner84bc5422007-12-31 04:13:23 +0000991 const TargetRegisterClass *RC = RegInfo.getRegClass(LI->second);
Evan Cheng6b2cf282008-01-30 19:35:32 +0000992 TII->copyRegToReg(*MF->begin(), MF->begin()->end(), LI->second,
Evan Cheng9efce632007-09-26 06:25:56 +0000993 LI->first, RC, RC);
994 }
Chris Lattner96645412006-05-16 06:10:58 +0000995 }
996
997
998 // Finally, emit the code for all of the scheduled instructions.
Evan Chengaf825c82007-07-10 07:08:32 +0000999 DenseMap<SDOperand, unsigned> VRBaseMap;
Evan Cheng42d60272007-09-26 21:36:17 +00001000 DenseMap<SUnit*, unsigned> CopyVRBaseMap;
Evan Chenge165a782006-05-11 23:55:42 +00001001 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
1002 if (SUnit *SU = Sequence[i]) {
Evan Chenga6fb1b62007-09-25 01:54:36 +00001003 for (unsigned j = 0, ee = SU->FlaggedNodes.size(); j != ee; ++j)
1004 EmitNode(SU->FlaggedNodes[j], SU->InstanceNo, VRBaseMap);
Evan Cheng42d60272007-09-26 21:36:17 +00001005 if (SU->Node)
1006 EmitNode(SU->Node, SU->InstanceNo, VRBaseMap);
1007 else
1008 EmitCrossRCCopy(SU, CopyVRBaseMap);
Evan Chenge165a782006-05-11 23:55:42 +00001009 } else {
1010 // Null SUnit* is a noop.
1011 EmitNoop();
1012 }
1013 }
1014}
1015
1016/// dump - dump the schedule.
1017void ScheduleDAG::dumpSchedule() const {
1018 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
1019 if (SUnit *SU = Sequence[i])
1020 SU->dump(&DAG);
1021 else
Bill Wendling832171c2006-12-07 20:04:42 +00001022 cerr << "**** NOOP ****\n";
Evan Chenge165a782006-05-11 23:55:42 +00001023 }
1024}
1025
1026
Evan Chenga9c20912006-01-21 02:32:06 +00001027/// Run - perform scheduling.
1028///
1029MachineBasicBlock *ScheduleDAG::Run() {
Evan Chenga9c20912006-01-21 02:32:06 +00001030 Schedule();
1031 return BB;
Chris Lattnerd32b2362005-08-18 18:45:24 +00001032}
Evan Cheng4ef10862006-01-23 07:01:07 +00001033
Evan Chenge165a782006-05-11 23:55:42 +00001034/// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
1035/// a group of nodes flagged together.
1036void SUnit::dump(const SelectionDAG *G) const {
Bill Wendling832171c2006-12-07 20:04:42 +00001037 cerr << "SU(" << NodeNum << "): ";
Evan Cheng42d60272007-09-26 21:36:17 +00001038 if (Node)
1039 Node->dump(G);
1040 else
1041 cerr << "CROSS RC COPY ";
Bill Wendling832171c2006-12-07 20:04:42 +00001042 cerr << "\n";
Evan Chenge165a782006-05-11 23:55:42 +00001043 if (FlaggedNodes.size() != 0) {
1044 for (unsigned i = 0, e = FlaggedNodes.size(); i != e; i++) {
Bill Wendling832171c2006-12-07 20:04:42 +00001045 cerr << " ";
Evan Chenge165a782006-05-11 23:55:42 +00001046 FlaggedNodes[i]->dump(G);
Bill Wendling832171c2006-12-07 20:04:42 +00001047 cerr << "\n";
Evan Chenge165a782006-05-11 23:55:42 +00001048 }
1049 }
1050}
Evan Cheng4ef10862006-01-23 07:01:07 +00001051
Evan Chenge165a782006-05-11 23:55:42 +00001052void SUnit::dumpAll(const SelectionDAG *G) const {
1053 dump(G);
1054
Bill Wendling832171c2006-12-07 20:04:42 +00001055 cerr << " # preds left : " << NumPredsLeft << "\n";
1056 cerr << " # succs left : " << NumSuccsLeft << "\n";
Bill Wendling832171c2006-12-07 20:04:42 +00001057 cerr << " Latency : " << Latency << "\n";
1058 cerr << " Depth : " << Depth << "\n";
1059 cerr << " Height : " << Height << "\n";
Evan Chenge165a782006-05-11 23:55:42 +00001060
1061 if (Preds.size() != 0) {
Bill Wendling832171c2006-12-07 20:04:42 +00001062 cerr << " Predecessors:\n";
Chris Lattner228a18e2006-08-17 00:09:56 +00001063 for (SUnit::const_succ_iterator I = Preds.begin(), E = Preds.end();
1064 I != E; ++I) {
Evan Cheng713a98d2007-09-19 01:38:40 +00001065 if (I->isCtrl)
Bill Wendling832171c2006-12-07 20:04:42 +00001066 cerr << " ch #";
Evan Chenge165a782006-05-11 23:55:42 +00001067 else
Bill Wendling832171c2006-12-07 20:04:42 +00001068 cerr << " val #";
Evan Chenga6fb1b62007-09-25 01:54:36 +00001069 cerr << I->Dep << " - SU(" << I->Dep->NodeNum << ")";
1070 if (I->isSpecial)
1071 cerr << " *";
1072 cerr << "\n";
Evan Chenge165a782006-05-11 23:55:42 +00001073 }
1074 }
1075 if (Succs.size() != 0) {
Bill Wendling832171c2006-12-07 20:04:42 +00001076 cerr << " Successors:\n";
Chris Lattner228a18e2006-08-17 00:09:56 +00001077 for (SUnit::const_succ_iterator I = Succs.begin(), E = Succs.end();
1078 I != E; ++I) {
Evan Cheng713a98d2007-09-19 01:38:40 +00001079 if (I->isCtrl)
Bill Wendling832171c2006-12-07 20:04:42 +00001080 cerr << " ch #";
Evan Chenge165a782006-05-11 23:55:42 +00001081 else
Bill Wendling832171c2006-12-07 20:04:42 +00001082 cerr << " val #";
Evan Chenga6fb1b62007-09-25 01:54:36 +00001083 cerr << I->Dep << " - SU(" << I->Dep->NodeNum << ")";
1084 if (I->isSpecial)
1085 cerr << " *";
1086 cerr << "\n";
Evan Chenge165a782006-05-11 23:55:42 +00001087 }
1088 }
Bill Wendling832171c2006-12-07 20:04:42 +00001089 cerr << "\n";
Evan Chenge165a782006-05-11 23:55:42 +00001090}