blob: 94d3a6dbfc7b7ec016714137dc0986d3ad1a021e [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===---- ScheduleDAG.cpp - Implement the ScheduleDAG class ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// 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.
13//
14//===----------------------------------------------------------------------===//
15
16#define DEBUG_TYPE "pre-RA-sched"
Nate Begemane2ba64f2008-02-14 08:57:00 +000017#include "llvm/Constants.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018#include "llvm/Type.h"
19#include "llvm/CodeGen/ScheduleDAG.h"
20#include "llvm/CodeGen/MachineConstantPool.h"
21#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner1b989192007-12-31 04:13:23 +000022#include "llvm/CodeGen/MachineRegisterInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000023#include "llvm/Target/TargetData.h"
24#include "llvm/Target/TargetMachine.h"
25#include "llvm/Target/TargetInstrInfo.h"
26#include "llvm/Target/TargetLowering.h"
Evan Cheng7f6ade32008-02-28 07:40:24 +000027#include "llvm/ADT/Statistic.h"
Evan Cheng8725a112008-03-12 22:19:41 +000028#include "llvm/Support/CommandLine.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000029#include "llvm/Support/Debug.h"
30#include "llvm/Support/MathExtras.h"
31using namespace llvm;
32
Evan Cheng7f6ade32008-02-28 07:40:24 +000033STATISTIC(NumCommutes, "Number of instructions commuted");
34
Evan Cheng8725a112008-03-12 22:19:41 +000035namespace {
36 static cl::opt<bool>
37 SchedLiveInCopies("schedule-livein-copies",
38 cl::desc("Schedule copies of livein registers"),
39 cl::init(false));
40}
41
Chris Lattner1b989192007-12-31 04:13:23 +000042ScheduleDAG::ScheduleDAG(SelectionDAG &dag, MachineBasicBlock *bb,
43 const TargetMachine &tm)
Evan Cheng8725a112008-03-12 22:19:41 +000044 : DAG(dag), BB(bb), TM(tm), MRI(BB->getParent()->getRegInfo()) {
Chris Lattner1b989192007-12-31 04:13:23 +000045 TII = TM.getInstrInfo();
Evan Cheng2d373922008-01-30 19:35:32 +000046 MF = &DAG.getMachineFunction();
Dan Gohman1e57df32008-02-10 18:45:23 +000047 TRI = TM.getRegisterInfo();
Chris Lattner1b989192007-12-31 04:13:23 +000048 ConstPool = BB->getParent()->getConstantPool();
49}
Evan Cheng93f143e2007-09-25 01:54:36 +000050
Evan Cheng93f143e2007-09-25 01:54:36 +000051/// CheckForPhysRegDependency - Check if the dependency between def and use of
52/// a specified operand is a physical register dependency. If so, returns the
53/// register and the cost of copying the register.
54static void CheckForPhysRegDependency(SDNode *Def, SDNode *Use, unsigned Op,
Dan Gohman1e57df32008-02-10 18:45:23 +000055 const TargetRegisterInfo *TRI,
Evan Cheng93f143e2007-09-25 01:54:36 +000056 const TargetInstrInfo *TII,
57 unsigned &PhysReg, int &Cost) {
58 if (Op != 2 || Use->getOpcode() != ISD::CopyToReg)
59 return;
60
61 unsigned Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
Dan Gohman1e57df32008-02-10 18:45:23 +000062 if (TargetRegisterInfo::isVirtualRegister(Reg))
Evan Cheng93f143e2007-09-25 01:54:36 +000063 return;
64
65 unsigned ResNo = Use->getOperand(2).ResNo;
66 if (Def->isTargetOpcode()) {
Chris Lattner5b930372008-01-07 07:27:27 +000067 const TargetInstrDesc &II = TII->get(Def->getTargetOpcode());
Chris Lattner0c2a4f32008-01-07 03:13:06 +000068 if (ResNo >= II.getNumDefs() &&
69 II.ImplicitDefs[ResNo - II.getNumDefs()] == Reg) {
Evan Cheng93f143e2007-09-25 01:54:36 +000070 PhysReg = Reg;
71 const TargetRegisterClass *RC =
Evan Cheng14cc83f2008-03-11 07:19:34 +000072 TRI->getPhysicalRegisterRegClass(Reg, Def->getValueType(ResNo));
Evan Cheng93f143e2007-09-25 01:54:36 +000073 Cost = RC->getCopyCost();
74 }
75 }
76}
77
78SUnit *ScheduleDAG::Clone(SUnit *Old) {
79 SUnit *SU = NewSUnit(Old->Node);
Dan Gohmanb100d802008-03-10 23:48:14 +000080 SU->FlaggedNodes = Old->FlaggedNodes;
Evan Cheng93f143e2007-09-25 01:54:36 +000081 SU->InstanceNo = SUnitMap[Old->Node].size();
82 SU->Latency = Old->Latency;
83 SU->isTwoAddress = Old->isTwoAddress;
84 SU->isCommutable = Old->isCommutable;
Evan Chengba597da2007-09-28 22:32:30 +000085 SU->hasPhysRegDefs = Old->hasPhysRegDefs;
Evan Cheng93f143e2007-09-25 01:54:36 +000086 SUnitMap[Old->Node].push_back(SU);
87 return SU;
88}
89
Evan Chengdd3f8b92007-10-05 01:39:18 +000090
Dan Gohmanf17a25c2007-07-18 16:29:46 +000091/// BuildSchedUnits - Build SUnits from the selection dag that we are input.
92/// This SUnit graph is similar to the SelectionDAG, but represents flagged
93/// together nodes with a single SUnit.
94void ScheduleDAG::BuildSchedUnits() {
95 // Reserve entries in the vector for each of the SUnits we are creating. This
96 // ensure that reallocation of the vector won't happen, so SUnit*'s won't get
97 // invalidated.
98 SUnits.reserve(std::distance(DAG.allnodes_begin(), DAG.allnodes_end()));
99
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000100 for (SelectionDAG::allnodes_iterator NI = DAG.allnodes_begin(),
101 E = DAG.allnodes_end(); NI != E; ++NI) {
102 if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate.
103 continue;
104
105 // If this node has already been processed, stop now.
Evan Cheng93f143e2007-09-25 01:54:36 +0000106 if (SUnitMap[NI].size()) continue;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000107
108 SUnit *NodeSUnit = NewSUnit(NI);
109
110 // See if anything is flagged to this node, if so, add them to flagged
111 // nodes. Nodes can have at most one flag input and one flag output. Flags
112 // are required the be the last operand and result of a node.
113
114 // Scan up, adding flagged preds to FlaggedNodes.
115 SDNode *N = NI;
116 if (N->getNumOperands() &&
117 N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Flag) {
118 do {
119 N = N->getOperand(N->getNumOperands()-1).Val;
120 NodeSUnit->FlaggedNodes.push_back(N);
Evan Cheng93f143e2007-09-25 01:54:36 +0000121 SUnitMap[N].push_back(NodeSUnit);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000122 } while (N->getNumOperands() &&
123 N->getOperand(N->getNumOperands()-1).getValueType()== MVT::Flag);
124 std::reverse(NodeSUnit->FlaggedNodes.begin(),
125 NodeSUnit->FlaggedNodes.end());
126 }
127
128 // Scan down, adding this node and any flagged succs to FlaggedNodes if they
129 // have a user of the flag operand.
130 N = NI;
131 while (N->getValueType(N->getNumValues()-1) == MVT::Flag) {
132 SDOperand FlagVal(N, N->getNumValues()-1);
133
134 // There are either zero or one users of the Flag result.
135 bool HasFlagUse = false;
136 for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end();
137 UI != E; ++UI)
Evan Chengd9387682008-03-04 00:41:45 +0000138 if (FlagVal.isOperandOf(*UI)) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000139 HasFlagUse = true;
140 NodeSUnit->FlaggedNodes.push_back(N);
Evan Cheng93f143e2007-09-25 01:54:36 +0000141 SUnitMap[N].push_back(NodeSUnit);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000142 N = *UI;
143 break;
144 }
145 if (!HasFlagUse) break;
146 }
147
148 // Now all flagged nodes are in FlaggedNodes and N is the bottom-most node.
149 // Update the SUnit
150 NodeSUnit->Node = N;
Evan Cheng93f143e2007-09-25 01:54:36 +0000151 SUnitMap[N].push_back(NodeSUnit);
Evan Chengdd3f8b92007-10-05 01:39:18 +0000152
153 ComputeLatency(NodeSUnit);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000154 }
155
156 // Pass 2: add the preds, succs, etc.
157 for (unsigned su = 0, e = SUnits.size(); su != e; ++su) {
158 SUnit *SU = &SUnits[su];
159 SDNode *MainNode = SU->Node;
160
161 if (MainNode->isTargetOpcode()) {
162 unsigned Opc = MainNode->getTargetOpcode();
Chris Lattner5b930372008-01-07 07:27:27 +0000163 const TargetInstrDesc &TID = TII->get(Opc);
Chris Lattner0c2a4f32008-01-07 03:13:06 +0000164 for (unsigned i = 0; i != TID.getNumOperands(); ++i) {
Evan Cheng93f143e2007-09-25 01:54:36 +0000165 if (TID.getOperandConstraint(i, TOI::TIED_TO) != -1) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000166 SU->isTwoAddress = true;
167 break;
168 }
169 }
Chris Lattnerd8529ab2008-01-07 06:42:05 +0000170 if (TID.isCommutable())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000171 SU->isCommutable = true;
172 }
173
174 // Find all predecessors and successors of the group.
175 // Temporarily add N to make code simpler.
176 SU->FlaggedNodes.push_back(MainNode);
177
178 for (unsigned n = 0, e = SU->FlaggedNodes.size(); n != e; ++n) {
179 SDNode *N = SU->FlaggedNodes[n];
Evan Chengba597da2007-09-28 22:32:30 +0000180 if (N->isTargetOpcode() &&
Chris Lattner0c2a4f32008-01-07 03:13:06 +0000181 TII->get(N->getTargetOpcode()).getImplicitDefs() &&
182 CountResults(N) > TII->get(N->getTargetOpcode()).getNumDefs())
Evan Chengba597da2007-09-28 22:32:30 +0000183 SU->hasPhysRegDefs = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184
185 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
186 SDNode *OpN = N->getOperand(i).Val;
187 if (isPassiveNode(OpN)) continue; // Not scheduled.
Evan Cheng93f143e2007-09-25 01:54:36 +0000188 SUnit *OpSU = SUnitMap[OpN].front();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189 assert(OpSU && "Node has no SUnit!");
190 if (OpSU == SU) continue; // In the same group.
191
192 MVT::ValueType OpVT = N->getOperand(i).getValueType();
193 assert(OpVT != MVT::Flag && "Flagged nodes should be in same sunit!");
194 bool isChain = OpVT == MVT::Other;
Evan Cheng93f143e2007-09-25 01:54:36 +0000195
196 unsigned PhysReg = 0;
197 int Cost = 1;
198 // Determine if this is a physical register dependency.
Dan Gohman1e57df32008-02-10 18:45:23 +0000199 CheckForPhysRegDependency(OpN, N, i, TRI, TII, PhysReg, Cost);
Evan Cheng93f143e2007-09-25 01:54:36 +0000200 SU->addPred(OpSU, isChain, false, PhysReg, Cost);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000201 }
202 }
203
204 // Remove MainNode from FlaggedNodes again.
205 SU->FlaggedNodes.pop_back();
206 }
207
208 return;
209}
210
Evan Chengdd3f8b92007-10-05 01:39:18 +0000211void ScheduleDAG::ComputeLatency(SUnit *SU) {
212 const InstrItineraryData &InstrItins = TM.getInstrItineraryData();
213
214 // Compute the latency for the node. We use the sum of the latencies for
215 // all nodes flagged together into this SUnit.
216 if (InstrItins.isEmpty()) {
217 // No latency information.
218 SU->Latency = 1;
219 } else {
220 SU->Latency = 0;
221 if (SU->Node->isTargetOpcode()) {
Chris Lattner3d54fcd2008-01-07 02:46:03 +0000222 unsigned SchedClass =
223 TII->get(SU->Node->getTargetOpcode()).getSchedClass();
Evan Chengdd3f8b92007-10-05 01:39:18 +0000224 InstrStage *S = InstrItins.begin(SchedClass);
225 InstrStage *E = InstrItins.end(SchedClass);
226 for (; S != E; ++S)
227 SU->Latency += S->Cycles;
228 }
229 for (unsigned i = 0, e = SU->FlaggedNodes.size(); i != e; ++i) {
230 SDNode *FNode = SU->FlaggedNodes[i];
231 if (FNode->isTargetOpcode()) {
Chris Lattner3d54fcd2008-01-07 02:46:03 +0000232 unsigned SchedClass =TII->get(FNode->getTargetOpcode()).getSchedClass();
Evan Chengdd3f8b92007-10-05 01:39:18 +0000233 InstrStage *S = InstrItins.begin(SchedClass);
234 InstrStage *E = InstrItins.end(SchedClass);
235 for (; S != E; ++S)
236 SU->Latency += S->Cycles;
237 }
238 }
239 }
240}
241
Roman Levenstein1db9b822008-03-04 11:19:43 +0000242/// CalculateDepths - compute depths using algorithms for the longest
243/// paths in the DAG
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000244void ScheduleDAG::CalculateDepths() {
Roman Levenstein1db9b822008-03-04 11:19:43 +0000245 unsigned DAGSize = SUnits.size();
246 std::vector<unsigned> InDegree(DAGSize);
247 std::vector<SUnit*> WorkList;
248 WorkList.reserve(DAGSize);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000249
Roman Levenstein1db9b822008-03-04 11:19:43 +0000250 // Initialize the data structures
251 for (unsigned i = 0, e = DAGSize; i != e; ++i) {
252 SUnit *SU = &SUnits[i];
253 int NodeNum = SU->NodeNum;
254 unsigned Degree = SU->Preds.size();
255 InDegree[NodeNum] = Degree;
256 SU->Depth = 0;
257
258 // Is it a node without dependencies?
259 if (Degree == 0) {
260 assert(SU->Preds.empty() && "SUnit should have no predecessors");
261 // Collect leaf nodes
262 WorkList.push_back(SU);
263 }
264 }
265
266 // Process nodes in the topological order
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000267 while (!WorkList.empty()) {
Roman Levenstein1db9b822008-03-04 11:19:43 +0000268 SUnit *SU = WorkList.back();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269 WorkList.pop_back();
Roman Levenstein1db9b822008-03-04 11:19:43 +0000270 unsigned &SUDepth = SU->Depth;
271
272 // Use dynamic programming:
273 // When current node is being processed, all of its dependencies
274 // are already processed.
275 // So, just iterate over all predecessors and take the longest path
276 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
277 I != E; ++I) {
278 unsigned PredDepth = I->Dep->Depth;
279 if (PredDepth+1 > SUDepth) {
280 SUDepth = PredDepth + 1;
281 }
282 }
283
284 // Update InDegrees of all nodes depending on current SUnit
285 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
286 I != E; ++I) {
287 SUnit *SU = I->Dep;
288 if (!--InDegree[SU->NodeNum])
289 // If all dependencies of the node are processed already,
290 // then the longest path for the node can be computed now
291 WorkList.push_back(SU);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292 }
293 }
294}
295
Roman Levenstein1db9b822008-03-04 11:19:43 +0000296/// CalculateHeights - compute heights using algorithms for the longest
297/// paths in the DAG
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000298void ScheduleDAG::CalculateHeights() {
Roman Levenstein1db9b822008-03-04 11:19:43 +0000299 unsigned DAGSize = SUnits.size();
300 std::vector<unsigned> InDegree(DAGSize);
301 std::vector<SUnit*> WorkList;
302 WorkList.reserve(DAGSize);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000303
Roman Levenstein1db9b822008-03-04 11:19:43 +0000304 // Initialize the data structures
305 for (unsigned i = 0, e = DAGSize; i != e; ++i) {
306 SUnit *SU = &SUnits[i];
307 int NodeNum = SU->NodeNum;
308 unsigned Degree = SU->Succs.size();
309 InDegree[NodeNum] = Degree;
310 SU->Height = 0;
311
312 // Is it a node without dependencies?
313 if (Degree == 0) {
314 assert(SU->Succs.empty() && "Something wrong");
315 assert(WorkList.empty() && "Should be empty");
316 // Collect leaf nodes
317 WorkList.push_back(SU);
318 }
319 }
320
321 // Process nodes in the topological order
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322 while (!WorkList.empty()) {
Roman Levenstein1db9b822008-03-04 11:19:43 +0000323 SUnit *SU = WorkList.back();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000324 WorkList.pop_back();
Roman Levenstein1db9b822008-03-04 11:19:43 +0000325 unsigned &SUHeight = SU->Height;
326
327 // Use dynamic programming:
328 // When current node is being processed, all of its dependencies
329 // are already processed.
330 // So, just iterate over all successors and take the longest path
331 for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
332 I != E; ++I) {
333 unsigned SuccHeight = I->Dep->Height;
334 if (SuccHeight+1 > SUHeight) {
335 SUHeight = SuccHeight + 1;
336 }
337 }
338
339 // Update InDegrees of all nodes depending on current SUnit
340 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
341 I != E; ++I) {
342 SUnit *SU = I->Dep;
343 if (!--InDegree[SU->NodeNum])
344 // If all dependencies of the node are processed already,
345 // then the longest path for the node can be computed now
346 WorkList.push_back(SU);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000347 }
348 }
349}
350
351/// CountResults - The results of target nodes have register or immediate
352/// operands first, then an optional chain, and optional flag operands (which do
Dan Gohman0256f1e2008-02-11 19:00:03 +0000353/// not go into the resulting MachineInstr).
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354unsigned ScheduleDAG::CountResults(SDNode *Node) {
355 unsigned N = Node->getNumValues();
356 while (N && Node->getValueType(N - 1) == MVT::Flag)
357 --N;
358 if (N && Node->getValueType(N - 1) == MVT::Other)
359 --N; // Skip over chain result.
360 return N;
361}
362
Dan Gohman12a9c082008-02-06 22:27:42 +0000363/// CountOperands - The inputs to target nodes have any actual inputs first,
Dan Gohmance256462008-02-16 00:36:48 +0000364/// followed by special operands that describe memory references, then an
365/// optional chain operand, then flag operands. Compute the number of
366/// actual operands that will go into the resulting MachineInstr.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000367unsigned ScheduleDAG::CountOperands(SDNode *Node) {
Dan Gohmance256462008-02-16 00:36:48 +0000368 unsigned N = ComputeMemOperandsEnd(Node);
Dan Gohman206208c2008-02-11 19:00:34 +0000369 while (N && isa<MemOperandSDNode>(Node->getOperand(N - 1).Val))
Dan Gohman12a9c082008-02-06 22:27:42 +0000370 --N; // Ignore MemOperand nodes
371 return N;
372}
373
Dan Gohmance256462008-02-16 00:36:48 +0000374/// ComputeMemOperandsEnd - Find the index one past the last MemOperandSDNode
375/// operand
376unsigned ScheduleDAG::ComputeMemOperandsEnd(SDNode *Node) {
Dan Gohman12a9c082008-02-06 22:27:42 +0000377 unsigned N = Node->getNumOperands();
378 while (N && Node->getOperand(N - 1).getValueType() == MVT::Flag)
379 --N;
380 if (N && Node->getOperand(N - 1).getValueType() == MVT::Other)
381 --N; // Ignore chain if it exists.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382 return N;
383}
384
385static const TargetRegisterClass *getInstrOperandRegClass(
Dan Gohman1e57df32008-02-10 18:45:23 +0000386 const TargetRegisterInfo *TRI,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000387 const TargetInstrInfo *TII,
Chris Lattner5b930372008-01-07 07:27:27 +0000388 const TargetInstrDesc &II,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000389 unsigned Op) {
Chris Lattner5b930372008-01-07 07:27:27 +0000390 if (Op >= II.getNumOperands()) {
391 assert(II.isVariadic() && "Invalid operand # of instruction");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000392 return NULL;
393 }
Chris Lattner5b930372008-01-07 07:27:27 +0000394 if (II.OpInfo[Op].isLookupPtrRegClass())
Chris Lattnereeedb482008-01-07 02:39:19 +0000395 return TII->getPointerRegClass();
Dan Gohman1e57df32008-02-10 18:45:23 +0000396 return TRI->getRegClass(II.OpInfo[Op].RegClass);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397}
398
Evan Cheng93f143e2007-09-25 01:54:36 +0000399void ScheduleDAG::EmitCopyFromReg(SDNode *Node, unsigned ResNo,
400 unsigned InstanceNo, unsigned SrcReg,
Evan Cheng26639782007-08-02 00:28:15 +0000401 DenseMap<SDOperand, unsigned> &VRBaseMap) {
402 unsigned VRBase = 0;
Dan Gohman1e57df32008-02-10 18:45:23 +0000403 if (TargetRegisterInfo::isVirtualRegister(SrcReg)) {
Evan Cheng26639782007-08-02 00:28:15 +0000404 // Just use the input register directly!
Evan Cheng93f143e2007-09-25 01:54:36 +0000405 if (InstanceNo > 0)
406 VRBaseMap.erase(SDOperand(Node, ResNo));
Evan Cheng26639782007-08-02 00:28:15 +0000407 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,ResNo),SrcReg));
408 assert(isNew && "Node emitted out of order - early");
409 return;
410 }
411
412 // If the node is only used by a CopyToReg and the dest reg is a vreg, use
413 // the CopyToReg'd destination register instead of creating a new vreg.
Evan Cheng93f143e2007-09-25 01:54:36 +0000414 bool MatchReg = true;
Evan Cheng26639782007-08-02 00:28:15 +0000415 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
416 UI != E; ++UI) {
417 SDNode *Use = *UI;
Evan Cheng93f143e2007-09-25 01:54:36 +0000418 bool Match = true;
Evan Cheng26639782007-08-02 00:28:15 +0000419 if (Use->getOpcode() == ISD::CopyToReg &&
420 Use->getOperand(2).Val == Node &&
421 Use->getOperand(2).ResNo == ResNo) {
422 unsigned DestReg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
Dan Gohman1e57df32008-02-10 18:45:23 +0000423 if (TargetRegisterInfo::isVirtualRegister(DestReg)) {
Evan Cheng26639782007-08-02 00:28:15 +0000424 VRBase = DestReg;
Evan Cheng93f143e2007-09-25 01:54:36 +0000425 Match = false;
426 } else if (DestReg != SrcReg)
427 Match = false;
428 } else {
429 for (unsigned i = 0, e = Use->getNumOperands(); i != e; ++i) {
430 SDOperand Op = Use->getOperand(i);
Evan Cheng4f0345c2007-12-14 08:25:15 +0000431 if (Op.Val != Node || Op.ResNo != ResNo)
Evan Cheng93f143e2007-09-25 01:54:36 +0000432 continue;
433 MVT::ValueType VT = Node->getValueType(Op.ResNo);
434 if (VT != MVT::Other && VT != MVT::Flag)
435 Match = false;
Evan Cheng26639782007-08-02 00:28:15 +0000436 }
437 }
Evan Cheng93f143e2007-09-25 01:54:36 +0000438 MatchReg &= Match;
439 if (VRBase)
440 break;
Evan Cheng26639782007-08-02 00:28:15 +0000441 }
442
Chris Lattnere6fdb062008-03-09 08:49:15 +0000443 const TargetRegisterClass *SrcRC = 0, *DstRC = 0;
Evan Cheng14cc83f2008-03-11 07:19:34 +0000444 SrcRC = TRI->getPhysicalRegisterRegClass(SrcReg, Node->getValueType(ResNo));
Chris Lattnere6fdb062008-03-09 08:49:15 +0000445
Evan Cheng93f143e2007-09-25 01:54:36 +0000446 // Figure out the register class to create for the destreg.
Chris Lattnere6fdb062008-03-09 08:49:15 +0000447 if (VRBase) {
Evan Cheng8725a112008-03-12 22:19:41 +0000448 DstRC = MRI.getRegClass(VRBase);
Chris Lattnere6fdb062008-03-09 08:49:15 +0000449 } else {
450 DstRC = DAG.getTargetLoweringInfo()
451 .getRegClassFor(Node->getValueType(ResNo));
452 }
Evan Cheng93f143e2007-09-25 01:54:36 +0000453
454 // If all uses are reading from the src physical register and copying the
455 // register is either impossible or very expensive, then don't create a copy.
Chris Lattnere6fdb062008-03-09 08:49:15 +0000456 if (MatchReg && SrcRC->getCopyCost() < 0) {
Evan Cheng93f143e2007-09-25 01:54:36 +0000457 VRBase = SrcReg;
458 } else {
Evan Cheng26639782007-08-02 00:28:15 +0000459 // Create the reg, emit the copy.
Evan Cheng8725a112008-03-12 22:19:41 +0000460 VRBase = MRI.createVirtualRegister(DstRC);
Chris Lattnere6fdb062008-03-09 08:49:15 +0000461 TII->copyRegToReg(*BB, BB->end(), VRBase, SrcReg, DstRC, SrcRC);
Evan Cheng26639782007-08-02 00:28:15 +0000462 }
Evan Cheng26639782007-08-02 00:28:15 +0000463
Evan Cheng93f143e2007-09-25 01:54:36 +0000464 if (InstanceNo > 0)
465 VRBaseMap.erase(SDOperand(Node, ResNo));
Evan Cheng26639782007-08-02 00:28:15 +0000466 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,ResNo), VRBase));
467 assert(isNew && "Node emitted out of order - early");
468}
469
Evan Cheng3c0eda52008-03-15 00:03:38 +0000470void ScheduleDAG::CreateVirtualRegisters(SDNode *Node, MachineInstr *MI,
Chris Lattner5b930372008-01-07 07:27:27 +0000471 const TargetInstrDesc &II,
Evan Cheng26639782007-08-02 00:28:15 +0000472 DenseMap<SDOperand, unsigned> &VRBaseMap) {
Chris Lattner0c2a4f32008-01-07 03:13:06 +0000473 for (unsigned i = 0; i < II.getNumDefs(); ++i) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000474 // If the specific node value is only used by a CopyToReg and the dest reg
475 // is a vreg, use the CopyToReg'd destination register instead of creating
476 // a new vreg.
477 unsigned VRBase = 0;
478 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
479 UI != E; ++UI) {
480 SDNode *Use = *UI;
481 if (Use->getOpcode() == ISD::CopyToReg &&
482 Use->getOperand(2).Val == Node &&
483 Use->getOperand(2).ResNo == i) {
484 unsigned Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
Dan Gohman1e57df32008-02-10 18:45:23 +0000485 if (TargetRegisterInfo::isVirtualRegister(Reg)) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000486 VRBase = Reg;
Chris Lattner63ab1f22007-12-30 00:41:17 +0000487 MI->addOperand(MachineOperand::CreateReg(Reg, true));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000488 break;
489 }
490 }
491 }
492
Evan Cheng26639782007-08-02 00:28:15 +0000493 // Create the result registers for this node and add the result regs to
494 // the machine instruction.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000495 if (VRBase == 0) {
Evan Cheng3c0eda52008-03-15 00:03:38 +0000496 const TargetRegisterClass *RC;
497 if (Node->getTargetOpcode() == TargetInstrInfo::IMPLICIT_DEF)
498 // IMPLICIT_DEF can produce any type of result so its TargetInstrDesc
499 // does not include operand register class info.
500 RC = DAG.getTargetLoweringInfo().getRegClassFor(Node->getValueType(0));
501 else
502 RC = getInstrOperandRegClass(TRI, TII, II, i);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000503 assert(RC && "Isn't a register operand!");
Evan Cheng8725a112008-03-12 22:19:41 +0000504 VRBase = MRI.createVirtualRegister(RC);
Chris Lattner63ab1f22007-12-30 00:41:17 +0000505 MI->addOperand(MachineOperand::CreateReg(VRBase, true));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506 }
507
508 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,i), VRBase));
509 assert(isNew && "Node emitted out of order - early");
510 }
511}
512
513/// getVR - Return the virtual register corresponding to the specified result
514/// of the specified node.
515static unsigned getVR(SDOperand Op, DenseMap<SDOperand, unsigned> &VRBaseMap) {
516 DenseMap<SDOperand, unsigned>::iterator I = VRBaseMap.find(Op);
517 assert(I != VRBaseMap.end() && "Node emitted out of order - late");
518 return I->second;
519}
520
521
522/// AddOperand - Add the specified operand to the specified machine instr. II
523/// specifies the instruction information for the node, and IIOpNum is the
524/// operand number (in the II) that we are adding. IIOpNum and II are used for
525/// assertions only.
526void ScheduleDAG::AddOperand(MachineInstr *MI, SDOperand Op,
527 unsigned IIOpNum,
Chris Lattner5b930372008-01-07 07:27:27 +0000528 const TargetInstrDesc *II,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000529 DenseMap<SDOperand, unsigned> &VRBaseMap) {
530 if (Op.isTargetOpcode()) {
531 // Note that this case is redundant with the final else block, but we
532 // include it because it is the most common and it makes the logic
533 // simpler here.
534 assert(Op.getValueType() != MVT::Other &&
535 Op.getValueType() != MVT::Flag &&
536 "Chain and flag operands should occur at end of operand list!");
537
538 // Get/emit the operand.
539 unsigned VReg = getVR(Op, VRBaseMap);
Chris Lattner5b930372008-01-07 07:27:27 +0000540 const TargetInstrDesc &TID = MI->getDesc();
541 bool isOptDef = (IIOpNum < TID.getNumOperands())
542 ? (TID.OpInfo[IIOpNum].isOptionalDef()) : false;
Chris Lattner63ab1f22007-12-30 00:41:17 +0000543 MI->addOperand(MachineOperand::CreateReg(VReg, isOptDef));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544
545 // Verify that it is right.
Dan Gohman1e57df32008-02-10 18:45:23 +0000546 assert(TargetRegisterInfo::isVirtualRegister(VReg) && "Not a vreg?");
Chris Lattnerc3d37ab2008-03-11 00:59:28 +0000547#ifndef NDEBUG
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000548 if (II) {
Chris Lattnerc3d37ab2008-03-11 00:59:28 +0000549 // There may be no register class for this operand if it is a variadic
550 // argument (RC will be NULL in this case). In this case, we just assume
551 // the regclass is ok.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000552 const TargetRegisterClass *RC =
Dan Gohman1e57df32008-02-10 18:45:23 +0000553 getInstrOperandRegClass(TRI, TII, *II, IIOpNum);
Chris Lattner92d51282008-03-11 03:14:42 +0000554 assert((RC || II->isVariadic()) && "Expected reg class info!");
Evan Cheng8725a112008-03-12 22:19:41 +0000555 const TargetRegisterClass *VRC = MRI.getRegClass(VReg);
Chris Lattnerc3d37ab2008-03-11 00:59:28 +0000556 if (RC && VRC != RC) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000557 cerr << "Register class of operand and regclass of use don't agree!\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000558 cerr << "Operand = " << IIOpNum << "\n";
559 cerr << "Op->Val = "; Op.Val->dump(&DAG); cerr << "\n";
560 cerr << "MI = "; MI->print(cerr);
561 cerr << "VReg = " << VReg << "\n";
562 cerr << "VReg RegClass size = " << VRC->getSize()
563 << ", align = " << VRC->getAlignment() << "\n";
564 cerr << "Expected RegClass size = " << RC->getSize()
565 << ", align = " << RC->getAlignment() << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000566 cerr << "Fatal error, aborting.\n";
567 abort();
568 }
569 }
Chris Lattnerc3d37ab2008-03-11 00:59:28 +0000570#endif
Chris Lattner8dfd3122007-12-30 00:51:11 +0000571 } else if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
Chris Lattner63ab1f22007-12-30 00:41:17 +0000572 MI->addOperand(MachineOperand::CreateImm(C->getValue()));
Nate Begemane2ba64f2008-02-14 08:57:00 +0000573 } else if (ConstantFPSDNode *F = dyn_cast<ConstantFPSDNode>(Op)) {
574 const Type *FType = MVT::getTypeForValueType(Op.getValueType());
575 ConstantFP *CFP = ConstantFP::get(FType, F->getValueAPF());
576 MI->addOperand(MachineOperand::CreateFPImm(CFP));
Chris Lattner8dfd3122007-12-30 00:51:11 +0000577 } else if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(Op)) {
Chris Lattner63ab1f22007-12-30 00:41:17 +0000578 MI->addOperand(MachineOperand::CreateReg(R->getReg(), false));
Chris Lattner8dfd3122007-12-30 00:51:11 +0000579 } else if (GlobalAddressSDNode *TGA = dyn_cast<GlobalAddressSDNode>(Op)) {
580 MI->addOperand(MachineOperand::CreateGA(TGA->getGlobal(),TGA->getOffset()));
581 } else if (BasicBlockSDNode *BB = dyn_cast<BasicBlockSDNode>(Op)) {
582 MI->addOperand(MachineOperand::CreateMBB(BB->getBasicBlock()));
583 } else if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(Op)) {
584 MI->addOperand(MachineOperand::CreateFI(FI->getIndex()));
585 } else if (JumpTableSDNode *JT = dyn_cast<JumpTableSDNode>(Op)) {
586 MI->addOperand(MachineOperand::CreateJTI(JT->getIndex()));
587 } else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Op)) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000588 int Offset = CP->getOffset();
589 unsigned Align = CP->getAlignment();
590 const Type *Type = CP->getType();
591 // MachineConstantPool wants an explicit alignment.
592 if (Align == 0) {
593 Align = TM.getTargetData()->getPreferredTypeAlignmentShift(Type);
594 if (Align == 0) {
595 // Alignment of vector types. FIXME!
Duncan Sandsf99fdc62007-11-01 20:53:16 +0000596 Align = TM.getTargetData()->getABITypeSize(Type);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000597 Align = Log2_64(Align);
598 }
599 }
600
601 unsigned Idx;
602 if (CP->isMachineConstantPoolEntry())
603 Idx = ConstPool->getConstantPoolIndex(CP->getMachineCPVal(), Align);
604 else
605 Idx = ConstPool->getConstantPoolIndex(CP->getConstVal(), Align);
Chris Lattner8dfd3122007-12-30 00:51:11 +0000606 MI->addOperand(MachineOperand::CreateCPI(Idx, Offset));
607 } else if (ExternalSymbolSDNode *ES = dyn_cast<ExternalSymbolSDNode>(Op)) {
608 MI->addOperand(MachineOperand::CreateES(ES->getSymbol()));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000609 } else {
610 assert(Op.getValueType() != MVT::Other &&
611 Op.getValueType() != MVT::Flag &&
612 "Chain and flag operands should occur at end of operand list!");
613 unsigned VReg = getVR(Op, VRBaseMap);
Chris Lattner63ab1f22007-12-30 00:41:17 +0000614 MI->addOperand(MachineOperand::CreateReg(VReg, false));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000615
Chris Lattnere6fdb062008-03-09 08:49:15 +0000616 // Verify that it is right. Note that the reg class of the physreg and the
617 // vreg don't necessarily need to match, but the target copy insertion has
618 // to be able to handle it. This handles things like copies from ST(0) to
619 // an FP vreg on x86.
Dan Gohman1e57df32008-02-10 18:45:23 +0000620 assert(TargetRegisterInfo::isVirtualRegister(VReg) && "Not a vreg?");
Chris Lattner92d51282008-03-11 03:14:42 +0000621 if (II && !II->isVariadic()) {
Chris Lattnere6fdb062008-03-09 08:49:15 +0000622 assert(getInstrOperandRegClass(TRI, TII, *II, IIOpNum) &&
623 "Don't have operand info for this instruction!");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000624 }
625 }
626
627}
628
Dan Gohman12a9c082008-02-06 22:27:42 +0000629void ScheduleDAG::AddMemOperand(MachineInstr *MI, const MemOperand &MO) {
630 MI->addMemOperand(MO);
631}
632
Christopher Lambe95328d2007-07-26 08:12:07 +0000633// Returns the Register Class of a subregister
634static const TargetRegisterClass *getSubRegisterRegClass(
635 const TargetRegisterClass *TRC,
636 unsigned SubIdx) {
637 // Pick the register class of the subregister
Dan Gohman1e57df32008-02-10 18:45:23 +0000638 TargetRegisterInfo::regclass_iterator I =
639 TRC->subregclasses_begin() + SubIdx-1;
Christopher Lambe95328d2007-07-26 08:12:07 +0000640 assert(I < TRC->subregclasses_end() &&
641 "Invalid subregister index for register class");
642 return *I;
643}
644
645static const TargetRegisterClass *getSuperregRegisterClass(
646 const TargetRegisterClass *TRC,
647 unsigned SubIdx,
648 MVT::ValueType VT) {
649 // Pick the register class of the superegister for this type
Dan Gohman1e57df32008-02-10 18:45:23 +0000650 for (TargetRegisterInfo::regclass_iterator I = TRC->superregclasses_begin(),
Christopher Lambe95328d2007-07-26 08:12:07 +0000651 E = TRC->superregclasses_end(); I != E; ++I)
652 if ((*I)->hasType(VT) && getSubRegisterRegClass(*I, SubIdx) == TRC)
653 return *I;
654 assert(false && "Couldn't find the register class");
655 return 0;
656}
657
658/// EmitSubregNode - Generate machine code for subreg nodes.
659///
660void ScheduleDAG::EmitSubregNode(SDNode *Node,
661 DenseMap<SDOperand, unsigned> &VRBaseMap) {
662 unsigned VRBase = 0;
663 unsigned Opc = Node->getTargetOpcode();
Christopher Lamb76d72da2008-03-16 03:12:01 +0000664
665 // If the node is only used by a CopyToReg and the dest reg is a vreg, use
666 // the CopyToReg'd destination register instead of creating a new vreg.
667 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
668 UI != E; ++UI) {
669 SDNode *Use = *UI;
670 if (Use->getOpcode() == ISD::CopyToReg &&
671 Use->getOperand(2).Val == Node) {
672 unsigned DestReg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
673 if (TargetRegisterInfo::isVirtualRegister(DestReg)) {
674 VRBase = DestReg;
675 break;
Christopher Lambe95328d2007-07-26 08:12:07 +0000676 }
677 }
Christopher Lamb76d72da2008-03-16 03:12:01 +0000678 }
679
680 if (Opc == TargetInstrInfo::EXTRACT_SUBREG) {
Christopher Lambe95328d2007-07-26 08:12:07 +0000681 unsigned SubIdx = cast<ConstantSDNode>(Node->getOperand(1))->getValue();
Christopher Lambe95328d2007-07-26 08:12:07 +0000682
Christopher Lambe95328d2007-07-26 08:12:07 +0000683 // Create the extract_subreg machine instruction.
684 MachineInstr *MI =
685 new MachineInstr(BB, TII->get(TargetInstrInfo::EXTRACT_SUBREG));
686
687 // Figure out the register class to create for the destreg.
688 unsigned VReg = getVR(Node->getOperand(0), VRBaseMap);
Evan Cheng8725a112008-03-12 22:19:41 +0000689 const TargetRegisterClass *TRC = MRI.getRegClass(VReg);
Christopher Lambe95328d2007-07-26 08:12:07 +0000690 const TargetRegisterClass *SRC = getSubRegisterRegClass(TRC, SubIdx);
691
692 if (VRBase) {
693 // Grab the destination register
Evan Cheng8725a112008-03-12 22:19:41 +0000694 const TargetRegisterClass *DRC = MRI.getRegClass(VRBase);
Christopher Lambe08d9ec2008-01-31 07:09:08 +0000695 assert(SRC && DRC && SRC == DRC &&
Christopher Lambe95328d2007-07-26 08:12:07 +0000696 "Source subregister and destination must have the same class");
697 } else {
698 // Create the reg
Christopher Lambe08d9ec2008-01-31 07:09:08 +0000699 assert(SRC && "Couldn't find source register class");
Evan Cheng8725a112008-03-12 22:19:41 +0000700 VRBase = MRI.createVirtualRegister(SRC);
Christopher Lambe95328d2007-07-26 08:12:07 +0000701 }
702
703 // Add def, source, and subreg index
Chris Lattner63ab1f22007-12-30 00:41:17 +0000704 MI->addOperand(MachineOperand::CreateReg(VRBase, true));
Christopher Lambe95328d2007-07-26 08:12:07 +0000705 AddOperand(MI, Node->getOperand(0), 0, 0, VRBaseMap);
Chris Lattner8dfd3122007-12-30 00:51:11 +0000706 MI->addOperand(MachineOperand::CreateImm(SubIdx));
Christopher Lambe95328d2007-07-26 08:12:07 +0000707
Christopher Lamb76d72da2008-03-16 03:12:01 +0000708 } else if (Opc == TargetInstrInfo::INSERT_SUBREG ||
709 Opc == TargetInstrInfo::SUBREG_TO_REG) {
Christopher Lambd0c8eaa2008-03-11 10:09:17 +0000710 SDOperand N0 = Node->getOperand(0);
711 SDOperand N1 = Node->getOperand(1);
712 SDOperand N2 = Node->getOperand(2);
713 unsigned SubReg = getVR(N1, VRBaseMap);
714 unsigned SubIdx = cast<ConstantSDNode>(N2)->getValue();
Christopher Lambe95328d2007-07-26 08:12:07 +0000715
Christopher Lambe95328d2007-07-26 08:12:07 +0000716
717 // Figure out the register class to create for the destreg.
718 const TargetRegisterClass *TRC = 0;
719 if (VRBase) {
Evan Cheng8725a112008-03-12 22:19:41 +0000720 TRC = MRI.getRegClass(VRBase);
Christopher Lambe95328d2007-07-26 08:12:07 +0000721 } else {
Evan Cheng8725a112008-03-12 22:19:41 +0000722 TRC = getSuperregRegisterClass(MRI.getRegClass(SubReg), SubIdx,
Christopher Lambe95328d2007-07-26 08:12:07 +0000723 Node->getValueType(0));
724 assert(TRC && "Couldn't determine register class for insert_subreg");
Evan Cheng8725a112008-03-12 22:19:41 +0000725 VRBase = MRI.createVirtualRegister(TRC); // Create the reg
Christopher Lambe95328d2007-07-26 08:12:07 +0000726 }
727
Christopher Lamb76d72da2008-03-16 03:12:01 +0000728 // Create the insert_subreg or subreg_to_reg machine instruction.
729 MachineInstr *MI =
730 new MachineInstr(BB, TII->get(Opc));
Chris Lattner63ab1f22007-12-30 00:41:17 +0000731 MI->addOperand(MachineOperand::CreateReg(VRBase, true));
Christopher Lambd0c8eaa2008-03-11 10:09:17 +0000732
Christopher Lamb76d72da2008-03-16 03:12:01 +0000733 // If creating a subreg_to_reg, then the first input operand
734 // is an implicit value immediate, otherwise it's a register
735 if (Opc == TargetInstrInfo::SUBREG_TO_REG) {
736 const ConstantSDNode *SD = cast<ConstantSDNode>(N0);
Christopher Lambd0c8eaa2008-03-11 10:09:17 +0000737 MI->addOperand(MachineOperand::CreateImm(SD->getValue()));
Christopher Lamb76d72da2008-03-16 03:12:01 +0000738 } else
Christopher Lambd0c8eaa2008-03-11 10:09:17 +0000739 AddOperand(MI, N0, 0, 0, VRBaseMap);
740 // Add the subregster being inserted
741 AddOperand(MI, N1, 0, 0, VRBaseMap);
Chris Lattner8dfd3122007-12-30 00:51:11 +0000742 MI->addOperand(MachineOperand::CreateImm(SubIdx));
Christopher Lambe95328d2007-07-26 08:12:07 +0000743 } else
Christopher Lamb76d72da2008-03-16 03:12:01 +0000744 assert(0 && "Node is not insert_subreg, extract_subreg, or subreg_to_reg");
Christopher Lambe95328d2007-07-26 08:12:07 +0000745
746 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,0), VRBase));
747 assert(isNew && "Node emitted out of order - early");
748}
749
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000750/// EmitNode - Generate machine code for an node and needed dependencies.
751///
Evan Cheng93f143e2007-09-25 01:54:36 +0000752void ScheduleDAG::EmitNode(SDNode *Node, unsigned InstanceNo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000753 DenseMap<SDOperand, unsigned> &VRBaseMap) {
754 // If machine instruction
755 if (Node->isTargetOpcode()) {
756 unsigned Opc = Node->getTargetOpcode();
Christopher Lambe95328d2007-07-26 08:12:07 +0000757
758 // Handle subreg insert/extract specially
759 if (Opc == TargetInstrInfo::EXTRACT_SUBREG ||
Christopher Lamb76d72da2008-03-16 03:12:01 +0000760 Opc == TargetInstrInfo::INSERT_SUBREG ||
761 Opc == TargetInstrInfo::SUBREG_TO_REG) {
Christopher Lambe95328d2007-07-26 08:12:07 +0000762 EmitSubregNode(Node, VRBaseMap);
763 return;
764 }
765
Chris Lattner5b930372008-01-07 07:27:27 +0000766 const TargetInstrDesc &II = TII->get(Opc);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000767
768 unsigned NumResults = CountResults(Node);
769 unsigned NodeOperands = CountOperands(Node);
Dan Gohmance256462008-02-16 00:36:48 +0000770 unsigned MemOperandsEnd = ComputeMemOperandsEnd(Node);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000771 unsigned NumMIOperands = NodeOperands + NumResults;
Chris Lattner0c2a4f32008-01-07 03:13:06 +0000772 bool HasPhysRegOuts = (NumResults > II.getNumDefs()) &&
773 II.getImplicitDefs() != 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000774#ifndef NDEBUG
Chris Lattner0c2a4f32008-01-07 03:13:06 +0000775 assert((II.getNumOperands() == NumMIOperands ||
Chris Lattner2fb37c02008-01-07 05:19:29 +0000776 HasPhysRegOuts || II.isVariadic()) &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000777 "#operands for dag node doesn't match .td file!");
778#endif
779
780 // Create the new machine instruction.
781 MachineInstr *MI = new MachineInstr(II);
782
783 // Add result register values for things that are defined by this
784 // instruction.
785 if (NumResults)
Evan Cheng26639782007-08-02 00:28:15 +0000786 CreateVirtualRegisters(Node, MI, II, VRBaseMap);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000787
788 // Emit all of the actual operands of this instruction, adding them to the
789 // instruction as appropriate.
790 for (unsigned i = 0; i != NodeOperands; ++i)
Chris Lattner0c2a4f32008-01-07 03:13:06 +0000791 AddOperand(MI, Node->getOperand(i), i+II.getNumDefs(), &II, VRBaseMap);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000792
Dan Gohman12a9c082008-02-06 22:27:42 +0000793 // Emit all of the memory operands of this instruction
Dan Gohmance256462008-02-16 00:36:48 +0000794 for (unsigned i = NodeOperands; i != MemOperandsEnd; ++i)
Dan Gohman12a9c082008-02-06 22:27:42 +0000795 AddMemOperand(MI, cast<MemOperandSDNode>(Node->getOperand(i))->MO);
796
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000797 // Commute node if it has been determined to be profitable.
798 if (CommuteSet.count(Node)) {
799 MachineInstr *NewMI = TII->commuteInstruction(MI);
800 if (NewMI == 0)
801 DOUT << "Sched: COMMUTING FAILED!\n";
802 else {
803 DOUT << "Sched: COMMUTED TO: " << *NewMI;
804 if (MI != NewMI) {
805 delete MI;
806 MI = NewMI;
807 }
Evan Cheng7f6ade32008-02-28 07:40:24 +0000808 ++NumCommutes;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000809 }
810 }
811
Evan Chenga53c40a2008-02-01 09:10:45 +0000812 if (II.usesCustomDAGSchedInsertionHook())
Evan Cheng2d373922008-01-30 19:35:32 +0000813 // Insert this instruction into the basic block using a target
814 // specific inserter which may returns a new basic block.
Evan Chenge637db12008-01-30 18:18:23 +0000815 BB = DAG.getTargetLoweringInfo().EmitInstrWithCustomInserter(MI, BB);
Evan Cheng2d373922008-01-30 19:35:32 +0000816 else
817 BB->push_back(MI);
Evan Cheng26639782007-08-02 00:28:15 +0000818
819 // Additional results must be an physical register def.
820 if (HasPhysRegOuts) {
Chris Lattner0c2a4f32008-01-07 03:13:06 +0000821 for (unsigned i = II.getNumDefs(); i < NumResults; ++i) {
822 unsigned Reg = II.getImplicitDefs()[i - II.getNumDefs()];
Evan Cheng0af04f72007-08-02 05:29:38 +0000823 if (Node->hasAnyUseOfValue(i))
Evan Cheng93f143e2007-09-25 01:54:36 +0000824 EmitCopyFromReg(Node, i, InstanceNo, Reg, VRBaseMap);
Evan Cheng26639782007-08-02 00:28:15 +0000825 }
826 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000827 } else {
828 switch (Node->getOpcode()) {
829 default:
830#ifndef NDEBUG
831 Node->dump(&DAG);
832#endif
833 assert(0 && "This target-independent node should have been selected!");
834 case ISD::EntryToken: // fall thru
835 case ISD::TokenFactor:
836 case ISD::LABEL:
Evan Cheng2e28d622008-02-02 04:07:54 +0000837 case ISD::DECLARE:
Dan Gohman12a9c082008-02-06 22:27:42 +0000838 case ISD::SRCVALUE:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000839 break;
840 case ISD::CopyToReg: {
Chris Lattner0d128722008-03-09 09:15:31 +0000841 unsigned SrcReg;
842 SDOperand SrcVal = Node->getOperand(2);
843 if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(SrcVal))
844 SrcReg = R->getReg();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000845 else
Chris Lattner0d128722008-03-09 09:15:31 +0000846 SrcReg = getVR(SrcVal, VRBaseMap);
847
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000848 unsigned DestReg = cast<RegisterSDNode>(Node->getOperand(1))->getReg();
Chris Lattner0d128722008-03-09 09:15:31 +0000849 if (SrcReg == DestReg) // Coalesced away the copy? Ignore.
850 break;
851
852 const TargetRegisterClass *SrcTRC = 0, *DstTRC = 0;
853 // Get the register classes of the src/dst.
854 if (TargetRegisterInfo::isVirtualRegister(SrcReg))
Evan Cheng8725a112008-03-12 22:19:41 +0000855 SrcTRC = MRI.getRegClass(SrcReg);
Chris Lattner0d128722008-03-09 09:15:31 +0000856 else
Evan Cheng14cc83f2008-03-11 07:19:34 +0000857 SrcTRC = TRI->getPhysicalRegisterRegClass(SrcReg,SrcVal.getValueType());
Chris Lattner0d128722008-03-09 09:15:31 +0000858
859 if (TargetRegisterInfo::isVirtualRegister(DestReg))
Evan Cheng8725a112008-03-12 22:19:41 +0000860 DstTRC = MRI.getRegClass(DestReg);
Chris Lattner0d128722008-03-09 09:15:31 +0000861 else
Evan Cheng14cc83f2008-03-11 07:19:34 +0000862 DstTRC = TRI->getPhysicalRegisterRegClass(DestReg,
863 Node->getOperand(1).getValueType());
Chris Lattner0d128722008-03-09 09:15:31 +0000864 TII->copyRegToReg(*BB, BB->end(), DestReg, SrcReg, DstTRC, SrcTRC);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000865 break;
866 }
867 case ISD::CopyFromReg: {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000868 unsigned SrcReg = cast<RegisterSDNode>(Node->getOperand(1))->getReg();
Evan Cheng93f143e2007-09-25 01:54:36 +0000869 EmitCopyFromReg(Node, 0, InstanceNo, SrcReg, VRBaseMap);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000870 break;
871 }
872 case ISD::INLINEASM: {
873 unsigned NumOps = Node->getNumOperands();
874 if (Node->getOperand(NumOps-1).getValueType() == MVT::Flag)
875 --NumOps; // Ignore the flag operand.
876
877 // Create the inline asm machine instruction.
878 MachineInstr *MI =
879 new MachineInstr(BB, TII->get(TargetInstrInfo::INLINEASM));
880
881 // Add the asm string as an external symbol operand.
882 const char *AsmStr =
883 cast<ExternalSymbolSDNode>(Node->getOperand(1))->getSymbol();
Chris Lattner8dfd3122007-12-30 00:51:11 +0000884 MI->addOperand(MachineOperand::CreateES(AsmStr));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000885
886 // Add all of the operand registers to the instruction.
887 for (unsigned i = 2; i != NumOps;) {
888 unsigned Flags = cast<ConstantSDNode>(Node->getOperand(i))->getValue();
889 unsigned NumVals = Flags >> 3;
890
Chris Lattner8dfd3122007-12-30 00:51:11 +0000891 MI->addOperand(MachineOperand::CreateImm(Flags));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000892 ++i; // Skip the ID value.
893
894 switch (Flags & 7) {
895 default: assert(0 && "Bad flags!");
896 case 1: // Use of register.
897 for (; NumVals; --NumVals, ++i) {
898 unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
Chris Lattner63ab1f22007-12-30 00:41:17 +0000899 MI->addOperand(MachineOperand::CreateReg(Reg, false));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000900 }
901 break;
902 case 2: // Def of register.
903 for (; NumVals; --NumVals, ++i) {
904 unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
Chris Lattner63ab1f22007-12-30 00:41:17 +0000905 MI->addOperand(MachineOperand::CreateReg(Reg, true));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000906 }
907 break;
908 case 3: { // Immediate.
Chris Lattner23544c12007-08-25 00:53:07 +0000909 for (; NumVals; --NumVals, ++i) {
910 if (ConstantSDNode *CS =
911 dyn_cast<ConstantSDNode>(Node->getOperand(i))) {
Chris Lattner63ab1f22007-12-30 00:41:17 +0000912 MI->addOperand(MachineOperand::CreateImm(CS->getValue()));
Dale Johannesencfb19e62007-11-05 21:20:28 +0000913 } else if (GlobalAddressSDNode *GA =
914 dyn_cast<GlobalAddressSDNode>(Node->getOperand(i))) {
Chris Lattner8dfd3122007-12-30 00:51:11 +0000915 MI->addOperand(MachineOperand::CreateGA(GA->getGlobal(),
916 GA->getOffset()));
Dale Johannesencfb19e62007-11-05 21:20:28 +0000917 } else {
Chris Lattner8dfd3122007-12-30 00:51:11 +0000918 BasicBlockSDNode *BB =cast<BasicBlockSDNode>(Node->getOperand(i));
919 MI->addOperand(MachineOperand::CreateMBB(BB->getBasicBlock()));
Chris Lattner23544c12007-08-25 00:53:07 +0000920 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000921 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000922 break;
923 }
924 case 4: // Addressing mode.
925 // The addressing mode has been selected, just add all of the
926 // operands to the machine instruction.
927 for (; NumVals; --NumVals, ++i)
928 AddOperand(MI, Node->getOperand(i), 0, 0, VRBaseMap);
929 break;
930 }
931 }
932 break;
933 }
934 }
935 }
936}
937
938void ScheduleDAG::EmitNoop() {
939 TII->insertNoop(*BB, BB->end());
940}
941
Chris Lattner4e15fcc2008-03-09 07:51:01 +0000942void ScheduleDAG::EmitCrossRCCopy(SUnit *SU,
943 DenseMap<SUnit*, unsigned> &VRBaseMap) {
Evan Cheng5ec4b762007-09-26 21:36:17 +0000944 for (SUnit::const_pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
945 I != E; ++I) {
946 if (I->isCtrl) continue; // ignore chain preds
947 if (!I->Dep->Node) {
948 // Copy to physical register.
949 DenseMap<SUnit*, unsigned>::iterator VRI = VRBaseMap.find(I->Dep);
950 assert(VRI != VRBaseMap.end() && "Node emitted out of order - late");
951 // Find the destination physical register.
952 unsigned Reg = 0;
953 for (SUnit::const_succ_iterator II = SU->Succs.begin(),
954 EE = SU->Succs.end(); II != EE; ++II) {
955 if (I->Reg) {
956 Reg = I->Reg;
957 break;
958 }
959 }
960 assert(I->Reg && "Unknown physical register!");
Owen Anderson8f2c8932007-12-31 06:32:00 +0000961 TII->copyRegToReg(*BB, BB->end(), Reg, VRI->second,
Evan Cheng5ec4b762007-09-26 21:36:17 +0000962 SU->CopyDstRC, SU->CopySrcRC);
963 } else {
964 // Copy from physical register.
965 assert(I->Reg && "Unknown physical register!");
Evan Cheng8725a112008-03-12 22:19:41 +0000966 unsigned VRBase = MRI.createVirtualRegister(SU->CopyDstRC);
Evan Cheng5ec4b762007-09-26 21:36:17 +0000967 bool isNew = VRBaseMap.insert(std::make_pair(SU, VRBase));
968 assert(isNew && "Node emitted out of order - early");
Owen Anderson8f2c8932007-12-31 06:32:00 +0000969 TII->copyRegToReg(*BB, BB->end(), VRBase, I->Reg,
Evan Cheng5ec4b762007-09-26 21:36:17 +0000970 SU->CopyDstRC, SU->CopySrcRC);
971 }
972 break;
973 }
974}
975
Evan Cheng8725a112008-03-12 22:19:41 +0000976/// EmitLiveInCopy - Emit a copy for a live in physical register. If the
977/// physical register has only a single copy use, then coalesced the copy
Evan Chenga96f9642008-03-14 00:14:55 +0000978/// if possible.
979void ScheduleDAG::EmitLiveInCopy(MachineBasicBlock *MBB,
980 MachineBasicBlock::iterator &InsertPos,
981 unsigned VirtReg, unsigned PhysReg,
982 const TargetRegisterClass *RC,
983 DenseMap<MachineInstr*, unsigned> &CopyRegMap){
Evan Cheng8725a112008-03-12 22:19:41 +0000984 unsigned NumUses = 0;
985 MachineInstr *UseMI = NULL;
986 for (MachineRegisterInfo::use_iterator UI = MRI.use_begin(VirtReg),
987 UE = MRI.use_end(); UI != UE; ++UI) {
988 UseMI = &*UI;
989 if (++NumUses > 1)
990 break;
991 }
992
993 // If the number of uses is not one, or the use is not a move instruction,
Evan Chenga96f9642008-03-14 00:14:55 +0000994 // don't coalesce. Also, only coalesce away a virtual register to virtual
995 // register copy.
996 bool Coalesced = false;
Evan Cheng8725a112008-03-12 22:19:41 +0000997 unsigned SrcReg, DstReg;
Evan Chenga96f9642008-03-14 00:14:55 +0000998 if (NumUses == 1 &&
999 TII->isMoveInstr(*UseMI, SrcReg, DstReg) &&
1000 TargetRegisterInfo::isVirtualRegister(DstReg)) {
1001 VirtReg = DstReg;
1002 Coalesced = true;
Evan Cheng8725a112008-03-12 22:19:41 +00001003 }
1004
Evan Chenga96f9642008-03-14 00:14:55 +00001005 // Now find an ideal location to insert the copy.
1006 MachineBasicBlock::iterator Pos = InsertPos;
1007 while (Pos != MBB->begin()) {
1008 MachineInstr *PrevMI = prior(Pos);
1009 DenseMap<MachineInstr*, unsigned>::iterator RI = CopyRegMap.find(PrevMI);
1010 // copyRegToReg might emit multiple instructions to do a copy.
1011 unsigned CopyDstReg = (RI == CopyRegMap.end()) ? 0 : RI->second;
1012 if (CopyDstReg && !TRI->regsOverlap(CopyDstReg, PhysReg))
1013 // This is what the BB looks like right now:
1014 // r1024 = mov r0
1015 // ...
1016 // r1 = mov r1024
1017 //
1018 // We want to insert "r1025 = mov r1". Inserting this copy below the
1019 // move to r1024 makes it impossible for that move to be coalesced.
1020 //
1021 // r1025 = mov r1
1022 // r1024 = mov r0
1023 // ...
1024 // r1 = mov 1024
1025 // r2 = mov 1025
1026 break; // Woot! Found a good location.
1027 --Pos;
1028 }
1029
1030 TII->copyRegToReg(*MBB, Pos, VirtReg, PhysReg, RC, RC);
1031 CopyRegMap.insert(std::make_pair(prior(Pos), VirtReg));
1032 if (Coalesced) {
Evan Cheng8725a112008-03-12 22:19:41 +00001033 if (&*InsertPos == UseMI) ++InsertPos;
1034 MBB->erase(UseMI);
Evan Cheng8725a112008-03-12 22:19:41 +00001035 }
Evan Cheng8725a112008-03-12 22:19:41 +00001036}
1037
1038/// EmitLiveInCopies - If this is the first basic block in the function,
1039/// and if it has live ins that need to be copied into vregs, emit the
1040/// copies into the top of the block.
1041void ScheduleDAG::EmitLiveInCopies(MachineBasicBlock *MBB) {
Evan Chenga96f9642008-03-14 00:14:55 +00001042 DenseMap<MachineInstr*, unsigned> CopyRegMap;
Evan Cheng8725a112008-03-12 22:19:41 +00001043 MachineBasicBlock::iterator InsertPos = MBB->begin();
1044 for (MachineRegisterInfo::livein_iterator LI = MRI.livein_begin(),
1045 E = MRI.livein_end(); LI != E; ++LI)
1046 if (LI->second) {
1047 const TargetRegisterClass *RC = MRI.getRegClass(LI->second);
Evan Chenga96f9642008-03-14 00:14:55 +00001048 EmitLiveInCopy(MBB, InsertPos, LI->second, LI->first, RC, CopyRegMap);
Evan Cheng8725a112008-03-12 22:19:41 +00001049 }
1050}
1051
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001052/// EmitSchedule - Emit the machine code in scheduled order.
1053void ScheduleDAG::EmitSchedule() {
Evan Cheng8725a112008-03-12 22:19:41 +00001054 bool isEntryBB = &MF->front() == BB;
1055
1056 if (isEntryBB && !SchedLiveInCopies) {
1057 // If this is the first basic block in the function, and if it has live ins
1058 // that need to be copied into vregs, emit the copies into the top of the
1059 // block before emitting the code for the block.
1060 for (MachineRegisterInfo::livein_iterator LI = MRI.livein_begin(),
1061 E = MRI.livein_end(); LI != E; ++LI)
Evan Chengb3d91cf2007-09-26 06:25:56 +00001062 if (LI->second) {
Evan Cheng8725a112008-03-12 22:19:41 +00001063 const TargetRegisterClass *RC = MRI.getRegClass(LI->second);
Evan Cheng2d373922008-01-30 19:35:32 +00001064 TII->copyRegToReg(*MF->begin(), MF->begin()->end(), LI->second,
Evan Chengb3d91cf2007-09-26 06:25:56 +00001065 LI->first, RC, RC);
1066 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001067 }
Evan Cheng8725a112008-03-12 22:19:41 +00001068
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001069 // Finally, emit the code for all of the scheduled instructions.
1070 DenseMap<SDOperand, unsigned> VRBaseMap;
Evan Cheng5ec4b762007-09-26 21:36:17 +00001071 DenseMap<SUnit*, unsigned> CopyVRBaseMap;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001072 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
1073 if (SUnit *SU = Sequence[i]) {
Evan Cheng93f143e2007-09-25 01:54:36 +00001074 for (unsigned j = 0, ee = SU->FlaggedNodes.size(); j != ee; ++j)
1075 EmitNode(SU->FlaggedNodes[j], SU->InstanceNo, VRBaseMap);
Evan Cheng5ec4b762007-09-26 21:36:17 +00001076 if (SU->Node)
1077 EmitNode(SU->Node, SU->InstanceNo, VRBaseMap);
1078 else
1079 EmitCrossRCCopy(SU, CopyVRBaseMap);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001080 } else {
1081 // Null SUnit* is a noop.
1082 EmitNoop();
1083 }
1084 }
Evan Cheng8725a112008-03-12 22:19:41 +00001085
1086 if (isEntryBB && SchedLiveInCopies)
1087 EmitLiveInCopies(MF->begin());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001088}
1089
1090/// dump - dump the schedule.
1091void ScheduleDAG::dumpSchedule() const {
1092 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
1093 if (SUnit *SU = Sequence[i])
1094 SU->dump(&DAG);
1095 else
1096 cerr << "**** NOOP ****\n";
1097 }
1098}
1099
1100
1101/// Run - perform scheduling.
1102///
1103MachineBasicBlock *ScheduleDAG::Run() {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001104 Schedule();
1105 return BB;
1106}
1107
1108/// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
1109/// a group of nodes flagged together.
1110void SUnit::dump(const SelectionDAG *G) const {
1111 cerr << "SU(" << NodeNum << "): ";
Evan Cheng5ec4b762007-09-26 21:36:17 +00001112 if (Node)
1113 Node->dump(G);
1114 else
1115 cerr << "CROSS RC COPY ";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001116 cerr << "\n";
1117 if (FlaggedNodes.size() != 0) {
1118 for (unsigned i = 0, e = FlaggedNodes.size(); i != e; i++) {
1119 cerr << " ";
1120 FlaggedNodes[i]->dump(G);
1121 cerr << "\n";
1122 }
1123 }
1124}
1125
1126void SUnit::dumpAll(const SelectionDAG *G) const {
1127 dump(G);
1128
1129 cerr << " # preds left : " << NumPredsLeft << "\n";
1130 cerr << " # succs left : " << NumSuccsLeft << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001131 cerr << " Latency : " << Latency << "\n";
1132 cerr << " Depth : " << Depth << "\n";
1133 cerr << " Height : " << Height << "\n";
1134
1135 if (Preds.size() != 0) {
1136 cerr << " Predecessors:\n";
1137 for (SUnit::const_succ_iterator I = Preds.begin(), E = Preds.end();
1138 I != E; ++I) {
Evan Chenge7959472007-09-19 01:38:40 +00001139 if (I->isCtrl)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001140 cerr << " ch #";
1141 else
1142 cerr << " val #";
Evan Cheng93f143e2007-09-25 01:54:36 +00001143 cerr << I->Dep << " - SU(" << I->Dep->NodeNum << ")";
1144 if (I->isSpecial)
1145 cerr << " *";
1146 cerr << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001147 }
1148 }
1149 if (Succs.size() != 0) {
1150 cerr << " Successors:\n";
1151 for (SUnit::const_succ_iterator I = Succs.begin(), E = Succs.end();
1152 I != E; ++I) {
Evan Chenge7959472007-09-19 01:38:40 +00001153 if (I->isCtrl)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001154 cerr << " ch #";
1155 else
1156 cerr << " val #";
Evan Cheng93f143e2007-09-25 01:54:36 +00001157 cerr << I->Dep << " - SU(" << I->Dep->NodeNum << ")";
1158 if (I->isSpecial)
1159 cerr << " *";
1160 cerr << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001161 }
1162 }
1163 cerr << "\n";
1164}