blob: 6ea37247d0935c30b828b4ec3ab9b722e5776678 [file] [log] [blame]
Chris Lattneraf50d002002-04-09 05:45:58 +00001//===- InstrScheduling.cpp - Generic Instruction Scheduling support -------===//
2//
3// This file implements the llvm/CodeGen/InstrScheduling.h interface, along with
4// generic support routines for instruction scheduling.
5//
6//===----------------------------------------------------------------------===//
Vikram S. Advec5b46322001-09-30 23:43:34 +00007
Chris Lattnerc6f3ae52002-04-29 17:42:12 +00008#include "SchedPriorities.h"
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00009#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner3462cae2002-02-03 07:28:30 +000010#include "llvm/CodeGen/MachineCodeForInstruction.h"
Vikram S. Adve0baf1c02002-07-08 22:59:23 +000011#include "llvm/CodeGen/MachineCodeForBasicBlock.h"
Chris Lattner3462cae2002-02-03 07:28:30 +000012#include "llvm/CodeGen/MachineCodeForMethod.h"
Chris Lattner483e14e2002-04-27 07:27:19 +000013#include "llvm/Analysis/LiveVar/FunctionLiveVarInfo.h" // FIXME: Remove when modularized better
Chris Lattner3462cae2002-02-03 07:28:30 +000014#include "llvm/Target/TargetMachine.h"
Chris Lattnerf35f2fb2002-02-04 16:35:45 +000015#include "llvm/BasicBlock.h"
Chris Lattner455889a2002-02-12 22:39:50 +000016#include "llvm/Instruction.h"
Chris Lattner70e60cb2002-05-22 17:08:27 +000017#include "Support/CommandLine.h"
Chris Lattner1ff63a12001-09-07 21:19:42 +000018#include <algorithm>
Chris Lattner697954c2002-01-20 22:54:45 +000019using std::cerr;
20using std::vector;
Vikram S. Advec5b46322001-09-30 23:43:34 +000021
Chris Lattner70e60cb2002-05-22 17:08:27 +000022SchedDebugLevel_t SchedDebugLevel;
Vikram S. Advec5b46322001-09-30 23:43:34 +000023
Chris Lattner70e60cb2002-05-22 17:08:27 +000024static cl::Enum<enum SchedDebugLevel_t> Opt(SchedDebugLevel,"dsched",cl::Hidden,
Vikram S. Adve0e1158f2001-08-28 23:07:19 +000025 "enable instruction scheduling debugging information",
26 clEnumValN(Sched_NoDebugInfo, "n", "disable debug output"),
Vikram S. Adve802cec42002-03-24 03:44:55 +000027 clEnumValN(Sched_Disable, "off", "disable instruction scheduling"),
Vikram S. Adve0e1158f2001-08-28 23:07:19 +000028 clEnumValN(Sched_PrintMachineCode, "y", "print machine code after scheduling"),
29 clEnumValN(Sched_PrintSchedTrace, "t", "print trace of scheduling actions"),
30 clEnumValN(Sched_PrintSchedGraphs, "g", "print scheduling graphs"), 0);
31
32
Vikram S. Advec5b46322001-09-30 23:43:34 +000033//************************* Internal Data Types *****************************/
34
Vikram S. Adve0e1158f2001-08-28 23:07:19 +000035class InstrSchedule;
36class SchedulingManager;
Vikram S. Adve0e1158f2001-08-28 23:07:19 +000037
Vikram S. Adve0e1158f2001-08-28 23:07:19 +000038
39//----------------------------------------------------------------------
40// class InstrGroup:
41//
42// Represents a group of instructions scheduled to be issued
43// in a single cycle.
44//----------------------------------------------------------------------
45
46class InstrGroup: public NonCopyable {
47public:
48 inline const SchedGraphNode* operator[](unsigned int slotNum) const {
49 assert(slotNum < group.size());
50 return group[slotNum];
51 }
52
53private:
54 friend class InstrSchedule;
55
56 inline void addInstr(const SchedGraphNode* node, unsigned int slotNum) {
57 assert(slotNum < group.size());
58 group[slotNum] = node;
59 }
60
61 /*ctor*/ InstrGroup(unsigned int nslots)
62 : group(nslots, NULL) {}
63
64 /*ctor*/ InstrGroup(); // disable: DO NOT IMPLEMENT
65
66private:
67 vector<const SchedGraphNode*> group;
68};
69
70
71//----------------------------------------------------------------------
72// class ScheduleIterator:
73//
74// Iterates over the machine instructions in the for a single basic block.
75// The schedule is represented by an InstrSchedule object.
76//----------------------------------------------------------------------
77
78template<class _NodeType>
79class ScheduleIterator: public std::forward_iterator<_NodeType, ptrdiff_t> {
80private:
81 unsigned cycleNum;
82 unsigned slotNum;
83 const InstrSchedule& S;
84public:
85 typedef ScheduleIterator<_NodeType> _Self;
86
87 /*ctor*/ inline ScheduleIterator(const InstrSchedule& _schedule,
88 unsigned _cycleNum,
89 unsigned _slotNum)
90 : cycleNum(_cycleNum), slotNum(_slotNum), S(_schedule) {
91 skipToNextInstr();
92 }
93
94 /*ctor*/ inline ScheduleIterator(const _Self& x)
95 : cycleNum(x.cycleNum), slotNum(x.slotNum), S(x.S) {}
96
97 inline bool operator==(const _Self& x) const {
98 return (slotNum == x.slotNum && cycleNum== x.cycleNum && &S==&x.S);
99 }
100
101 inline bool operator!=(const _Self& x) const { return !operator==(x); }
102
103 inline _NodeType* operator*() const {
104 assert(cycleNum < S.groups.size());
105 return (*S.groups[cycleNum])[slotNum];
106 }
107 inline _NodeType* operator->() const { return operator*(); }
108
109 _Self& operator++(); // Preincrement
110 inline _Self operator++(int) { // Postincrement
111 _Self tmp(*this); ++*this; return tmp;
112 }
113
114 static _Self begin(const InstrSchedule& _schedule);
115 static _Self end( const InstrSchedule& _schedule);
116
117private:
118 inline _Self& operator=(const _Self& x); // DISABLE -- DO NOT IMPLEMENT
119 void skipToNextInstr();
120};
121
122
123//----------------------------------------------------------------------
124// class InstrSchedule:
125//
126// Represents the schedule of machine instructions for a single basic block.
127//----------------------------------------------------------------------
128
129class InstrSchedule: public NonCopyable {
130private:
131 const unsigned int nslots;
132 unsigned int numInstr;
133 vector<InstrGroup*> groups; // indexed by cycle number
134 vector<cycles_t> startTime; // indexed by node id
135
136public: // iterators
137 typedef ScheduleIterator<SchedGraphNode> iterator;
138 typedef ScheduleIterator<const SchedGraphNode> const_iterator;
139
140 iterator begin();
141 const_iterator begin() const;
142 iterator end();
143 const_iterator end() const;
144
145public: // constructors and destructor
146 /*ctor*/ InstrSchedule (unsigned int _nslots,
147 unsigned int _numNodes);
148 /*dtor*/ ~InstrSchedule ();
149
150public: // accessor functions to query chosen schedule
151 const SchedGraphNode* getInstr (unsigned int slotNum,
152 cycles_t c) const {
153 const InstrGroup* igroup = this->getIGroup(c);
154 return (igroup == NULL)? NULL : (*igroup)[slotNum];
155 }
156
157 inline InstrGroup* getIGroup (cycles_t c) {
Chris Lattnerdfb8b952002-02-24 23:01:50 +0000158 if ((unsigned)c >= groups.size())
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000159 groups.resize(c+1);
160 if (groups[c] == NULL)
161 groups[c] = new InstrGroup(nslots);
162 return groups[c];
163 }
164
165 inline const InstrGroup* getIGroup (cycles_t c) const {
Chris Lattnerdfb8b952002-02-24 23:01:50 +0000166 assert((unsigned)c < groups.size());
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000167 return groups[c];
168 }
169
170 inline cycles_t getStartTime (unsigned int nodeId) const {
171 assert(nodeId < startTime.size());
172 return startTime[nodeId];
173 }
174
175 unsigned int getNumInstructions() const {
176 return numInstr;
177 }
178
179 inline void scheduleInstr (const SchedGraphNode* node,
180 unsigned int slotNum,
181 cycles_t cycle) {
182 InstrGroup* igroup = this->getIGroup(cycle);
183 assert((*igroup)[slotNum] == NULL && "Slot already filled?");
184 igroup->addInstr(node, slotNum);
185 assert(node->getNodeId() < startTime.size());
186 startTime[node->getNodeId()] = cycle;
187 ++numInstr;
188 }
189
190private:
191 friend class iterator;
192 friend class const_iterator;
193 /*ctor*/ InstrSchedule (); // Disable: DO NOT IMPLEMENT.
194};
195
196
197/*ctor*/
198InstrSchedule::InstrSchedule(unsigned int _nslots, unsigned int _numNodes)
199 : nslots(_nslots),
200 numInstr(0),
201 groups(2 * _numNodes / _nslots), // 2 x lower-bound for #cycles
202 startTime(_numNodes, (cycles_t) -1) // set all to -1
203{
204}
205
206
207/*dtor*/
208InstrSchedule::~InstrSchedule()
209{
210 for (unsigned c=0, NC=groups.size(); c < NC; c++)
211 if (groups[c] != NULL)
212 delete groups[c]; // delete InstrGroup objects
213}
214
215
216template<class _NodeType>
217inline
218void
219ScheduleIterator<_NodeType>::skipToNextInstr()
220{
221 while(cycleNum < S.groups.size() && S.groups[cycleNum] == NULL)
222 ++cycleNum; // skip cycles with no instructions
223
224 while (cycleNum < S.groups.size() &&
225 (*S.groups[cycleNum])[slotNum] == NULL)
226 {
227 ++slotNum;
228 if (slotNum == S.nslots)
229 {
230 ++cycleNum;
231 slotNum = 0;
232 while(cycleNum < S.groups.size() && S.groups[cycleNum] == NULL)
233 ++cycleNum; // skip cycles with no instructions
234 }
235 }
236}
237
238template<class _NodeType>
239inline
240ScheduleIterator<_NodeType>&
241ScheduleIterator<_NodeType>::operator++() // Preincrement
242{
243 ++slotNum;
244 if (slotNum == S.nslots)
245 {
246 ++cycleNum;
247 slotNum = 0;
248 }
249 skipToNextInstr();
250 return *this;
251}
252
253template<class _NodeType>
254ScheduleIterator<_NodeType>
255ScheduleIterator<_NodeType>::begin(const InstrSchedule& _schedule)
256{
257 return _Self(_schedule, 0, 0);
258}
259
260template<class _NodeType>
261ScheduleIterator<_NodeType>
262ScheduleIterator<_NodeType>::end(const InstrSchedule& _schedule)
263{
264 return _Self(_schedule, _schedule.groups.size(), 0);
265}
266
267InstrSchedule::iterator
268InstrSchedule::begin()
269{
270 return iterator::begin(*this);
271}
272
273InstrSchedule::const_iterator
274InstrSchedule::begin() const
275{
276 return const_iterator::begin(*this);
277}
278
279InstrSchedule::iterator
280InstrSchedule::end()
281{
282 return iterator::end(*this);
283}
284
285InstrSchedule::const_iterator
286InstrSchedule::end() const
287{
288 return const_iterator::end( *this);
289}
290
291
292//----------------------------------------------------------------------
293// class DelaySlotInfo:
294//
295// Record information about delay slots for a single branch instruction.
296// Delay slots are simply indexed by slot number 1 ... numDelaySlots
297//----------------------------------------------------------------------
298
299class DelaySlotInfo: public NonCopyable {
300private:
301 const SchedGraphNode* brNode;
302 unsigned int ndelays;
303 vector<const SchedGraphNode*> delayNodeVec;
304 cycles_t delayedNodeCycle;
305 unsigned int delayedNodeSlotNum;
306
307public:
308 /*ctor*/ DelaySlotInfo (const SchedGraphNode* _brNode,
309 unsigned _ndelays)
310 : brNode(_brNode), ndelays(_ndelays),
311 delayedNodeCycle(0), delayedNodeSlotNum(0) {}
312
313 inline unsigned getNumDelays () {
314 return ndelays;
315 }
316
317 inline const vector<const SchedGraphNode*>& getDelayNodeVec() {
318 return delayNodeVec;
319 }
320
321 inline void addDelayNode (const SchedGraphNode* node) {
322 delayNodeVec.push_back(node);
323 assert(delayNodeVec.size() <= ndelays && "Too many delay slot instrs!");
324 }
325
326 inline void recordChosenSlot (cycles_t cycle, unsigned slotNum) {
327 delayedNodeCycle = cycle;
328 delayedNodeSlotNum = slotNum;
329 }
330
Vikram S. Advec5b46322001-09-30 23:43:34 +0000331 unsigned scheduleDelayedNode (SchedulingManager& S);
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000332};
333
334
335//----------------------------------------------------------------------
336// class SchedulingManager:
337//
338// Represents the schedule of machine instructions for a single basic block.
339//----------------------------------------------------------------------
340
341class SchedulingManager: public NonCopyable {
342public: // publicly accessible data members
343 const unsigned int nslots;
344 const MachineSchedInfo& schedInfo;
345 SchedPriorities& schedPrio;
346 InstrSchedule isched;
347
348private:
349 unsigned int totalInstrCount;
350 cycles_t curTime;
351 cycles_t nextEarliestIssueTime; // next cycle we can issue
Chris Lattner697954c2002-01-20 22:54:45 +0000352 vector<std::hash_set<const SchedGraphNode*> > choicesForSlot; // indexed by slot#
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000353 vector<const SchedGraphNode*> choiceVec; // indexed by node ptr
354 vector<int> numInClass; // indexed by sched class
355 vector<cycles_t> nextEarliestStartTime; // indexed by opCode
Chris Lattner697954c2002-01-20 22:54:45 +0000356 std::hash_map<const SchedGraphNode*, DelaySlotInfo*> delaySlotInfoForBranches;
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000357 // indexed by branch node ptr
358
359public:
Chris Lattneraf50d002002-04-09 05:45:58 +0000360 SchedulingManager(const TargetMachine& _target, const SchedGraph* graph,
361 SchedPriorities& schedPrio);
362 ~SchedulingManager() {
363 for (std::hash_map<const SchedGraphNode*,
364 DelaySlotInfo*>::iterator I = delaySlotInfoForBranches.begin(),
365 E = delaySlotInfoForBranches.end(); I != E; ++I)
366 delete I->second;
367 }
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000368
369 //----------------------------------------------------------------------
370 // Simplify access to the machine instruction info
371 //----------------------------------------------------------------------
372
373 inline const MachineInstrInfo& getInstrInfo () const {
374 return schedInfo.getInstrInfo();
375 }
376
377 //----------------------------------------------------------------------
378 // Interface for checking and updating the current time
379 //----------------------------------------------------------------------
380
381 inline cycles_t getTime () const {
382 return curTime;
383 }
384
385 inline cycles_t getEarliestIssueTime() const {
386 return nextEarliestIssueTime;
387 }
388
389 inline cycles_t getEarliestStartTimeForOp(MachineOpCode opCode) const {
390 assert(opCode < (int) nextEarliestStartTime.size());
391 return nextEarliestStartTime[opCode];
392 }
393
394 // Update current time to specified cycle
395 inline void updateTime (cycles_t c) {
396 curTime = c;
397 schedPrio.updateTime(c);
398 }
399
400 //----------------------------------------------------------------------
401 // Functions to manage the choices for the current cycle including:
402 // -- a vector of choices by priority (choiceVec)
403 // -- vectors of the choices for each instruction slot (choicesForSlot[])
404 // -- number of choices in each sched class, used to check issue conflicts
405 // between choices for a single cycle
406 //----------------------------------------------------------------------
407
408 inline unsigned int getNumChoices () const {
409 return choiceVec.size();
410 }
411
412 inline unsigned getNumChoicesInClass (const InstrSchedClass& sc) const {
413 assert(sc < (int) numInClass.size() && "Invalid op code or sched class!");
414 return numInClass[sc];
415 }
416
417 inline const SchedGraphNode* getChoice(unsigned int i) const {
418 // assert(i < choiceVec.size()); don't check here.
419 return choiceVec[i];
420 }
421
Chris Lattner697954c2002-01-20 22:54:45 +0000422 inline std::hash_set<const SchedGraphNode*>& getChoicesForSlot(unsigned slotNum) {
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000423 assert(slotNum < nslots);
424 return choicesForSlot[slotNum];
425 }
426
427 inline void addChoice (const SchedGraphNode* node) {
428 // Append the instruction to the vector of choices for current cycle.
429 // Increment numInClass[c] for the sched class to which the instr belongs.
430 choiceVec.push_back(node);
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000431 const InstrSchedClass& sc = schedInfo.getSchedClass(node->getOpCode());
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000432 assert(sc < (int) numInClass.size());
433 numInClass[sc]++;
434 }
435
436 inline void addChoiceToSlot (unsigned int slotNum,
437 const SchedGraphNode* node) {
438 // Add the instruction to the choice set for the specified slot
439 assert(slotNum < nslots);
440 choicesForSlot[slotNum].insert(node);
441 }
442
443 inline void resetChoices () {
444 choiceVec.clear();
445 for (unsigned int s=0; s < nslots; s++)
446 choicesForSlot[s].clear();
447 for (unsigned int c=0; c < numInClass.size(); c++)
448 numInClass[c] = 0;
449 }
450
451 //----------------------------------------------------------------------
452 // Code to query and manage the partial instruction schedule so far
453 //----------------------------------------------------------------------
454
455 inline unsigned int getNumScheduled () const {
456 return isched.getNumInstructions();
457 }
458
459 inline unsigned int getNumUnscheduled() const {
460 return totalInstrCount - isched.getNumInstructions();
461 }
462
463 inline bool isScheduled (const SchedGraphNode* node) const {
464 return (isched.getStartTime(node->getNodeId()) >= 0);
465 }
466
467 inline void scheduleInstr (const SchedGraphNode* node,
468 unsigned int slotNum,
469 cycles_t cycle)
470 {
471 assert(! isScheduled(node) && "Instruction already scheduled?");
472
473 // add the instruction to the schedule
474 isched.scheduleInstr(node, slotNum, cycle);
475
476 // update the earliest start times of all nodes that conflict with `node'
477 // and the next-earliest time anything can issue if `node' causes bubbles
478 updateEarliestStartTimes(node, cycle);
479
480 // remove the instruction from the choice sets for all slots
481 for (unsigned s=0; s < nslots; s++)
482 choicesForSlot[s].erase(node);
483
484 // and decrement the instr count for the sched class to which it belongs
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000485 const InstrSchedClass& sc = schedInfo.getSchedClass(node->getOpCode());
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000486 assert(sc < (int) numInClass.size());
487 numInClass[sc]--;
488 }
Chris Lattner1ff63a12001-09-07 21:19:42 +0000489
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000490 //----------------------------------------------------------------------
491 // Create and retrieve delay slot info for delayed instructions
492 //----------------------------------------------------------------------
493
494 inline DelaySlotInfo* getDelaySlotInfoForInstr(const SchedGraphNode* bn,
495 bool createIfMissing=false)
496 {
Chris Lattneraf50d002002-04-09 05:45:58 +0000497 std::hash_map<const SchedGraphNode*, DelaySlotInfo*>::const_iterator
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000498 I = delaySlotInfoForBranches.find(bn);
Chris Lattneraf50d002002-04-09 05:45:58 +0000499 if (I != delaySlotInfoForBranches.end())
500 return I->second;
501
502 if (!createIfMissing) return 0;
503
504 DelaySlotInfo *dinfo =
505 new DelaySlotInfo(bn, getInstrInfo().getNumDelaySlots(bn->getOpCode()));
506 return delaySlotInfoForBranches[bn] = dinfo;
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000507 }
508
509private:
Chris Lattneraf50d002002-04-09 05:45:58 +0000510 SchedulingManager(); // DISABLED: DO NOT IMPLEMENT
511 void updateEarliestStartTimes(const SchedGraphNode* node, cycles_t schedTime);
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000512};
513
514
515/*ctor*/
516SchedulingManager::SchedulingManager(const TargetMachine& target,
517 const SchedGraph* graph,
518 SchedPriorities& _schedPrio)
Vikram S. Advef0ba2802001-09-18 12:51:38 +0000519 : nslots(target.getSchedInfo().getMaxNumIssueTotal()),
520 schedInfo(target.getSchedInfo()),
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000521 schedPrio(_schedPrio),
522 isched(nslots, graph->getNumNodes()),
523 totalInstrCount(graph->getNumNodes() - 2),
524 nextEarliestIssueTime(0),
525 choicesForSlot(nslots),
Vikram S. Advef0ba2802001-09-18 12:51:38 +0000526 numInClass(target.getSchedInfo().getNumSchedClasses(), 0), // set all to 0
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000527 nextEarliestStartTime(target.getInstrInfo().getNumRealOpCodes(),
528 (cycles_t) 0) // set all to 0
529{
530 updateTime(0);
531
532 // Note that an upper bound on #choices for each slot is = nslots since
533 // we use this vector to hold a feasible set of instructions, and more
534 // would be infeasible. Reserve that much memory since it is probably small.
535 for (unsigned int i=0; i < nslots; i++)
536 choicesForSlot[i].resize(nslots);
537}
538
539
540void
541SchedulingManager::updateEarliestStartTimes(const SchedGraphNode* node,
542 cycles_t schedTime)
543{
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000544 if (schedInfo.numBubblesAfter(node->getOpCode()) > 0)
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000545 { // Update next earliest time before which *nothing* can issue.
Chris Lattner697954c2002-01-20 22:54:45 +0000546 nextEarliestIssueTime = std::max(nextEarliestIssueTime,
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000547 curTime + 1 + schedInfo.numBubblesAfter(node->getOpCode()));
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000548 }
549
550 const vector<MachineOpCode>*
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000551 conflictVec = schedInfo.getConflictList(node->getOpCode());
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000552
553 if (conflictVec != NULL)
554 for (unsigned i=0; i < conflictVec->size(); i++)
555 {
556 MachineOpCode toOp = (*conflictVec)[i];
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000557 cycles_t est = schedTime + schedInfo.getMinIssueGap(node->getOpCode(),
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000558 toOp);
559 assert(toOp < (int) nextEarliestStartTime.size());
560 if (nextEarliestStartTime[toOp] < est)
561 nextEarliestStartTime[toOp] = est;
562 }
563}
564
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000565//************************* Internal Functions *****************************/
566
567
568static void
Vikram S. Advec5b46322001-09-30 23:43:34 +0000569AssignInstructionsToSlots(class SchedulingManager& S, unsigned maxIssue)
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000570{
Vikram S. Advec5b46322001-09-30 23:43:34 +0000571 // find the slot to start from, in the current cycle
572 unsigned int startSlot = 0;
573 cycles_t curTime = S.getTime();
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000574
Vikram S. Advec5b46322001-09-30 23:43:34 +0000575 assert(maxIssue > 0 && maxIssue <= S.nslots - startSlot);
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000576
Vikram S. Advec5b46322001-09-30 23:43:34 +0000577 // If only one instruction can be issued, do so.
578 if (maxIssue == 1)
579 for (unsigned s=startSlot; s < S.nslots; s++)
580 if (S.getChoicesForSlot(s).size() > 0)
581 {// found the one instruction
582 S.scheduleInstr(*S.getChoicesForSlot(s).begin(), s, curTime);
583 return;
584 }
585
586 // Otherwise, choose from the choices for each slot
587 //
588 InstrGroup* igroup = S.isched.getIGroup(S.getTime());
589 assert(igroup != NULL && "Group creation failed?");
590
591 // Find a slot that has only a single choice, and take it.
592 // If all slots have 0 or multiple choices, pick the first slot with
593 // choices and use its last instruction (just to avoid shifting the vector).
594 unsigned numIssued;
595 for (numIssued = 0; numIssued < maxIssue; numIssued++)
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000596 {
Chris Lattner697954c2002-01-20 22:54:45 +0000597 int chosenSlot = -1;
Vikram S. Advec5b46322001-09-30 23:43:34 +0000598 for (unsigned s=startSlot; s < S.nslots; s++)
599 if ((*igroup)[s] == NULL && S.getChoicesForSlot(s).size() == 1)
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000600 {
Vikram S. Advec5b46322001-09-30 23:43:34 +0000601 chosenSlot = (int) s;
602 break;
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000603 }
604
Vikram S. Advec5b46322001-09-30 23:43:34 +0000605 if (chosenSlot == -1)
606 for (unsigned s=startSlot; s < S.nslots; s++)
607 if ((*igroup)[s] == NULL && S.getChoicesForSlot(s).size() > 0)
608 {
609 chosenSlot = (int) s;
610 break;
611 }
612
613 if (chosenSlot != -1)
614 { // Insert the chosen instr in the chosen slot and
615 // erase it from all slots.
616 const SchedGraphNode* node= *S.getChoicesForSlot(chosenSlot).begin();
617 S.scheduleInstr(node, chosenSlot, curTime);
618 }
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000619 }
Vikram S. Advec5b46322001-09-30 23:43:34 +0000620
621 assert(numIssued > 0 && "Should not happen when maxIssue > 0!");
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000622}
623
624
625//
626// For now, just assume we are scheduling within a single basic block.
627// Get the machine instruction vector for the basic block and clear it,
628// then append instructions in scheduled order.
629// Also, re-insert the dummy PHI instructions that were at the beginning
630// of the basic block, since they are not part of the schedule.
631//
632static void
633RecordSchedule(const BasicBlock* bb, const SchedulingManager& S)
634{
Vikram S. Adve0baf1c02002-07-08 22:59:23 +0000635 MachineCodeForBasicBlock& mvec = MachineCodeForBasicBlock::get(bb);
Vikram S. Advef0ba2802001-09-18 12:51:38 +0000636 const MachineInstrInfo& mii = S.schedInfo.getInstrInfo();
637
638#ifndef NDEBUG
639 // Lets make sure we didn't lose any instructions, except possibly
640 // some NOPs from delay slots. Also, PHIs are not included in the schedule.
641 unsigned numInstr = 0;
642 for (MachineCodeForBasicBlock::iterator I=mvec.begin(); I != mvec.end(); ++I)
643 if (! mii.isNop((*I)->getOpCode()) &&
644 ! mii.isDummyPhiInstr((*I)->getOpCode()))
645 ++numInstr;
646 assert(S.isched.getNumInstructions() >= numInstr &&
647 "Lost some non-NOP instructions during scheduling!");
648#endif
649
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000650 if (S.isched.getNumInstructions() == 0)
651 return; // empty basic block!
652
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000653 // First find the dummy instructions at the start of the basic block
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000654 MachineCodeForBasicBlock::iterator I = mvec.begin();
655 for ( ; I != mvec.end(); ++I)
656 if (! mii.isDummyPhiInstr((*I)->getOpCode()))
657 break;
658
659 // Erase all except the dummy PHI instructions from mvec, and
Vikram S. Advef0ba2802001-09-18 12:51:38 +0000660 // pre-allocate create space for the ones we will put back in.
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000661 mvec.erase(I, mvec.end());
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000662
663 InstrSchedule::const_iterator NIend = S.isched.end();
664 for (InstrSchedule::const_iterator NI = S.isched.begin(); NI != NIend; ++NI)
Chris Lattner2e530932001-09-09 19:41:52 +0000665 mvec.push_back(const_cast<MachineInstr*>((*NI)->getMachineInstr()));
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000666}
667
668
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000669
670static void
671MarkSuccessorsReady(SchedulingManager& S, const SchedGraphNode* node)
672{
673 // Check if any successors are now ready that were not already marked
674 // ready before, and that have not yet been scheduled.
675 //
676 for (sg_succ_const_iterator SI = succ_begin(node); SI !=succ_end(node); ++SI)
677 if (! (*SI)->isDummyNode()
678 && ! S.isScheduled(*SI)
679 && ! S.schedPrio.nodeIsReady(*SI))
680 {// successor not scheduled and not marked ready; check *its* preds.
681
682 bool succIsReady = true;
683 for (sg_pred_const_iterator P=pred_begin(*SI); P != pred_end(*SI); ++P)
684 if (! (*P)->isDummyNode()
685 && ! S.isScheduled(*P))
686 {
687 succIsReady = false;
688 break;
689 }
690
691 if (succIsReady) // add the successor to the ready list
692 S.schedPrio.insertReady(*SI);
693 }
694}
695
696
697// Choose up to `nslots' FEASIBLE instructions and assign each
698// instruction to all possible slots that do not violate feasibility.
699// FEASIBLE means it should be guaranteed that the set
700// of chosen instructions can be issued in a single group.
701//
702// Return value:
703// maxIssue : total number of feasible instructions
704// S.choicesForSlot[i=0..nslots] : set of instructions feasible in slot i
705//
706static unsigned
707FindSlotChoices(SchedulingManager& S,
708 DelaySlotInfo*& getDelaySlotInfo)
709{
710 // initialize result vectors to empty
711 S.resetChoices();
712
713 // find the slot to start from, in the current cycle
714 unsigned int startSlot = 0;
715 InstrGroup* igroup = S.isched.getIGroup(S.getTime());
716 for (int s = S.nslots - 1; s >= 0; s--)
717 if ((*igroup)[s] != NULL)
718 {
719 startSlot = s+1;
720 break;
721 }
722
723 // Make sure we pick at most one instruction that would break the group.
724 // Also, if we do pick one, remember which it was.
725 unsigned int indexForBreakingNode = S.nslots;
726 unsigned int indexForDelayedInstr = S.nslots;
727 DelaySlotInfo* delaySlotInfo = NULL;
728
729 getDelaySlotInfo = NULL;
730
731 // Choose instructions in order of priority.
732 // Add choices to the choice vector in the SchedulingManager class as
733 // we choose them so that subsequent choices will be correctly tested
734 // for feasibility, w.r.t. higher priority choices for the same cycle.
735 //
736 while (S.getNumChoices() < S.nslots - startSlot)
737 {
738 const SchedGraphNode* nextNode=S.schedPrio.getNextHighest(S,S.getTime());
739 if (nextNode == NULL)
740 break; // no more instructions for this cycle
741
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000742 if (S.getInstrInfo().getNumDelaySlots(nextNode->getOpCode()) > 0)
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000743 {
744 delaySlotInfo = S.getDelaySlotInfoForInstr(nextNode);
745 if (delaySlotInfo != NULL)
746 {
747 if (indexForBreakingNode < S.nslots)
748 // cannot issue a delayed instr in the same cycle as one
749 // that breaks the issue group or as another delayed instr
750 nextNode = NULL;
751 else
752 indexForDelayedInstr = S.getNumChoices();
753 }
754 }
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000755 else if (S.schedInfo.breaksIssueGroup(nextNode->getOpCode()))
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000756 {
757 if (indexForBreakingNode < S.nslots)
758 // have a breaking instruction already so throw this one away
759 nextNode = NULL;
760 else
761 indexForBreakingNode = S.getNumChoices();
762 }
763
764 if (nextNode != NULL)
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000765 {
766 S.addChoice(nextNode);
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000767
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000768 if (S.schedInfo.isSingleIssue(nextNode->getOpCode()))
769 {
770 assert(S.getNumChoices() == 1 &&
771 "Prioritizer returned invalid instr for this cycle!");
772 break;
773 }
774 }
775
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000776 if (indexForDelayedInstr < S.nslots)
777 break; // leave the rest for delay slots
778 }
779
780 assert(S.getNumChoices() <= S.nslots);
781 assert(! (indexForDelayedInstr < S.nslots &&
782 indexForBreakingNode < S.nslots) && "Cannot have both in a cycle");
783
784 // Assign each chosen instruction to all possible slots for that instr.
785 // But if only one instruction was chosen, put it only in the first
786 // feasible slot; no more analysis will be needed.
787 //
788 if (indexForDelayedInstr >= S.nslots &&
789 indexForBreakingNode >= S.nslots)
790 { // No instructions that break the issue group or that have delay slots.
791 // This is the common case, so handle it separately for efficiency.
792
793 if (S.getNumChoices() == 1)
794 {
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000795 MachineOpCode opCode = S.getChoice(0)->getOpCode();
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000796 unsigned int s;
797 for (s=startSlot; s < S.nslots; s++)
798 if (S.schedInfo.instrCanUseSlot(opCode, s))
799 break;
800 assert(s < S.nslots && "No feasible slot for this opCode?");
801 S.addChoiceToSlot(s, S.getChoice(0));
802 }
803 else
804 {
805 for (unsigned i=0; i < S.getNumChoices(); i++)
806 {
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000807 MachineOpCode opCode = S.getChoice(i)->getOpCode();
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000808 for (unsigned int s=startSlot; s < S.nslots; s++)
809 if (S.schedInfo.instrCanUseSlot(opCode, s))
810 S.addChoiceToSlot(s, S.getChoice(i));
811 }
812 }
813 }
814 else if (indexForDelayedInstr < S.nslots)
815 {
816 // There is an instruction that needs delay slots.
817 // Try to assign that instruction to a higher slot than any other
818 // instructions in the group, so that its delay slots can go
819 // right after it.
820 //
821
822 assert(indexForDelayedInstr == S.getNumChoices() - 1 &&
823 "Instruction with delay slots should be last choice!");
824 assert(delaySlotInfo != NULL && "No delay slot info for instr?");
825
826 const SchedGraphNode* delayedNode = S.getChoice(indexForDelayedInstr);
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000827 MachineOpCode delayOpCode = delayedNode->getOpCode();
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000828 unsigned ndelays= S.getInstrInfo().getNumDelaySlots(delayOpCode);
829
830 unsigned delayedNodeSlot = S.nslots;
831 int highestSlotUsed;
832
833 // Find the last possible slot for the delayed instruction that leaves
834 // at least `d' slots vacant after it (d = #delay slots)
835 for (int s = S.nslots-ndelays-1; s >= (int) startSlot; s--)
836 if (S.schedInfo.instrCanUseSlot(delayOpCode, s))
837 {
838 delayedNodeSlot = s;
839 break;
840 }
841
842 highestSlotUsed = -1;
843 for (unsigned i=0; i < S.getNumChoices() - 1; i++)
844 {
845 // Try to assign every other instruction to a lower numbered
846 // slot than delayedNodeSlot.
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000847 MachineOpCode opCode =S.getChoice(i)->getOpCode();
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000848 bool noSlotFound = true;
849 unsigned int s;
850 for (s=startSlot; s < delayedNodeSlot; s++)
851 if (S.schedInfo.instrCanUseSlot(opCode, s))
852 {
853 S.addChoiceToSlot(s, S.getChoice(i));
854 noSlotFound = false;
855 }
856
857 // No slot before `delayedNodeSlot' was found for this opCode
858 // Use a later slot, and allow some delay slots to fall in
859 // the next cycle.
860 if (noSlotFound)
861 for ( ; s < S.nslots; s++)
862 if (S.schedInfo.instrCanUseSlot(opCode, s))
863 {
864 S.addChoiceToSlot(s, S.getChoice(i));
865 break;
866 }
867
868 assert(s < S.nslots && "No feasible slot for instruction?");
869
Chris Lattner697954c2002-01-20 22:54:45 +0000870 highestSlotUsed = std::max(highestSlotUsed, (int) s);
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000871 }
872
873 assert(highestSlotUsed <= (int) S.nslots-1 && "Invalid slot used?");
874
875 // We will put the delayed node in the first slot after the
876 // highest slot used. But we just mark that for now, and
877 // schedule it separately because we want to schedule the delay
878 // slots for the node at the same time.
879 cycles_t dcycle = S.getTime();
880 unsigned int dslot = highestSlotUsed + 1;
881 if (dslot == S.nslots)
882 {
883 dslot = 0;
884 ++dcycle;
885 }
886 delaySlotInfo->recordChosenSlot(dcycle, dslot);
887 getDelaySlotInfo = delaySlotInfo;
888 }
889 else
890 { // There is an instruction that breaks the issue group.
891 // For such an instruction, assign to the last possible slot in
892 // the current group, and then don't assign any other instructions
893 // to later slots.
894 assert(indexForBreakingNode < S.nslots);
895 const SchedGraphNode* breakingNode=S.getChoice(indexForBreakingNode);
896 unsigned breakingSlot = INT_MAX;
897 unsigned int nslotsToUse = S.nslots;
898
899 // Find the last possible slot for this instruction.
900 for (int s = S.nslots-1; s >= (int) startSlot; s--)
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000901 if (S.schedInfo.instrCanUseSlot(breakingNode->getOpCode(), s))
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000902 {
903 breakingSlot = s;
904 break;
905 }
906 assert(breakingSlot < S.nslots &&
907 "No feasible slot for `breakingNode'?");
908
909 // Higher priority instructions than the one that breaks the group:
910 // These can be assigned to all slots, but will be assigned only
911 // to earlier slots if possible.
912 for (unsigned i=0;
913 i < S.getNumChoices() && i < indexForBreakingNode; i++)
914 {
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000915 MachineOpCode opCode =S.getChoice(i)->getOpCode();
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000916
917 // If a higher priority instruction cannot be assigned to
918 // any earlier slots, don't schedule the breaking instruction.
919 //
920 bool foundLowerSlot = false;
921 nslotsToUse = S.nslots; // May be modified in the loop
922 for (unsigned int s=startSlot; s < nslotsToUse; s++)
923 if (S.schedInfo.instrCanUseSlot(opCode, s))
924 {
925 if (breakingSlot < S.nslots && s < breakingSlot)
926 {
927 foundLowerSlot = true;
928 nslotsToUse = breakingSlot; // RESETS LOOP UPPER BOUND!
929 }
930
931 S.addChoiceToSlot(s, S.getChoice(i));
932 }
933
934 if (!foundLowerSlot)
935 breakingSlot = INT_MAX; // disable breaking instr
936 }
937
938 // Assign the breaking instruction (if any) to a single slot
939 // Otherwise, just ignore the instruction. It will simply be
940 // scheduled in a later cycle.
941 if (breakingSlot < S.nslots)
942 {
943 S.addChoiceToSlot(breakingSlot, breakingNode);
944 nslotsToUse = breakingSlot;
945 }
946 else
947 nslotsToUse = S.nslots;
948
949 // For lower priority instructions than the one that breaks the
950 // group, only assign them to slots lower than the breaking slot.
951 // Otherwise, just ignore the instruction.
952 for (unsigned i=indexForBreakingNode+1; i < S.getNumChoices(); i++)
953 {
Vikram S. Advefb1a6c82001-11-09 02:14:20 +0000954 MachineOpCode opCode = S.getChoice(i)->getOpCode();
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000955 for (unsigned int s=startSlot; s < nslotsToUse; s++)
956 if (S.schedInfo.instrCanUseSlot(opCode, s))
957 S.addChoiceToSlot(s, S.getChoice(i));
958 }
959 } // endif (no delay slots and no breaking slots)
960
961 return S.getNumChoices();
962}
963
964
Vikram S. Advec5b46322001-09-30 23:43:34 +0000965static unsigned
966ChooseOneGroup(SchedulingManager& S)
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000967{
Vikram S. Advec5b46322001-09-30 23:43:34 +0000968 assert(S.schedPrio.getNumReady() > 0
969 && "Don't get here without ready instructions.");
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000970
Vikram S. Advec5b46322001-09-30 23:43:34 +0000971 cycles_t firstCycle = S.getTime();
972 DelaySlotInfo* getDelaySlotInfo = NULL;
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000973
Vikram S. Advec5b46322001-09-30 23:43:34 +0000974 // Choose up to `nslots' feasible instructions and their possible slots.
975 unsigned numIssued = FindSlotChoices(S, getDelaySlotInfo);
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000976
Vikram S. Advec5b46322001-09-30 23:43:34 +0000977 while (numIssued == 0)
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000978 {
Vikram S. Advec5b46322001-09-30 23:43:34 +0000979 S.updateTime(S.getTime()+1);
980 numIssued = FindSlotChoices(S, getDelaySlotInfo);
Vikram S. Adve0e1158f2001-08-28 23:07:19 +0000981 }
982
Vikram S. Advec5b46322001-09-30 23:43:34 +0000983 AssignInstructionsToSlots(S, numIssued);
984
985 if (getDelaySlotInfo != NULL)
986 numIssued += getDelaySlotInfo->scheduleDelayedNode(S);
987
988 // Print trace of scheduled instructions before newly ready ones
989 if (SchedDebugLevel >= Sched_PrintSchedTrace)
990 {
991 for (cycles_t c = firstCycle; c <= S.getTime(); c++)
992 {
Chris Lattner697954c2002-01-20 22:54:45 +0000993 cerr << " Cycle " << (long)c << " : Scheduled instructions:\n";
Vikram S. Advec5b46322001-09-30 23:43:34 +0000994 const InstrGroup* igroup = S.isched.getIGroup(c);
995 for (unsigned int s=0; s < S.nslots; s++)
996 {
Chris Lattner697954c2002-01-20 22:54:45 +0000997 cerr << " ";
Vikram S. Advec5b46322001-09-30 23:43:34 +0000998 if ((*igroup)[s] != NULL)
Chris Lattner697954c2002-01-20 22:54:45 +0000999 cerr << * ((*igroup)[s])->getMachineInstr() << "\n";
Vikram S. Advec5b46322001-09-30 23:43:34 +00001000 else
Chris Lattner697954c2002-01-20 22:54:45 +00001001 cerr << "<none>\n";
Vikram S. Advec5b46322001-09-30 23:43:34 +00001002 }
1003 }
1004 }
1005
1006 return numIssued;
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001007}
1008
1009
Vikram S. Advec5b46322001-09-30 23:43:34 +00001010static void
1011ForwardListSchedule(SchedulingManager& S)
1012{
1013 unsigned N;
1014 const SchedGraphNode* node;
1015
1016 S.schedPrio.initialize();
1017
1018 while ((N = S.schedPrio.getNumReady()) > 0)
1019 {
1020 cycles_t nextCycle = S.getTime();
1021
1022 // Choose one group of instructions for a cycle, plus any delay slot
1023 // instructions (which may overflow into successive cycles).
1024 // This will advance S.getTime() to the last cycle in which
1025 // instructions are actually issued.
1026 //
1027 unsigned numIssued = ChooseOneGroup(S);
1028 assert(numIssued > 0 && "Deadlock in list scheduling algorithm?");
1029
1030 // Notify the priority manager of scheduled instructions and mark
1031 // any successors that may now be ready
1032 //
1033 for (cycles_t c = nextCycle; c <= S.getTime(); c++)
1034 {
1035 const InstrGroup* igroup = S.isched.getIGroup(c);
1036 for (unsigned int s=0; s < S.nslots; s++)
1037 if ((node = (*igroup)[s]) != NULL)
1038 {
1039 S.schedPrio.issuedReadyNodeAt(S.getTime(), node);
1040 MarkSuccessorsReady(S, node);
1041 }
1042 }
1043
1044 // Move to the next the next earliest cycle for which
1045 // an instruction can be issued, or the next earliest in which
1046 // one will be ready, or to the next cycle, whichever is latest.
1047 //
Chris Lattner697954c2002-01-20 22:54:45 +00001048 S.updateTime(std::max(S.getTime() + 1,
1049 std::max(S.getEarliestIssueTime(),
1050 S.schedPrio.getEarliestReadyTime())));
Vikram S. Advec5b46322001-09-30 23:43:34 +00001051 }
1052}
1053
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001054
1055//---------------------------------------------------------------------
1056// Code for filling delay slots for delayed terminator instructions
1057// (e.g., BRANCH and RETURN). Delay slots for non-terminator
1058// instructions (e.g., CALL) are not handled here because they almost
1059// always can be filled with instructions from the call sequence code
1060// before a call. That's preferable because we incur many tradeoffs here
1061// when we cannot find single-cycle instructions that can be reordered.
1062//----------------------------------------------------------------------
1063
Vikram S. Advec5b46322001-09-30 23:43:34 +00001064static bool
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001065NodeCanFillDelaySlot(const SchedulingManager& S,
1066 const SchedGraphNode* node,
1067 const SchedGraphNode* brNode,
1068 bool nodeIsPredecessor)
1069{
1070 assert(! node->isDummyNode());
1071
1072 // don't put a branch in the delay slot of another branch
Vikram S. Advefb1a6c82001-11-09 02:14:20 +00001073 if (S.getInstrInfo().isBranch(node->getOpCode()))
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001074 return false;
1075
1076 // don't put a single-issue instruction in the delay slot of a branch
Vikram S. Advefb1a6c82001-11-09 02:14:20 +00001077 if (S.schedInfo.isSingleIssue(node->getOpCode()))
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001078 return false;
1079
1080 // don't put a load-use dependence in the delay slot of a branch
1081 const MachineInstrInfo& mii = S.getInstrInfo();
1082
1083 for (SchedGraphNode::const_iterator EI = node->beginInEdges();
1084 EI != node->endInEdges(); ++EI)
1085 if (! (*EI)->getSrc()->isDummyNode()
Vikram S. Advefb1a6c82001-11-09 02:14:20 +00001086 && mii.isLoad((*EI)->getSrc()->getOpCode())
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001087 && (*EI)->getDepType() == SchedGraphEdge::CtrlDep)
1088 return false;
1089
1090 // for now, don't put an instruction that does not have operand
1091 // interlocks in the delay slot of a branch
Vikram S. Advefb1a6c82001-11-09 02:14:20 +00001092 if (! S.getInstrInfo().hasOperandInterlock(node->getOpCode()))
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001093 return false;
1094
1095 // Finally, if the instruction preceeds the branch, we make sure the
1096 // instruction can be reordered relative to the branch. We simply check
1097 // if the instr. has only 1 outgoing edge, viz., a CD edge to the branch.
1098 //
1099 if (nodeIsPredecessor)
1100 {
1101 bool onlyCDEdgeToBranch = true;
1102 for (SchedGraphNode::const_iterator OEI = node->beginOutEdges();
1103 OEI != node->endOutEdges(); ++OEI)
1104 if (! (*OEI)->getSink()->isDummyNode()
1105 && ((*OEI)->getSink() != brNode
1106 || (*OEI)->getDepType() != SchedGraphEdge::CtrlDep))
1107 {
1108 onlyCDEdgeToBranch = false;
1109 break;
1110 }
1111
1112 if (!onlyCDEdgeToBranch)
1113 return false;
1114 }
1115
1116 return true;
1117}
1118
1119
Vikram S. Advec5b46322001-09-30 23:43:34 +00001120static void
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001121MarkNodeForDelaySlot(SchedulingManager& S,
Vikram S. Advef0ba2802001-09-18 12:51:38 +00001122 SchedGraph* graph,
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001123 SchedGraphNode* node,
1124 const SchedGraphNode* brNode,
1125 bool nodeIsPredecessor)
1126{
1127 if (nodeIsPredecessor)
1128 { // If node is in the same basic block (i.e., preceeds brNode),
Vikram S. Advef0ba2802001-09-18 12:51:38 +00001129 // remove it and all its incident edges from the graph. Make sure we
1130 // add dummy edges for pred/succ nodes that become entry/exit nodes.
1131 graph->eraseIncidentEdges(node, /*addDummyEdges*/ true);
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001132 }
1133 else
1134 { // If the node was from a target block, add the node to the graph
1135 // and add a CD edge from brNode to node.
1136 assert(0 && "NOT IMPLEMENTED YET");
1137 }
1138
1139 DelaySlotInfo* dinfo = S.getDelaySlotInfoForInstr(brNode, /*create*/ true);
1140 dinfo->addDelayNode(node);
1141}
1142
1143
Vikram S. Advec5b46322001-09-30 23:43:34 +00001144void
1145FindUsefulInstructionsForDelaySlots(SchedulingManager& S,
1146 SchedGraphNode* brNode,
1147 vector<SchedGraphNode*>& sdelayNodeVec)
1148{
1149 const MachineInstrInfo& mii = S.getInstrInfo();
1150 unsigned ndelays =
Vikram S. Advefb1a6c82001-11-09 02:14:20 +00001151 mii.getNumDelaySlots(brNode->getOpCode());
Vikram S. Advec5b46322001-09-30 23:43:34 +00001152
1153 if (ndelays == 0)
1154 return;
1155
1156 sdelayNodeVec.reserve(ndelays);
1157
1158 // Use a separate vector to hold the feasible multi-cycle nodes.
1159 // These will be used if not enough single-cycle nodes are found.
1160 //
1161 vector<SchedGraphNode*> mdelayNodeVec;
1162
1163 for (sg_pred_iterator P = pred_begin(brNode);
1164 P != pred_end(brNode) && sdelayNodeVec.size() < ndelays; ++P)
1165 if (! (*P)->isDummyNode() &&
Vikram S. Advefb1a6c82001-11-09 02:14:20 +00001166 ! mii.isNop((*P)->getOpCode()) &&
Vikram S. Advec5b46322001-09-30 23:43:34 +00001167 NodeCanFillDelaySlot(S, *P, brNode, /*pred*/ true))
1168 {
Vikram S. Advefb1a6c82001-11-09 02:14:20 +00001169 if (mii.maxLatency((*P)->getOpCode()) > 1)
Vikram S. Advec5b46322001-09-30 23:43:34 +00001170 mdelayNodeVec.push_back(*P);
1171 else
1172 sdelayNodeVec.push_back(*P);
1173 }
1174
1175 // If not enough single-cycle instructions were found, select the
1176 // lowest-latency multi-cycle instructions and use them.
1177 // Note that this is the most efficient code when only 1 (or even 2)
1178 // values need to be selected.
1179 //
1180 while (sdelayNodeVec.size() < ndelays && mdelayNodeVec.size() > 0)
1181 {
1182 unsigned lmin =
Vikram S. Advefb1a6c82001-11-09 02:14:20 +00001183 mii.maxLatency(mdelayNodeVec[0]->getOpCode());
Vikram S. Advec5b46322001-09-30 23:43:34 +00001184 unsigned minIndex = 0;
1185 for (unsigned i=1; i < mdelayNodeVec.size(); i++)
1186 {
1187 unsigned li =
Vikram S. Advefb1a6c82001-11-09 02:14:20 +00001188 mii.maxLatency(mdelayNodeVec[i]->getOpCode());
Vikram S. Advec5b46322001-09-30 23:43:34 +00001189 if (lmin >= li)
1190 {
1191 lmin = li;
1192 minIndex = i;
1193 }
1194 }
1195 sdelayNodeVec.push_back(mdelayNodeVec[minIndex]);
1196 if (sdelayNodeVec.size() < ndelays) // avoid the last erase!
1197 mdelayNodeVec.erase(mdelayNodeVec.begin() + minIndex);
1198 }
1199}
1200
1201
1202// Remove the NOPs currently in delay slots from the graph.
1203// Mark instructions specified in sdelayNodeVec to replace them.
1204// If not enough useful instructions were found, mark the NOPs to be used
1205// for filling delay slots, otherwise, otherwise just discard them.
1206//
1207void
1208ReplaceNopsWithUsefulInstr(SchedulingManager& S,
1209 SchedGraphNode* node,
1210 vector<SchedGraphNode*> sdelayNodeVec,
1211 SchedGraph* graph)
1212{
Vikram S. Advefb8c0532001-10-22 13:49:27 +00001213 vector<SchedGraphNode*> nopNodeVec; // this will hold unused NOPs
Vikram S. Advec5b46322001-09-30 23:43:34 +00001214 const MachineInstrInfo& mii = S.getInstrInfo();
Vikram S. Advefb8c0532001-10-22 13:49:27 +00001215 const MachineInstr* brInstr = node->getMachineInstr();
1216 unsigned ndelays= mii.getNumDelaySlots(brInstr->getOpCode());
Vikram S. Advec5b46322001-09-30 23:43:34 +00001217 assert(ndelays > 0 && "Unnecessary call to replace NOPs");
1218
1219 // Remove the NOPs currently in delay slots from the graph.
1220 // If not enough useful instructions were found, use the NOPs to
1221 // fill delay slots, otherwise, just discard them.
Vikram S. Advefb8c0532001-10-22 13:49:27 +00001222 //
Vikram S. Adveaf00d482001-11-12 14:18:01 +00001223 unsigned int firstDelaySlotIdx = node->getOrigIndexInBB() + 1;
Vikram S. Adve0baf1c02002-07-08 22:59:23 +00001224 MachineCodeForBasicBlock& bbMvec = MachineCodeForBasicBlock::get(node->getBB());
Vikram S. Adveaf00d482001-11-12 14:18:01 +00001225 assert(bbMvec[firstDelaySlotIdx - 1] == brInstr &&
1226 "Incorrect instr. index in basic block for brInstr");
Vikram S. Advefb8c0532001-10-22 13:49:27 +00001227
1228 // First find all useful instructions already in the delay slots
1229 // and USE THEM. We'll throw away the unused alternatives below
1230 //
1231 for (unsigned i=firstDelaySlotIdx; i < firstDelaySlotIdx + ndelays; ++i)
Vikram S. Adveaf00d482001-11-12 14:18:01 +00001232 if (! mii.isNop(bbMvec[i]->getOpCode()))
Vikram S. Advefb8c0532001-10-22 13:49:27 +00001233 sdelayNodeVec.insert(sdelayNodeVec.begin(),
Vikram S. Adveaf00d482001-11-12 14:18:01 +00001234 graph->getGraphNodeForInstr(bbMvec[i]));
Vikram S. Advefb8c0532001-10-22 13:49:27 +00001235
1236 // Then find the NOPs and keep only as many as are needed.
1237 // Put the rest in nopNodeVec to be deleted.
1238 for (unsigned i=firstDelaySlotIdx; i < firstDelaySlotIdx + ndelays; ++i)
Vikram S. Adveaf00d482001-11-12 14:18:01 +00001239 if (mii.isNop(bbMvec[i]->getOpCode()))
Vikram S. Advefb8c0532001-10-22 13:49:27 +00001240 if (sdelayNodeVec.size() < ndelays)
Vikram S. Adveaf00d482001-11-12 14:18:01 +00001241 sdelayNodeVec.push_back(graph->getGraphNodeForInstr(bbMvec[i]));
Vikram S. Advefb8c0532001-10-22 13:49:27 +00001242 else
Vikram S. Adveaf00d482001-11-12 14:18:01 +00001243 nopNodeVec.push_back(graph->getGraphNodeForInstr(bbMvec[i]));
Vikram S. Advefb8c0532001-10-22 13:49:27 +00001244
1245 assert(sdelayNodeVec.size() >= ndelays);
1246
1247 // If some delay slots were already filled, throw away that many new choices
1248 if (sdelayNodeVec.size() > ndelays)
1249 sdelayNodeVec.resize(ndelays);
Vikram S. Advec5b46322001-09-30 23:43:34 +00001250
1251 // Mark the nodes chosen for delay slots. This removes them from the graph.
1252 for (unsigned i=0; i < sdelayNodeVec.size(); i++)
1253 MarkNodeForDelaySlot(S, graph, sdelayNodeVec[i], node, true);
1254
1255 // And remove the unused NOPs from the graph.
1256 for (unsigned i=0; i < nopNodeVec.size(); i++)
1257 graph->eraseIncidentEdges(nopNodeVec[i], /*addDummyEdges*/ true);
1258}
1259
1260
1261// For all delayed instructions, choose instructions to put in the delay
1262// slots and pull those out of the graph. Mark them for the delay slots
1263// in the DelaySlotInfo object for that graph node. If no useful work
1264// is found for a delay slot, use the NOP that is currently in that slot.
1265//
1266// We try to fill the delay slots with useful work for all instructions
Vikram S. Adve6db77c52001-10-10 20:58:11 +00001267// EXCEPT CALLS AND RETURNS.
1268// For CALLs and RETURNs, it is nearly always possible to use one of the
Vikram S. Advec5b46322001-09-30 23:43:34 +00001269// call sequence instrs and putting anything else in the delay slot could be
Vikram S. Adve6db77c52001-10-10 20:58:11 +00001270// suboptimal. Also, it complicates generating the calling sequence code in
1271// regalloc.
Vikram S. Advec5b46322001-09-30 23:43:34 +00001272//
1273static void
1274ChooseInstructionsForDelaySlots(SchedulingManager& S,
Chris Lattner3462cae2002-02-03 07:28:30 +00001275 const BasicBlock *bb,
1276 SchedGraph *graph)
Vikram S. Advec5b46322001-09-30 23:43:34 +00001277{
1278 const MachineInstrInfo& mii = S.getInstrInfo();
Chris Lattner455889a2002-02-12 22:39:50 +00001279 const Instruction *termInstr = (Instruction*)bb->getTerminator();
Chris Lattner3462cae2002-02-03 07:28:30 +00001280 MachineCodeForInstruction &termMvec=MachineCodeForInstruction::get(termInstr);
Vikram S. Advec5b46322001-09-30 23:43:34 +00001281 vector<SchedGraphNode*> delayNodeVec;
Vikram S. Adve6db77c52001-10-10 20:58:11 +00001282 const MachineInstr* brInstr = NULL;
Vikram S. Advec5b46322001-09-30 23:43:34 +00001283
Vikram S. Adve6db77c52001-10-10 20:58:11 +00001284 if (termInstr->getOpcode() != Instruction::Ret)
Vikram S. Advec5b46322001-09-30 23:43:34 +00001285 {
Vikram S. Adve6db77c52001-10-10 20:58:11 +00001286 // To find instructions that need delay slots without searching the full
1287 // machine code, we assume that the only delayed instructions are CALLs
1288 // or instructions generated for the terminator inst.
1289 // Find the first branch instr in the sequence of machine instrs for term
1290 //
1291 unsigned first = 0;
1292 while (first < termMvec.size() &&
1293 ! mii.isBranch(termMvec[first]->getOpCode()))
1294 {
1295 ++first;
1296 }
1297 assert(first < termMvec.size() &&
1298 "No branch instructions for BR? Ok, but weird! Delete assertion.");
1299
1300 brInstr = (first < termMvec.size())? termMvec[first] : NULL;
1301
1302 // Compute a vector of the nodes chosen for delay slots and then
1303 // mark delay slots to replace NOPs with these useful instructions.
1304 //
1305 if (brInstr != NULL)
1306 {
1307 SchedGraphNode* brNode = graph->getGraphNodeForInstr(brInstr);
1308 FindUsefulInstructionsForDelaySlots(S, brNode, delayNodeVec);
1309 ReplaceNopsWithUsefulInstr(S, brNode, delayNodeVec, graph);
1310 }
Vikram S. Advec5b46322001-09-30 23:43:34 +00001311 }
1312
1313 // Also mark delay slots for other delayed instructions to hold NOPs.
1314 // Simply passing in an empty delayNodeVec will have this effect.
1315 //
1316 delayNodeVec.clear();
Vikram S. Adve0baf1c02002-07-08 22:59:23 +00001317 const MachineCodeForBasicBlock& bbMvec = MachineCodeForBasicBlock::get(bb);
Vikram S. Advec5b46322001-09-30 23:43:34 +00001318 for (unsigned i=0; i < bbMvec.size(); i++)
1319 if (bbMvec[i] != brInstr &&
1320 mii.getNumDelaySlots(bbMvec[i]->getOpCode()) > 0)
1321 {
1322 SchedGraphNode* node = graph->getGraphNodeForInstr(bbMvec[i]);
1323 ReplaceNopsWithUsefulInstr(S, node, delayNodeVec, graph);
1324 }
1325}
1326
1327
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001328//
1329// Schedule the delayed branch and its delay slots
1330//
Vikram S. Advec5b46322001-09-30 23:43:34 +00001331unsigned
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001332DelaySlotInfo::scheduleDelayedNode(SchedulingManager& S)
1333{
1334 assert(delayedNodeSlotNum < S.nslots && "Illegal slot for branch");
1335 assert(S.isched.getInstr(delayedNodeSlotNum, delayedNodeCycle) == NULL
1336 && "Slot for branch should be empty");
1337
1338 unsigned int nextSlot = delayedNodeSlotNum;
1339 cycles_t nextTime = delayedNodeCycle;
1340
1341 S.scheduleInstr(brNode, nextSlot, nextTime);
1342
1343 for (unsigned d=0; d < ndelays; d++)
1344 {
1345 ++nextSlot;
1346 if (nextSlot == S.nslots)
1347 {
1348 nextSlot = 0;
1349 nextTime++;
1350 }
1351
1352 // Find the first feasible instruction for this delay slot
1353 // Note that we only check for issue restrictions here.
1354 // We do *not* check for flow dependences but rely on pipeline
1355 // interlocks to resolve them. Machines without interlocks
1356 // will require this code to be modified.
1357 for (unsigned i=0; i < delayNodeVec.size(); i++)
1358 {
1359 const SchedGraphNode* dnode = delayNodeVec[i];
1360 if ( ! S.isScheduled(dnode)
Vikram S. Advefb1a6c82001-11-09 02:14:20 +00001361 && S.schedInfo.instrCanUseSlot(dnode->getOpCode(), nextSlot)
1362 && instrIsFeasible(S, dnode->getOpCode()))
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001363 {
Vikram S. Advefb1a6c82001-11-09 02:14:20 +00001364 assert(S.getInstrInfo().hasOperandInterlock(dnode->getOpCode())
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001365 && "Instructions without interlocks not yet supported "
1366 "when filling branch delay slots");
1367 S.scheduleInstr(dnode, nextSlot, nextTime);
1368 break;
1369 }
1370 }
1371 }
1372
1373 // Update current time if delay slots overflowed into later cycles.
1374 // Do this here because we know exactly which cycle is the last cycle
1375 // that contains delay slots. The next loop doesn't compute that.
1376 if (nextTime > S.getTime())
1377 S.updateTime(nextTime);
1378
1379 // Now put any remaining instructions in the unfilled delay slots.
1380 // This could lead to suboptimal performance but needed for correctness.
1381 nextSlot = delayedNodeSlotNum;
1382 nextTime = delayedNodeCycle;
1383 for (unsigned i=0; i < delayNodeVec.size(); i++)
1384 if (! S.isScheduled(delayNodeVec[i]))
1385 {
1386 do { // find the next empty slot
1387 ++nextSlot;
1388 if (nextSlot == S.nslots)
1389 {
1390 nextSlot = 0;
1391 nextTime++;
1392 }
1393 } while (S.isched.getInstr(nextSlot, nextTime) != NULL);
1394
1395 S.scheduleInstr(delayNodeVec[i], nextSlot, nextTime);
1396 break;
1397 }
Vikram S. Advec5b46322001-09-30 23:43:34 +00001398
1399 return 1 + ndelays;
Vikram S. Adve0e1158f2001-08-28 23:07:19 +00001400}
1401
Vikram S. Advec5b46322001-09-30 23:43:34 +00001402
1403// Check if the instruction would conflict with instructions already
1404// chosen for the current cycle
1405//
1406static inline bool
1407ConflictsWithChoices(const SchedulingManager& S,
1408 MachineOpCode opCode)
1409{
1410 // Check if the instruction must issue by itself, and some feasible
1411 // choices have already been made for this cycle
1412 if (S.getNumChoices() > 0 && S.schedInfo.isSingleIssue(opCode))
1413 return true;
1414
1415 // For each class that opCode belongs to, check if there are too many
1416 // instructions of that class.
1417 //
1418 const InstrSchedClass sc = S.schedInfo.getSchedClass(opCode);
1419 return (S.getNumChoicesInClass(sc) == S.schedInfo.getMaxIssueForClass(sc));
1420}
1421
1422
1423//************************* External Functions *****************************/
1424
1425
1426//---------------------------------------------------------------------------
1427// Function: ViolatesMinimumGap
1428//
1429// Purpose:
1430// Check minimum gap requirements relative to instructions scheduled in
1431// previous cycles.
1432// Note that we do not need to consider `nextEarliestIssueTime' here because
1433// that is also captured in the earliest start times for each opcode.
1434//---------------------------------------------------------------------------
1435
1436static inline bool
1437ViolatesMinimumGap(const SchedulingManager& S,
1438 MachineOpCode opCode,
1439 const cycles_t inCycle)
1440{
1441 return (inCycle < S.getEarliestStartTimeForOp(opCode));
1442}
1443
1444
1445//---------------------------------------------------------------------------
1446// Function: instrIsFeasible
1447//
1448// Purpose:
1449// Check if any issue restrictions would prevent the instruction from
1450// being issued in the current cycle
1451//---------------------------------------------------------------------------
1452
1453bool
1454instrIsFeasible(const SchedulingManager& S,
1455 MachineOpCode opCode)
1456{
1457 // skip the instruction if it cannot be issued due to issue restrictions
1458 // caused by previously issued instructions
1459 if (ViolatesMinimumGap(S, opCode, S.getTime()))
1460 return false;
1461
1462 // skip the instruction if it cannot be issued due to issue restrictions
1463 // caused by previously chosen instructions for the current cycle
1464 if (ConflictsWithChoices(S, opCode))
1465 return false;
1466
1467 return true;
1468}
1469
1470//---------------------------------------------------------------------------
1471// Function: ScheduleInstructionsWithSSA
1472//
1473// Purpose:
1474// Entry point for instruction scheduling on SSA form.
1475// Schedules the machine instructions generated by instruction selection.
1476// Assumes that register allocation has not been done, i.e., operands
1477// are still in SSA form.
1478//---------------------------------------------------------------------------
1479
Chris Lattner9adb7ad2002-02-04 20:02:16 +00001480namespace {
Chris Lattnerf57b8452002-04-27 06:56:12 +00001481 class InstructionSchedulingWithSSA : public FunctionPass {
Vikram S. Adve802cec42002-03-24 03:44:55 +00001482 const TargetMachine &target;
Chris Lattner9adb7ad2002-02-04 20:02:16 +00001483 public:
Vikram S. Adve802cec42002-03-24 03:44:55 +00001484 inline InstructionSchedulingWithSSA(const TargetMachine &T) : target(T) {}
Chris Lattner96c466b2002-04-29 14:57:45 +00001485
1486 const char *getPassName() const { return "Instruction Scheduling"; }
Vikram S. Adve802cec42002-03-24 03:44:55 +00001487
Chris Lattnerf57b8452002-04-27 06:56:12 +00001488 // getAnalysisUsage - We use LiveVarInfo...
1489 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
Chris Lattner483e14e2002-04-27 07:27:19 +00001490 AU.addRequired(FunctionLiveVarInfo::ID);
Vikram S. Advec5b46322001-09-30 23:43:34 +00001491 }
Vikram S. Adve802cec42002-03-24 03:44:55 +00001492
Chris Lattner7e708292002-06-25 16:13:24 +00001493 bool runOnFunction(Function &F);
Chris Lattner9adb7ad2002-02-04 20:02:16 +00001494 };
1495} // end anonymous namespace
1496
Vikram S. Adve802cec42002-03-24 03:44:55 +00001497
Chris Lattner7e708292002-06-25 16:13:24 +00001498bool InstructionSchedulingWithSSA::runOnFunction(Function &F)
Vikram S. Adve802cec42002-03-24 03:44:55 +00001499{
1500 if (SchedDebugLevel == Sched_Disable)
1501 return false;
1502
Chris Lattner7e708292002-06-25 16:13:24 +00001503 SchedGraphSet graphSet(&F, target);
Vikram S. Adve802cec42002-03-24 03:44:55 +00001504
1505 if (SchedDebugLevel >= Sched_PrintSchedGraphs)
1506 {
1507 cerr << "\n*** SCHEDULING GRAPHS FOR INSTRUCTION SCHEDULING\n";
1508 graphSet.dump();
1509 }
1510
1511 for (SchedGraphSet::const_iterator GI=graphSet.begin(), GE=graphSet.end();
1512 GI != GE; ++GI)
1513 {
1514 SchedGraph* graph = (*GI);
1515 const vector<const BasicBlock*> &bbvec = graph->getBasicBlocks();
1516 assert(bbvec.size() == 1 && "Cannot schedule multiple basic blocks");
1517 const BasicBlock* bb = bbvec[0];
1518
1519 if (SchedDebugLevel >= Sched_PrintSchedTrace)
1520 cerr << "\n*** TRACE OF INSTRUCTION SCHEDULING OPERATIONS\n\n";
1521
1522 // expensive!
Chris Lattner7e708292002-06-25 16:13:24 +00001523 SchedPriorities schedPrio(&F, graph,getAnalysis<FunctionLiveVarInfo>());
Vikram S. Adve802cec42002-03-24 03:44:55 +00001524 SchedulingManager S(target, graph, schedPrio);
1525
1526 ChooseInstructionsForDelaySlots(S, bb, graph); // modifies graph
1527
1528 ForwardListSchedule(S); // computes schedule in S
1529
1530 RecordSchedule(bb, S); // records schedule in BB
1531 }
1532
1533 if (SchedDebugLevel >= Sched_PrintMachineCode)
1534 {
1535 cerr << "\n*** Machine instructions after INSTRUCTION SCHEDULING\n";
Chris Lattner7e708292002-06-25 16:13:24 +00001536 MachineCodeForMethod::get(&F).dump();
Vikram S. Adve802cec42002-03-24 03:44:55 +00001537 }
1538
1539 return false;
1540}
1541
1542
Chris Lattnerf57b8452002-04-27 06:56:12 +00001543Pass *createInstructionSchedulingWithSSAPass(const TargetMachine &tgt) {
Vikram S. Adve802cec42002-03-24 03:44:55 +00001544 return new InstructionSchedulingWithSSA(tgt);
Vikram S. Advec5b46322001-09-30 23:43:34 +00001545}