blob: 51f9db5d002e87accb6883e4d8b40f6b33921158 [file] [log] [blame]
Chris Lattner179cdfb2002-08-09 20:08:03 +00001//===-- SchedGraph.h - Scheduling Graph --------------------------*- C++ -*--=//
2//
3// Purpose:
4// Scheduling graph based on SSA graph plus extra dependence edges
5// capturing dependences due to machine resources (machine registers,
6// CC registers, and any others).
7//
8// Strategy:
9// This graph tries to leverage the SSA graph as much as possible,
10// but captures the extra dependences through a common interface.
11//
12//===----------------------------------------------------------------------===//
Vikram S. Adve78ef1392001-08-28 23:06:02 +000013
14#ifndef LLVM_CODEGEN_SCHEDGRAPH_H
15#define LLVM_CODEGEN_SCHEDGRAPH_H
16
Vikram S. Advee64574c2001-11-08 05:20:23 +000017#include "llvm/CodeGen/MachineInstr.h"
Chris Lattnercee8f9a2001-11-27 00:03:19 +000018#include "Support/HashExtras.h"
19#include "Support/GraphTraits.h"
Vikram S. Adve78ef1392001-08-28 23:06:02 +000020
21class Value;
22class Instruction;
Chris Lattner3ff43872001-09-28 22:56:31 +000023class TerminatorInst;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000024class BasicBlock;
Chris Lattnere7506a32002-03-23 22:51:58 +000025class Function;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000026class TargetMachine;
27class SchedGraphEdge;
28class SchedGraphNode;
29class SchedGraph;
Vikram S. Adve4a87b382001-09-30 23:37:26 +000030class RegToRefVecMap;
Vikram S. Advec352d2c2001-11-05 04:04:23 +000031class ValueToDefVecMap;
32class RefVec;
Chris Lattnerc0c77082001-09-14 17:55:51 +000033class MachineInstr;
Misha Brukmanfce11432002-10-28 00:28:31 +000034class MachineBasicBlock;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000035
Vikram S. Adve78ef1392001-08-28 23:06:02 +000036
37/******************** Exported Data Types and Constants ********************/
38
39typedef int ResourceId;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000040const ResourceId InvalidRID = -1;
41const ResourceId MachineCCRegsRID = -2; // use +ve numbers for actual regs
42const ResourceId MachineIntRegsRID = -3; // use +ve numbers for actual regs
43const ResourceId MachineFPRegsRID = -4; // use +ve numbers for actual regs
Vikram S. Adve78ef1392001-08-28 23:06:02 +000044
45
46//*********************** Public Class Declarations ************************/
47
48class SchedGraphEdge: public NonCopyable {
49public:
50 enum SchedGraphEdgeDepType {
Vikram S. Adve200a4352001-11-12 18:53:43 +000051 CtrlDep, MemoryDep, ValueDep, MachineRegister, MachineResource
Vikram S. Adve78ef1392001-08-28 23:06:02 +000052 };
53 enum DataDepOrderType {
Vikram S. Adved0d79c02001-10-28 21:45:02 +000054 TrueDep = 0x1, AntiDep=0x2, OutputDep=0x4, NonDataDep=0x8
Vikram S. Adve78ef1392001-08-28 23:06:02 +000055 };
56
57protected:
58 SchedGraphNode* src;
59 SchedGraphNode* sink;
60 SchedGraphEdgeDepType depType;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000061 unsigned int depOrderType;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000062 int minDelay; // cached latency (assumes fixed target arch)
63
64 union {
Vikram S. Adve4a87b382001-09-30 23:37:26 +000065 const Value* val;
66 int machineRegNum;
67 ResourceId resourceId;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000068 };
69
70public:
71 // For all constructors, if minDelay is unspecified, minDelay is
72 // set to _src->getLatency().
73 // constructor for CtrlDep or MemoryDep edges, selected by 3rd argument
74 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
75 SchedGraphNode* _sink,
76 SchedGraphEdgeDepType _depType,
Vikram S. Adve200a4352001-11-12 18:53:43 +000077 unsigned int _depOrderType,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000078 int _minDelay = -1);
79
Vikram S. Adve200a4352001-11-12 18:53:43 +000080 // constructor for explicit value dependence (may be true/anti/output)
Vikram S. Adve78ef1392001-08-28 23:06:02 +000081 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
82 SchedGraphNode* _sink,
Vikram S. Adve4a87b382001-09-30 23:37:26 +000083 const Value* _val,
Vikram S. Adve200a4352001-11-12 18:53:43 +000084 unsigned int _depOrderType,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000085 int _minDelay = -1);
86
87 // constructor for machine register dependence
88 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
89 SchedGraphNode* _sink,
90 unsigned int _regNum,
Vikram S. Adve200a4352001-11-12 18:53:43 +000091 unsigned int _depOrderType,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000092 int _minDelay = -1);
93
94 // constructor for any other machine resource dependences.
95 // DataDepOrderType is always NonDataDep. It it not an argument to
96 // avoid overloading ambiguity with previous constructor.
97 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
98 SchedGraphNode* _sink,
99 ResourceId _resourceId,
100 int _minDelay = -1);
101
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000102 /*dtor*/ ~SchedGraphEdge();
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000103
104 SchedGraphNode* getSrc () const { return src; }
105 SchedGraphNode* getSink () const { return sink; }
106 int getMinDelay () const { return minDelay; }
107 SchedGraphEdgeDepType getDepType () const { return depType; }
108
109 const Value* getValue () const {
Vikram S. Adve200a4352001-11-12 18:53:43 +0000110 assert(depType == ValueDep); return val;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000111 }
112 int getMachineReg () const {
113 assert(depType == MachineRegister); return machineRegNum;
114 }
115 int getResourceId () const {
116 assert(depType == MachineResource); return resourceId;
117 }
118
119public:
120 //
121 // Debugging support
122 //
Chris Lattner697954c2002-01-20 22:54:45 +0000123 friend std::ostream& operator<<(std::ostream& os, const SchedGraphEdge& edge);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000124
Chris Lattnercffebdc2001-09-07 21:07:10 +0000125 void dump (int indent=0) const;
126
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000127private:
128 // disable default ctor
129 /*ctor*/ SchedGraphEdge(); // DO NOT IMPLEMENT
130};
131
132
133
134class SchedGraphNode: public NonCopyable {
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000135 unsigned nodeId;
136 MachineBasicBlock *MBB;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000137 const MachineInstr* minstr;
Chris Lattner697954c2002-01-20 22:54:45 +0000138 std::vector<SchedGraphEdge*> inEdges;
139 std::vector<SchedGraphEdge*> outEdges;
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000140 int origIndexInBB; // original position of machine instr in BB
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000141 int latency;
142
143public:
Chris Lattner697954c2002-01-20 22:54:45 +0000144 typedef std::vector<SchedGraphEdge*>:: iterator iterator;
145 typedef std::vector<SchedGraphEdge*>::const_iterator const_iterator;
146 typedef std::vector<SchedGraphEdge*>:: reverse_iterator reverse_iterator;
147 typedef std::vector<SchedGraphEdge*>::const_reverse_iterator const_reverse_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000148
149public:
150 //
151 // Accessor methods
152 //
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000153 unsigned getNodeId () const { return nodeId; }
154 const MachineInstr* getMachineInstr () const { return minstr; }
155 const MachineOpCode getOpCode () const { return minstr->getOpCode(); }
156 int getLatency () const { return latency; }
157 unsigned getNumInEdges () const { return inEdges.size(); }
158 unsigned getNumOutEdges () const { return outEdges.size(); }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000159 bool isDummyNode () const { return (minstr == NULL); }
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000160 MachineBasicBlock &getMachineBasicBlock() const { return *MBB; }
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000161 int getOrigIndexInBB() const { return origIndexInBB; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000162
163 //
164 // Iterators
165 //
166 iterator beginInEdges () { return inEdges.begin(); }
167 iterator endInEdges () { return inEdges.end(); }
168 iterator beginOutEdges () { return outEdges.begin(); }
169 iterator endOutEdges () { return outEdges.end(); }
170
171 const_iterator beginInEdges () const { return inEdges.begin(); }
172 const_iterator endInEdges () const { return inEdges.end(); }
173 const_iterator beginOutEdges () const { return outEdges.begin(); }
174 const_iterator endOutEdges () const { return outEdges.end(); }
175
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000176public:
177 //
178 // Debugging support
179 //
Chris Lattner697954c2002-01-20 22:54:45 +0000180 friend std::ostream& operator<<(std::ostream& os, const SchedGraphNode& node);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000181
Chris Lattnercffebdc2001-09-07 21:07:10 +0000182 void dump (int indent=0) const;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000183
184private:
185 friend class SchedGraph; // give access for ctor and dtor
186 friend class SchedGraphEdge; // give access for adding edges
187
188 void addInEdge (SchedGraphEdge* edge);
189 void addOutEdge (SchedGraphEdge* edge);
190
191 void removeInEdge (const SchedGraphEdge* edge);
192 void removeOutEdge (const SchedGraphEdge* edge);
193
194 // disable default constructor and provide a ctor for single-block graphs
195 /*ctor*/ SchedGraphNode(); // DO NOT IMPLEMENT
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000196 /*ctor*/ SchedGraphNode (unsigned nodeId,
197 MachineBasicBlock *mbb,
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000198 int indexInBB,
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000199 const TargetMachine& Target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000200 /*dtor*/ ~SchedGraphNode ();
201};
202
203
204
205class SchedGraph :
206 public NonCopyable,
Chris Lattner09ff1122002-07-24 21:21:32 +0000207 private hash_map<const MachineInstr*, SchedGraphNode*>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000208{
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000209 MachineBasicBlock &MBB; // basic blocks for this graph
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000210 SchedGraphNode* graphRoot; // the root and leaf are not inserted
211 SchedGraphNode* graphLeaf; // in the hash_map (see getNumNodes())
212
Chris Lattner09ff1122002-07-24 21:21:32 +0000213 typedef hash_map<const MachineInstr*, SchedGraphNode*> map_base;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000214public:
Chris Lattner697954c2002-01-20 22:54:45 +0000215 using map_base::iterator;
216 using map_base::const_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000217
218public:
219 //
220 // Accessor methods
221 //
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000222 MachineBasicBlock &getBasicBlock() const { return MBB; }
223 unsigned getNumNodes() const { return size()+2; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000224 SchedGraphNode* getRoot() const { return graphRoot; }
225 SchedGraphNode* getLeaf() const { return graphLeaf; }
226
227 SchedGraphNode* getGraphNodeForInstr(const MachineInstr* minstr) const {
228 const_iterator onePair = this->find(minstr);
229 return (onePair != this->end())? (*onePair).second : NULL;
230 }
231
232 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000233 // Delete nodes or edges from the graph.
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000234 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000235 void eraseNode (SchedGraphNode* node);
236
237 void eraseIncomingEdges (SchedGraphNode* node,
238 bool addDummyEdges = true);
239
240 void eraseOutgoingEdges (SchedGraphNode* node,
241 bool addDummyEdges = true);
242
243 void eraseIncidentEdges (SchedGraphNode* node,
244 bool addDummyEdges = true);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000245
246 //
247 // Unordered iterators.
248 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
249 //
Chris Lattner697954c2002-01-20 22:54:45 +0000250 using map_base::begin;
251 using map_base::end;
252
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000253 //
254 // Ordered iterators.
255 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
256 //
257 // void postord_init();
258 // postorder_iterator postord_begin();
259 // postorder_iterator postord_end();
260 // const_postorder_iterator postord_begin() const;
261 // const_postorder_iterator postord_end() const;
262
263 //
264 // Debugging support
265 //
266 void dump () const;
267
268private:
269 friend class SchedGraphSet; // give access to ctor
270
271 // disable default constructor and provide a ctor for single-block graphs
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000272 /*ctor*/ SchedGraph (MachineBasicBlock &bb,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000273 const TargetMachine& target);
274 /*dtor*/ ~SchedGraph ();
275
276 inline void noteGraphNodeForInstr (const MachineInstr* minstr,
277 SchedGraphNode* node)
278 {
279 assert((*this)[minstr] == NULL);
280 (*this)[minstr] = node;
281 }
282
283 //
284 // Graph builder
285 //
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000286 void buildGraph (const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000287
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000288 void buildNodesForBB (const TargetMachine& target,
289 MachineBasicBlock &MBB,
Vikram S. Adve7952d602003-05-31 07:37:05 +0000290 std::vector<SchedGraphNode*>& memNV,
291 std::vector<SchedGraphNode*>& callNV,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000292 RegToRefVecMap& regToRefVecMap,
293 ValueToDefVecMap& valueToDefVecMap);
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000294
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000295 void findDefUseInfoAtInstr (const TargetMachine& target,
296 SchedGraphNode* node,
Vikram S. Adve7952d602003-05-31 07:37:05 +0000297 std::vector<SchedGraphNode*>& memNV,
298 std::vector<SchedGraphNode*>& callNV,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000299 RegToRefVecMap& regToRefVecMap,
300 ValueToDefVecMap& valueToDefVecMap);
301
Vikram S. Advee64574c2001-11-08 05:20:23 +0000302 void addEdgesForInstruction(const MachineInstr& minstr,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000303 const ValueToDefVecMap& valueToDefVecMap,
304 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000305
306 void addCDEdges (const TerminatorInst* term,
307 const TargetMachine& target);
308
Vikram S. Adve7952d602003-05-31 07:37:05 +0000309 void addMemEdges (const std::vector<SchedGraphNode*>& memNV,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000310 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000311
Vikram S. Adve7952d602003-05-31 07:37:05 +0000312 void addCallDepEdges (const std::vector<SchedGraphNode*>& callNV,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000313 const TargetMachine& target);
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000314
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000315 void addMachineRegEdges (RegToRefVecMap& regToRefVecMap,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000316 const TargetMachine& target);
317
Vikram S. Adve200a4352001-11-12 18:53:43 +0000318 void addEdgesForValue (SchedGraphNode* refNode,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000319 const RefVec& defVec,
Vikram S. Advef43e3362001-10-17 23:55:16 +0000320 const Value* defValue,
Vikram S. Adve200a4352001-11-12 18:53:43 +0000321 bool refNodeIsDef,
Vikram S. Adve0baf1c02002-07-08 22:59:23 +0000322 bool refNodeIsDefAndUse,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000323 const TargetMachine& target);
324
325 void addDummyEdges ();
326};
327
328
329class SchedGraphSet :
330 public NonCopyable,
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000331 private std::vector<SchedGraph*>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000332{
333private:
Chris Lattnere7506a32002-03-23 22:51:58 +0000334 const Function* method;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000335
336public:
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000337 typedef std::vector<SchedGraph*> baseVector;
338 using baseVector::iterator;
339 using baseVector::const_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000340
341public:
Chris Lattnere7506a32002-03-23 22:51:58 +0000342 /*ctor*/ SchedGraphSet (const Function * function,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000343 const TargetMachine& target);
344 /*dtor*/ ~SchedGraphSet ();
345
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000346 // Iterators
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000347 using baseVector::begin;
348 using baseVector::end;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000349
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000350 // Debugging support
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000351 void dump () const;
352
353private:
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000354 inline void addGraph(SchedGraph* graph) {
355 assert(graph != NULL);
356 this->push_back(graph);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000357 }
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000358
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000359 // Graph builder
Chris Lattnere7506a32002-03-23 22:51:58 +0000360 void buildGraphsForMethod (const Function *F,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000361 const TargetMachine& target);
362};
363
364
365//********************** Sched Graph Iterators *****************************/
366
367// Ok to make it a template because it shd get instantiated at most twice:
368// for <SchedGraphNode, SchedGraphNode::iterator> and
369// for <const SchedGraphNode, SchedGraphNode::const_iterator>.
370//
371template <class _NodeType, class _EdgeType, class _EdgeIter>
Chris Lattner0c0edf82002-07-25 06:17:51 +0000372class SGPredIterator: public bidirectional_iterator<_NodeType, ptrdiff_t> {
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000373protected:
374 _EdgeIter oi;
375public:
Chris Lattner455889a2002-02-12 22:39:50 +0000376 typedef SGPredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000377
Chris Lattner455889a2002-02-12 22:39:50 +0000378 inline SGPredIterator(_EdgeIter startEdge) : oi(startEdge) {}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000379
380 inline bool operator==(const _Self& x) const { return oi == x.oi; }
381 inline bool operator!=(const _Self& x) const { return !operator==(x); }
382
383 // operator*() differs for pred or succ iterator
Chris Lattnercffebdc2001-09-07 21:07:10 +0000384 inline _NodeType* operator*() const { return (*oi)->getSrc(); }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000385 inline _NodeType* operator->() const { return operator*(); }
386
387 inline _EdgeType* getEdge() const { return *(oi); }
388
Chris Lattnercffebdc2001-09-07 21:07:10 +0000389 inline _Self &operator++() { ++oi; return *this; } // Preincrement
390 inline _Self operator++(int) { // Postincrement
391 _Self tmp(*this); ++*this; return tmp;
392 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000393
Chris Lattnercffebdc2001-09-07 21:07:10 +0000394 inline _Self &operator--() { --oi; return *this; } // Predecrement
395 inline _Self operator--(int) { // Postdecrement
396 _Self tmp = *this; --*this; return tmp;
397 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000398};
399
400template <class _NodeType, class _EdgeType, class _EdgeIter>
Chris Lattner0c0edf82002-07-25 06:17:51 +0000401class SGSuccIterator : public bidirectional_iterator<_NodeType, ptrdiff_t> {
Chris Lattnercffebdc2001-09-07 21:07:10 +0000402protected:
403 _EdgeIter oi;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000404public:
Chris Lattner455889a2002-02-12 22:39:50 +0000405 typedef SGSuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000406
Chris Lattner455889a2002-02-12 22:39:50 +0000407 inline SGSuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000408
Chris Lattnercffebdc2001-09-07 21:07:10 +0000409 inline bool operator==(const _Self& x) const { return oi == x.oi; }
410 inline bool operator!=(const _Self& x) const { return !operator==(x); }
411
412 inline _NodeType* operator*() const { return (*oi)->getSink(); }
413 inline _NodeType* operator->() const { return operator*(); }
414
415 inline _EdgeType* getEdge() const { return *(oi); }
416
417 inline _Self &operator++() { ++oi; return *this; } // Preincrement
418 inline _Self operator++(int) { // Postincrement
419 _Self tmp(*this); ++*this; return tmp;
420 }
421
422 inline _Self &operator--() { --oi; return *this; } // Predecrement
423 inline _Self operator--(int) { // Postdecrement
424 _Self tmp = *this; --*this; return tmp;
425 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000426};
427
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000428//
429// sg_pred_iterator
430// sg_pred_const_iterator
431//
Chris Lattner455889a2002-02-12 22:39:50 +0000432typedef SGPredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000433 sg_pred_iterator;
Chris Lattner455889a2002-02-12 22:39:50 +0000434typedef SGPredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000435 sg_pred_const_iterator;
436
437inline sg_pred_iterator pred_begin( SchedGraphNode *N) {
438 return sg_pred_iterator(N->beginInEdges());
439}
440inline sg_pred_iterator pred_end( SchedGraphNode *N) {
441 return sg_pred_iterator(N->endInEdges());
442}
443inline sg_pred_const_iterator pred_begin(const SchedGraphNode *N) {
444 return sg_pred_const_iterator(N->beginInEdges());
445}
446inline sg_pred_const_iterator pred_end( const SchedGraphNode *N) {
447 return sg_pred_const_iterator(N->endInEdges());
448}
449
450
451//
452// sg_succ_iterator
453// sg_succ_const_iterator
454//
Chris Lattner455889a2002-02-12 22:39:50 +0000455typedef SGSuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000456 sg_succ_iterator;
Chris Lattner455889a2002-02-12 22:39:50 +0000457typedef SGSuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000458 sg_succ_const_iterator;
459
460inline sg_succ_iterator succ_begin( SchedGraphNode *N) {
461 return sg_succ_iterator(N->beginOutEdges());
462}
463inline sg_succ_iterator succ_end( SchedGraphNode *N) {
464 return sg_succ_iterator(N->endOutEdges());
465}
466inline sg_succ_const_iterator succ_begin(const SchedGraphNode *N) {
467 return sg_succ_const_iterator(N->beginOutEdges());
468}
469inline sg_succ_const_iterator succ_end( const SchedGraphNode *N) {
470 return sg_succ_const_iterator(N->endOutEdges());
471}
472
Chris Lattner3ff43872001-09-28 22:56:31 +0000473// Provide specializations of GraphTraits to be able to use graph iterators on
474// the scheduling graph!
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000475//
Chris Lattner3ff43872001-09-28 22:56:31 +0000476template <> struct GraphTraits<SchedGraph*> {
477 typedef SchedGraphNode NodeType;
478 typedef sg_succ_iterator ChildIteratorType;
479
480 static inline NodeType *getEntryNode(SchedGraph *SG) { return SG->getRoot(); }
481 static inline ChildIteratorType child_begin(NodeType *N) {
482 return succ_begin(N);
483 }
484 static inline ChildIteratorType child_end(NodeType *N) {
485 return succ_end(N);
486 }
487};
488
489template <> struct GraphTraits<const SchedGraph*> {
490 typedef const SchedGraphNode NodeType;
491 typedef sg_succ_const_iterator ChildIteratorType;
492
493 static inline NodeType *getEntryNode(const SchedGraph *SG) {
494 return SG->getRoot();
495 }
496 static inline ChildIteratorType child_begin(NodeType *N) {
497 return succ_begin(N);
498 }
499 static inline ChildIteratorType child_end(NodeType *N) {
500 return succ_end(N);
501 }
502};
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000503
504
Chris Lattner697954c2002-01-20 22:54:45 +0000505std::ostream &operator<<(std::ostream& os, const SchedGraphEdge& edge);
506std::ostream &operator<<(std::ostream &os, const SchedGraphNode& node);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000507
508#endif