blob: 8cff5b55585e96ef623b335fa22952d29cf06d32 [file] [log] [blame]
Dan Gohmana629b482008-12-08 17:50:35 +00001//===---- ScheduleDAGInstrs.cpp - MachineInstr Rescheduling ---------------===//
Dan Gohman343f0c02008-11-19 23:18:57 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Dan Gohmana629b482008-12-08 17:50:35 +000010// This implements the ScheduleDAGInstrs class, which implements re-scheduling
11// of MachineInstrs.
Dan Gohman343f0c02008-11-19 23:18:57 +000012//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "sched-instrs"
Dan Gohman3f237442008-12-16 03:25:46 +000016#include "llvm/CodeGen/MachineDominators.h"
17#include "llvm/CodeGen/MachineFunctionPass.h"
Dan Gohman8749b612008-12-16 03:35:01 +000018#include "llvm/CodeGen/MachineLoopInfo.h"
Dan Gohman3f237442008-12-16 03:25:46 +000019#include "llvm/CodeGen/MachineRegisterInfo.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000020#include "llvm/CodeGen/ScheduleDAGInstrs.h"
Dan Gohman6a9041e2008-12-04 01:35:46 +000021#include "llvm/CodeGen/PseudoSourceValue.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000022#include "llvm/Target/TargetMachine.h"
23#include "llvm/Target/TargetInstrInfo.h"
24#include "llvm/Target/TargetRegisterInfo.h"
Dan Gohman3f237442008-12-16 03:25:46 +000025#include "llvm/Target/TargetSubtarget.h"
26#include "llvm/Support/Compiler.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000027#include "llvm/Support/Debug.h"
28#include "llvm/Support/raw_ostream.h"
Dan Gohman3f237442008-12-16 03:25:46 +000029#include "llvm/ADT/SmallSet.h"
Dan Gohman6a9041e2008-12-04 01:35:46 +000030#include <map>
Dan Gohman343f0c02008-11-19 23:18:57 +000031using namespace llvm;
32
Dan Gohman8749b612008-12-16 03:35:01 +000033namespace {
34 class VISIBILITY_HIDDEN LoopDependencies {
35 const MachineLoopInfo &MLI;
36 const MachineDominatorTree &MDT;
37
38 public:
39 typedef std::map<unsigned, std::pair<const MachineOperand *, unsigned> >
40 LoopDeps;
41 LoopDeps Deps;
42
43 LoopDependencies(const MachineLoopInfo &mli,
44 const MachineDominatorTree &mdt) :
45 MLI(mli), MDT(mdt) {}
46
47 void VisitLoop(const MachineLoop *Loop) {
48 Deps.clear();
49 MachineBasicBlock *Header = Loop->getHeader();
50 SmallSet<unsigned, 8> LoopLiveIns;
51 for (MachineBasicBlock::livein_iterator LI = Header->livein_begin(),
52 LE = Header->livein_end(); LI != LE; ++LI)
53 LoopLiveIns.insert(*LI);
54
55 VisitRegion(MDT.getNode(Header), Loop, LoopLiveIns);
56 }
57
58 private:
59 void VisitRegion(const MachineDomTreeNode *Node,
60 const MachineLoop *Loop,
61 const SmallSet<unsigned, 8> &LoopLiveIns) {
62 MachineBasicBlock *MBB = Node->getBlock();
63 if (!Loop->contains(MBB)) return;
64
65 unsigned Count = 0;
66 for (MachineBasicBlock::const_iterator I = MBB->begin(), E = MBB->end();
67 I != E; ++I, ++Count) {
68 const MachineInstr *MI = I;
69 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
70 const MachineOperand &MO = MI->getOperand(i);
71 if (!MO.isReg() || !MO.isUse())
72 continue;
73 unsigned MOReg = MO.getReg();
74 if (LoopLiveIns.count(MOReg))
75 Deps.insert(std::make_pair(MOReg, std::make_pair(&MO, Count)));
76 }
77 }
78
79 const std::vector<MachineDomTreeNode*> &Children = Node->getChildren();
80 for (unsigned I = 0, E = Children.size(); I != E; ++I)
81 VisitRegion(Children[I], Loop, LoopLiveIns);
82 }
83 };
84}
85
Dan Gohman343f0c02008-11-19 23:18:57 +000086ScheduleDAGInstrs::ScheduleDAGInstrs(MachineBasicBlock *bb,
Dan Gohman3f237442008-12-16 03:25:46 +000087 const TargetMachine &tm,
88 const MachineLoopInfo &mli,
89 const MachineDominatorTree &mdt)
90 : ScheduleDAG(0, bb, tm), MLI(mli), MDT(mdt) {}
Dan Gohman343f0c02008-11-19 23:18:57 +000091
Dan Gohmanc9a5b9e2008-12-23 18:36:58 +000092void ScheduleDAGInstrs::BuildSchedGraph() {
Dan Gohman343f0c02008-11-19 23:18:57 +000093 SUnits.clear();
94 SUnits.reserve(BB->size());
95
Dan Gohman6a9041e2008-12-04 01:35:46 +000096 // We build scheduling units by walking a block's instruction list from bottom
97 // to top.
98
99 // Remember where defs and uses of each physical register are as we procede.
Dan Gohman3f237442008-12-16 03:25:46 +0000100 std::vector<SUnit *> Defs[TargetRegisterInfo::FirstVirtualRegister] = {};
Dan Gohman343f0c02008-11-19 23:18:57 +0000101 std::vector<SUnit *> Uses[TargetRegisterInfo::FirstVirtualRegister] = {};
Dan Gohman6a9041e2008-12-04 01:35:46 +0000102
103 // Remember where unknown loads are after the most recent unknown store
104 // as we procede.
105 std::vector<SUnit *> PendingLoads;
106
107 // Remember where a generic side-effecting instruction is as we procede. If
108 // ChainMMO is null, this is assumed to have arbitrary side-effects. If
109 // ChainMMO is non-null, then Chain makes only a single memory reference.
110 SUnit *Chain = 0;
111 MachineMemOperand *ChainMMO = 0;
112
113 // Memory references to specific known memory locations are tracked so that
114 // they can be given more precise dependencies.
115 std::map<const Value *, SUnit *> MemDefs;
116 std::map<const Value *, std::vector<SUnit *> > MemUses;
117
118 // Terminators can perform control transfers, we we need to make sure that
119 // all the work of the block is done before the terminator.
120 SUnit *Terminator = 0;
Dan Gohman343f0c02008-11-19 23:18:57 +0000121
Dan Gohman8749b612008-12-16 03:35:01 +0000122 LoopDependencies LoopRegs(MLI, MDT);
123
124 // Track which regs are live into a loop, to help guide back-edge-aware
125 // scheduling.
126 SmallSet<unsigned, 8> LoopLiveInRegs;
127 if (MachineLoop *ML = MLI.getLoopFor(BB))
128 if (BB == ML->getLoopLatch()) {
129 MachineBasicBlock *Header = ML->getHeader();
130 for (MachineBasicBlock::livein_iterator I = Header->livein_begin(),
131 E = Header->livein_end(); I != E; ++I)
132 LoopLiveInRegs.insert(*I);
133 LoopRegs.VisitLoop(ML);
134 }
135
Dan Gohman3f237442008-12-16 03:25:46 +0000136 // Check to see if the scheduler cares about latencies.
137 bool UnitLatencies = ForceUnitLatencies();
138
Dan Gohman8749b612008-12-16 03:35:01 +0000139 // Ask the target if address-backscheduling is desirable, and if so how much.
140 unsigned SpecialAddressLatency =
141 TM.getSubtarget<TargetSubtarget>().getSpecialAddressLatency();
142
Dan Gohman343f0c02008-11-19 23:18:57 +0000143 for (MachineBasicBlock::iterator MII = BB->end(), MIE = BB->begin();
144 MII != MIE; --MII) {
145 MachineInstr *MI = prior(MII);
Dan Gohman3f237442008-12-16 03:25:46 +0000146 const TargetInstrDesc &TID = MI->getDesc();
Dan Gohman343f0c02008-11-19 23:18:57 +0000147 SUnit *SU = NewSUnit(MI);
148
Dan Gohman54e4c362008-12-09 22:54:47 +0000149 // Assign the Latency field of SU using target-provided information.
Dan Gohman3f237442008-12-16 03:25:46 +0000150 if (UnitLatencies)
151 SU->Latency = 1;
152 else
153 ComputeLatency(SU);
Dan Gohman54e4c362008-12-09 22:54:47 +0000154
Dan Gohman6a9041e2008-12-04 01:35:46 +0000155 // Add register-based dependencies (data, anti, and output).
Dan Gohman343f0c02008-11-19 23:18:57 +0000156 for (unsigned j = 0, n = MI->getNumOperands(); j != n; ++j) {
157 const MachineOperand &MO = MI->getOperand(j);
158 if (!MO.isReg()) continue;
159 unsigned Reg = MO.getReg();
160 if (Reg == 0) continue;
161
162 assert(TRI->isPhysicalRegister(Reg) && "Virtual register encountered!");
163 std::vector<SUnit *> &UseList = Uses[Reg];
Dan Gohman3f237442008-12-16 03:25:46 +0000164 std::vector<SUnit *> &DefList = Defs[Reg];
Dan Gohmanfc626b62008-11-21 19:16:58 +0000165 // Optionally add output and anti dependencies.
Dan Gohman54e4c362008-12-09 22:54:47 +0000166 // TODO: Using a latency of 1 here assumes there's no cost for
167 // reusing registers.
168 SDep::Kind Kind = MO.isUse() ? SDep::Anti : SDep::Output;
Dan Gohman3f237442008-12-16 03:25:46 +0000169 for (unsigned i = 0, e = DefList.size(); i != e; ++i) {
170 SUnit *DefSU = DefList[i];
171 if (DefSU != SU &&
172 (Kind != SDep::Output || !MO.isDead() ||
173 !DefSU->getInstr()->registerDefIsDead(Reg)))
174 DefSU->addPred(SDep(SU, Kind, /*Latency=*/1, /*Reg=*/Reg));
175 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000176 for (const unsigned *Alias = TRI->getAliasSet(Reg); *Alias; ++Alias) {
Dan Gohman3f237442008-12-16 03:25:46 +0000177 std::vector<SUnit *> &DefList = Defs[*Alias];
178 for (unsigned i = 0, e = DefList.size(); i != e; ++i) {
179 SUnit *DefSU = DefList[i];
180 if (DefSU != SU &&
181 (Kind != SDep::Output || !MO.isDead() ||
182 !DefSU->getInstr()->registerDefIsDead(Reg)))
183 DefSU->addPred(SDep(SU, Kind, /*Latency=*/1, /*Reg=*/ *Alias));
184 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000185 }
186
187 if (MO.isDef()) {
188 // Add any data dependencies.
Dan Gohman3f237442008-12-16 03:25:46 +0000189 unsigned DataLatency = SU->Latency;
190 for (unsigned i = 0, e = UseList.size(); i != e; ++i) {
191 SUnit *UseSU = UseList[i];
192 if (UseSU != SU) {
Dan Gohman8749b612008-12-16 03:35:01 +0000193 unsigned LDataLatency = DataLatency;
194 // Optionally add in a special extra latency for nodes that
195 // feed addresses.
196 // TODO: Do this for register aliases too.
197 if (SpecialAddressLatency != 0 && !UnitLatencies) {
198 MachineInstr *UseMI = UseSU->getInstr();
199 const TargetInstrDesc &UseTID = UseMI->getDesc();
200 int RegUseIndex = UseMI->findRegisterUseOperandIdx(Reg);
201 assert(RegUseIndex >= 0 && "UseMI doesn's use register!");
202 if ((UseTID.mayLoad() || UseTID.mayStore()) &&
203 (unsigned)RegUseIndex < UseTID.getNumOperands() &&
204 UseTID.OpInfo[RegUseIndex].isLookupPtrRegClass())
205 LDataLatency += SpecialAddressLatency;
206 }
207 UseSU->addPred(SDep(SU, SDep::Data, LDataLatency, Reg));
Dan Gohman3f237442008-12-16 03:25:46 +0000208 }
209 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000210 for (const unsigned *Alias = TRI->getAliasSet(Reg); *Alias; ++Alias) {
211 std::vector<SUnit *> &UseList = Uses[*Alias];
Dan Gohman3f237442008-12-16 03:25:46 +0000212 for (unsigned i = 0, e = UseList.size(); i != e; ++i) {
213 SUnit *UseSU = UseList[i];
214 if (UseSU != SU)
215 UseSU->addPred(SDep(SU, SDep::Data, DataLatency, *Alias));
216 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000217 }
218
Dan Gohman8749b612008-12-16 03:35:01 +0000219 // If a def is going to wrap back around to the top of the loop,
220 // backschedule it.
221 // TODO: Blocks in loops without terminators can benefit too.
222 if (!UnitLatencies && Terminator && DefList.empty()) {
223 LoopDependencies::LoopDeps::iterator I = LoopRegs.Deps.find(Reg);
224 if (I != LoopRegs.Deps.end()) {
225 const MachineOperand *UseMO = I->second.first;
226 unsigned Count = I->second.second;
227 const MachineInstr *UseMI = UseMO->getParent();
228 unsigned UseMOIdx = UseMO - &UseMI->getOperand(0);
229 const TargetInstrDesc &UseTID = UseMI->getDesc();
230 // TODO: If we knew the total depth of the region here, we could
231 // handle the case where the whole loop is inside the region but
232 // is large enough that the isScheduleHigh trick isn't needed.
233 if (UseMOIdx < UseTID.getNumOperands()) {
234 // Currently, we only support scheduling regions consisting of
235 // single basic blocks. Check to see if the instruction is in
236 // the same region by checking to see if it has the same parent.
237 if (UseMI->getParent() != MI->getParent()) {
238 unsigned Latency = SU->Latency;
239 if (UseTID.OpInfo[UseMOIdx].isLookupPtrRegClass())
240 Latency += SpecialAddressLatency;
241 // This is a wild guess as to the portion of the latency which
242 // will be overlapped by work done outside the current
243 // scheduling region.
244 Latency -= std::min(Latency, Count);
245 // Add the artifical edge.
246 Terminator->addPred(SDep(SU, SDep::Order, Latency,
247 /*Reg=*/0, /*isNormalMemory=*/false,
248 /*isMustAlias=*/false,
249 /*isArtificial=*/true));
250 } else if (SpecialAddressLatency > 0 &&
251 UseTID.OpInfo[UseMOIdx].isLookupPtrRegClass()) {
252 // The entire loop body is within the current scheduling region
253 // and the latency of this operation is assumed to be greater
254 // than the latency of the loop.
255 // TODO: Recursively mark data-edge predecessors as
256 // isScheduleHigh too.
257 SU->isScheduleHigh = true;
258 }
259 }
260 LoopRegs.Deps.erase(I);
261 }
262 }
263
Dan Gohman343f0c02008-11-19 23:18:57 +0000264 UseList.clear();
Dan Gohman3f237442008-12-16 03:25:46 +0000265 if (!MO.isDead())
266 DefList.clear();
267 DefList.push_back(SU);
Dan Gohman343f0c02008-11-19 23:18:57 +0000268 } else {
269 UseList.push_back(SU);
270 }
271 }
Dan Gohman6a9041e2008-12-04 01:35:46 +0000272
273 // Add chain dependencies.
274 // Note that isStoreToStackSlot and isLoadFromStackSLot are not usable
275 // after stack slots are lowered to actual addresses.
276 // TODO: Use an AliasAnalysis and do real alias-analysis queries, and
277 // produce more precise dependence information.
Dan Gohman237dee12008-12-23 17:28:50 +0000278 if (TID.isCall() || TID.isTerminator() || TID.hasUnmodeledSideEffects()) {
Dan Gohman6a9041e2008-12-04 01:35:46 +0000279 new_chain:
Dan Gohmana629b482008-12-08 17:50:35 +0000280 // This is the conservative case. Add dependencies on all memory
281 // references.
Dan Gohman343f0c02008-11-19 23:18:57 +0000282 if (Chain)
Dan Gohman54e4c362008-12-09 22:54:47 +0000283 Chain->addPred(SDep(SU, SDep::Order, SU->Latency));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000284 Chain = SU;
Dan Gohman343f0c02008-11-19 23:18:57 +0000285 for (unsigned k = 0, m = PendingLoads.size(); k != m; ++k)
Dan Gohman54e4c362008-12-09 22:54:47 +0000286 PendingLoads[k]->addPred(SDep(SU, SDep::Order, SU->Latency));
Dan Gohman343f0c02008-11-19 23:18:57 +0000287 PendingLoads.clear();
Dan Gohman6a9041e2008-12-04 01:35:46 +0000288 for (std::map<const Value *, SUnit *>::iterator I = MemDefs.begin(),
289 E = MemDefs.end(); I != E; ++I) {
Dan Gohman54e4c362008-12-09 22:54:47 +0000290 I->second->addPred(SDep(SU, SDep::Order, SU->Latency));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000291 I->second = SU;
292 }
293 for (std::map<const Value *, std::vector<SUnit *> >::iterator I =
294 MemUses.begin(), E = MemUses.end(); I != E; ++I) {
295 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
Dan Gohman54e4c362008-12-09 22:54:47 +0000296 I->second[i]->addPred(SDep(SU, SDep::Order, SU->Latency));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000297 I->second.clear();
298 }
299 // See if it is known to just have a single memory reference.
300 MachineInstr *ChainMI = Chain->getInstr();
301 const TargetInstrDesc &ChainTID = ChainMI->getDesc();
Dan Gohman237dee12008-12-23 17:28:50 +0000302 if (!ChainTID.isCall() && !ChainTID.isTerminator() &&
Dan Gohman6a9041e2008-12-04 01:35:46 +0000303 !ChainTID.hasUnmodeledSideEffects() &&
304 ChainMI->hasOneMemOperand() &&
305 !ChainMI->memoperands_begin()->isVolatile() &&
306 ChainMI->memoperands_begin()->getValue())
307 // We know that the Chain accesses one specific memory location.
308 ChainMMO = &*ChainMI->memoperands_begin();
309 else
310 // Unknown memory accesses. Assume the worst.
311 ChainMMO = 0;
312 } else if (TID.mayStore()) {
313 if (MI->hasOneMemOperand() &&
314 MI->memoperands_begin()->getValue() &&
315 !MI->memoperands_begin()->isVolatile() &&
316 isa<PseudoSourceValue>(MI->memoperands_begin()->getValue())) {
317 // A store to a specific PseudoSourceValue. Add precise dependencies.
318 const Value *V = MI->memoperands_begin()->getValue();
319 // Handle the def in MemDefs, if there is one.
320 std::map<const Value *, SUnit *>::iterator I = MemDefs.find(V);
321 if (I != MemDefs.end()) {
Dan Gohman54e4c362008-12-09 22:54:47 +0000322 I->second->addPred(SDep(SU, SDep::Order, SU->Latency, /*Reg=*/0,
323 /*isNormalMemory=*/true));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000324 I->second = SU;
325 } else {
326 MemDefs[V] = SU;
327 }
328 // Handle the uses in MemUses, if there are any.
Dan Gohmana629b482008-12-08 17:50:35 +0000329 std::map<const Value *, std::vector<SUnit *> >::iterator J =
330 MemUses.find(V);
Dan Gohman6a9041e2008-12-04 01:35:46 +0000331 if (J != MemUses.end()) {
332 for (unsigned i = 0, e = J->second.size(); i != e; ++i)
Dan Gohman54e4c362008-12-09 22:54:47 +0000333 J->second[i]->addPred(SDep(SU, SDep::Order, SU->Latency, /*Reg=*/0,
334 /*isNormalMemory=*/true));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000335 J->second.clear();
336 }
337 // Add a general dependence too, if needed.
338 if (Chain)
Dan Gohman54e4c362008-12-09 22:54:47 +0000339 Chain->addPred(SDep(SU, SDep::Order, SU->Latency));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000340 } else
341 // Treat all other stores conservatively.
342 goto new_chain;
343 } else if (TID.mayLoad()) {
344 if (TII->isInvariantLoad(MI)) {
345 // Invariant load, no chain dependencies needed!
346 } else if (MI->hasOneMemOperand() &&
347 MI->memoperands_begin()->getValue() &&
348 !MI->memoperands_begin()->isVolatile() &&
349 isa<PseudoSourceValue>(MI->memoperands_begin()->getValue())) {
350 // A load from a specific PseudoSourceValue. Add precise dependencies.
351 const Value *V = MI->memoperands_begin()->getValue();
352 std::map<const Value *, SUnit *>::iterator I = MemDefs.find(V);
353 if (I != MemDefs.end())
Dan Gohman54e4c362008-12-09 22:54:47 +0000354 I->second->addPred(SDep(SU, SDep::Order, SU->Latency, /*Reg=*/0,
355 /*isNormalMemory=*/true));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000356 MemUses[V].push_back(SU);
357
358 // Add a general dependence too, if needed.
359 if (Chain && (!ChainMMO ||
360 (ChainMMO->isStore() || ChainMMO->isVolatile())))
Dan Gohman54e4c362008-12-09 22:54:47 +0000361 Chain->addPred(SDep(SU, SDep::Order, SU->Latency));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000362 } else if (MI->hasVolatileMemoryRef()) {
363 // Treat volatile loads conservatively. Note that this includes
364 // cases where memoperand information is unavailable.
365 goto new_chain;
366 } else {
367 // A normal load. Just depend on the general chain.
368 if (Chain)
Dan Gohman54e4c362008-12-09 22:54:47 +0000369 Chain->addPred(SDep(SU, SDep::Order, SU->Latency));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000370 PendingLoads.push_back(SU);
371 }
Dan Gohman343f0c02008-11-19 23:18:57 +0000372 }
Dan Gohman6a9041e2008-12-04 01:35:46 +0000373
Dan Gohmana629b482008-12-08 17:50:35 +0000374 // Add chain edges from the terminator to ensure that all the work of the
375 // block is completed before any control transfers.
Dan Gohman343f0c02008-11-19 23:18:57 +0000376 if (Terminator && SU->Succs.empty())
Dan Gohman54e4c362008-12-09 22:54:47 +0000377 Terminator->addPred(SDep(SU, SDep::Order, SU->Latency));
Dan Gohman6a9041e2008-12-04 01:35:46 +0000378 if (TID.isTerminator() || MI->isLabel())
Dan Gohman343f0c02008-11-19 23:18:57 +0000379 Terminator = SU;
380 }
381}
382
Dan Gohmanc8c28272008-11-21 00:12:10 +0000383void ScheduleDAGInstrs::ComputeLatency(SUnit *SU) {
384 const InstrItineraryData &InstrItins = TM.getInstrItineraryData();
385
386 // Compute the latency for the node. We use the sum of the latencies for
387 // all nodes flagged together into this SUnit.
388 SU->Latency =
389 InstrItins.getLatency(SU->getInstr()->getDesc().getSchedClass());
Dan Gohman4ea8e852008-12-16 02:38:22 +0000390
391 // Simplistic target-independent heuristic: assume that loads take
392 // extra time.
393 if (InstrItins.isEmpty())
394 if (SU->getInstr()->getDesc().mayLoad())
395 SU->Latency += 2;
Dan Gohmanc8c28272008-11-21 00:12:10 +0000396}
397
Dan Gohman343f0c02008-11-19 23:18:57 +0000398void ScheduleDAGInstrs::dumpNode(const SUnit *SU) const {
399 SU->getInstr()->dump();
400}
401
402std::string ScheduleDAGInstrs::getGraphNodeLabel(const SUnit *SU) const {
403 std::string s;
404 raw_string_ostream oss(s);
405 SU->getInstr()->print(oss);
406 return oss.str();
407}
408
409// EmitSchedule - Emit the machine code in scheduled order.
410MachineBasicBlock *ScheduleDAGInstrs::EmitSchedule() {
411 // For MachineInstr-based scheduling, we're rescheduling the instructions in
412 // the block, so start by removing them from the block.
413 while (!BB->empty())
414 BB->remove(BB->begin());
415
416 for (unsigned i = 0, e = Sequence.size(); i != e; i++) {
417 SUnit *SU = Sequence[i];
418 if (!SU) {
419 // Null SUnit* is a noop.
420 EmitNoop();
421 continue;
422 }
423
424 BB->push_back(SU->getInstr());
425 }
426
427 return BB;
428}