blob: 5c8e59045929ed5751574b1a4b22230a4310be76 [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);
72 for (unsigned i = 0, e = SU->FlaggedNodes.size(); i != e; ++i)
73 SU->FlaggedNodes.push_back(SU->FlaggedNodes[i]);
74 SU->InstanceNo = SUnitMap[Old->Node].size();
75 SU->Latency = Old->Latency;
76 SU->isTwoAddress = Old->isTwoAddress;
77 SU->isCommutable = Old->isCommutable;
Evan Cheng22a52992007-09-28 22:32:30 +000078 SU->hasPhysRegDefs = Old->hasPhysRegDefs;
Evan Chenga6fb1b62007-09-25 01:54:36 +000079 SUnitMap[Old->Node].push_back(SU);
80 return SU;
81}
82
Evan Chengf10c9732007-10-05 01:39:18 +000083
Evan Chenge165a782006-05-11 23:55:42 +000084/// BuildSchedUnits - Build SUnits from the selection dag that we are input.
85/// This SUnit graph is similar to the SelectionDAG, but represents flagged
86/// together nodes with a single SUnit.
87void ScheduleDAG::BuildSchedUnits() {
88 // Reserve entries in the vector for each of the SUnits we are creating. This
89 // ensure that reallocation of the vector won't happen, so SUnit*'s won't get
90 // invalidated.
91 SUnits.reserve(std::distance(DAG.allnodes_begin(), DAG.allnodes_end()));
92
Evan Chenge165a782006-05-11 23:55:42 +000093 for (SelectionDAG::allnodes_iterator NI = DAG.allnodes_begin(),
94 E = DAG.allnodes_end(); NI != E; ++NI) {
95 if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate.
96 continue;
97
98 // If this node has already been processed, stop now.
Evan Chenga6fb1b62007-09-25 01:54:36 +000099 if (SUnitMap[NI].size()) continue;
Evan Chenge165a782006-05-11 23:55:42 +0000100
101 SUnit *NodeSUnit = NewSUnit(NI);
102
103 // See if anything is flagged to this node, if so, add them to flagged
104 // nodes. Nodes can have at most one flag input and one flag output. Flags
105 // are required the be the last operand and result of a node.
106
107 // Scan up, adding flagged preds to FlaggedNodes.
108 SDNode *N = NI;
Evan Cheng3b97acd2006-08-07 22:12:12 +0000109 if (N->getNumOperands() &&
110 N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Flag) {
111 do {
112 N = N->getOperand(N->getNumOperands()-1).Val;
113 NodeSUnit->FlaggedNodes.push_back(N);
Evan Chenga6fb1b62007-09-25 01:54:36 +0000114 SUnitMap[N].push_back(NodeSUnit);
Evan Cheng3b97acd2006-08-07 22:12:12 +0000115 } while (N->getNumOperands() &&
116 N->getOperand(N->getNumOperands()-1).getValueType()== MVT::Flag);
117 std::reverse(NodeSUnit->FlaggedNodes.begin(),
118 NodeSUnit->FlaggedNodes.end());
Evan Chenge165a782006-05-11 23:55:42 +0000119 }
120
121 // Scan down, adding this node and any flagged succs to FlaggedNodes if they
122 // have a user of the flag operand.
123 N = NI;
124 while (N->getValueType(N->getNumValues()-1) == MVT::Flag) {
125 SDOperand FlagVal(N, N->getNumValues()-1);
126
127 // There are either zero or one users of the Flag result.
128 bool HasFlagUse = false;
129 for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end();
130 UI != E; ++UI)
Evan Cheng917be682008-03-04 00:41:45 +0000131 if (FlagVal.isOperandOf(*UI)) {
Evan Chenge165a782006-05-11 23:55:42 +0000132 HasFlagUse = true;
133 NodeSUnit->FlaggedNodes.push_back(N);
Evan Chenga6fb1b62007-09-25 01:54:36 +0000134 SUnitMap[N].push_back(NodeSUnit);
Evan Chenge165a782006-05-11 23:55:42 +0000135 N = *UI;
136 break;
137 }
Chris Lattner228a18e2006-08-17 00:09:56 +0000138 if (!HasFlagUse) break;
Evan Chenge165a782006-05-11 23:55:42 +0000139 }
140
141 // Now all flagged nodes are in FlaggedNodes and N is the bottom-most node.
142 // Update the SUnit
143 NodeSUnit->Node = N;
Evan Chenga6fb1b62007-09-25 01:54:36 +0000144 SUnitMap[N].push_back(NodeSUnit);
Evan Chengf10c9732007-10-05 01:39:18 +0000145
146 ComputeLatency(NodeSUnit);
Evan Chenge165a782006-05-11 23:55:42 +0000147 }
148
149 // Pass 2: add the preds, succs, etc.
150 for (unsigned su = 0, e = SUnits.size(); su != e; ++su) {
151 SUnit *SU = &SUnits[su];
152 SDNode *MainNode = SU->Node;
153
154 if (MainNode->isTargetOpcode()) {
155 unsigned Opc = MainNode->getTargetOpcode();
Chris Lattner749c6f62008-01-07 07:27:27 +0000156 const TargetInstrDesc &TID = TII->get(Opc);
Chris Lattner349c4952008-01-07 03:13:06 +0000157 for (unsigned i = 0; i != TID.getNumOperands(); ++i) {
Evan Chenga6fb1b62007-09-25 01:54:36 +0000158 if (TID.getOperandConstraint(i, TOI::TIED_TO) != -1) {
Evan Cheng95f6ede2006-11-04 09:44:31 +0000159 SU->isTwoAddress = true;
160 break;
161 }
162 }
Chris Lattner0ff23962008-01-07 06:42:05 +0000163 if (TID.isCommutable())
Evan Cheng13d41b92006-05-12 01:58:24 +0000164 SU->isCommutable = true;
Evan Chenge165a782006-05-11 23:55:42 +0000165 }
166
167 // Find all predecessors and successors of the group.
168 // Temporarily add N to make code simpler.
169 SU->FlaggedNodes.push_back(MainNode);
170
171 for (unsigned n = 0, e = SU->FlaggedNodes.size(); n != e; ++n) {
172 SDNode *N = SU->FlaggedNodes[n];
Evan Cheng22a52992007-09-28 22:32:30 +0000173 if (N->isTargetOpcode() &&
Chris Lattner349c4952008-01-07 03:13:06 +0000174 TII->get(N->getTargetOpcode()).getImplicitDefs() &&
175 CountResults(N) > TII->get(N->getTargetOpcode()).getNumDefs())
Evan Cheng22a52992007-09-28 22:32:30 +0000176 SU->hasPhysRegDefs = true;
Evan Chenge165a782006-05-11 23:55:42 +0000177
178 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
179 SDNode *OpN = N->getOperand(i).Val;
180 if (isPassiveNode(OpN)) continue; // Not scheduled.
Evan Chenga6fb1b62007-09-25 01:54:36 +0000181 SUnit *OpSU = SUnitMap[OpN].front();
Evan Chenge165a782006-05-11 23:55:42 +0000182 assert(OpSU && "Node has no SUnit!");
183 if (OpSU == SU) continue; // In the same group.
184
185 MVT::ValueType OpVT = N->getOperand(i).getValueType();
186 assert(OpVT != MVT::Flag && "Flagged nodes should be in same sunit!");
187 bool isChain = OpVT == MVT::Other;
Evan Chenga6fb1b62007-09-25 01:54:36 +0000188
189 unsigned PhysReg = 0;
190 int Cost = 1;
191 // Determine if this is a physical register dependency.
Dan Gohman6f0d0242008-02-10 18:45:23 +0000192 CheckForPhysRegDependency(OpN, N, i, TRI, TII, PhysReg, Cost);
Evan Chenga6fb1b62007-09-25 01:54:36 +0000193 SU->addPred(OpSU, isChain, false, PhysReg, Cost);
Evan Chenge165a782006-05-11 23:55:42 +0000194 }
195 }
196
197 // Remove MainNode from FlaggedNodes again.
198 SU->FlaggedNodes.pop_back();
199 }
200
201 return;
202}
203
Evan Chengf10c9732007-10-05 01:39:18 +0000204void ScheduleDAG::ComputeLatency(SUnit *SU) {
205 const InstrItineraryData &InstrItins = TM.getInstrItineraryData();
206
207 // Compute the latency for the node. We use the sum of the latencies for
208 // all nodes flagged together into this SUnit.
209 if (InstrItins.isEmpty()) {
210 // No latency information.
211 SU->Latency = 1;
212 } else {
213 SU->Latency = 0;
214 if (SU->Node->isTargetOpcode()) {
Chris Lattnerba6da5d2008-01-07 02:46:03 +0000215 unsigned SchedClass =
216 TII->get(SU->Node->getTargetOpcode()).getSchedClass();
Evan Chengf10c9732007-10-05 01:39:18 +0000217 InstrStage *S = InstrItins.begin(SchedClass);
218 InstrStage *E = InstrItins.end(SchedClass);
219 for (; S != E; ++S)
220 SU->Latency += S->Cycles;
221 }
222 for (unsigned i = 0, e = SU->FlaggedNodes.size(); i != e; ++i) {
223 SDNode *FNode = SU->FlaggedNodes[i];
224 if (FNode->isTargetOpcode()) {
Chris Lattnerba6da5d2008-01-07 02:46:03 +0000225 unsigned SchedClass =TII->get(FNode->getTargetOpcode()).getSchedClass();
Evan Chengf10c9732007-10-05 01:39:18 +0000226 InstrStage *S = InstrItins.begin(SchedClass);
227 InstrStage *E = InstrItins.end(SchedClass);
228 for (; S != E; ++S)
229 SU->Latency += S->Cycles;
230 }
231 }
232 }
233}
234
Roman Levensteind86449e2008-03-04 11:19:43 +0000235/// CalculateDepths - compute depths using algorithms for the longest
236/// paths in the DAG
Evan Chenge165a782006-05-11 23:55:42 +0000237void ScheduleDAG::CalculateDepths() {
Roman Levensteind86449e2008-03-04 11:19:43 +0000238 unsigned DAGSize = SUnits.size();
239 std::vector<unsigned> InDegree(DAGSize);
240 std::vector<SUnit*> WorkList;
241 WorkList.reserve(DAGSize);
Evan Chenge165a782006-05-11 23:55:42 +0000242
Roman Levensteind86449e2008-03-04 11:19:43 +0000243 // Initialize the data structures
244 for (unsigned i = 0, e = DAGSize; i != e; ++i) {
245 SUnit *SU = &SUnits[i];
246 int NodeNum = SU->NodeNum;
247 unsigned Degree = SU->Preds.size();
248 InDegree[NodeNum] = Degree;
249 SU->Depth = 0;
250
251 // Is it a node without dependencies?
252 if (Degree == 0) {
253 assert(SU->Preds.empty() && "SUnit should have no predecessors");
254 // Collect leaf nodes
255 WorkList.push_back(SU);
256 }
257 }
258
259 // Process nodes in the topological order
Evan Cheng99126282007-07-06 01:37:28 +0000260 while (!WorkList.empty()) {
Roman Levensteind86449e2008-03-04 11:19:43 +0000261 SUnit *SU = WorkList.back();
Evan Cheng99126282007-07-06 01:37:28 +0000262 WorkList.pop_back();
Roman Levensteind86449e2008-03-04 11:19:43 +0000263 unsigned &SUDepth = SU->Depth;
264
265 // Use dynamic programming:
266 // When current node is being processed, all of its dependencies
267 // are already processed.
268 // So, just iterate over all predecessors and take the longest path
269 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
270 I != E; ++I) {
271 unsigned PredDepth = I->Dep->Depth;
272 if (PredDepth+1 > SUDepth) {
273 SUDepth = PredDepth + 1;
274 }
275 }
276
277 // Update InDegrees of all nodes depending on current SUnit
278 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
279 I != E; ++I) {
280 SUnit *SU = I->Dep;
281 if (!--InDegree[SU->NodeNum])
282 // If all dependencies of the node are processed already,
283 // then the longest path for the node can be computed now
284 WorkList.push_back(SU);
Evan Cheng99126282007-07-06 01:37:28 +0000285 }
Evan Cheng626da3d2006-05-12 06:05:18 +0000286 }
Evan Chenge165a782006-05-11 23:55:42 +0000287}
Evan Cheng99126282007-07-06 01:37:28 +0000288
Roman Levensteind86449e2008-03-04 11:19:43 +0000289/// CalculateHeights - compute heights using algorithms for the longest
290/// paths in the DAG
Evan Chenge165a782006-05-11 23:55:42 +0000291void ScheduleDAG::CalculateHeights() {
Roman Levensteind86449e2008-03-04 11:19:43 +0000292 unsigned DAGSize = SUnits.size();
293 std::vector<unsigned> InDegree(DAGSize);
294 std::vector<SUnit*> WorkList;
295 WorkList.reserve(DAGSize);
Evan Cheng99126282007-07-06 01:37:28 +0000296
Roman Levensteind86449e2008-03-04 11:19:43 +0000297 // Initialize the data structures
298 for (unsigned i = 0, e = DAGSize; i != e; ++i) {
299 SUnit *SU = &SUnits[i];
300 int NodeNum = SU->NodeNum;
301 unsigned Degree = SU->Succs.size();
302 InDegree[NodeNum] = Degree;
303 SU->Height = 0;
304
305 // Is it a node without dependencies?
306 if (Degree == 0) {
307 assert(SU->Succs.empty() && "Something wrong");
308 assert(WorkList.empty() && "Should be empty");
309 // Collect leaf nodes
310 WorkList.push_back(SU);
311 }
312 }
313
314 // Process nodes in the topological order
Evan Cheng99126282007-07-06 01:37:28 +0000315 while (!WorkList.empty()) {
Roman Levensteind86449e2008-03-04 11:19:43 +0000316 SUnit *SU = WorkList.back();
Evan Cheng99126282007-07-06 01:37:28 +0000317 WorkList.pop_back();
Roman Levensteind86449e2008-03-04 11:19:43 +0000318 unsigned &SUHeight = SU->Height;
319
320 // Use dynamic programming:
321 // When current node is being processed, all of its dependencies
322 // are already processed.
323 // So, just iterate over all successors and take the longest path
324 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
325 I != E; ++I) {
326 unsigned SuccHeight = I->Dep->Height;
327 if (SuccHeight+1 > SUHeight) {
328 SUHeight = SuccHeight + 1;
329 }
330 }
331
332 // Update InDegrees of all nodes depending on current SUnit
333 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
334 I != E; ++I) {
335 SUnit *SU = I->Dep;
336 if (!--InDegree[SU->NodeNum])
337 // If all dependencies of the node are processed already,
338 // then the longest path for the node can be computed now
339 WorkList.push_back(SU);
Evan Cheng99126282007-07-06 01:37:28 +0000340 }
341 }
Evan Chenge165a782006-05-11 23:55:42 +0000342}
343
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000344/// CountResults - The results of target nodes have register or immediate
345/// operands first, then an optional chain, and optional flag operands (which do
Dan Gohman027ee7e2008-02-11 19:00:03 +0000346/// not go into the resulting MachineInstr).
Evan Cheng95f6ede2006-11-04 09:44:31 +0000347unsigned ScheduleDAG::CountResults(SDNode *Node) {
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000348 unsigned N = Node->getNumValues();
349 while (N && Node->getValueType(N - 1) == MVT::Flag)
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000350 --N;
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000351 if (N && Node->getValueType(N - 1) == MVT::Other)
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000352 --N; // Skip over chain result.
353 return N;
354}
355
Dan Gohman69de1932008-02-06 22:27:42 +0000356/// CountOperands - The inputs to target nodes have any actual inputs first,
Dan Gohman42a77882008-02-16 00:36:48 +0000357/// followed by special operands that describe memory references, then an
358/// optional chain operand, then flag operands. Compute the number of
359/// actual operands that will go into the resulting MachineInstr.
Evan Cheng95f6ede2006-11-04 09:44:31 +0000360unsigned ScheduleDAG::CountOperands(SDNode *Node) {
Dan Gohman42a77882008-02-16 00:36:48 +0000361 unsigned N = ComputeMemOperandsEnd(Node);
Dan Gohmancc20cd52008-02-11 19:00:34 +0000362 while (N && isa<MemOperandSDNode>(Node->getOperand(N - 1).Val))
Dan Gohman69de1932008-02-06 22:27:42 +0000363 --N; // Ignore MemOperand nodes
364 return N;
365}
366
Dan Gohman42a77882008-02-16 00:36:48 +0000367/// ComputeMemOperandsEnd - Find the index one past the last MemOperandSDNode
368/// operand
369unsigned ScheduleDAG::ComputeMemOperandsEnd(SDNode *Node) {
Dan Gohman69de1932008-02-06 22:27:42 +0000370 unsigned N = Node->getNumOperands();
371 while (N && Node->getOperand(N - 1).getValueType() == MVT::Flag)
372 --N;
373 if (N && Node->getOperand(N - 1).getValueType() == MVT::Other)
374 --N; // Ignore chain if it exists.
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000375 return N;
376}
377
Jim Laskey60f09922006-07-21 20:57:35 +0000378static const TargetRegisterClass *getInstrOperandRegClass(
Dan Gohman6f0d0242008-02-10 18:45:23 +0000379 const TargetRegisterInfo *TRI,
Jim Laskey60f09922006-07-21 20:57:35 +0000380 const TargetInstrInfo *TII,
Chris Lattner749c6f62008-01-07 07:27:27 +0000381 const TargetInstrDesc &II,
Jim Laskey60f09922006-07-21 20:57:35 +0000382 unsigned Op) {
Chris Lattner749c6f62008-01-07 07:27:27 +0000383 if (Op >= II.getNumOperands()) {
384 assert(II.isVariadic() && "Invalid operand # of instruction");
Jim Laskey60f09922006-07-21 20:57:35 +0000385 return NULL;
386 }
Chris Lattner749c6f62008-01-07 07:27:27 +0000387 if (II.OpInfo[Op].isLookupPtrRegClass())
Chris Lattner8ca5c672008-01-07 02:39:19 +0000388 return TII->getPointerRegClass();
Dan Gohman6f0d0242008-02-10 18:45:23 +0000389 return TRI->getRegClass(II.OpInfo[Op].RegClass);
Jim Laskey60f09922006-07-21 20:57:35 +0000390}
391
Evan Chenga6fb1b62007-09-25 01:54:36 +0000392void ScheduleDAG::EmitCopyFromReg(SDNode *Node, unsigned ResNo,
393 unsigned InstanceNo, unsigned SrcReg,
Evan Cheng84097472007-08-02 00:28:15 +0000394 DenseMap<SDOperand, unsigned> &VRBaseMap) {
395 unsigned VRBase = 0;
Dan Gohman6f0d0242008-02-10 18:45:23 +0000396 if (TargetRegisterInfo::isVirtualRegister(SrcReg)) {
Evan Cheng84097472007-08-02 00:28:15 +0000397 // Just use the input register directly!
Evan Chenga6fb1b62007-09-25 01:54:36 +0000398 if (InstanceNo > 0)
399 VRBaseMap.erase(SDOperand(Node, ResNo));
Evan Cheng84097472007-08-02 00:28:15 +0000400 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,ResNo),SrcReg));
401 assert(isNew && "Node emitted out of order - early");
402 return;
403 }
404
405 // If the node is only used by a CopyToReg and the dest reg is a vreg, use
406 // the CopyToReg'd destination register instead of creating a new vreg.
Evan Chenga6fb1b62007-09-25 01:54:36 +0000407 bool MatchReg = true;
Evan Cheng84097472007-08-02 00:28:15 +0000408 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
409 UI != E; ++UI) {
410 SDNode *Use = *UI;
Evan Chenga6fb1b62007-09-25 01:54:36 +0000411 bool Match = true;
Evan Cheng84097472007-08-02 00:28:15 +0000412 if (Use->getOpcode() == ISD::CopyToReg &&
413 Use->getOperand(2).Val == Node &&
414 Use->getOperand(2).ResNo == ResNo) {
415 unsigned DestReg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
Dan Gohman6f0d0242008-02-10 18:45:23 +0000416 if (TargetRegisterInfo::isVirtualRegister(DestReg)) {
Evan Cheng84097472007-08-02 00:28:15 +0000417 VRBase = DestReg;
Evan Chenga6fb1b62007-09-25 01:54:36 +0000418 Match = false;
419 } else if (DestReg != SrcReg)
420 Match = false;
421 } else {
422 for (unsigned i = 0, e = Use->getNumOperands(); i != e; ++i) {
423 SDOperand Op = Use->getOperand(i);
Evan Cheng7c07aeb2007-12-14 08:25:15 +0000424 if (Op.Val != Node || Op.ResNo != ResNo)
Evan Chenga6fb1b62007-09-25 01:54:36 +0000425 continue;
426 MVT::ValueType VT = Node->getValueType(Op.ResNo);
427 if (VT != MVT::Other && VT != MVT::Flag)
428 Match = false;
Evan Cheng84097472007-08-02 00:28:15 +0000429 }
430 }
Evan Chenga6fb1b62007-09-25 01:54:36 +0000431 MatchReg &= Match;
432 if (VRBase)
433 break;
Evan Cheng84097472007-08-02 00:28:15 +0000434 }
435
Evan Cheng84097472007-08-02 00:28:15 +0000436 const TargetRegisterClass *TRC = 0;
Evan Chenga6fb1b62007-09-25 01:54:36 +0000437 // Figure out the register class to create for the destreg.
438 if (VRBase)
Chris Lattner84bc5422007-12-31 04:13:23 +0000439 TRC = RegInfo.getRegClass(VRBase);
Evan Chenga6fb1b62007-09-25 01:54:36 +0000440 else
Dan Gohman6f0d0242008-02-10 18:45:23 +0000441 TRC = TRI->getPhysicalRegisterRegClass(Node->getValueType(ResNo), SrcReg);
Evan Chenga6fb1b62007-09-25 01:54:36 +0000442
443 // If all uses are reading from the src physical register and copying the
444 // register is either impossible or very expensive, then don't create a copy.
445 if (MatchReg && TRC->getCopyCost() < 0) {
446 VRBase = SrcReg;
447 } else {
Evan Cheng84097472007-08-02 00:28:15 +0000448 // Create the reg, emit the copy.
Chris Lattner84bc5422007-12-31 04:13:23 +0000449 VRBase = RegInfo.createVirtualRegister(TRC);
Owen Andersond10fd972007-12-31 06:32:00 +0000450 TII->copyRegToReg(*BB, BB->end(), VRBase, SrcReg, TRC, TRC);
Evan Cheng84097472007-08-02 00:28:15 +0000451 }
Evan Cheng84097472007-08-02 00:28:15 +0000452
Evan Chenga6fb1b62007-09-25 01:54:36 +0000453 if (InstanceNo > 0)
454 VRBaseMap.erase(SDOperand(Node, ResNo));
Evan Cheng84097472007-08-02 00:28:15 +0000455 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,ResNo), VRBase));
456 assert(isNew && "Node emitted out of order - early");
457}
458
459void ScheduleDAG::CreateVirtualRegisters(SDNode *Node,
460 MachineInstr *MI,
Chris Lattner749c6f62008-01-07 07:27:27 +0000461 const TargetInstrDesc &II,
Evan Cheng84097472007-08-02 00:28:15 +0000462 DenseMap<SDOperand, unsigned> &VRBaseMap) {
Chris Lattner349c4952008-01-07 03:13:06 +0000463 for (unsigned i = 0; i < II.getNumDefs(); ++i) {
Evan Chengaf825c82007-07-10 07:08:32 +0000464 // If the specific node value is only used by a CopyToReg and the dest reg
465 // is a vreg, use the CopyToReg'd destination register instead of creating
466 // a new vreg.
467 unsigned VRBase = 0;
468 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
469 UI != E; ++UI) {
470 SDNode *Use = *UI;
471 if (Use->getOpcode() == ISD::CopyToReg &&
472 Use->getOperand(2).Val == Node &&
473 Use->getOperand(2).ResNo == i) {
474 unsigned Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
Dan Gohman6f0d0242008-02-10 18:45:23 +0000475 if (TargetRegisterInfo::isVirtualRegister(Reg)) {
Evan Chengaf825c82007-07-10 07:08:32 +0000476 VRBase = Reg;
Chris Lattner8019f412007-12-30 00:41:17 +0000477 MI->addOperand(MachineOperand::CreateReg(Reg, true));
Evan Chengaf825c82007-07-10 07:08:32 +0000478 break;
479 }
480 }
481 }
482
Evan Cheng84097472007-08-02 00:28:15 +0000483 // Create the result registers for this node and add the result regs to
484 // the machine instruction.
Evan Chengaf825c82007-07-10 07:08:32 +0000485 if (VRBase == 0) {
Dan Gohman6f0d0242008-02-10 18:45:23 +0000486 const TargetRegisterClass *RC = getInstrOperandRegClass(TRI, TII, II, i);
Evan Chengaf825c82007-07-10 07:08:32 +0000487 assert(RC && "Isn't a register operand!");
Chris Lattner84bc5422007-12-31 04:13:23 +0000488 VRBase = RegInfo.createVirtualRegister(RC);
Chris Lattner8019f412007-12-30 00:41:17 +0000489 MI->addOperand(MachineOperand::CreateReg(VRBase, true));
Evan Chengaf825c82007-07-10 07:08:32 +0000490 }
491
492 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,i), VRBase));
493 assert(isNew && "Node emitted out of order - early");
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000494 }
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000495}
496
Chris Lattnerdf375062006-03-10 07:25:12 +0000497/// getVR - Return the virtual register corresponding to the specified result
498/// of the specified node.
Evan Chengaf825c82007-07-10 07:08:32 +0000499static unsigned getVR(SDOperand Op, DenseMap<SDOperand, unsigned> &VRBaseMap) {
500 DenseMap<SDOperand, unsigned>::iterator I = VRBaseMap.find(Op);
Chris Lattnerdf375062006-03-10 07:25:12 +0000501 assert(I != VRBaseMap.end() && "Node emitted out of order - late");
Evan Chengaf825c82007-07-10 07:08:32 +0000502 return I->second;
Chris Lattnerdf375062006-03-10 07:25:12 +0000503}
504
505
Chris Lattnered18b682006-02-24 18:54:03 +0000506/// AddOperand - Add the specified operand to the specified machine instr. II
507/// specifies the instruction information for the node, and IIOpNum is the
508/// operand number (in the II) that we are adding. IIOpNum and II are used for
509/// assertions only.
510void ScheduleDAG::AddOperand(MachineInstr *MI, SDOperand Op,
511 unsigned IIOpNum,
Chris Lattner749c6f62008-01-07 07:27:27 +0000512 const TargetInstrDesc *II,
Evan Chengaf825c82007-07-10 07:08:32 +0000513 DenseMap<SDOperand, unsigned> &VRBaseMap) {
Chris Lattnered18b682006-02-24 18:54:03 +0000514 if (Op.isTargetOpcode()) {
515 // Note that this case is redundant with the final else block, but we
516 // include it because it is the most common and it makes the logic
517 // simpler here.
518 assert(Op.getValueType() != MVT::Other &&
519 Op.getValueType() != MVT::Flag &&
520 "Chain and flag operands should occur at end of operand list!");
521
522 // Get/emit the operand.
Chris Lattnerdf375062006-03-10 07:25:12 +0000523 unsigned VReg = getVR(Op, VRBaseMap);
Chris Lattner749c6f62008-01-07 07:27:27 +0000524 const TargetInstrDesc &TID = MI->getDesc();
525 bool isOptDef = (IIOpNum < TID.getNumOperands())
526 ? (TID.OpInfo[IIOpNum].isOptionalDef()) : false;
Chris Lattner8019f412007-12-30 00:41:17 +0000527 MI->addOperand(MachineOperand::CreateReg(VReg, isOptDef));
Chris Lattnered18b682006-02-24 18:54:03 +0000528
529 // Verify that it is right.
Dan Gohman6f0d0242008-02-10 18:45:23 +0000530 assert(TargetRegisterInfo::isVirtualRegister(VReg) && "Not a vreg?");
Chris Lattnered18b682006-02-24 18:54:03 +0000531 if (II) {
Jim Laskey60f09922006-07-21 20:57:35 +0000532 const TargetRegisterClass *RC =
Dan Gohman6f0d0242008-02-10 18:45:23 +0000533 getInstrOperandRegClass(TRI, TII, *II, IIOpNum);
Evan Cheng21d03f22006-05-18 20:42:07 +0000534 assert(RC && "Don't have operand info for this instruction!");
Chris Lattner84bc5422007-12-31 04:13:23 +0000535 const TargetRegisterClass *VRC = RegInfo.getRegClass(VReg);
Chris Lattner01528292007-02-15 18:17:56 +0000536 if (VRC != RC) {
537 cerr << "Register class of operand and regclass of use don't agree!\n";
538#ifndef NDEBUG
539 cerr << "Operand = " << IIOpNum << "\n";
Chris Lattner95ad9432007-02-17 06:38:37 +0000540 cerr << "Op->Val = "; Op.Val->dump(&DAG); cerr << "\n";
Chris Lattner01528292007-02-15 18:17:56 +0000541 cerr << "MI = "; MI->print(cerr);
542 cerr << "VReg = " << VReg << "\n";
543 cerr << "VReg RegClass size = " << VRC->getSize()
Chris Lattner5d4a9f72007-02-15 18:19:15 +0000544 << ", align = " << VRC->getAlignment() << "\n";
Chris Lattner01528292007-02-15 18:17:56 +0000545 cerr << "Expected RegClass size = " << RC->getSize()
Chris Lattner5d4a9f72007-02-15 18:19:15 +0000546 << ", align = " << RC->getAlignment() << "\n";
Chris Lattner01528292007-02-15 18:17:56 +0000547#endif
548 cerr << "Fatal error, aborting.\n";
549 abort();
550 }
Chris Lattnered18b682006-02-24 18:54:03 +0000551 }
Chris Lattnerfec65d52007-12-30 00:51:11 +0000552 } else if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
Chris Lattner8019f412007-12-30 00:41:17 +0000553 MI->addOperand(MachineOperand::CreateImm(C->getValue()));
Nate Begemane1795842008-02-14 08:57:00 +0000554 } else if (ConstantFPSDNode *F = dyn_cast<ConstantFPSDNode>(Op)) {
555 const Type *FType = MVT::getTypeForValueType(Op.getValueType());
556 ConstantFP *CFP = ConstantFP::get(FType, F->getValueAPF());
557 MI->addOperand(MachineOperand::CreateFPImm(CFP));
Chris Lattnerfec65d52007-12-30 00:51:11 +0000558 } else if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(Op)) {
Chris Lattner8019f412007-12-30 00:41:17 +0000559 MI->addOperand(MachineOperand::CreateReg(R->getReg(), false));
Chris Lattnerfec65d52007-12-30 00:51:11 +0000560 } else if (GlobalAddressSDNode *TGA = dyn_cast<GlobalAddressSDNode>(Op)) {
561 MI->addOperand(MachineOperand::CreateGA(TGA->getGlobal(),TGA->getOffset()));
562 } else if (BasicBlockSDNode *BB = dyn_cast<BasicBlockSDNode>(Op)) {
563 MI->addOperand(MachineOperand::CreateMBB(BB->getBasicBlock()));
564 } else if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Op)) {
565 MI->addOperand(MachineOperand::CreateFI(FI->getIndex()));
566 } else if (JumpTableSDNode *JT = dyn_cast<JumpTableSDNode>(Op)) {
567 MI->addOperand(MachineOperand::CreateJTI(JT->getIndex()));
568 } else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Op)) {
Evan Cheng404cb4f2006-02-25 09:54:52 +0000569 int Offset = CP->getOffset();
Chris Lattnered18b682006-02-24 18:54:03 +0000570 unsigned Align = CP->getAlignment();
Evan Chengd6594ae2006-09-12 21:00:35 +0000571 const Type *Type = CP->getType();
Chris Lattnered18b682006-02-24 18:54:03 +0000572 // MachineConstantPool wants an explicit alignment.
573 if (Align == 0) {
Evan Chengde268f72007-01-24 07:03:39 +0000574 Align = TM.getTargetData()->getPreferredTypeAlignmentShift(Type);
Evan Chengf6d039a2007-01-22 23:13:55 +0000575 if (Align == 0) {
Reid Spencerac9dcb92007-02-15 03:39:18 +0000576 // Alignment of vector types. FIXME!
Duncan Sands514ab342007-11-01 20:53:16 +0000577 Align = TM.getTargetData()->getABITypeSize(Type);
Evan Chengf6d039a2007-01-22 23:13:55 +0000578 Align = Log2_64(Align);
Chris Lattner54a30b92006-03-20 01:51:46 +0000579 }
Chris Lattnered18b682006-02-24 18:54:03 +0000580 }
581
Evan Chengd6594ae2006-09-12 21:00:35 +0000582 unsigned Idx;
583 if (CP->isMachineConstantPoolEntry())
584 Idx = ConstPool->getConstantPoolIndex(CP->getMachineCPVal(), Align);
585 else
586 Idx = ConstPool->getConstantPoolIndex(CP->getConstVal(), Align);
Chris Lattnerfec65d52007-12-30 00:51:11 +0000587 MI->addOperand(MachineOperand::CreateCPI(Idx, Offset));
588 } else if (ExternalSymbolSDNode *ES = dyn_cast<ExternalSymbolSDNode>(Op)) {
589 MI->addOperand(MachineOperand::CreateES(ES->getSymbol()));
Chris Lattnered18b682006-02-24 18:54:03 +0000590 } else {
591 assert(Op.getValueType() != MVT::Other &&
592 Op.getValueType() != MVT::Flag &&
593 "Chain and flag operands should occur at end of operand list!");
Chris Lattnerdf375062006-03-10 07:25:12 +0000594 unsigned VReg = getVR(Op, VRBaseMap);
Chris Lattner8019f412007-12-30 00:41:17 +0000595 MI->addOperand(MachineOperand::CreateReg(VReg, false));
Chris Lattnered18b682006-02-24 18:54:03 +0000596
597 // Verify that it is right.
Dan Gohman6f0d0242008-02-10 18:45:23 +0000598 assert(TargetRegisterInfo::isVirtualRegister(VReg) && "Not a vreg?");
Chris Lattnered18b682006-02-24 18:54:03 +0000599 if (II) {
Jim Laskey60f09922006-07-21 20:57:35 +0000600 const TargetRegisterClass *RC =
Dan Gohman6f0d0242008-02-10 18:45:23 +0000601 getInstrOperandRegClass(TRI, TII, *II, IIOpNum);
Evan Cheng21d03f22006-05-18 20:42:07 +0000602 assert(RC && "Don't have operand info for this instruction!");
Chris Lattner84bc5422007-12-31 04:13:23 +0000603 assert(RegInfo.getRegClass(VReg) == RC &&
Chris Lattnered18b682006-02-24 18:54:03 +0000604 "Register class of operand and regclass of use don't agree!");
605 }
606 }
607
608}
609
Dan Gohman69de1932008-02-06 22:27:42 +0000610void ScheduleDAG::AddMemOperand(MachineInstr *MI, const MemOperand &MO) {
611 MI->addMemOperand(MO);
612}
613
Christopher Lambe24f8f12007-07-26 08:12:07 +0000614// Returns the Register Class of a subregister
615static const TargetRegisterClass *getSubRegisterRegClass(
616 const TargetRegisterClass *TRC,
617 unsigned SubIdx) {
618 // Pick the register class of the subregister
Dan Gohman6f0d0242008-02-10 18:45:23 +0000619 TargetRegisterInfo::regclass_iterator I =
620 TRC->subregclasses_begin() + SubIdx-1;
Christopher Lambe24f8f12007-07-26 08:12:07 +0000621 assert(I < TRC->subregclasses_end() &&
622 "Invalid subregister index for register class");
623 return *I;
624}
625
626static const TargetRegisterClass *getSuperregRegisterClass(
627 const TargetRegisterClass *TRC,
628 unsigned SubIdx,
629 MVT::ValueType VT) {
630 // Pick the register class of the superegister for this type
Dan Gohman6f0d0242008-02-10 18:45:23 +0000631 for (TargetRegisterInfo::regclass_iterator I = TRC->superregclasses_begin(),
Christopher Lambe24f8f12007-07-26 08:12:07 +0000632 E = TRC->superregclasses_end(); I != E; ++I)
633 if ((*I)->hasType(VT) && getSubRegisterRegClass(*I, SubIdx) == TRC)
634 return *I;
635 assert(false && "Couldn't find the register class");
636 return 0;
637}
638
639/// EmitSubregNode - Generate machine code for subreg nodes.
640///
641void ScheduleDAG::EmitSubregNode(SDNode *Node,
642 DenseMap<SDOperand, unsigned> &VRBaseMap) {
643 unsigned VRBase = 0;
644 unsigned Opc = Node->getTargetOpcode();
645 if (Opc == TargetInstrInfo::EXTRACT_SUBREG) {
646 // If the node is only used by a CopyToReg and the dest reg is a vreg, use
647 // the CopyToReg'd destination register instead of creating a new vreg.
648 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
649 UI != E; ++UI) {
650 SDNode *Use = *UI;
651 if (Use->getOpcode() == ISD::CopyToReg &&
652 Use->getOperand(2).Val == Node) {
653 unsigned DestReg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
Dan Gohman6f0d0242008-02-10 18:45:23 +0000654 if (TargetRegisterInfo::isVirtualRegister(DestReg)) {
Christopher Lambe24f8f12007-07-26 08:12:07 +0000655 VRBase = DestReg;
656 break;
657 }
658 }
659 }
660
661 unsigned SubIdx = cast<ConstantSDNode>(Node->getOperand(1))->getValue();
662
663 // TODO: If the node is a use of a CopyFromReg from a physical register
664 // fold the extract into the copy now
665
Christopher Lambe24f8f12007-07-26 08:12:07 +0000666 // Create the extract_subreg machine instruction.
667 MachineInstr *MI =
668 new MachineInstr(BB, TII->get(TargetInstrInfo::EXTRACT_SUBREG));
669
670 // Figure out the register class to create for the destreg.
671 unsigned VReg = getVR(Node->getOperand(0), VRBaseMap);
Chris Lattner84bc5422007-12-31 04:13:23 +0000672 const TargetRegisterClass *TRC = RegInfo.getRegClass(VReg);
Christopher Lambe24f8f12007-07-26 08:12:07 +0000673 const TargetRegisterClass *SRC = getSubRegisterRegClass(TRC, SubIdx);
674
675 if (VRBase) {
676 // Grab the destination register
677 const TargetRegisterClass *DRC = 0;
Chris Lattner84bc5422007-12-31 04:13:23 +0000678 DRC = RegInfo.getRegClass(VRBase);
Christopher Lamb175e8152008-01-31 07:09:08 +0000679 assert(SRC && DRC && SRC == DRC &&
Christopher Lambe24f8f12007-07-26 08:12:07 +0000680 "Source subregister and destination must have the same class");
681 } else {
682 // Create the reg
Christopher Lamb175e8152008-01-31 07:09:08 +0000683 assert(SRC && "Couldn't find source register class");
Chris Lattner84bc5422007-12-31 04:13:23 +0000684 VRBase = RegInfo.createVirtualRegister(SRC);
Christopher Lambe24f8f12007-07-26 08:12:07 +0000685 }
686
687 // Add def, source, and subreg index
Chris Lattner8019f412007-12-30 00:41:17 +0000688 MI->addOperand(MachineOperand::CreateReg(VRBase, true));
Christopher Lambe24f8f12007-07-26 08:12:07 +0000689 AddOperand(MI, Node->getOperand(0), 0, 0, VRBaseMap);
Chris Lattnerfec65d52007-12-30 00:51:11 +0000690 MI->addOperand(MachineOperand::CreateImm(SubIdx));
Christopher Lambe24f8f12007-07-26 08:12:07 +0000691
692 } else if (Opc == TargetInstrInfo::INSERT_SUBREG) {
693 assert((Node->getNumOperands() == 2 || Node->getNumOperands() == 3) &&
694 "Malformed insert_subreg node");
695 bool isUndefInput = (Node->getNumOperands() == 2);
696 unsigned SubReg = 0;
697 unsigned SubIdx = 0;
698
699 if (isUndefInput) {
700 SubReg = getVR(Node->getOperand(0), VRBaseMap);
701 SubIdx = cast<ConstantSDNode>(Node->getOperand(1))->getValue();
702 } else {
703 SubReg = getVR(Node->getOperand(1), VRBaseMap);
704 SubIdx = cast<ConstantSDNode>(Node->getOperand(2))->getValue();
705 }
706
Chris Lattner534bcfb2007-12-31 04:16:08 +0000707 // TODO: Add tracking info to MachineRegisterInfo of which vregs are subregs
Christopher Lambe24f8f12007-07-26 08:12:07 +0000708 // to allow coalescing in the allocator
709
710 // If the node is only used by a CopyToReg and the dest reg is a vreg, use
711 // the CopyToReg'd destination register instead of creating a new vreg.
712 // If the CopyToReg'd destination register is physical, then fold the
713 // insert into the copy
714 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
715 UI != E; ++UI) {
716 SDNode *Use = *UI;
717 if (Use->getOpcode() == ISD::CopyToReg &&
718 Use->getOperand(2).Val == Node) {
719 unsigned DestReg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
Dan Gohman6f0d0242008-02-10 18:45:23 +0000720 if (TargetRegisterInfo::isVirtualRegister(DestReg)) {
Christopher Lambe24f8f12007-07-26 08:12:07 +0000721 VRBase = DestReg;
722 break;
723 }
724 }
725 }
726
727 // Create the insert_subreg machine instruction.
728 MachineInstr *MI =
729 new MachineInstr(BB, TII->get(TargetInstrInfo::INSERT_SUBREG));
730
731 // Figure out the register class to create for the destreg.
732 const TargetRegisterClass *TRC = 0;
733 if (VRBase) {
Chris Lattner84bc5422007-12-31 04:13:23 +0000734 TRC = RegInfo.getRegClass(VRBase);
Christopher Lambe24f8f12007-07-26 08:12:07 +0000735 } else {
Chris Lattner84bc5422007-12-31 04:13:23 +0000736 TRC = getSuperregRegisterClass(RegInfo.getRegClass(SubReg), SubIdx,
Christopher Lambe24f8f12007-07-26 08:12:07 +0000737 Node->getValueType(0));
738 assert(TRC && "Couldn't determine register class for insert_subreg");
Chris Lattner84bc5422007-12-31 04:13:23 +0000739 VRBase = RegInfo.createVirtualRegister(TRC); // Create the reg
Christopher Lambe24f8f12007-07-26 08:12:07 +0000740 }
741
Chris Lattner8019f412007-12-30 00:41:17 +0000742 MI->addOperand(MachineOperand::CreateReg(VRBase, true));
Christopher Lambe24f8f12007-07-26 08:12:07 +0000743 AddOperand(MI, Node->getOperand(0), 0, 0, VRBaseMap);
744 if (!isUndefInput)
745 AddOperand(MI, Node->getOperand(1), 0, 0, VRBaseMap);
Chris Lattnerfec65d52007-12-30 00:51:11 +0000746 MI->addOperand(MachineOperand::CreateImm(SubIdx));
Christopher Lambe24f8f12007-07-26 08:12:07 +0000747 } else
748 assert(0 && "Node is not a subreg insert or extract");
749
750 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,0), VRBase));
751 assert(isNew && "Node emitted out of order - early");
752}
753
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000754/// EmitNode - Generate machine code for an node and needed dependencies.
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000755///
Evan Chenga6fb1b62007-09-25 01:54:36 +0000756void ScheduleDAG::EmitNode(SDNode *Node, unsigned InstanceNo,
Evan Chengaf825c82007-07-10 07:08:32 +0000757 DenseMap<SDOperand, unsigned> &VRBaseMap) {
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000758 // If machine instruction
759 if (Node->isTargetOpcode()) {
760 unsigned Opc = Node->getTargetOpcode();
Christopher Lambe24f8f12007-07-26 08:12:07 +0000761
762 // Handle subreg insert/extract specially
763 if (Opc == TargetInstrInfo::EXTRACT_SUBREG ||
764 Opc == TargetInstrInfo::INSERT_SUBREG) {
765 EmitSubregNode(Node, VRBaseMap);
766 return;
767 }
768
Chris Lattner749c6f62008-01-07 07:27:27 +0000769 const TargetInstrDesc &II = TII->get(Opc);
Chris Lattner2d973e42005-08-18 20:07:59 +0000770
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000771 unsigned NumResults = CountResults(Node);
772 unsigned NodeOperands = CountOperands(Node);
Dan Gohman42a77882008-02-16 00:36:48 +0000773 unsigned MemOperandsEnd = ComputeMemOperandsEnd(Node);
Jim Laskeye6b90fb2005-09-26 21:57:04 +0000774 unsigned NumMIOperands = NodeOperands + NumResults;
Chris Lattner349c4952008-01-07 03:13:06 +0000775 bool HasPhysRegOuts = (NumResults > II.getNumDefs()) &&
776 II.getImplicitDefs() != 0;
Chris Lattnerda8abb02005-09-01 18:44:10 +0000777#ifndef NDEBUG
Chris Lattner349c4952008-01-07 03:13:06 +0000778 assert((II.getNumOperands() == NumMIOperands ||
Chris Lattner8f707e12008-01-07 05:19:29 +0000779 HasPhysRegOuts || II.isVariadic()) &&
Chris Lattner2d973e42005-08-18 20:07:59 +0000780 "#operands for dag node doesn't match .td file!");
Chris Lattnerca6aa2f2005-08-19 01:01:34 +0000781#endif
Chris Lattner2d973e42005-08-18 20:07:59 +0000782
783 // Create the new machine instruction.
Evan Chengc0f64ff2006-11-27 23:37:22 +0000784 MachineInstr *MI = new MachineInstr(II);
Chris Lattner2d973e42005-08-18 20:07:59 +0000785
786 // Add result register values for things that are defined by this
787 // instruction.
Evan Chengaf825c82007-07-10 07:08:32 +0000788 if (NumResults)
Evan Cheng84097472007-08-02 00:28:15 +0000789 CreateVirtualRegisters(Node, MI, II, VRBaseMap);
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000790
791 // Emit all of the actual operands of this instruction, adding them to the
792 // instruction as appropriate.
Chris Lattnered18b682006-02-24 18:54:03 +0000793 for (unsigned i = 0; i != NodeOperands; ++i)
Chris Lattner349c4952008-01-07 03:13:06 +0000794 AddOperand(MI, Node->getOperand(i), i+II.getNumDefs(), &II, VRBaseMap);
Evan Cheng13d41b92006-05-12 01:58:24 +0000795
Dan Gohman69de1932008-02-06 22:27:42 +0000796 // Emit all of the memory operands of this instruction
Dan Gohman42a77882008-02-16 00:36:48 +0000797 for (unsigned i = NodeOperands; i != MemOperandsEnd; ++i)
Dan Gohman69de1932008-02-06 22:27:42 +0000798 AddMemOperand(MI, cast<MemOperandSDNode>(Node->getOperand(i))->MO);
799
Evan Cheng13d41b92006-05-12 01:58:24 +0000800 // Commute node if it has been determined to be profitable.
801 if (CommuteSet.count(Node)) {
802 MachineInstr *NewMI = TII->commuteInstruction(MI);
803 if (NewMI == 0)
Bill Wendling832171c2006-12-07 20:04:42 +0000804 DOUT << "Sched: COMMUTING FAILED!\n";
Evan Cheng13d41b92006-05-12 01:58:24 +0000805 else {
Bill Wendling832171c2006-12-07 20:04:42 +0000806 DOUT << "Sched: COMMUTED TO: " << *NewMI;
Evan Cheng4c6f2f92006-05-31 18:03:39 +0000807 if (MI != NewMI) {
808 delete MI;
809 MI = NewMI;
810 }
Evan Cheng643afa52008-02-28 07:40:24 +0000811 ++NumCommutes;
Evan Cheng13d41b92006-05-12 01:58:24 +0000812 }
813 }
814
Evan Cheng1b08bbc2008-02-01 09:10:45 +0000815 if (II.usesCustomDAGSchedInsertionHook())
Evan Cheng6b2cf282008-01-30 19:35:32 +0000816 // Insert this instruction into the basic block using a target
817 // specific inserter which may returns a new basic block.
Evan Chengff9b3732008-01-30 18:18:23 +0000818 BB = DAG.getTargetLoweringInfo().EmitInstrWithCustomInserter(MI, BB);
Evan Cheng6b2cf282008-01-30 19:35:32 +0000819 else
820 BB->push_back(MI);
Evan Cheng84097472007-08-02 00:28:15 +0000821
822 // Additional results must be an physical register def.
823 if (HasPhysRegOuts) {
Chris Lattner349c4952008-01-07 03:13:06 +0000824 for (unsigned i = II.getNumDefs(); i < NumResults; ++i) {
825 unsigned Reg = II.getImplicitDefs()[i - II.getNumDefs()];
Evan Cheng33d55952007-08-02 05:29:38 +0000826 if (Node->hasAnyUseOfValue(i))
Evan Chenga6fb1b62007-09-25 01:54:36 +0000827 EmitCopyFromReg(Node, i, InstanceNo, Reg, VRBaseMap);
Evan Cheng84097472007-08-02 00:28:15 +0000828 }
829 }
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000830 } else {
831 switch (Node->getOpcode()) {
832 default:
Jim Laskey16d42c62006-07-11 18:25:13 +0000833#ifndef NDEBUG
Dan Gohmanb5bec2b2007-06-19 14:13:56 +0000834 Node->dump(&DAG);
Jim Laskey16d42c62006-07-11 18:25:13 +0000835#endif
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000836 assert(0 && "This target-independent node should have been selected!");
837 case ISD::EntryToken: // fall thru
838 case ISD::TokenFactor:
Jim Laskey1ee29252007-01-26 14:34:52 +0000839 case ISD::LABEL:
Evan Chenga844bde2008-02-02 04:07:54 +0000840 case ISD::DECLARE:
Dan Gohman69de1932008-02-06 22:27:42 +0000841 case ISD::SRCVALUE:
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000842 break;
843 case ISD::CopyToReg: {
Evan Cheng489a87c2007-01-05 20:59:06 +0000844 unsigned InReg;
845 if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(Node->getOperand(2)))
846 InReg = R->getReg();
847 else
848 InReg = getVR(Node->getOperand(2), VRBaseMap);
Chris Lattnera4176522005-10-30 18:54:27 +0000849 unsigned DestReg = cast<RegisterSDNode>(Node->getOperand(1))->getReg();
Lauro Ramos Venancio8334b9f2007-03-20 16:46:44 +0000850 if (InReg != DestReg) {// Coalesced away the copy?
851 const TargetRegisterClass *TRC = 0;
852 // Get the target register class
Dan Gohman6f0d0242008-02-10 18:45:23 +0000853 if (TargetRegisterInfo::isVirtualRegister(InReg))
Chris Lattner84bc5422007-12-31 04:13:23 +0000854 TRC = RegInfo.getRegClass(InReg);
Lauro Ramos Venancioa0a26b72007-03-20 20:09:03 +0000855 else
Evan Cheng42d60272007-09-26 21:36:17 +0000856 TRC =
Dan Gohman6f0d0242008-02-10 18:45:23 +0000857 TRI->getPhysicalRegisterRegClass(Node->getOperand(2).getValueType(),
Lauro Ramos Venancioa0a26b72007-03-20 20:09:03 +0000858 InReg);
Owen Andersond10fd972007-12-31 06:32:00 +0000859 TII->copyRegToReg(*BB, BB->end(), DestReg, InReg, TRC, TRC);
Lauro Ramos Venancio8334b9f2007-03-20 16:46:44 +0000860 }
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000861 break;
862 }
863 case ISD::CopyFromReg: {
864 unsigned SrcReg = cast<RegisterSDNode>(Node->getOperand(1))->getReg();
Evan Chenga6fb1b62007-09-25 01:54:36 +0000865 EmitCopyFromReg(Node, 0, InstanceNo, SrcReg, VRBaseMap);
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000866 break;
867 }
Chris Lattneracc43bf2006-01-26 23:28:04 +0000868 case ISD::INLINEASM: {
869 unsigned NumOps = Node->getNumOperands();
870 if (Node->getOperand(NumOps-1).getValueType() == MVT::Flag)
871 --NumOps; // Ignore the flag operand.
872
873 // Create the inline asm machine instruction.
874 MachineInstr *MI =
Evan Chengc0f64ff2006-11-27 23:37:22 +0000875 new MachineInstr(BB, TII->get(TargetInstrInfo::INLINEASM));
Chris Lattneracc43bf2006-01-26 23:28:04 +0000876
877 // Add the asm string as an external symbol operand.
878 const char *AsmStr =
879 cast<ExternalSymbolSDNode>(Node->getOperand(1))->getSymbol();
Chris Lattnerfec65d52007-12-30 00:51:11 +0000880 MI->addOperand(MachineOperand::CreateES(AsmStr));
Chris Lattneracc43bf2006-01-26 23:28:04 +0000881
882 // Add all of the operand registers to the instruction.
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000883 for (unsigned i = 2; i != NumOps;) {
884 unsigned Flags = cast<ConstantSDNode>(Node->getOperand(i))->getValue();
Chris Lattnerfd6d2822006-02-24 19:18:20 +0000885 unsigned NumVals = Flags >> 3;
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000886
Chris Lattnerfec65d52007-12-30 00:51:11 +0000887 MI->addOperand(MachineOperand::CreateImm(Flags));
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000888 ++i; // Skip the ID value.
889
890 switch (Flags & 7) {
Chris Lattneracc43bf2006-01-26 23:28:04 +0000891 default: assert(0 && "Bad flags!");
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000892 case 1: // Use of register.
Chris Lattnerfd6d2822006-02-24 19:18:20 +0000893 for (; NumVals; --NumVals, ++i) {
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000894 unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
Chris Lattner8019f412007-12-30 00:41:17 +0000895 MI->addOperand(MachineOperand::CreateReg(Reg, false));
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000896 }
Chris Lattnerdc19b702006-02-04 02:26:14 +0000897 break;
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000898 case 2: // Def of register.
Chris Lattnerfd6d2822006-02-24 19:18:20 +0000899 for (; NumVals; --NumVals, ++i) {
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000900 unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
Chris Lattner8019f412007-12-30 00:41:17 +0000901 MI->addOperand(MachineOperand::CreateReg(Reg, true));
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +0000902 }
Chris Lattnerdc19b702006-02-04 02:26:14 +0000903 break;
Chris Lattnerdc19b702006-02-04 02:26:14 +0000904 case 3: { // Immediate.
Chris Lattner7df31dc2007-08-25 00:53:07 +0000905 for (; NumVals; --NumVals, ++i) {
906 if (ConstantSDNode *CS =
907 dyn_cast<ConstantSDNode>(Node->getOperand(i))) {
Chris Lattner8019f412007-12-30 00:41:17 +0000908 MI->addOperand(MachineOperand::CreateImm(CS->getValue()));
Dale Johanneseneb57ea72007-11-05 21:20:28 +0000909 } else if (GlobalAddressSDNode *GA =
910 dyn_cast<GlobalAddressSDNode>(Node->getOperand(i))) {
Chris Lattnerfec65d52007-12-30 00:51:11 +0000911 MI->addOperand(MachineOperand::CreateGA(GA->getGlobal(),
912 GA->getOffset()));
Dale Johanneseneb57ea72007-11-05 21:20:28 +0000913 } else {
Chris Lattnerfec65d52007-12-30 00:51:11 +0000914 BasicBlockSDNode *BB =cast<BasicBlockSDNode>(Node->getOperand(i));
915 MI->addOperand(MachineOperand::CreateMBB(BB->getBasicBlock()));
Chris Lattner7df31dc2007-08-25 00:53:07 +0000916 }
Chris Lattnerefa46ce2006-10-31 20:01:56 +0000917 }
Chris Lattnerdc19b702006-02-04 02:26:14 +0000918 break;
919 }
Chris Lattnerfd6d2822006-02-24 19:18:20 +0000920 case 4: // Addressing mode.
921 // The addressing mode has been selected, just add all of the
922 // operands to the machine instruction.
923 for (; NumVals; --NumVals, ++i)
Chris Lattnerdf375062006-03-10 07:25:12 +0000924 AddOperand(MI, Node->getOperand(i), 0, 0, VRBaseMap);
Chris Lattnerfd6d2822006-02-24 19:18:20 +0000925 break;
Chris Lattnerdc19b702006-02-04 02:26:14 +0000926 }
Chris Lattneracc43bf2006-01-26 23:28:04 +0000927 }
928 break;
929 }
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000930 }
931 }
Jim Laskeyb6d4c2c2005-09-30 19:15:27 +0000932}
933
Chris Lattnera93dfcd2006-03-05 23:51:47 +0000934void ScheduleDAG::EmitNoop() {
935 TII->insertNoop(*BB, BB->end());
936}
937
Chris Lattnerd9c4c452008-03-09 07:51:01 +0000938void ScheduleDAG::EmitCrossRCCopy(SUnit *SU,
939 DenseMap<SUnit*, unsigned> &VRBaseMap) {
Evan Cheng42d60272007-09-26 21:36:17 +0000940 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
941 I != E; ++I) {
942 if (I->isCtrl) continue; // ignore chain preds
943 if (!I->Dep->Node) {
944 // Copy to physical register.
945 DenseMap<SUnit*, unsigned>::iterator VRI = VRBaseMap.find(I->Dep);
946 assert(VRI != VRBaseMap.end() && "Node emitted out of order - late");
947 // Find the destination physical register.
948 unsigned Reg = 0;
949 for (SUnit::const_succ_iterator II = SU->Succs.begin(),
950 EE = SU->Succs.end(); II != EE; ++II) {
951 if (I->Reg) {
952 Reg = I->Reg;
953 break;
954 }
955 }
956 assert(I->Reg && "Unknown physical register!");
Owen Andersond10fd972007-12-31 06:32:00 +0000957 TII->copyRegToReg(*BB, BB->end(), Reg, VRI->second,
Evan Cheng42d60272007-09-26 21:36:17 +0000958 SU->CopyDstRC, SU->CopySrcRC);
959 } else {
960 // Copy from physical register.
961 assert(I->Reg && "Unknown physical register!");
Chris Lattner84bc5422007-12-31 04:13:23 +0000962 unsigned VRBase = RegInfo.createVirtualRegister(SU->CopyDstRC);
Evan Cheng42d60272007-09-26 21:36:17 +0000963 bool isNew = VRBaseMap.insert(std::make_pair(SU, VRBase));
964 assert(isNew && "Node emitted out of order - early");
Owen Andersond10fd972007-12-31 06:32:00 +0000965 TII->copyRegToReg(*BB, BB->end(), VRBase, I->Reg,
Evan Cheng42d60272007-09-26 21:36:17 +0000966 SU->CopyDstRC, SU->CopySrcRC);
967 }
968 break;
969 }
970}
971
Evan Chenge165a782006-05-11 23:55:42 +0000972/// EmitSchedule - Emit the machine code in scheduled order.
973void ScheduleDAG::EmitSchedule() {
Chris Lattner96645412006-05-16 06:10:58 +0000974 // If this is the first basic block in the function, and if it has live ins
975 // that need to be copied into vregs, emit the copies into the top of the
976 // block before emitting the code for the block.
Evan Cheng6b2cf282008-01-30 19:35:32 +0000977 if (&MF->front() == BB) {
Chris Lattner84bc5422007-12-31 04:13:23 +0000978 for (MachineRegisterInfo::livein_iterator LI = RegInfo.livein_begin(),
979 E = RegInfo.livein_end(); LI != E; ++LI)
Evan Cheng9efce632007-09-26 06:25:56 +0000980 if (LI->second) {
Chris Lattner84bc5422007-12-31 04:13:23 +0000981 const TargetRegisterClass *RC = RegInfo.getRegClass(LI->second);
Evan Cheng6b2cf282008-01-30 19:35:32 +0000982 TII->copyRegToReg(*MF->begin(), MF->begin()->end(), LI->second,
Evan Cheng9efce632007-09-26 06:25:56 +0000983 LI->first, RC, RC);
984 }
Chris Lattner96645412006-05-16 06:10:58 +0000985 }
986
987
988 // Finally, emit the code for all of the scheduled instructions.
Evan Chengaf825c82007-07-10 07:08:32 +0000989 DenseMap<SDOperand, unsigned> VRBaseMap;
Evan Cheng42d60272007-09-26 21:36:17 +0000990 DenseMap<SUnit*, unsigned> CopyVRBaseMap;
Evan Chenge165a782006-05-11 23:55:42 +0000991 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
992 if (SUnit *SU = Sequence[i]) {
Evan Chenga6fb1b62007-09-25 01:54:36 +0000993 for (unsigned j = 0, ee = SU->FlaggedNodes.size(); j != ee; ++j)
994 EmitNode(SU->FlaggedNodes[j], SU->InstanceNo, VRBaseMap);
Evan Cheng42d60272007-09-26 21:36:17 +0000995 if (SU->Node)
996 EmitNode(SU->Node, SU->InstanceNo, VRBaseMap);
997 else
998 EmitCrossRCCopy(SU, CopyVRBaseMap);
Evan Chenge165a782006-05-11 23:55:42 +0000999 } else {
1000 // Null SUnit* is a noop.
1001 EmitNoop();
1002 }
1003 }
1004}
1005
1006/// dump - dump the schedule.
1007void ScheduleDAG::dumpSchedule() const {
1008 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
1009 if (SUnit *SU = Sequence[i])
1010 SU->dump(&DAG);
1011 else
Bill Wendling832171c2006-12-07 20:04:42 +00001012 cerr << "**** NOOP ****\n";
Evan Chenge165a782006-05-11 23:55:42 +00001013 }
1014}
1015
1016
Evan Chenga9c20912006-01-21 02:32:06 +00001017/// Run - perform scheduling.
1018///
1019MachineBasicBlock *ScheduleDAG::Run() {
Evan Chenga9c20912006-01-21 02:32:06 +00001020 Schedule();
1021 return BB;
Chris Lattnerd32b2362005-08-18 18:45:24 +00001022}
Evan Cheng4ef10862006-01-23 07:01:07 +00001023
Evan Chenge165a782006-05-11 23:55:42 +00001024/// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
1025/// a group of nodes flagged together.
1026void SUnit::dump(const SelectionDAG *G) const {
Bill Wendling832171c2006-12-07 20:04:42 +00001027 cerr << "SU(" << NodeNum << "): ";
Evan Cheng42d60272007-09-26 21:36:17 +00001028 if (Node)
1029 Node->dump(G);
1030 else
1031 cerr << "CROSS RC COPY ";
Bill Wendling832171c2006-12-07 20:04:42 +00001032 cerr << "\n";
Evan Chenge165a782006-05-11 23:55:42 +00001033 if (FlaggedNodes.size() != 0) {
1034 for (unsigned i = 0, e = FlaggedNodes.size(); i != e; i++) {
Bill Wendling832171c2006-12-07 20:04:42 +00001035 cerr << " ";
Evan Chenge165a782006-05-11 23:55:42 +00001036 FlaggedNodes[i]->dump(G);
Bill Wendling832171c2006-12-07 20:04:42 +00001037 cerr << "\n";
Evan Chenge165a782006-05-11 23:55:42 +00001038 }
1039 }
1040}
Evan Cheng4ef10862006-01-23 07:01:07 +00001041
Evan Chenge165a782006-05-11 23:55:42 +00001042void SUnit::dumpAll(const SelectionDAG *G) const {
1043 dump(G);
1044
Bill Wendling832171c2006-12-07 20:04:42 +00001045 cerr << " # preds left : " << NumPredsLeft << "\n";
1046 cerr << " # succs left : " << NumSuccsLeft << "\n";
Bill Wendling832171c2006-12-07 20:04:42 +00001047 cerr << " Latency : " << Latency << "\n";
1048 cerr << " Depth : " << Depth << "\n";
1049 cerr << " Height : " << Height << "\n";
Evan Chenge165a782006-05-11 23:55:42 +00001050
1051 if (Preds.size() != 0) {
Bill Wendling832171c2006-12-07 20:04:42 +00001052 cerr << " Predecessors:\n";
Chris Lattner228a18e2006-08-17 00:09:56 +00001053 for (SUnit::const_succ_iterator I = Preds.begin(), E = Preds.end();
1054 I != E; ++I) {
Evan Cheng713a98d2007-09-19 01:38:40 +00001055 if (I->isCtrl)
Bill Wendling832171c2006-12-07 20:04:42 +00001056 cerr << " ch #";
Evan Chenge165a782006-05-11 23:55:42 +00001057 else
Bill Wendling832171c2006-12-07 20:04:42 +00001058 cerr << " val #";
Evan Chenga6fb1b62007-09-25 01:54:36 +00001059 cerr << I->Dep << " - SU(" << I->Dep->NodeNum << ")";
1060 if (I->isSpecial)
1061 cerr << " *";
1062 cerr << "\n";
Evan Chenge165a782006-05-11 23:55:42 +00001063 }
1064 }
1065 if (Succs.size() != 0) {
Bill Wendling832171c2006-12-07 20:04:42 +00001066 cerr << " Successors:\n";
Chris Lattner228a18e2006-08-17 00:09:56 +00001067 for (SUnit::const_succ_iterator I = Succs.begin(), E = Succs.end();
1068 I != E; ++I) {
Evan Cheng713a98d2007-09-19 01:38:40 +00001069 if (I->isCtrl)
Bill Wendling832171c2006-12-07 20:04:42 +00001070 cerr << " ch #";
Evan Chenge165a782006-05-11 23:55:42 +00001071 else
Bill Wendling832171c2006-12-07 20:04:42 +00001072 cerr << " val #";
Evan Chenga6fb1b62007-09-25 01:54:36 +00001073 cerr << I->Dep << " - SU(" << I->Dep->NodeNum << ")";
1074 if (I->isSpecial)
1075 cerr << " *";
1076 cerr << "\n";
Evan Chenge165a782006-05-11 23:55:42 +00001077 }
1078 }
Bill Wendling832171c2006-12-07 20:04:42 +00001079 cerr << "\n";
Evan Chenge165a782006-05-11 23:55:42 +00001080}