blob: dc5d0059e572d46395a8382c50567c49082a2804 [file] [log] [blame]
Vikram S. Adve78ef1392001-08-28 23:06:02 +00001/* -*-C++-*-
2 ****************************************************************************
3 * File:
4 * SchedGraph.h
5 *
6 * Purpose:
7 * Scheduling graph based on SSA graph plus extra dependence edges
8 * capturing dependences due to machine resources (machine registers,
9 * CC registers, and any others).
10 *
11 * Strategy:
12 * This graph tries to leverage the SSA graph as much as possible,
13 * but captures the extra dependences through a common interface.
14 *
15 * History:
16 * 7/20/01 - Vikram Adve - Created
17 ***************************************************************************/
18
19#ifndef LLVM_CODEGEN_SCHEDGRAPH_H
20#define LLVM_CODEGEN_SCHEDGRAPH_H
21
Vikram S. Adve78ef1392001-08-28 23:06:02 +000022#include "llvm/Support/NonCopyable.h"
23#include "llvm/Support/HashExtras.h"
Chris Lattner3ff43872001-09-28 22:56:31 +000024#include "llvm/Support/GraphTraits.h"
Vikram S. Advee64574c2001-11-08 05:20:23 +000025#include "llvm/Target/MachineInstrInfo.h"
26#include "llvm/CodeGen/MachineInstr.h"
Chris Lattnercffebdc2001-09-07 21:07:10 +000027#include <hash_map>
Vikram S. Adve78ef1392001-08-28 23:06:02 +000028
29class Value;
30class Instruction;
Chris Lattner3ff43872001-09-28 22:56:31 +000031class TerminatorInst;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000032class BasicBlock;
33class Method;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000034class TargetMachine;
35class SchedGraphEdge;
36class SchedGraphNode;
37class SchedGraph;
Vikram S. Adve4a87b382001-09-30 23:37:26 +000038class RegToRefVecMap;
Vikram S. Advec352d2c2001-11-05 04:04:23 +000039class ValueToDefVecMap;
40class RefVec;
Chris Lattnerc0c77082001-09-14 17:55:51 +000041class MachineInstr;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000042class MachineCodeForBasicBlock;
43
Vikram S. Adve78ef1392001-08-28 23:06:02 +000044
45/******************** Exported Data Types and Constants ********************/
46
47typedef int ResourceId;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000048const ResourceId InvalidRID = -1;
49const ResourceId MachineCCRegsRID = -2; // use +ve numbers for actual regs
50const ResourceId MachineIntRegsRID = -3; // use +ve numbers for actual regs
51const ResourceId MachineFPRegsRID = -4; // use +ve numbers for actual regs
Vikram S. Adve78ef1392001-08-28 23:06:02 +000052
53
54//*********************** Public Class Declarations ************************/
55
56class SchedGraphEdge: public NonCopyable {
57public:
58 enum SchedGraphEdgeDepType {
59 CtrlDep, MemoryDep, DefUseDep, MachineRegister, MachineResource
60 };
61 enum DataDepOrderType {
Vikram S. Adved0d79c02001-10-28 21:45:02 +000062 TrueDep = 0x1, AntiDep=0x2, OutputDep=0x4, NonDataDep=0x8
Vikram S. Adve78ef1392001-08-28 23:06:02 +000063 };
64
65protected:
66 SchedGraphNode* src;
67 SchedGraphNode* sink;
68 SchedGraphEdgeDepType depType;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000069 unsigned int depOrderType;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000070 int minDelay; // cached latency (assumes fixed target arch)
71
72 union {
Vikram S. Adve4a87b382001-09-30 23:37:26 +000073 const Value* val;
74 int machineRegNum;
75 ResourceId resourceId;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000076 };
77
78public:
79 // For all constructors, if minDelay is unspecified, minDelay is
80 // set to _src->getLatency().
81 // constructor for CtrlDep or MemoryDep edges, selected by 3rd argument
82 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
83 SchedGraphNode* _sink,
84 SchedGraphEdgeDepType _depType,
Vikram S. Adved0d79c02001-10-28 21:45:02 +000085 unsigned int _depOrderType =TrueDep,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000086 int _minDelay = -1);
87
88 // constructor for explicit def-use or memory def-use edge
89 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
90 SchedGraphNode* _sink,
Vikram S. Adve4a87b382001-09-30 23:37:26 +000091 const Value* _val,
Vikram S. Adved0d79c02001-10-28 21:45:02 +000092 unsigned int _depOrderType =TrueDep,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000093 int _minDelay = -1);
94
95 // constructor for machine register dependence
96 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
97 SchedGraphNode* _sink,
98 unsigned int _regNum,
Vikram S. Adved0d79c02001-10-28 21:45:02 +000099 unsigned int _depOrderType =TrueDep,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000100 int _minDelay = -1);
101
102 // constructor for any other machine resource dependences.
103 // DataDepOrderType is always NonDataDep. It it not an argument to
104 // avoid overloading ambiguity with previous constructor.
105 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
106 SchedGraphNode* _sink,
107 ResourceId _resourceId,
108 int _minDelay = -1);
109
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000110 /*dtor*/ ~SchedGraphEdge();
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000111
112 SchedGraphNode* getSrc () const { return src; }
113 SchedGraphNode* getSink () const { return sink; }
114 int getMinDelay () const { return minDelay; }
115 SchedGraphEdgeDepType getDepType () const { return depType; }
116
117 const Value* getValue () const {
118 assert(depType == DefUseDep || depType == MemoryDep); return val;
119 }
120 int getMachineReg () const {
121 assert(depType == MachineRegister); return machineRegNum;
122 }
123 int getResourceId () const {
124 assert(depType == MachineResource); return resourceId;
125 }
126
127public:
128 //
129 // Debugging support
130 //
131 friend ostream& operator<<(ostream& os, const SchedGraphEdge& edge);
132
Chris Lattnercffebdc2001-09-07 21:07:10 +0000133 void dump (int indent=0) const;
134
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000135private:
136 // disable default ctor
137 /*ctor*/ SchedGraphEdge(); // DO NOT IMPLEMENT
138};
139
140
141
142class SchedGraphNode: public NonCopyable {
143private:
144 unsigned int nodeId;
145 const Instruction* instr;
146 const MachineInstr* minstr;
147 vector<SchedGraphEdge*> inEdges;
148 vector<SchedGraphEdge*> outEdges;
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000149 int origIndexInBB; // original position of machine instr in BB
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000150 int latency;
151
152public:
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000153 typedef vector<SchedGraphEdge*>:: iterator iterator;
154 typedef vector<SchedGraphEdge*>::const_iterator const_iterator;
155 typedef vector<SchedGraphEdge*>:: reverse_iterator reverse_iterator;
156 typedef vector<SchedGraphEdge*>::const_reverse_iterator const_reverse_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000157
158public:
159 //
160 // Accessor methods
161 //
162 unsigned int getNodeId () const { return nodeId; }
163 const Instruction* getInstr () const { return instr; }
164 const MachineInstr* getMachineInstr () const { return minstr; }
Vikram S. Advee64574c2001-11-08 05:20:23 +0000165 const MachineOpCode getOpCode () const { return minstr->getOpCode();}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000166 int getLatency () const { return latency; }
167 unsigned int getNumInEdges () const { return inEdges.size(); }
168 unsigned int getNumOutEdges () const { return outEdges.size(); }
169 bool isDummyNode () const { return (minstr == NULL); }
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000170 int getOrigIndexInBB() const { return origIndexInBB; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000171
172 //
173 // Iterators
174 //
175 iterator beginInEdges () { return inEdges.begin(); }
176 iterator endInEdges () { return inEdges.end(); }
177 iterator beginOutEdges () { return outEdges.begin(); }
178 iterator endOutEdges () { return outEdges.end(); }
179
180 const_iterator beginInEdges () const { return inEdges.begin(); }
181 const_iterator endInEdges () const { return inEdges.end(); }
182 const_iterator beginOutEdges () const { return outEdges.begin(); }
183 const_iterator endOutEdges () const { return outEdges.end(); }
184
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000185public:
186 //
187 // Debugging support
188 //
189 friend ostream& operator<<(ostream& os, const SchedGraphNode& node);
190
Chris Lattnercffebdc2001-09-07 21:07:10 +0000191 void dump (int indent=0) const;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000192
193private:
194 friend class SchedGraph; // give access for ctor and dtor
195 friend class SchedGraphEdge; // give access for adding edges
196
197 void addInEdge (SchedGraphEdge* edge);
198 void addOutEdge (SchedGraphEdge* edge);
199
200 void removeInEdge (const SchedGraphEdge* edge);
201 void removeOutEdge (const SchedGraphEdge* edge);
202
203 // disable default constructor and provide a ctor for single-block graphs
204 /*ctor*/ SchedGraphNode(); // DO NOT IMPLEMENT
205 /*ctor*/ SchedGraphNode (unsigned int _nodeId,
206 const Instruction* _instr,
207 const MachineInstr* _minstr,
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000208 int indexInBB,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000209 const TargetMachine& _target);
210 /*dtor*/ ~SchedGraphNode ();
211};
212
213
214
215class SchedGraph :
216 public NonCopyable,
217 private hash_map<const MachineInstr*, SchedGraphNode*>
218{
219private:
220 vector<const BasicBlock*> bbVec; // basic blocks included in the graph
221 SchedGraphNode* graphRoot; // the root and leaf are not inserted
222 SchedGraphNode* graphLeaf; // in the hash_map (see getNumNodes())
223
224public:
225 typedef hash_map<const MachineInstr*, SchedGraphNode*>::iterator iterator;
226 typedef hash_map<const MachineInstr*, SchedGraphNode*>::const_iterator const_iterator;
227
228public:
229 //
230 // Accessor methods
231 //
232 const vector<const BasicBlock*>& getBasicBlocks() const { return bbVec; }
233 const unsigned int getNumNodes() const { return size()+2; }
234 SchedGraphNode* getRoot() const { return graphRoot; }
235 SchedGraphNode* getLeaf() const { return graphLeaf; }
236
237 SchedGraphNode* getGraphNodeForInstr(const MachineInstr* minstr) const {
238 const_iterator onePair = this->find(minstr);
239 return (onePair != this->end())? (*onePair).second : NULL;
240 }
241
242 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000243 // Delete nodes or edges from the graph.
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000244 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000245 void eraseNode (SchedGraphNode* node);
246
247 void eraseIncomingEdges (SchedGraphNode* node,
248 bool addDummyEdges = true);
249
250 void eraseOutgoingEdges (SchedGraphNode* node,
251 bool addDummyEdges = true);
252
253 void eraseIncidentEdges (SchedGraphNode* node,
254 bool addDummyEdges = true);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000255
256 //
257 // Unordered iterators.
258 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
259 //
260 iterator begin() {
261 return hash_map<const MachineInstr*, SchedGraphNode*>::begin();
262 }
263 iterator end() {
264 return hash_map<const MachineInstr*, SchedGraphNode*>::end();
265 }
266 const_iterator begin() const {
267 return hash_map<const MachineInstr*, SchedGraphNode*>::begin();
268 }
269 const_iterator end() const {
270 return hash_map<const MachineInstr*, SchedGraphNode*>::end();
271 }
272
273 //
274 // Ordered iterators.
275 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
276 //
277 // void postord_init();
278 // postorder_iterator postord_begin();
279 // postorder_iterator postord_end();
280 // const_postorder_iterator postord_begin() const;
281 // const_postorder_iterator postord_end() const;
282
283 //
284 // Debugging support
285 //
286 void dump () const;
287
288private:
289 friend class SchedGraphSet; // give access to ctor
290
291 // disable default constructor and provide a ctor for single-block graphs
292 /*ctor*/ SchedGraph (); // DO NOT IMPLEMENT
293 /*ctor*/ SchedGraph (const BasicBlock* bb,
294 const TargetMachine& target);
295 /*dtor*/ ~SchedGraph ();
296
297 inline void noteGraphNodeForInstr (const MachineInstr* minstr,
298 SchedGraphNode* node)
299 {
300 assert((*this)[minstr] == NULL);
301 (*this)[minstr] = node;
302 }
303
304 //
305 // Graph builder
306 //
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000307 void buildGraph (const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000308
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000309 void buildNodesforBB (const TargetMachine& target,
310 const BasicBlock* bb,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000311 vector<SchedGraphNode*>& memNodeVec,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000312 RegToRefVecMap& regToRefVecMap,
313 ValueToDefVecMap& valueToDefVecMap);
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000314
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000315 void findDefUseInfoAtInstr (const TargetMachine& target,
316 SchedGraphNode* node,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000317 vector<SchedGraphNode*>& memNodeVec,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000318 RegToRefVecMap& regToRefVecMap,
319 ValueToDefVecMap& valueToDefVecMap);
320
Vikram S. Advee64574c2001-11-08 05:20:23 +0000321 void addEdgesForInstruction(const MachineInstr& minstr,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000322 const ValueToDefVecMap& valueToDefVecMap,
323 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000324
325 void addCDEdges (const TerminatorInst* term,
326 const TargetMachine& target);
327
Vikram S. Advee64574c2001-11-08 05:20:23 +0000328 void addMemEdges (const vector<SchedGraphNode*>& memNodeVec,
329 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000330
Vikram S. Advee64574c2001-11-08 05:20:23 +0000331 void addCallCCEdges (const vector<SchedGraphNode*>& memNodeVec,
332 MachineCodeForBasicBlock& bbMvec,
333 const TargetMachine& target);
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000334
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000335 void addMachineRegEdges (RegToRefVecMap& regToRefVecMap,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000336 const TargetMachine& target);
337
338 void addSSAEdge (SchedGraphNode* node,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000339 const RefVec& defVec,
Vikram S. Advef43e3362001-10-17 23:55:16 +0000340 const Value* defValue,
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000341 const TargetMachine& target);
342
343 void addNonSSAEdgesForValue (const Instruction* instr,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000344 const TargetMachine& target);
345
346 void addDummyEdges ();
347};
348
349
350class SchedGraphSet :
351 public NonCopyable,
352 private hash_map<const BasicBlock*, SchedGraph*>
353{
354private:
355 const Method* method;
356
357public:
358 typedef hash_map<const BasicBlock*, SchedGraph*>::iterator iterator;
359 typedef hash_map<const BasicBlock*, SchedGraph*>::const_iterator const_iterator;
360
361public:
362 /*ctor*/ SchedGraphSet (const Method* _method,
363 const TargetMachine& target);
364 /*dtor*/ ~SchedGraphSet ();
365
366 //
367 // Accessors
368 //
369 SchedGraph* getGraphForBasicBlock (const BasicBlock* bb) const {
370 const_iterator onePair = this->find(bb);
371 return (onePair != this->end())? (*onePair).second : NULL;
372 }
373
374 //
375 // Iterators
376 //
377 iterator begin() {
378 return hash_map<const BasicBlock*, SchedGraph*>::begin();
379 }
380 iterator end() {
381 return hash_map<const BasicBlock*, SchedGraph*>::end();
382 }
383 const_iterator begin() const {
384 return hash_map<const BasicBlock*, SchedGraph*>::begin();
385 }
386 const_iterator end() const {
387 return hash_map<const BasicBlock*, SchedGraph*>::end();
388 }
389
390 //
391 // Debugging support
392 //
393 void dump () const;
394
395private:
396 inline void noteGraphForBlock(const BasicBlock* bb, SchedGraph* graph) {
397 assert((*this)[bb] == NULL);
398 (*this)[bb] = graph;
399 }
400
401 //
402 // Graph builder
403 //
404 void buildGraphsForMethod (const Method *method,
405 const TargetMachine& target);
406};
407
408
409//********************** Sched Graph Iterators *****************************/
410
411// Ok to make it a template because it shd get instantiated at most twice:
412// for <SchedGraphNode, SchedGraphNode::iterator> and
413// for <const SchedGraphNode, SchedGraphNode::const_iterator>.
414//
415template <class _NodeType, class _EdgeType, class _EdgeIter>
Chris Lattnercffebdc2001-09-07 21:07:10 +0000416class PredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000417protected:
418 _EdgeIter oi;
419public:
Chris Lattnercffebdc2001-09-07 21:07:10 +0000420 typedef PredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000421
Chris Lattnercffebdc2001-09-07 21:07:10 +0000422 inline PredIterator(_EdgeIter startEdge) : oi(startEdge) {}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000423
424 inline bool operator==(const _Self& x) const { return oi == x.oi; }
425 inline bool operator!=(const _Self& x) const { return !operator==(x); }
426
427 // operator*() differs for pred or succ iterator
Chris Lattnercffebdc2001-09-07 21:07:10 +0000428 inline _NodeType* operator*() const { return (*oi)->getSrc(); }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000429 inline _NodeType* operator->() const { return operator*(); }
430
431 inline _EdgeType* getEdge() const { return *(oi); }
432
Chris Lattnercffebdc2001-09-07 21:07:10 +0000433 inline _Self &operator++() { ++oi; return *this; } // Preincrement
434 inline _Self operator++(int) { // Postincrement
435 _Self tmp(*this); ++*this; return tmp;
436 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000437
Chris Lattnercffebdc2001-09-07 21:07:10 +0000438 inline _Self &operator--() { --oi; return *this; } // Predecrement
439 inline _Self operator--(int) { // Postdecrement
440 _Self tmp = *this; --*this; return tmp;
441 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000442};
443
444template <class _NodeType, class _EdgeType, class _EdgeIter>
Chris Lattnercffebdc2001-09-07 21:07:10 +0000445class SuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
446protected:
447 _EdgeIter oi;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000448public:
Chris Lattnercffebdc2001-09-07 21:07:10 +0000449 typedef SuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000450
Chris Lattnercffebdc2001-09-07 21:07:10 +0000451 inline SuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000452
Chris Lattnercffebdc2001-09-07 21:07:10 +0000453 inline bool operator==(const _Self& x) const { return oi == x.oi; }
454 inline bool operator!=(const _Self& x) const { return !operator==(x); }
455
456 inline _NodeType* operator*() const { return (*oi)->getSink(); }
457 inline _NodeType* operator->() const { return operator*(); }
458
459 inline _EdgeType* getEdge() const { return *(oi); }
460
461 inline _Self &operator++() { ++oi; return *this; } // Preincrement
462 inline _Self operator++(int) { // Postincrement
463 _Self tmp(*this); ++*this; return tmp;
464 }
465
466 inline _Self &operator--() { --oi; return *this; } // Predecrement
467 inline _Self operator--(int) { // Postdecrement
468 _Self tmp = *this; --*this; return tmp;
469 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000470};
471
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000472//
473// sg_pred_iterator
474// sg_pred_const_iterator
475//
476typedef PredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
477 sg_pred_iterator;
478typedef PredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
479 sg_pred_const_iterator;
480
481inline sg_pred_iterator pred_begin( SchedGraphNode *N) {
482 return sg_pred_iterator(N->beginInEdges());
483}
484inline sg_pred_iterator pred_end( SchedGraphNode *N) {
485 return sg_pred_iterator(N->endInEdges());
486}
487inline sg_pred_const_iterator pred_begin(const SchedGraphNode *N) {
488 return sg_pred_const_iterator(N->beginInEdges());
489}
490inline sg_pred_const_iterator pred_end( const SchedGraphNode *N) {
491 return sg_pred_const_iterator(N->endInEdges());
492}
493
494
495//
496// sg_succ_iterator
497// sg_succ_const_iterator
498//
499typedef SuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
500 sg_succ_iterator;
501typedef SuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
502 sg_succ_const_iterator;
503
504inline sg_succ_iterator succ_begin( SchedGraphNode *N) {
505 return sg_succ_iterator(N->beginOutEdges());
506}
507inline sg_succ_iterator succ_end( SchedGraphNode *N) {
508 return sg_succ_iterator(N->endOutEdges());
509}
510inline sg_succ_const_iterator succ_begin(const SchedGraphNode *N) {
511 return sg_succ_const_iterator(N->beginOutEdges());
512}
513inline sg_succ_const_iterator succ_end( const SchedGraphNode *N) {
514 return sg_succ_const_iterator(N->endOutEdges());
515}
516
Chris Lattner3ff43872001-09-28 22:56:31 +0000517// Provide specializations of GraphTraits to be able to use graph iterators on
518// the scheduling graph!
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000519//
Chris Lattner3ff43872001-09-28 22:56:31 +0000520template <> struct GraphTraits<SchedGraph*> {
521 typedef SchedGraphNode NodeType;
522 typedef sg_succ_iterator ChildIteratorType;
523
524 static inline NodeType *getEntryNode(SchedGraph *SG) { return SG->getRoot(); }
525 static inline ChildIteratorType child_begin(NodeType *N) {
526 return succ_begin(N);
527 }
528 static inline ChildIteratorType child_end(NodeType *N) {
529 return succ_end(N);
530 }
531};
532
533template <> struct GraphTraits<const SchedGraph*> {
534 typedef const SchedGraphNode NodeType;
535 typedef sg_succ_const_iterator ChildIteratorType;
536
537 static inline NodeType *getEntryNode(const SchedGraph *SG) {
538 return SG->getRoot();
539 }
540 static inline ChildIteratorType child_begin(NodeType *N) {
541 return succ_begin(N);
542 }
543 static inline ChildIteratorType child_end(NodeType *N) {
544 return succ_end(N);
545 }
546};
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000547
548
549//************************ External Functions *****************************/
550
551
552ostream& operator<<(ostream& os, const SchedGraphEdge& edge);
553
554ostream& operator<<(ostream& os, const SchedGraphNode& node);
555
556
557/***************************************************************************/
558
559#endif