blob: aa258813c37630dd528a20aadd8b2904100ffb3d [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/CodeGen/MachineInstr.h"
Chris Lattnercee8f9a2001-11-27 00:03:19 +000023#include "Support/HashExtras.h"
24#include "Support/GraphTraits.h"
Vikram S. Adve78ef1392001-08-28 23:06:02 +000025
26class Value;
27class Instruction;
Chris Lattner3ff43872001-09-28 22:56:31 +000028class TerminatorInst;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000029class BasicBlock;
Chris Lattnere7506a32002-03-23 22:51:58 +000030class Function;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000031class TargetMachine;
32class SchedGraphEdge;
33class SchedGraphNode;
34class SchedGraph;
Vikram S. Adve4a87b382001-09-30 23:37:26 +000035class RegToRefVecMap;
Vikram S. Advec352d2c2001-11-05 04:04:23 +000036class ValueToDefVecMap;
37class RefVec;
Chris Lattnerc0c77082001-09-14 17:55:51 +000038class MachineInstr;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000039class MachineCodeForBasicBlock;
40
Vikram S. Adve78ef1392001-08-28 23:06:02 +000041
42/******************** Exported Data Types and Constants ********************/
43
44typedef int ResourceId;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000045const ResourceId InvalidRID = -1;
46const ResourceId MachineCCRegsRID = -2; // use +ve numbers for actual regs
47const ResourceId MachineIntRegsRID = -3; // use +ve numbers for actual regs
48const ResourceId MachineFPRegsRID = -4; // use +ve numbers for actual regs
Vikram S. Adve78ef1392001-08-28 23:06:02 +000049
50
51//*********************** Public Class Declarations ************************/
52
53class SchedGraphEdge: public NonCopyable {
54public:
55 enum SchedGraphEdgeDepType {
Vikram S. Adve200a4352001-11-12 18:53:43 +000056 CtrlDep, MemoryDep, ValueDep, MachineRegister, MachineResource
Vikram S. Adve78ef1392001-08-28 23:06:02 +000057 };
58 enum DataDepOrderType {
Vikram S. Adved0d79c02001-10-28 21:45:02 +000059 TrueDep = 0x1, AntiDep=0x2, OutputDep=0x4, NonDataDep=0x8
Vikram S. Adve78ef1392001-08-28 23:06:02 +000060 };
61
62protected:
63 SchedGraphNode* src;
64 SchedGraphNode* sink;
65 SchedGraphEdgeDepType depType;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000066 unsigned int depOrderType;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000067 int minDelay; // cached latency (assumes fixed target arch)
68
69 union {
Vikram S. Adve4a87b382001-09-30 23:37:26 +000070 const Value* val;
71 int machineRegNum;
72 ResourceId resourceId;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000073 };
74
75public:
76 // For all constructors, if minDelay is unspecified, minDelay is
77 // set to _src->getLatency().
78 // constructor for CtrlDep or MemoryDep edges, selected by 3rd argument
79 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
80 SchedGraphNode* _sink,
81 SchedGraphEdgeDepType _depType,
Vikram S. Adve200a4352001-11-12 18:53:43 +000082 unsigned int _depOrderType,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000083 int _minDelay = -1);
84
Vikram S. Adve200a4352001-11-12 18:53:43 +000085 // constructor for explicit value dependence (may be true/anti/output)
Vikram S. Adve78ef1392001-08-28 23:06:02 +000086 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
87 SchedGraphNode* _sink,
Vikram S. Adve4a87b382001-09-30 23:37:26 +000088 const Value* _val,
Vikram S. Adve200a4352001-11-12 18:53:43 +000089 unsigned int _depOrderType,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000090 int _minDelay = -1);
91
92 // constructor for machine register dependence
93 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
94 SchedGraphNode* _sink,
95 unsigned int _regNum,
Vikram S. Adve200a4352001-11-12 18:53:43 +000096 unsigned int _depOrderType,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000097 int _minDelay = -1);
98
99 // constructor for any other machine resource dependences.
100 // DataDepOrderType is always NonDataDep. It it not an argument to
101 // avoid overloading ambiguity with previous constructor.
102 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
103 SchedGraphNode* _sink,
104 ResourceId _resourceId,
105 int _minDelay = -1);
106
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000107 /*dtor*/ ~SchedGraphEdge();
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000108
109 SchedGraphNode* getSrc () const { return src; }
110 SchedGraphNode* getSink () const { return sink; }
111 int getMinDelay () const { return minDelay; }
112 SchedGraphEdgeDepType getDepType () const { return depType; }
113
114 const Value* getValue () const {
Vikram S. Adve200a4352001-11-12 18:53:43 +0000115 assert(depType == ValueDep); return val;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000116 }
117 int getMachineReg () const {
118 assert(depType == MachineRegister); return machineRegNum;
119 }
120 int getResourceId () const {
121 assert(depType == MachineResource); return resourceId;
122 }
123
124public:
125 //
126 // Debugging support
127 //
Chris Lattner697954c2002-01-20 22:54:45 +0000128 friend std::ostream& operator<<(std::ostream& os, const SchedGraphEdge& edge);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000129
Chris Lattnercffebdc2001-09-07 21:07:10 +0000130 void dump (int indent=0) const;
131
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000132private:
133 // disable default ctor
134 /*ctor*/ SchedGraphEdge(); // DO NOT IMPLEMENT
135};
136
137
138
139class SchedGraphNode: public NonCopyable {
140private:
141 unsigned int nodeId;
Vikram S. Adveaf00d482001-11-12 14:18:01 +0000142 const BasicBlock* bb;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000143 const MachineInstr* minstr;
Chris Lattner697954c2002-01-20 22:54:45 +0000144 std::vector<SchedGraphEdge*> inEdges;
145 std::vector<SchedGraphEdge*> outEdges;
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000146 int origIndexInBB; // original position of machine instr in BB
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000147 int latency;
148
149public:
Chris Lattner697954c2002-01-20 22:54:45 +0000150 typedef std::vector<SchedGraphEdge*>:: iterator iterator;
151 typedef std::vector<SchedGraphEdge*>::const_iterator const_iterator;
152 typedef std::vector<SchedGraphEdge*>:: reverse_iterator reverse_iterator;
153 typedef std::vector<SchedGraphEdge*>::const_reverse_iterator const_reverse_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000154
155public:
156 //
157 // Accessor methods
158 //
159 unsigned int getNodeId () const { return nodeId; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000160 const MachineInstr* getMachineInstr () const { return minstr; }
Vikram S. Advee64574c2001-11-08 05:20:23 +0000161 const MachineOpCode getOpCode () const { return minstr->getOpCode();}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000162 int getLatency () const { return latency; }
163 unsigned int getNumInEdges () const { return inEdges.size(); }
164 unsigned int getNumOutEdges () const { return outEdges.size(); }
165 bool isDummyNode () const { return (minstr == NULL); }
Vikram S. Adveaf00d482001-11-12 14:18:01 +0000166 const BasicBlock* getBB () const { return bb; }
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000167 int getOrigIndexInBB() const { return origIndexInBB; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000168
169 //
170 // Iterators
171 //
172 iterator beginInEdges () { return inEdges.begin(); }
173 iterator endInEdges () { return inEdges.end(); }
174 iterator beginOutEdges () { return outEdges.begin(); }
175 iterator endOutEdges () { return outEdges.end(); }
176
177 const_iterator beginInEdges () const { return inEdges.begin(); }
178 const_iterator endInEdges () const { return inEdges.end(); }
179 const_iterator beginOutEdges () const { return outEdges.begin(); }
180 const_iterator endOutEdges () const { return outEdges.end(); }
181
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000182public:
183 //
184 // Debugging support
185 //
Chris Lattner697954c2002-01-20 22:54:45 +0000186 friend std::ostream& operator<<(std::ostream& os, const SchedGraphNode& node);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000187
Chris Lattnercffebdc2001-09-07 21:07:10 +0000188 void dump (int indent=0) const;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000189
190private:
191 friend class SchedGraph; // give access for ctor and dtor
192 friend class SchedGraphEdge; // give access for adding edges
193
194 void addInEdge (SchedGraphEdge* edge);
195 void addOutEdge (SchedGraphEdge* edge);
196
197 void removeInEdge (const SchedGraphEdge* edge);
198 void removeOutEdge (const SchedGraphEdge* edge);
199
200 // disable default constructor and provide a ctor for single-block graphs
201 /*ctor*/ SchedGraphNode(); // DO NOT IMPLEMENT
202 /*ctor*/ SchedGraphNode (unsigned int _nodeId,
Vikram S. Adveaf00d482001-11-12 14:18:01 +0000203 const BasicBlock* _bb,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000204 const MachineInstr* _minstr,
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000205 int indexInBB,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000206 const TargetMachine& _target);
207 /*dtor*/ ~SchedGraphNode ();
208};
209
210
211
212class SchedGraph :
213 public NonCopyable,
Chris Lattner697954c2002-01-20 22:54:45 +0000214 private std::hash_map<const MachineInstr*, SchedGraphNode*>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000215{
216private:
Chris Lattner697954c2002-01-20 22:54:45 +0000217 std::vector<const BasicBlock*> bbVec; // basic blocks included in the graph
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000218 SchedGraphNode* graphRoot; // the root and leaf are not inserted
219 SchedGraphNode* graphLeaf; // in the hash_map (see getNumNodes())
220
Chris Lattner697954c2002-01-20 22:54:45 +0000221 typedef std::hash_map<const MachineInstr*, SchedGraphNode*> map_base;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000222public:
Chris Lattner697954c2002-01-20 22:54:45 +0000223 using map_base::iterator;
224 using map_base::const_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000225
226public:
227 //
228 // Accessor methods
229 //
Chris Lattner697954c2002-01-20 22:54:45 +0000230 const std::vector<const BasicBlock*>& getBasicBlocks() const { return bbVec; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000231 const unsigned int getNumNodes() const { return size()+2; }
232 SchedGraphNode* getRoot() const { return graphRoot; }
233 SchedGraphNode* getLeaf() const { return graphLeaf; }
234
235 SchedGraphNode* getGraphNodeForInstr(const MachineInstr* minstr) const {
236 const_iterator onePair = this->find(minstr);
237 return (onePair != this->end())? (*onePair).second : NULL;
238 }
239
240 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000241 // Delete nodes or edges from the graph.
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000242 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000243 void eraseNode (SchedGraphNode* node);
244
245 void eraseIncomingEdges (SchedGraphNode* node,
246 bool addDummyEdges = true);
247
248 void eraseOutgoingEdges (SchedGraphNode* node,
249 bool addDummyEdges = true);
250
251 void eraseIncidentEdges (SchedGraphNode* node,
252 bool addDummyEdges = true);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000253
254 //
255 // Unordered iterators.
256 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
257 //
Chris Lattner697954c2002-01-20 22:54:45 +0000258 using map_base::begin;
259 using map_base::end;
260
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000261 //
262 // Ordered iterators.
263 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
264 //
265 // void postord_init();
266 // postorder_iterator postord_begin();
267 // postorder_iterator postord_end();
268 // const_postorder_iterator postord_begin() const;
269 // const_postorder_iterator postord_end() const;
270
271 //
272 // Debugging support
273 //
274 void dump () const;
275
276private:
277 friend class SchedGraphSet; // give access to ctor
278
279 // disable default constructor and provide a ctor for single-block graphs
280 /*ctor*/ SchedGraph (); // DO NOT IMPLEMENT
281 /*ctor*/ SchedGraph (const BasicBlock* bb,
282 const TargetMachine& target);
283 /*dtor*/ ~SchedGraph ();
284
285 inline void noteGraphNodeForInstr (const MachineInstr* minstr,
286 SchedGraphNode* node)
287 {
288 assert((*this)[minstr] == NULL);
289 (*this)[minstr] = node;
290 }
291
292 //
293 // Graph builder
294 //
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000295 void buildGraph (const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000296
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000297 void buildNodesforBB (const TargetMachine& target,
298 const BasicBlock* bb,
Chris Lattner697954c2002-01-20 22:54:45 +0000299 std::vector<SchedGraphNode*>& memNod,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000300 RegToRefVecMap& regToRefVecMap,
301 ValueToDefVecMap& valueToDefVecMap);
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000302
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000303 void findDefUseInfoAtInstr (const TargetMachine& target,
304 SchedGraphNode* node,
Chris Lattner697954c2002-01-20 22:54:45 +0000305 std::vector<SchedGraphNode*>& memNode,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000306 RegToRefVecMap& regToRefVecMap,
307 ValueToDefVecMap& valueToDefVecMap);
308
Vikram S. Advee64574c2001-11-08 05:20:23 +0000309 void addEdgesForInstruction(const MachineInstr& minstr,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000310 const ValueToDefVecMap& valueToDefVecMap,
311 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000312
313 void addCDEdges (const TerminatorInst* term,
314 const TargetMachine& target);
315
Chris Lattner697954c2002-01-20 22:54:45 +0000316 void addMemEdges (const std::vector<SchedGraphNode*>& memNod,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000317 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000318
Chris Lattner697954c2002-01-20 22:54:45 +0000319 void addCallCCEdges (const std::vector<SchedGraphNode*>& memNod,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000320 MachineCodeForBasicBlock& bbMvec,
321 const TargetMachine& target);
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000322
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000323 void addMachineRegEdges (RegToRefVecMap& regToRefVecMap,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000324 const TargetMachine& target);
325
Vikram S. Adve200a4352001-11-12 18:53:43 +0000326 void addEdgesForValue (SchedGraphNode* refNode,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000327 const RefVec& defVec,
Vikram S. Advef43e3362001-10-17 23:55:16 +0000328 const Value* defValue,
Vikram S. Adve200a4352001-11-12 18:53:43 +0000329 bool refNodeIsDef,
Vikram S. Adve0baf1c02002-07-08 22:59:23 +0000330 bool refNodeIsDefAndUse,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000331 const TargetMachine& target);
332
333 void addDummyEdges ();
334};
335
336
337class SchedGraphSet :
338 public NonCopyable,
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000339 private std::vector<SchedGraph*>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000340{
341private:
Chris Lattnere7506a32002-03-23 22:51:58 +0000342 const Function* method;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000343
344public:
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000345 typedef std::vector<SchedGraph*> baseVector;
346 using baseVector::iterator;
347 using baseVector::const_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000348
349public:
Chris Lattnere7506a32002-03-23 22:51:58 +0000350 /*ctor*/ SchedGraphSet (const Function * function,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000351 const TargetMachine& target);
352 /*dtor*/ ~SchedGraphSet ();
353
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000354 // Iterators
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000355 using baseVector::begin;
356 using baseVector::end;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000357
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000358 // Debugging support
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000359 void dump () const;
360
361private:
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000362 inline void addGraph(SchedGraph* graph) {
363 assert(graph != NULL);
364 this->push_back(graph);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000365 }
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000366
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000367 // Graph builder
Chris Lattnere7506a32002-03-23 22:51:58 +0000368 void buildGraphsForMethod (const Function *F,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000369 const TargetMachine& target);
370};
371
372
373//********************** Sched Graph Iterators *****************************/
374
375// Ok to make it a template because it shd get instantiated at most twice:
376// for <SchedGraphNode, SchedGraphNode::iterator> and
377// for <const SchedGraphNode, SchedGraphNode::const_iterator>.
378//
379template <class _NodeType, class _EdgeType, class _EdgeIter>
Chris Lattner455889a2002-02-12 22:39:50 +0000380class SGPredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000381protected:
382 _EdgeIter oi;
383public:
Chris Lattner455889a2002-02-12 22:39:50 +0000384 typedef SGPredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000385
Chris Lattner455889a2002-02-12 22:39:50 +0000386 inline SGPredIterator(_EdgeIter startEdge) : oi(startEdge) {}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000387
388 inline bool operator==(const _Self& x) const { return oi == x.oi; }
389 inline bool operator!=(const _Self& x) const { return !operator==(x); }
390
391 // operator*() differs for pred or succ iterator
Chris Lattnercffebdc2001-09-07 21:07:10 +0000392 inline _NodeType* operator*() const { return (*oi)->getSrc(); }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000393 inline _NodeType* operator->() const { return operator*(); }
394
395 inline _EdgeType* getEdge() const { return *(oi); }
396
Chris Lattnercffebdc2001-09-07 21:07:10 +0000397 inline _Self &operator++() { ++oi; return *this; } // Preincrement
398 inline _Self operator++(int) { // Postincrement
399 _Self tmp(*this); ++*this; return tmp;
400 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000401
Chris Lattnercffebdc2001-09-07 21:07:10 +0000402 inline _Self &operator--() { --oi; return *this; } // Predecrement
403 inline _Self operator--(int) { // Postdecrement
404 _Self tmp = *this; --*this; return tmp;
405 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000406};
407
408template <class _NodeType, class _EdgeType, class _EdgeIter>
Chris Lattner455889a2002-02-12 22:39:50 +0000409class SGSuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
Chris Lattnercffebdc2001-09-07 21:07:10 +0000410protected:
411 _EdgeIter oi;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000412public:
Chris Lattner455889a2002-02-12 22:39:50 +0000413 typedef SGSuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000414
Chris Lattner455889a2002-02-12 22:39:50 +0000415 inline SGSuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000416
Chris Lattnercffebdc2001-09-07 21:07:10 +0000417 inline bool operator==(const _Self& x) const { return oi == x.oi; }
418 inline bool operator!=(const _Self& x) const { return !operator==(x); }
419
420 inline _NodeType* operator*() const { return (*oi)->getSink(); }
421 inline _NodeType* operator->() const { return operator*(); }
422
423 inline _EdgeType* getEdge() const { return *(oi); }
424
425 inline _Self &operator++() { ++oi; return *this; } // Preincrement
426 inline _Self operator++(int) { // Postincrement
427 _Self tmp(*this); ++*this; return tmp;
428 }
429
430 inline _Self &operator--() { --oi; return *this; } // Predecrement
431 inline _Self operator--(int) { // Postdecrement
432 _Self tmp = *this; --*this; return tmp;
433 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000434};
435
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000436//
437// sg_pred_iterator
438// sg_pred_const_iterator
439//
Chris Lattner455889a2002-02-12 22:39:50 +0000440typedef SGPredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000441 sg_pred_iterator;
Chris Lattner455889a2002-02-12 22:39:50 +0000442typedef SGPredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000443 sg_pred_const_iterator;
444
445inline sg_pred_iterator pred_begin( SchedGraphNode *N) {
446 return sg_pred_iterator(N->beginInEdges());
447}
448inline sg_pred_iterator pred_end( SchedGraphNode *N) {
449 return sg_pred_iterator(N->endInEdges());
450}
451inline sg_pred_const_iterator pred_begin(const SchedGraphNode *N) {
452 return sg_pred_const_iterator(N->beginInEdges());
453}
454inline sg_pred_const_iterator pred_end( const SchedGraphNode *N) {
455 return sg_pred_const_iterator(N->endInEdges());
456}
457
458
459//
460// sg_succ_iterator
461// sg_succ_const_iterator
462//
Chris Lattner455889a2002-02-12 22:39:50 +0000463typedef SGSuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000464 sg_succ_iterator;
Chris Lattner455889a2002-02-12 22:39:50 +0000465typedef SGSuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000466 sg_succ_const_iterator;
467
468inline sg_succ_iterator succ_begin( SchedGraphNode *N) {
469 return sg_succ_iterator(N->beginOutEdges());
470}
471inline sg_succ_iterator succ_end( SchedGraphNode *N) {
472 return sg_succ_iterator(N->endOutEdges());
473}
474inline sg_succ_const_iterator succ_begin(const SchedGraphNode *N) {
475 return sg_succ_const_iterator(N->beginOutEdges());
476}
477inline sg_succ_const_iterator succ_end( const SchedGraphNode *N) {
478 return sg_succ_const_iterator(N->endOutEdges());
479}
480
Chris Lattner3ff43872001-09-28 22:56:31 +0000481// Provide specializations of GraphTraits to be able to use graph iterators on
482// the scheduling graph!
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000483//
Chris Lattner3ff43872001-09-28 22:56:31 +0000484template <> struct GraphTraits<SchedGraph*> {
485 typedef SchedGraphNode NodeType;
486 typedef sg_succ_iterator ChildIteratorType;
487
488 static inline NodeType *getEntryNode(SchedGraph *SG) { return SG->getRoot(); }
489 static inline ChildIteratorType child_begin(NodeType *N) {
490 return succ_begin(N);
491 }
492 static inline ChildIteratorType child_end(NodeType *N) {
493 return succ_end(N);
494 }
495};
496
497template <> struct GraphTraits<const SchedGraph*> {
498 typedef const SchedGraphNode NodeType;
499 typedef sg_succ_const_iterator ChildIteratorType;
500
501 static inline NodeType *getEntryNode(const SchedGraph *SG) {
502 return SG->getRoot();
503 }
504 static inline ChildIteratorType child_begin(NodeType *N) {
505 return succ_begin(N);
506 }
507 static inline ChildIteratorType child_end(NodeType *N) {
508 return succ_end(N);
509 }
510};
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000511
512
Chris Lattner697954c2002-01-20 22:54:45 +0000513std::ostream &operator<<(std::ostream& os, const SchedGraphEdge& edge);
514std::ostream &operator<<(std::ostream &os, const SchedGraphNode& node);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000515
516#endif