1 //===---- ScheduleDAG.cpp - Implement the ScheduleDAG class ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #define DEBUG_TYPE "pre-RA-sched"
17 #include "llvm/Type.h"
18 #include "llvm/CodeGen/ScheduleDAG.h"
19 #include "llvm/CodeGen/MachineConstantPool.h"
20 #include "llvm/CodeGen/MachineFunction.h"
21 #include "llvm/CodeGen/SSARegMap.h"
22 #include "llvm/Target/TargetData.h"
23 #include "llvm/Target/TargetMachine.h"
24 #include "llvm/Target/TargetInstrInfo.h"
25 #include "llvm/Target/TargetLowering.h"
26 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/MathExtras.h"
30 /// BuildSchedUnits - Build SUnits from the selection dag that we are input.
31 /// This SUnit graph is similar to the SelectionDAG, but represents flagged
32 /// together nodes with a single SUnit.
33 void ScheduleDAG::BuildSchedUnits() {
34 // Reserve entries in the vector for each of the SUnits we are creating. This
35 // ensure that reallocation of the vector won't happen, so SUnit*'s won't get
37 SUnits.reserve(std::distance(DAG.allnodes_begin(), DAG.allnodes_end()));
39 const InstrItineraryData &InstrItins = TM.getInstrItineraryData();
41 for (SelectionDAG::allnodes_iterator NI = DAG.allnodes_begin(),
42 E = DAG.allnodes_end(); NI != E; ++NI) {
43 if (isPassiveNode(NI)) // Leaf node, e.g. a TargetImmediate.
46 // If this node has already been processed, stop now.
47 if (SUnitMap[NI]) continue;
49 SUnit *NodeSUnit = NewSUnit(NI);
51 // See if anything is flagged to this node, if so, add them to flagged
52 // nodes. Nodes can have at most one flag input and one flag output. Flags
53 // are required the be the last operand and result of a node.
55 // Scan up, adding flagged preds to FlaggedNodes.
57 if (N->getNumOperands() &&
58 N->getOperand(N->getNumOperands()-1).getValueType() == MVT::Flag) {
60 N = N->getOperand(N->getNumOperands()-1).Val;
61 NodeSUnit->FlaggedNodes.push_back(N);
62 SUnitMap[N] = NodeSUnit;
63 } while (N->getNumOperands() &&
64 N->getOperand(N->getNumOperands()-1).getValueType()== MVT::Flag);
65 std::reverse(NodeSUnit->FlaggedNodes.begin(),
66 NodeSUnit->FlaggedNodes.end());
69 // Scan down, adding this node and any flagged succs to FlaggedNodes if they
70 // have a user of the flag operand.
72 while (N->getValueType(N->getNumValues()-1) == MVT::Flag) {
73 SDOperand FlagVal(N, N->getNumValues()-1);
75 // There are either zero or one users of the Flag result.
76 bool HasFlagUse = false;
77 for (SDNode::use_iterator UI = N->use_begin(), E = N->use_end();
79 if (FlagVal.isOperand(*UI)) {
81 NodeSUnit->FlaggedNodes.push_back(N);
82 SUnitMap[N] = NodeSUnit;
86 if (!HasFlagUse) break;
89 // Now all flagged nodes are in FlaggedNodes and N is the bottom-most node.
92 SUnitMap[N] = NodeSUnit;
94 // Compute the latency for the node. We use the sum of the latencies for
95 // all nodes flagged together into this SUnit.
96 if (InstrItins.isEmpty()) {
97 // No latency information.
98 NodeSUnit->Latency = 1;
100 NodeSUnit->Latency = 0;
101 if (N->isTargetOpcode()) {
102 unsigned SchedClass = TII->getSchedClass(N->getTargetOpcode());
103 InstrStage *S = InstrItins.begin(SchedClass);
104 InstrStage *E = InstrItins.end(SchedClass);
106 NodeSUnit->Latency += S->Cycles;
108 for (unsigned i = 0, e = NodeSUnit->FlaggedNodes.size(); i != e; ++i) {
109 SDNode *FNode = NodeSUnit->FlaggedNodes[i];
110 if (FNode->isTargetOpcode()) {
111 unsigned SchedClass = TII->getSchedClass(FNode->getTargetOpcode());
112 InstrStage *S = InstrItins.begin(SchedClass);
113 InstrStage *E = InstrItins.end(SchedClass);
115 NodeSUnit->Latency += S->Cycles;
121 // Pass 2: add the preds, succs, etc.
122 for (unsigned su = 0, e = SUnits.size(); su != e; ++su) {
123 SUnit *SU = &SUnits[su];
124 SDNode *MainNode = SU->Node;
126 if (MainNode->isTargetOpcode()) {
127 unsigned Opc = MainNode->getTargetOpcode();
128 for (unsigned i = 0, ee = TII->getNumOperands(Opc); i != ee; ++i) {
129 if (TII->getOperandConstraint(Opc, i, TOI::TIED_TO) != -1) {
130 SU->isTwoAddress = true;
134 if (TII->isCommutableInstr(Opc))
135 SU->isCommutable = true;
138 // Find all predecessors and successors of the group.
139 // Temporarily add N to make code simpler.
140 SU->FlaggedNodes.push_back(MainNode);
142 for (unsigned n = 0, e = SU->FlaggedNodes.size(); n != e; ++n) {
143 SDNode *N = SU->FlaggedNodes[n];
145 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
146 SDNode *OpN = N->getOperand(i).Val;
147 if (isPassiveNode(OpN)) continue; // Not scheduled.
148 SUnit *OpSU = SUnitMap[OpN];
149 assert(OpSU && "Node has no SUnit!");
150 if (OpSU == SU) continue; // In the same group.
152 MVT::ValueType OpVT = N->getOperand(i).getValueType();
153 assert(OpVT != MVT::Flag && "Flagged nodes should be in same sunit!");
154 bool isChain = OpVT == MVT::Other;
156 if (SU->addPred(OpSU, isChain)) {
161 SU->NumChainPredsLeft++;
164 if (OpSU->addSucc(SU, isChain)) {
167 OpSU->NumSuccsLeft++;
169 OpSU->NumChainSuccsLeft++;
175 // Remove MainNode from FlaggedNodes again.
176 SU->FlaggedNodes.pop_back();
182 void ScheduleDAG::CalculateDepths() {
183 std::vector<std::pair<SUnit*, unsigned> > WorkList;
184 for (unsigned i = 0, e = SUnits.size(); i != e; ++i)
185 if (SUnits[i].Preds.size() == 0/* && &SUnits[i] != Entry*/)
186 WorkList.push_back(std::make_pair(&SUnits[i], 0U));
188 while (!WorkList.empty()) {
189 SUnit *SU = WorkList.back().first;
190 unsigned Depth = WorkList.back().second;
192 if (SU->Depth == 0 || Depth > SU->Depth) {
194 for (SUnit::succ_iterator I = SU->Succs.begin(), E = SU->Succs.end();
196 WorkList.push_back(std::make_pair(I->first, Depth+1));
201 void ScheduleDAG::CalculateHeights() {
202 std::vector<std::pair<SUnit*, unsigned> > WorkList;
203 SUnit *Root = SUnitMap[DAG.getRoot().Val];
204 WorkList.push_back(std::make_pair(Root, 0U));
206 while (!WorkList.empty()) {
207 SUnit *SU = WorkList.back().first;
208 unsigned Height = WorkList.back().second;
210 if (SU->Height == 0 || Height > SU->Height) {
212 for (SUnit::pred_iterator I = SU->Preds.begin(), E = SU->Preds.end();
214 WorkList.push_back(std::make_pair(I->first, Height+1));
219 /// CountResults - The results of target nodes have register or immediate
220 /// operands first, then an optional chain, and optional flag operands (which do
221 /// not go into the machine instrs.)
222 unsigned ScheduleDAG::CountResults(SDNode *Node) {
223 unsigned N = Node->getNumValues();
224 while (N && Node->getValueType(N - 1) == MVT::Flag)
226 if (N && Node->getValueType(N - 1) == MVT::Other)
227 --N; // Skip over chain result.
231 /// CountOperands The inputs to target nodes have any actual inputs first,
232 /// followed by an optional chain operand, then flag operands. Compute the
233 /// number of actual operands that will go into the machine instr.
234 unsigned ScheduleDAG::CountOperands(SDNode *Node) {
235 unsigned N = Node->getNumOperands();
236 while (N && Node->getOperand(N - 1).getValueType() == MVT::Flag)
238 if (N && Node->getOperand(N - 1).getValueType() == MVT::Other)
239 --N; // Ignore chain if it exists.
243 static const TargetRegisterClass *getInstrOperandRegClass(
244 const MRegisterInfo *MRI,
245 const TargetInstrInfo *TII,
246 const TargetInstrDescriptor *II,
248 if (Op >= II->numOperands) {
249 assert((II->Flags & M_VARIABLE_OPS)&& "Invalid operand # of instruction");
252 const TargetOperandInfo &toi = II->OpInfo[Op];
253 return (toi.Flags & M_LOOK_UP_PTR_REG_CLASS)
254 ? TII->getPointerRegClass() : MRI->getRegClass(toi.RegClass);
257 static void CreateVirtualRegisters(SDNode *Node,
259 const MRegisterInfo *MRI,
262 const TargetInstrInfo *TII,
263 const TargetInstrDescriptor &II,
264 DenseMap<SDOperand, unsigned> &VRBaseMap) {
265 for (unsigned i = 0; i < NumResults; ++i) {
266 // If the specific node value is only used by a CopyToReg and the dest reg
267 // is a vreg, use the CopyToReg'd destination register instead of creating
270 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
273 if (Use->getOpcode() == ISD::CopyToReg &&
274 Use->getOperand(2).Val == Node &&
275 Use->getOperand(2).ResNo == i) {
276 unsigned Reg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
277 if (MRegisterInfo::isVirtualRegister(Reg)) {
279 MI->addRegOperand(Reg, true);
286 // Create the result registers for this node and add the result regs to
287 // the machine instruction.
288 const TargetRegisterClass *RC = getInstrOperandRegClass(MRI, TII, &II, i);
289 assert(RC && "Isn't a register operand!");
290 VRBase = RegMap->createVirtualRegister(RC);
291 MI->addRegOperand(VRBase, true);
294 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,i), VRBase));
295 assert(isNew && "Node emitted out of order - early");
299 /// getVR - Return the virtual register corresponding to the specified result
300 /// of the specified node.
301 static unsigned getVR(SDOperand Op, DenseMap<SDOperand, unsigned> &VRBaseMap) {
302 DenseMap<SDOperand, unsigned>::iterator I = VRBaseMap.find(Op);
303 assert(I != VRBaseMap.end() && "Node emitted out of order - late");
308 /// AddOperand - Add the specified operand to the specified machine instr. II
309 /// specifies the instruction information for the node, and IIOpNum is the
310 /// operand number (in the II) that we are adding. IIOpNum and II are used for
312 void ScheduleDAG::AddOperand(MachineInstr *MI, SDOperand Op,
314 const TargetInstrDescriptor *II,
315 DenseMap<SDOperand, unsigned> &VRBaseMap) {
316 if (Op.isTargetOpcode()) {
317 // Note that this case is redundant with the final else block, but we
318 // include it because it is the most common and it makes the logic
320 assert(Op.getValueType() != MVT::Other &&
321 Op.getValueType() != MVT::Flag &&
322 "Chain and flag operands should occur at end of operand list!");
324 // Get/emit the operand.
325 unsigned VReg = getVR(Op, VRBaseMap);
326 const TargetInstrDescriptor *TID = MI->getInstrDescriptor();
327 bool isOptDef = (IIOpNum < TID->numOperands)
328 ? (TID->OpInfo[IIOpNum].Flags & M_OPTIONAL_DEF_OPERAND) : false;
329 MI->addRegOperand(VReg, isOptDef);
331 // Verify that it is right.
332 assert(MRegisterInfo::isVirtualRegister(VReg) && "Not a vreg?");
334 const TargetRegisterClass *RC =
335 getInstrOperandRegClass(MRI, TII, II, IIOpNum);
336 assert(RC && "Don't have operand info for this instruction!");
337 const TargetRegisterClass *VRC = RegMap->getRegClass(VReg);
339 cerr << "Register class of operand and regclass of use don't agree!\n";
341 cerr << "Operand = " << IIOpNum << "\n";
342 cerr << "Op->Val = "; Op.Val->dump(&DAG); cerr << "\n";
343 cerr << "MI = "; MI->print(cerr);
344 cerr << "VReg = " << VReg << "\n";
345 cerr << "VReg RegClass size = " << VRC->getSize()
346 << ", align = " << VRC->getAlignment() << "\n";
347 cerr << "Expected RegClass size = " << RC->getSize()
348 << ", align = " << RC->getAlignment() << "\n";
350 cerr << "Fatal error, aborting.\n";
354 } else if (ConstantSDNode *C =
355 dyn_cast<ConstantSDNode>(Op)) {
356 MI->addImmOperand(C->getValue());
357 } else if (RegisterSDNode *R =
358 dyn_cast<RegisterSDNode>(Op)) {
359 MI->addRegOperand(R->getReg(), false);
360 } else if (GlobalAddressSDNode *TGA =
361 dyn_cast<GlobalAddressSDNode>(Op)) {
362 MI->addGlobalAddressOperand(TGA->getGlobal(), TGA->getOffset());
363 } else if (BasicBlockSDNode *BB =
364 dyn_cast<BasicBlockSDNode>(Op)) {
365 MI->addMachineBasicBlockOperand(BB->getBasicBlock());
366 } else if (FrameIndexSDNode *FI =
367 dyn_cast<FrameIndexSDNode>(Op)) {
368 MI->addFrameIndexOperand(FI->getIndex());
369 } else if (JumpTableSDNode *JT =
370 dyn_cast<JumpTableSDNode>(Op)) {
371 MI->addJumpTableIndexOperand(JT->getIndex());
372 } else if (ConstantPoolSDNode *CP =
373 dyn_cast<ConstantPoolSDNode>(Op)) {
374 int Offset = CP->getOffset();
375 unsigned Align = CP->getAlignment();
376 const Type *Type = CP->getType();
377 // MachineConstantPool wants an explicit alignment.
379 Align = TM.getTargetData()->getPreferredTypeAlignmentShift(Type);
381 // Alignment of vector types. FIXME!
382 Align = TM.getTargetData()->getTypeSize(Type);
383 Align = Log2_64(Align);
388 if (CP->isMachineConstantPoolEntry())
389 Idx = ConstPool->getConstantPoolIndex(CP->getMachineCPVal(), Align);
391 Idx = ConstPool->getConstantPoolIndex(CP->getConstVal(), Align);
392 MI->addConstantPoolIndexOperand(Idx, Offset);
393 } else if (ExternalSymbolSDNode *ES =
394 dyn_cast<ExternalSymbolSDNode>(Op)) {
395 MI->addExternalSymbolOperand(ES->getSymbol());
397 assert(Op.getValueType() != MVT::Other &&
398 Op.getValueType() != MVT::Flag &&
399 "Chain and flag operands should occur at end of operand list!");
400 unsigned VReg = getVR(Op, VRBaseMap);
401 MI->addRegOperand(VReg, false);
403 // Verify that it is right.
404 assert(MRegisterInfo::isVirtualRegister(VReg) && "Not a vreg?");
406 const TargetRegisterClass *RC =
407 getInstrOperandRegClass(MRI, TII, II, IIOpNum);
408 assert(RC && "Don't have operand info for this instruction!");
409 assert(RegMap->getRegClass(VReg) == RC &&
410 "Register class of operand and regclass of use don't agree!");
416 // Returns the Register Class of a physical register
417 static const TargetRegisterClass *getPhysicalRegisterRegClass(
418 const MRegisterInfo *MRI,
421 assert(MRegisterInfo::isPhysicalRegister(reg) &&
422 "reg must be a physical register");
423 // Pick the register class of the right type that contains this physreg.
424 for (MRegisterInfo::regclass_iterator I = MRI->regclass_begin(),
425 E = MRI->regclass_end(); I != E; ++I)
426 if ((*I)->hasType(VT) && (*I)->contains(reg))
428 assert(false && "Couldn't find the register class");
432 /// EmitNode - Generate machine code for an node and needed dependencies.
434 void ScheduleDAG::EmitNode(SDNode *Node,
435 DenseMap<SDOperand, unsigned> &VRBaseMap) {
436 // If machine instruction
437 if (Node->isTargetOpcode()) {
438 unsigned Opc = Node->getTargetOpcode();
439 const TargetInstrDescriptor &II = TII->get(Opc);
441 unsigned NumResults = CountResults(Node);
442 unsigned NodeOperands = CountOperands(Node);
443 unsigned NumMIOperands = NodeOperands + NumResults;
445 assert((unsigned(II.numOperands) == NumMIOperands ||
446 (II.Flags & M_VARIABLE_OPS)) &&
447 "#operands for dag node doesn't match .td file!");
450 // Create the new machine instruction.
451 MachineInstr *MI = new MachineInstr(II);
453 // Add result register values for things that are defined by this
456 CreateVirtualRegisters(Node, NumResults, MRI, MI, RegMap,
459 // Emit all of the actual operands of this instruction, adding them to the
460 // instruction as appropriate.
461 for (unsigned i = 0; i != NodeOperands; ++i)
462 AddOperand(MI, Node->getOperand(i), i+NumResults, &II, VRBaseMap);
464 // Commute node if it has been determined to be profitable.
465 if (CommuteSet.count(Node)) {
466 MachineInstr *NewMI = TII->commuteInstruction(MI);
468 DOUT << "Sched: COMMUTING FAILED!\n";
470 DOUT << "Sched: COMMUTED TO: " << *NewMI;
478 // Now that we have emitted all operands, emit this instruction itself.
479 if ((II.Flags & M_USES_CUSTOM_DAG_SCHED_INSERTION) == 0) {
480 BB->insert(BB->end(), MI);
482 // Insert this instruction into the end of the basic block, potentially
483 // taking some custom action.
484 BB = DAG.getTargetLoweringInfo().InsertAtEndOfBasicBlock(MI, BB);
487 switch (Node->getOpcode()) {
492 assert(0 && "This target-independent node should have been selected!");
493 case ISD::EntryToken: // fall thru
494 case ISD::TokenFactor:
497 case ISD::CopyToReg: {
499 if (RegisterSDNode *R = dyn_cast<RegisterSDNode>(Node->getOperand(2)))
502 InReg = getVR(Node->getOperand(2), VRBaseMap);
503 unsigned DestReg = cast<RegisterSDNode>(Node->getOperand(1))->getReg();
504 if (InReg != DestReg) {// Coalesced away the copy?
505 const TargetRegisterClass *TRC = 0;
506 // Get the target register class
507 if (MRegisterInfo::isVirtualRegister(InReg))
508 TRC = RegMap->getRegClass(InReg);
510 TRC = getPhysicalRegisterRegClass(MRI,
511 Node->getOperand(2).getValueType(),
513 MRI->copyRegToReg(*BB, BB->end(), DestReg, InReg, TRC);
517 case ISD::CopyFromReg: {
519 unsigned SrcReg = cast<RegisterSDNode>(Node->getOperand(1))->getReg();
520 if (MRegisterInfo::isVirtualRegister(SrcReg)) {
521 // Just use the input register directly!
522 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,0),SrcReg));
523 assert(isNew && "Node emitted out of order - early");
527 // If the node is only used by a CopyToReg and the dest reg is a vreg, use
528 // the CopyToReg'd destination register instead of creating a new vreg.
529 for (SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end();
532 if (Use->getOpcode() == ISD::CopyToReg &&
533 Use->getOperand(2).Val == Node) {
534 unsigned DestReg = cast<RegisterSDNode>(Use->getOperand(1))->getReg();
535 if (MRegisterInfo::isVirtualRegister(DestReg)) {
542 // Figure out the register class to create for the destreg.
543 const TargetRegisterClass *TRC = 0;
545 TRC = RegMap->getRegClass(VRBase);
547 TRC = getPhysicalRegisterRegClass(MRI, Node->getValueType(0), SrcReg);
549 // Create the reg, emit the copy.
550 VRBase = RegMap->createVirtualRegister(TRC);
552 MRI->copyRegToReg(*BB, BB->end(), VRBase, SrcReg, TRC);
554 bool isNew = VRBaseMap.insert(std::make_pair(SDOperand(Node,0), VRBase));
555 assert(isNew && "Node emitted out of order - early");
558 case ISD::INLINEASM: {
559 unsigned NumOps = Node->getNumOperands();
560 if (Node->getOperand(NumOps-1).getValueType() == MVT::Flag)
561 --NumOps; // Ignore the flag operand.
563 // Create the inline asm machine instruction.
565 new MachineInstr(BB, TII->get(TargetInstrInfo::INLINEASM));
567 // Add the asm string as an external symbol operand.
569 cast<ExternalSymbolSDNode>(Node->getOperand(1))->getSymbol();
570 MI->addExternalSymbolOperand(AsmStr);
572 // Add all of the operand registers to the instruction.
573 for (unsigned i = 2; i != NumOps;) {
574 unsigned Flags = cast<ConstantSDNode>(Node->getOperand(i))->getValue();
575 unsigned NumVals = Flags >> 3;
577 MI->addImmOperand(Flags);
578 ++i; // Skip the ID value.
581 default: assert(0 && "Bad flags!");
582 case 1: // Use of register.
583 for (; NumVals; --NumVals, ++i) {
584 unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
585 MI->addRegOperand(Reg, false);
588 case 2: // Def of register.
589 for (; NumVals; --NumVals, ++i) {
590 unsigned Reg = cast<RegisterSDNode>(Node->getOperand(i))->getReg();
591 MI->addRegOperand(Reg, true);
594 case 3: { // Immediate.
595 assert(NumVals == 1 && "Unknown immediate value!");
596 if (ConstantSDNode *CS=dyn_cast<ConstantSDNode>(Node->getOperand(i))){
597 MI->addImmOperand(CS->getValue());
599 GlobalAddressSDNode *GA =
600 cast<GlobalAddressSDNode>(Node->getOperand(i));
601 MI->addGlobalAddressOperand(GA->getGlobal(), GA->getOffset());
606 case 4: // Addressing mode.
607 // The addressing mode has been selected, just add all of the
608 // operands to the machine instruction.
609 for (; NumVals; --NumVals, ++i)
610 AddOperand(MI, Node->getOperand(i), 0, 0, VRBaseMap);
620 void ScheduleDAG::EmitNoop() {
621 TII->insertNoop(*BB, BB->end());
624 /// EmitSchedule - Emit the machine code in scheduled order.
625 void ScheduleDAG::EmitSchedule() {
626 // If this is the first basic block in the function, and if it has live ins
627 // that need to be copied into vregs, emit the copies into the top of the
628 // block before emitting the code for the block.
629 MachineFunction &MF = DAG.getMachineFunction();
630 if (&MF.front() == BB && MF.livein_begin() != MF.livein_end()) {
631 for (MachineFunction::livein_iterator LI = MF.livein_begin(),
632 E = MF.livein_end(); LI != E; ++LI)
634 MRI->copyRegToReg(*MF.begin(), MF.begin()->end(), LI->second,
635 LI->first, RegMap->getRegClass(LI->second));
639 // Finally, emit the code for all of the scheduled instructions.
640 DenseMap<SDOperand, unsigned> VRBaseMap;
641 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
642 if (SUnit *SU = Sequence[i]) {
643 for (unsigned j = 0, ee = SU->FlaggedNodes.size(); j != ee; j++)
644 EmitNode(SU->FlaggedNodes[j], VRBaseMap);
645 EmitNode(SU->Node, VRBaseMap);
647 // Null SUnit* is a noop.
653 /// dump - dump the schedule.
654 void ScheduleDAG::dumpSchedule() const {
655 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
656 if (SUnit *SU = Sequence[i])
659 cerr << "**** NOOP ****\n";
664 /// Run - perform scheduling.
666 MachineBasicBlock *ScheduleDAG::Run() {
667 TII = TM.getInstrInfo();
668 MRI = TM.getRegisterInfo();
669 RegMap = BB->getParent()->getSSARegMap();
670 ConstPool = BB->getParent()->getConstantPool();
676 /// SUnit - Scheduling unit. It's an wrapper around either a single SDNode or
677 /// a group of nodes flagged together.
678 void SUnit::dump(const SelectionDAG *G) const {
679 cerr << "SU(" << NodeNum << "): ";
682 if (FlaggedNodes.size() != 0) {
683 for (unsigned i = 0, e = FlaggedNodes.size(); i != e; i++) {
685 FlaggedNodes[i]->dump(G);
691 void SUnit::dumpAll(const SelectionDAG *G) const {
694 cerr << " # preds left : " << NumPredsLeft << "\n";
695 cerr << " # succs left : " << NumSuccsLeft << "\n";
696 cerr << " # chain preds left : " << NumChainPredsLeft << "\n";
697 cerr << " # chain succs left : " << NumChainSuccsLeft << "\n";
698 cerr << " Latency : " << Latency << "\n";
699 cerr << " Depth : " << Depth << "\n";
700 cerr << " Height : " << Height << "\n";
702 if (Preds.size() != 0) {
703 cerr << " Predecessors:\n";
704 for (SUnit::const_succ_iterator I = Preds.begin(), E = Preds.end();
710 cerr << I->first << " - SU(" << I->first->NodeNum << ")\n";
713 if (Succs.size() != 0) {
714 cerr << " Successors:\n";
715 for (SUnit::const_succ_iterator I = Succs.begin(), E = Succs.end();
721 cerr << I->first << " - SU(" << I->first->NodeNum << ")\n";