blob: 2890241d59dbc0b217f84c144a19a105964b425e [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. Advee64574c2001-11-08 05:20:23 +000022#include "llvm/Target/MachineInstrInfo.h"
23#include "llvm/CodeGen/MachineInstr.h"
Chris Lattnercee8f9a2001-11-27 00:03:19 +000024#include "Support/NonCopyable.h"
25#include "Support/HashExtras.h"
26#include "Support/GraphTraits.h"
Chris Lattner697954c2002-01-20 22:54:45 +000027#include <ext/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 {
Vikram S. Adve200a4352001-11-12 18:53:43 +000059 CtrlDep, MemoryDep, ValueDep, MachineRegister, MachineResource
Vikram S. Adve78ef1392001-08-28 23:06:02 +000060 };
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. Adve200a4352001-11-12 18:53:43 +000085 unsigned int _depOrderType,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000086 int _minDelay = -1);
87
Vikram S. Adve200a4352001-11-12 18:53:43 +000088 // constructor for explicit value dependence (may be true/anti/output)
Vikram S. Adve78ef1392001-08-28 23:06:02 +000089 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
90 SchedGraphNode* _sink,
Vikram S. Adve4a87b382001-09-30 23:37:26 +000091 const Value* _val,
Vikram S. Adve200a4352001-11-12 18:53:43 +000092 unsigned int _depOrderType,
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. Adve200a4352001-11-12 18:53:43 +000099 unsigned int _depOrderType,
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 {
Vikram S. Adve200a4352001-11-12 18:53:43 +0000118 assert(depType == ValueDep); return val;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000119 }
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 //
Chris Lattner697954c2002-01-20 22:54:45 +0000131 friend std::ostream& operator<<(std::ostream& os, const SchedGraphEdge& edge);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000132
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;
Vikram S. Adveaf00d482001-11-12 14:18:01 +0000145 const BasicBlock* bb;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000146 const MachineInstr* minstr;
Chris Lattner697954c2002-01-20 22:54:45 +0000147 std::vector<SchedGraphEdge*> inEdges;
148 std::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:
Chris Lattner697954c2002-01-20 22:54:45 +0000153 typedef std::vector<SchedGraphEdge*>:: iterator iterator;
154 typedef std::vector<SchedGraphEdge*>::const_iterator const_iterator;
155 typedef std::vector<SchedGraphEdge*>:: reverse_iterator reverse_iterator;
156 typedef std::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; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000163 const MachineInstr* getMachineInstr () const { return minstr; }
Vikram S. Advee64574c2001-11-08 05:20:23 +0000164 const MachineOpCode getOpCode () const { return minstr->getOpCode();}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000165 int getLatency () const { return latency; }
166 unsigned int getNumInEdges () const { return inEdges.size(); }
167 unsigned int getNumOutEdges () const { return outEdges.size(); }
168 bool isDummyNode () const { return (minstr == NULL); }
Vikram S. Adveaf00d482001-11-12 14:18:01 +0000169 const BasicBlock* getBB () const { return bb; }
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 //
Chris Lattner697954c2002-01-20 22:54:45 +0000189 friend std::ostream& operator<<(std::ostream& os, const SchedGraphNode& node);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000190
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,
Vikram S. Adveaf00d482001-11-12 14:18:01 +0000206 const BasicBlock* _bb,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000207 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,
Chris Lattner697954c2002-01-20 22:54:45 +0000217 private std::hash_map<const MachineInstr*, SchedGraphNode*>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000218{
219private:
Chris Lattner697954c2002-01-20 22:54:45 +0000220 std::vector<const BasicBlock*> bbVec; // basic blocks included in the graph
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000221 SchedGraphNode* graphRoot; // the root and leaf are not inserted
222 SchedGraphNode* graphLeaf; // in the hash_map (see getNumNodes())
223
Chris Lattner697954c2002-01-20 22:54:45 +0000224 typedef std::hash_map<const MachineInstr*, SchedGraphNode*> map_base;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000225public:
Chris Lattner697954c2002-01-20 22:54:45 +0000226 using map_base::iterator;
227 using map_base::const_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000228
229public:
230 //
231 // Accessor methods
232 //
Chris Lattner697954c2002-01-20 22:54:45 +0000233 const std::vector<const BasicBlock*>& getBasicBlocks() const { return bbVec; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000234 const unsigned int getNumNodes() const { return size()+2; }
235 SchedGraphNode* getRoot() const { return graphRoot; }
236 SchedGraphNode* getLeaf() const { return graphLeaf; }
237
238 SchedGraphNode* getGraphNodeForInstr(const MachineInstr* minstr) const {
239 const_iterator onePair = this->find(minstr);
240 return (onePair != this->end())? (*onePair).second : NULL;
241 }
242
243 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000244 // Delete nodes or edges from the graph.
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000245 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000246 void eraseNode (SchedGraphNode* node);
247
248 void eraseIncomingEdges (SchedGraphNode* node,
249 bool addDummyEdges = true);
250
251 void eraseOutgoingEdges (SchedGraphNode* node,
252 bool addDummyEdges = true);
253
254 void eraseIncidentEdges (SchedGraphNode* node,
255 bool addDummyEdges = true);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000256
257 //
258 // Unordered iterators.
259 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
260 //
Chris Lattner697954c2002-01-20 22:54:45 +0000261 using map_base::begin;
262 using map_base::end;
263
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000264 //
265 // Ordered iterators.
266 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
267 //
268 // void postord_init();
269 // postorder_iterator postord_begin();
270 // postorder_iterator postord_end();
271 // const_postorder_iterator postord_begin() const;
272 // const_postorder_iterator postord_end() const;
273
274 //
275 // Debugging support
276 //
277 void dump () const;
278
279private:
280 friend class SchedGraphSet; // give access to ctor
281
282 // disable default constructor and provide a ctor for single-block graphs
283 /*ctor*/ SchedGraph (); // DO NOT IMPLEMENT
284 /*ctor*/ SchedGraph (const BasicBlock* bb,
285 const TargetMachine& target);
286 /*dtor*/ ~SchedGraph ();
287
288 inline void noteGraphNodeForInstr (const MachineInstr* minstr,
289 SchedGraphNode* node)
290 {
291 assert((*this)[minstr] == NULL);
292 (*this)[minstr] = node;
293 }
294
295 //
296 // Graph builder
297 //
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000298 void buildGraph (const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000299
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000300 void buildNodesforBB (const TargetMachine& target,
301 const BasicBlock* bb,
Chris Lattner697954c2002-01-20 22:54:45 +0000302 std::vector<SchedGraphNode*>& memNod,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000303 RegToRefVecMap& regToRefVecMap,
304 ValueToDefVecMap& valueToDefVecMap);
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000305
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000306 void findDefUseInfoAtInstr (const TargetMachine& target,
307 SchedGraphNode* node,
Chris Lattner697954c2002-01-20 22:54:45 +0000308 std::vector<SchedGraphNode*>& memNode,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000309 RegToRefVecMap& regToRefVecMap,
310 ValueToDefVecMap& valueToDefVecMap);
311
Vikram S. Advee64574c2001-11-08 05:20:23 +0000312 void addEdgesForInstruction(const MachineInstr& minstr,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000313 const ValueToDefVecMap& valueToDefVecMap,
314 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000315
316 void addCDEdges (const TerminatorInst* term,
317 const TargetMachine& target);
318
Chris Lattner697954c2002-01-20 22:54:45 +0000319 void addMemEdges (const std::vector<SchedGraphNode*>& memNod,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000320 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000321
Chris Lattner697954c2002-01-20 22:54:45 +0000322 void addCallCCEdges (const std::vector<SchedGraphNode*>& memNod,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000323 MachineCodeForBasicBlock& bbMvec,
324 const TargetMachine& target);
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000325
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000326 void addMachineRegEdges (RegToRefVecMap& regToRefVecMap,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000327 const TargetMachine& target);
328
Vikram S. Adve200a4352001-11-12 18:53:43 +0000329 void addEdgesForValue (SchedGraphNode* refNode,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000330 const RefVec& defVec,
Vikram S. Advef43e3362001-10-17 23:55:16 +0000331 const Value* defValue,
Vikram S. Adve200a4352001-11-12 18:53:43 +0000332 bool refNodeIsDef,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000333 const TargetMachine& target);
334
335 void addDummyEdges ();
336};
337
338
339class SchedGraphSet :
340 public NonCopyable,
Chris Lattner697954c2002-01-20 22:54:45 +0000341 private std::hash_map<const BasicBlock*, SchedGraph*>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000342{
343private:
344 const Method* method;
345
346public:
Chris Lattner697954c2002-01-20 22:54:45 +0000347 typedef std::hash_map<const BasicBlock*, SchedGraph*> map_base;
348 using map_base::iterator;
349 using map_base::const_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000350
351public:
352 /*ctor*/ SchedGraphSet (const Method* _method,
353 const TargetMachine& target);
354 /*dtor*/ ~SchedGraphSet ();
355
356 //
357 // Accessors
358 //
359 SchedGraph* getGraphForBasicBlock (const BasicBlock* bb) const {
360 const_iterator onePair = this->find(bb);
361 return (onePair != this->end())? (*onePair).second : NULL;
362 }
363
364 //
365 // Iterators
366 //
Chris Lattner697954c2002-01-20 22:54:45 +0000367 using map_base::begin;
368 using map_base::end;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000369
370 //
371 // Debugging support
372 //
373 void dump () const;
374
375private:
376 inline void noteGraphForBlock(const BasicBlock* bb, SchedGraph* graph) {
377 assert((*this)[bb] == NULL);
378 (*this)[bb] = graph;
379 }
380
381 //
382 // Graph builder
383 //
384 void buildGraphsForMethod (const Method *method,
385 const TargetMachine& target);
386};
387
388
389//********************** Sched Graph Iterators *****************************/
390
391// Ok to make it a template because it shd get instantiated at most twice:
392// for <SchedGraphNode, SchedGraphNode::iterator> and
393// for <const SchedGraphNode, SchedGraphNode::const_iterator>.
394//
395template <class _NodeType, class _EdgeType, class _EdgeIter>
Chris Lattnercffebdc2001-09-07 21:07:10 +0000396class PredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000397protected:
398 _EdgeIter oi;
399public:
Chris Lattnercffebdc2001-09-07 21:07:10 +0000400 typedef PredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000401
Chris Lattnercffebdc2001-09-07 21:07:10 +0000402 inline PredIterator(_EdgeIter startEdge) : oi(startEdge) {}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000403
404 inline bool operator==(const _Self& x) const { return oi == x.oi; }
405 inline bool operator!=(const _Self& x) const { return !operator==(x); }
406
407 // operator*() differs for pred or succ iterator
Chris Lattnercffebdc2001-09-07 21:07:10 +0000408 inline _NodeType* operator*() const { return (*oi)->getSrc(); }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000409 inline _NodeType* operator->() const { return operator*(); }
410
411 inline _EdgeType* getEdge() const { return *(oi); }
412
Chris Lattnercffebdc2001-09-07 21:07:10 +0000413 inline _Self &operator++() { ++oi; return *this; } // Preincrement
414 inline _Self operator++(int) { // Postincrement
415 _Self tmp(*this); ++*this; return tmp;
416 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000417
Chris Lattnercffebdc2001-09-07 21:07:10 +0000418 inline _Self &operator--() { --oi; return *this; } // Predecrement
419 inline _Self operator--(int) { // Postdecrement
420 _Self tmp = *this; --*this; return tmp;
421 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000422};
423
424template <class _NodeType, class _EdgeType, class _EdgeIter>
Chris Lattnercffebdc2001-09-07 21:07:10 +0000425class SuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
426protected:
427 _EdgeIter oi;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000428public:
Chris Lattnercffebdc2001-09-07 21:07:10 +0000429 typedef SuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000430
Chris Lattnercffebdc2001-09-07 21:07:10 +0000431 inline SuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000432
Chris Lattnercffebdc2001-09-07 21:07:10 +0000433 inline bool operator==(const _Self& x) const { return oi == x.oi; }
434 inline bool operator!=(const _Self& x) const { return !operator==(x); }
435
436 inline _NodeType* operator*() const { return (*oi)->getSink(); }
437 inline _NodeType* operator->() const { return operator*(); }
438
439 inline _EdgeType* getEdge() const { return *(oi); }
440
441 inline _Self &operator++() { ++oi; return *this; } // Preincrement
442 inline _Self operator++(int) { // Postincrement
443 _Self tmp(*this); ++*this; return tmp;
444 }
445
446 inline _Self &operator--() { --oi; return *this; } // Predecrement
447 inline _Self operator--(int) { // Postdecrement
448 _Self tmp = *this; --*this; return tmp;
449 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000450};
451
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000452//
453// sg_pred_iterator
454// sg_pred_const_iterator
455//
456typedef PredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
457 sg_pred_iterator;
458typedef PredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
459 sg_pred_const_iterator;
460
461inline sg_pred_iterator pred_begin( SchedGraphNode *N) {
462 return sg_pred_iterator(N->beginInEdges());
463}
464inline sg_pred_iterator pred_end( SchedGraphNode *N) {
465 return sg_pred_iterator(N->endInEdges());
466}
467inline sg_pred_const_iterator pred_begin(const SchedGraphNode *N) {
468 return sg_pred_const_iterator(N->beginInEdges());
469}
470inline sg_pred_const_iterator pred_end( const SchedGraphNode *N) {
471 return sg_pred_const_iterator(N->endInEdges());
472}
473
474
475//
476// sg_succ_iterator
477// sg_succ_const_iterator
478//
479typedef SuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
480 sg_succ_iterator;
481typedef SuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
482 sg_succ_const_iterator;
483
484inline sg_succ_iterator succ_begin( SchedGraphNode *N) {
485 return sg_succ_iterator(N->beginOutEdges());
486}
487inline sg_succ_iterator succ_end( SchedGraphNode *N) {
488 return sg_succ_iterator(N->endOutEdges());
489}
490inline sg_succ_const_iterator succ_begin(const SchedGraphNode *N) {
491 return sg_succ_const_iterator(N->beginOutEdges());
492}
493inline sg_succ_const_iterator succ_end( const SchedGraphNode *N) {
494 return sg_succ_const_iterator(N->endOutEdges());
495}
496
Chris Lattner3ff43872001-09-28 22:56:31 +0000497// Provide specializations of GraphTraits to be able to use graph iterators on
498// the scheduling graph!
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000499//
Chris Lattner3ff43872001-09-28 22:56:31 +0000500template <> struct GraphTraits<SchedGraph*> {
501 typedef SchedGraphNode NodeType;
502 typedef sg_succ_iterator ChildIteratorType;
503
504 static inline NodeType *getEntryNode(SchedGraph *SG) { return SG->getRoot(); }
505 static inline ChildIteratorType child_begin(NodeType *N) {
506 return succ_begin(N);
507 }
508 static inline ChildIteratorType child_end(NodeType *N) {
509 return succ_end(N);
510 }
511};
512
513template <> struct GraphTraits<const SchedGraph*> {
514 typedef const SchedGraphNode NodeType;
515 typedef sg_succ_const_iterator ChildIteratorType;
516
517 static inline NodeType *getEntryNode(const SchedGraph *SG) {
518 return SG->getRoot();
519 }
520 static inline ChildIteratorType child_begin(NodeType *N) {
521 return succ_begin(N);
522 }
523 static inline ChildIteratorType child_end(NodeType *N) {
524 return succ_end(N);
525 }
526};
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000527
528
Chris Lattner697954c2002-01-20 22:54:45 +0000529std::ostream &operator<<(std::ostream& os, const SchedGraphEdge& edge);
530std::ostream &operator<<(std::ostream &os, const SchedGraphNode& node);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000531
532#endif