blob: 37c22be2b075a8aedde916e8dbf6f0a0a6fa49af [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"
Chris Lattner747a0442003-06-02 22:05:13 +000020#include "Support/NonCopyable.h"
Vikram S. Adve78ef1392001-08-28 23:06:02 +000021
22class Value;
23class Instruction;
Chris Lattner3ff43872001-09-28 22:56:31 +000024class TerminatorInst;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000025class BasicBlock;
Chris Lattnere7506a32002-03-23 22:51:58 +000026class Function;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000027class TargetMachine;
28class SchedGraphEdge;
29class SchedGraphNode;
30class SchedGraph;
Vikram S. Adve4a87b382001-09-30 23:37:26 +000031class RegToRefVecMap;
Vikram S. Advec352d2c2001-11-05 04:04:23 +000032class ValueToDefVecMap;
33class RefVec;
Chris Lattnerc0c77082001-09-14 17:55:51 +000034class MachineInstr;
Misha Brukmanfce11432002-10-28 00:28:31 +000035class MachineBasicBlock;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000036
Vikram S. Adve78ef1392001-08-28 23:06:02 +000037
38/******************** Exported Data Types and Constants ********************/
39
40typedef int ResourceId;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000041const ResourceId InvalidRID = -1;
42const ResourceId MachineCCRegsRID = -2; // use +ve numbers for actual regs
43const ResourceId MachineIntRegsRID = -3; // use +ve numbers for actual regs
44const ResourceId MachineFPRegsRID = -4; // use +ve numbers for actual regs
Vikram S. Adve78ef1392001-08-28 23:06:02 +000045
46
47//*********************** Public Class Declarations ************************/
48
49class SchedGraphEdge: public NonCopyable {
50public:
51 enum SchedGraphEdgeDepType {
Vikram S. Adve200a4352001-11-12 18:53:43 +000052 CtrlDep, MemoryDep, ValueDep, MachineRegister, MachineResource
Vikram S. Adve78ef1392001-08-28 23:06:02 +000053 };
54 enum DataDepOrderType {
Vikram S. Adved0d79c02001-10-28 21:45:02 +000055 TrueDep = 0x1, AntiDep=0x2, OutputDep=0x4, NonDataDep=0x8
Vikram S. Adve78ef1392001-08-28 23:06:02 +000056 };
57
58protected:
59 SchedGraphNode* src;
60 SchedGraphNode* sink;
61 SchedGraphEdgeDepType depType;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000062 unsigned int depOrderType;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000063 int minDelay; // cached latency (assumes fixed target arch)
64
65 union {
Vikram S. Adve4a87b382001-09-30 23:37:26 +000066 const Value* val;
67 int machineRegNum;
68 ResourceId resourceId;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000069 };
70
71public:
72 // For all constructors, if minDelay is unspecified, minDelay is
73 // set to _src->getLatency().
74 // constructor for CtrlDep or MemoryDep edges, selected by 3rd argument
75 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
76 SchedGraphNode* _sink,
77 SchedGraphEdgeDepType _depType,
Vikram S. Adve200a4352001-11-12 18:53:43 +000078 unsigned int _depOrderType,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000079 int _minDelay = -1);
80
Vikram S. Adve200a4352001-11-12 18:53:43 +000081 // constructor for explicit value dependence (may be true/anti/output)
Vikram S. Adve78ef1392001-08-28 23:06:02 +000082 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
83 SchedGraphNode* _sink,
Vikram S. Adve4a87b382001-09-30 23:37:26 +000084 const Value* _val,
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
88 // constructor for machine register dependence
89 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
90 SchedGraphNode* _sink,
91 unsigned int _regNum,
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 any other machine resource dependences.
96 // DataDepOrderType is always NonDataDep. It it not an argument to
97 // avoid overloading ambiguity with previous constructor.
98 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
99 SchedGraphNode* _sink,
100 ResourceId _resourceId,
101 int _minDelay = -1);
102
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000103 /*dtor*/ ~SchedGraphEdge();
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000104
105 SchedGraphNode* getSrc () const { return src; }
106 SchedGraphNode* getSink () const { return sink; }
107 int getMinDelay () const { return minDelay; }
108 SchedGraphEdgeDepType getDepType () const { return depType; }
109
110 const Value* getValue () const {
Vikram S. Adve200a4352001-11-12 18:53:43 +0000111 assert(depType == ValueDep); return val;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000112 }
113 int getMachineReg () const {
114 assert(depType == MachineRegister); return machineRegNum;
115 }
116 int getResourceId () const {
117 assert(depType == MachineResource); return resourceId;
118 }
119
120public:
121 //
122 // Debugging support
123 //
Chris Lattner697954c2002-01-20 22:54:45 +0000124 friend std::ostream& operator<<(std::ostream& os, const SchedGraphEdge& edge);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000125
Chris Lattnercffebdc2001-09-07 21:07:10 +0000126 void dump (int indent=0) const;
127
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000128private:
129 // disable default ctor
130 /*ctor*/ SchedGraphEdge(); // DO NOT IMPLEMENT
131};
132
133
134
135class SchedGraphNode: public NonCopyable {
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000136 unsigned nodeId;
137 MachineBasicBlock *MBB;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000138 const MachineInstr* minstr;
Chris Lattner697954c2002-01-20 22:54:45 +0000139 std::vector<SchedGraphEdge*> inEdges;
140 std::vector<SchedGraphEdge*> outEdges;
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000141 int origIndexInBB; // original position of machine instr in BB
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000142 int latency;
143
144public:
Chris Lattner697954c2002-01-20 22:54:45 +0000145 typedef std::vector<SchedGraphEdge*>:: iterator iterator;
146 typedef std::vector<SchedGraphEdge*>::const_iterator const_iterator;
147 typedef std::vector<SchedGraphEdge*>:: reverse_iterator reverse_iterator;
148 typedef std::vector<SchedGraphEdge*>::const_reverse_iterator const_reverse_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000149
150public:
151 //
152 // Accessor methods
153 //
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000154 unsigned getNodeId () const { return nodeId; }
155 const MachineInstr* getMachineInstr () const { return minstr; }
156 const MachineOpCode getOpCode () const { return minstr->getOpCode(); }
157 int getLatency () const { return latency; }
158 unsigned getNumInEdges () const { return inEdges.size(); }
159 unsigned getNumOutEdges () const { return outEdges.size(); }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000160 bool isDummyNode () const { return (minstr == NULL); }
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000161 MachineBasicBlock &getMachineBasicBlock() const { return *MBB; }
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000162 int getOrigIndexInBB() const { return origIndexInBB; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000163
164 //
165 // Iterators
166 //
167 iterator beginInEdges () { return inEdges.begin(); }
168 iterator endInEdges () { return inEdges.end(); }
169 iterator beginOutEdges () { return outEdges.begin(); }
170 iterator endOutEdges () { return outEdges.end(); }
171
172 const_iterator beginInEdges () const { return inEdges.begin(); }
173 const_iterator endInEdges () const { return inEdges.end(); }
174 const_iterator beginOutEdges () const { return outEdges.begin(); }
175 const_iterator endOutEdges () const { return outEdges.end(); }
176
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000177public:
178 //
179 // Debugging support
180 //
Chris Lattner697954c2002-01-20 22:54:45 +0000181 friend std::ostream& operator<<(std::ostream& os, const SchedGraphNode& node);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000182
Chris Lattnercffebdc2001-09-07 21:07:10 +0000183 void dump (int indent=0) const;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000184
185private:
186 friend class SchedGraph; // give access for ctor and dtor
187 friend class SchedGraphEdge; // give access for adding edges
188
189 void addInEdge (SchedGraphEdge* edge);
190 void addOutEdge (SchedGraphEdge* edge);
191
192 void removeInEdge (const SchedGraphEdge* edge);
193 void removeOutEdge (const SchedGraphEdge* edge);
194
195 // disable default constructor and provide a ctor for single-block graphs
196 /*ctor*/ SchedGraphNode(); // DO NOT IMPLEMENT
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000197 /*ctor*/ SchedGraphNode (unsigned nodeId,
198 MachineBasicBlock *mbb,
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000199 int indexInBB,
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000200 const TargetMachine& Target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000201 /*dtor*/ ~SchedGraphNode ();
202};
203
204
205
206class SchedGraph :
207 public NonCopyable,
Chris Lattner09ff1122002-07-24 21:21:32 +0000208 private hash_map<const MachineInstr*, SchedGraphNode*>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000209{
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000210 MachineBasicBlock &MBB; // basic blocks for this graph
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000211 SchedGraphNode* graphRoot; // the root and leaf are not inserted
212 SchedGraphNode* graphLeaf; // in the hash_map (see getNumNodes())
213
Chris Lattner09ff1122002-07-24 21:21:32 +0000214 typedef hash_map<const MachineInstr*, SchedGraphNode*> map_base;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000215public:
Chris Lattner697954c2002-01-20 22:54:45 +0000216 using map_base::iterator;
217 using map_base::const_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000218
219public:
220 //
221 // Accessor methods
222 //
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000223 MachineBasicBlock &getBasicBlock() const { return MBB; }
224 unsigned getNumNodes() const { return size()+2; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000225 SchedGraphNode* getRoot() const { return graphRoot; }
226 SchedGraphNode* getLeaf() const { return graphLeaf; }
227
228 SchedGraphNode* getGraphNodeForInstr(const MachineInstr* minstr) const {
229 const_iterator onePair = this->find(minstr);
230 return (onePair != this->end())? (*onePair).second : NULL;
231 }
232
233 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000234 // Delete nodes or edges from the graph.
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000235 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000236 void eraseNode (SchedGraphNode* node);
237
238 void eraseIncomingEdges (SchedGraphNode* node,
239 bool addDummyEdges = true);
240
241 void eraseOutgoingEdges (SchedGraphNode* node,
242 bool addDummyEdges = true);
243
244 void eraseIncidentEdges (SchedGraphNode* node,
245 bool addDummyEdges = true);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000246
247 //
248 // Unordered iterators.
249 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
250 //
Chris Lattner697954c2002-01-20 22:54:45 +0000251 using map_base::begin;
252 using map_base::end;
253
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000254 //
255 // Ordered iterators.
256 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
257 //
258 // void postord_init();
259 // postorder_iterator postord_begin();
260 // postorder_iterator postord_end();
261 // const_postorder_iterator postord_begin() const;
262 // const_postorder_iterator postord_end() const;
263
264 //
265 // Debugging support
266 //
267 void dump () const;
268
269private:
270 friend class SchedGraphSet; // give access to ctor
271
272 // disable default constructor and provide a ctor for single-block graphs
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000273 /*ctor*/ SchedGraph (MachineBasicBlock &bb,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000274 const TargetMachine& target);
275 /*dtor*/ ~SchedGraph ();
276
277 inline void noteGraphNodeForInstr (const MachineInstr* minstr,
278 SchedGraphNode* node)
279 {
280 assert((*this)[minstr] == NULL);
281 (*this)[minstr] = node;
282 }
283
284 //
285 // Graph builder
286 //
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000287 void buildGraph (const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000288
Chris Lattnerfb3a0aed2002-10-28 18:50:08 +0000289 void buildNodesForBB (const TargetMachine& target,
290 MachineBasicBlock &MBB,
Vikram S. Adve7952d602003-05-31 07:37:05 +0000291 std::vector<SchedGraphNode*>& memNV,
292 std::vector<SchedGraphNode*>& callNV,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000293 RegToRefVecMap& regToRefVecMap,
294 ValueToDefVecMap& valueToDefVecMap);
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000295
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000296 void findDefUseInfoAtInstr (const TargetMachine& target,
297 SchedGraphNode* node,
Vikram S. Adve7952d602003-05-31 07:37:05 +0000298 std::vector<SchedGraphNode*>& memNV,
299 std::vector<SchedGraphNode*>& callNV,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000300 RegToRefVecMap& regToRefVecMap,
301 ValueToDefVecMap& valueToDefVecMap);
302
Vikram S. Advee64574c2001-11-08 05:20:23 +0000303 void addEdgesForInstruction(const MachineInstr& minstr,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000304 const ValueToDefVecMap& valueToDefVecMap,
305 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000306
307 void addCDEdges (const TerminatorInst* term,
308 const TargetMachine& target);
309
Vikram S. Adve7952d602003-05-31 07:37:05 +0000310 void addMemEdges (const std::vector<SchedGraphNode*>& memNV,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000311 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000312
Vikram S. Adve7952d602003-05-31 07:37:05 +0000313 void addCallDepEdges (const std::vector<SchedGraphNode*>& callNV,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000314 const TargetMachine& target);
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000315
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000316 void addMachineRegEdges (RegToRefVecMap& regToRefVecMap,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000317 const TargetMachine& target);
318
Vikram S. Adve200a4352001-11-12 18:53:43 +0000319 void addEdgesForValue (SchedGraphNode* refNode,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000320 const RefVec& defVec,
Vikram S. Advef43e3362001-10-17 23:55:16 +0000321 const Value* defValue,
Vikram S. Adve200a4352001-11-12 18:53:43 +0000322 bool refNodeIsDef,
Vikram S. Adve0baf1c02002-07-08 22:59:23 +0000323 bool refNodeIsDefAndUse,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000324 const TargetMachine& target);
325
326 void addDummyEdges ();
327};
328
329
330class SchedGraphSet :
331 public NonCopyable,
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000332 private std::vector<SchedGraph*>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000333{
334private:
Chris Lattnere7506a32002-03-23 22:51:58 +0000335 const Function* method;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000336
337public:
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000338 typedef std::vector<SchedGraph*> baseVector;
339 using baseVector::iterator;
340 using baseVector::const_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000341
342public:
Chris Lattnere7506a32002-03-23 22:51:58 +0000343 /*ctor*/ SchedGraphSet (const Function * function,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000344 const TargetMachine& target);
345 /*dtor*/ ~SchedGraphSet ();
346
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000347 // Iterators
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000348 using baseVector::begin;
349 using baseVector::end;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000350
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000351 // Debugging support
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000352 void dump () const;
353
354private:
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000355 inline void addGraph(SchedGraph* graph) {
356 assert(graph != NULL);
357 this->push_back(graph);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000358 }
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000359
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000360 // Graph builder
Chris Lattnere7506a32002-03-23 22:51:58 +0000361 void buildGraphsForMethod (const Function *F,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000362 const TargetMachine& target);
363};
364
365
366//********************** Sched Graph Iterators *****************************/
367
368// Ok to make it a template because it shd get instantiated at most twice:
369// for <SchedGraphNode, SchedGraphNode::iterator> and
370// for <const SchedGraphNode, SchedGraphNode::const_iterator>.
371//
372template <class _NodeType, class _EdgeType, class _EdgeIter>
Chris Lattner0c0edf82002-07-25 06:17:51 +0000373class SGPredIterator: public bidirectional_iterator<_NodeType, ptrdiff_t> {
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000374protected:
375 _EdgeIter oi;
376public:
Chris Lattner455889a2002-02-12 22:39:50 +0000377 typedef SGPredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000378
Chris Lattner455889a2002-02-12 22:39:50 +0000379 inline SGPredIterator(_EdgeIter startEdge) : oi(startEdge) {}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000380
381 inline bool operator==(const _Self& x) const { return oi == x.oi; }
382 inline bool operator!=(const _Self& x) const { return !operator==(x); }
383
384 // operator*() differs for pred or succ iterator
Chris Lattnercffebdc2001-09-07 21:07:10 +0000385 inline _NodeType* operator*() const { return (*oi)->getSrc(); }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000386 inline _NodeType* operator->() const { return operator*(); }
387
388 inline _EdgeType* getEdge() const { return *(oi); }
389
Chris Lattnercffebdc2001-09-07 21:07:10 +0000390 inline _Self &operator++() { ++oi; return *this; } // Preincrement
391 inline _Self operator++(int) { // Postincrement
392 _Self tmp(*this); ++*this; return tmp;
393 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000394
Chris Lattnercffebdc2001-09-07 21:07:10 +0000395 inline _Self &operator--() { --oi; return *this; } // Predecrement
396 inline _Self operator--(int) { // Postdecrement
397 _Self tmp = *this; --*this; return tmp;
398 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000399};
400
401template <class _NodeType, class _EdgeType, class _EdgeIter>
Chris Lattner0c0edf82002-07-25 06:17:51 +0000402class SGSuccIterator : public bidirectional_iterator<_NodeType, ptrdiff_t> {
Chris Lattnercffebdc2001-09-07 21:07:10 +0000403protected:
404 _EdgeIter oi;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000405public:
Chris Lattner455889a2002-02-12 22:39:50 +0000406 typedef SGSuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000407
Chris Lattner455889a2002-02-12 22:39:50 +0000408 inline SGSuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000409
Chris Lattnercffebdc2001-09-07 21:07:10 +0000410 inline bool operator==(const _Self& x) const { return oi == x.oi; }
411 inline bool operator!=(const _Self& x) const { return !operator==(x); }
412
413 inline _NodeType* operator*() const { return (*oi)->getSink(); }
414 inline _NodeType* operator->() const { return operator*(); }
415
416 inline _EdgeType* getEdge() const { return *(oi); }
417
418 inline _Self &operator++() { ++oi; return *this; } // Preincrement
419 inline _Self operator++(int) { // Postincrement
420 _Self tmp(*this); ++*this; return tmp;
421 }
422
423 inline _Self &operator--() { --oi; return *this; } // Predecrement
424 inline _Self operator--(int) { // Postdecrement
425 _Self tmp = *this; --*this; return tmp;
426 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000427};
428
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000429//
430// sg_pred_iterator
431// sg_pred_const_iterator
432//
Chris Lattner455889a2002-02-12 22:39:50 +0000433typedef SGPredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000434 sg_pred_iterator;
Chris Lattner455889a2002-02-12 22:39:50 +0000435typedef SGPredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000436 sg_pred_const_iterator;
437
438inline sg_pred_iterator pred_begin( SchedGraphNode *N) {
439 return sg_pred_iterator(N->beginInEdges());
440}
441inline sg_pred_iterator pred_end( SchedGraphNode *N) {
442 return sg_pred_iterator(N->endInEdges());
443}
444inline sg_pred_const_iterator pred_begin(const SchedGraphNode *N) {
445 return sg_pred_const_iterator(N->beginInEdges());
446}
447inline sg_pred_const_iterator pred_end( const SchedGraphNode *N) {
448 return sg_pred_const_iterator(N->endInEdges());
449}
450
451
452//
453// sg_succ_iterator
454// sg_succ_const_iterator
455//
Chris Lattner455889a2002-02-12 22:39:50 +0000456typedef SGSuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000457 sg_succ_iterator;
Chris Lattner455889a2002-02-12 22:39:50 +0000458typedef SGSuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000459 sg_succ_const_iterator;
460
461inline sg_succ_iterator succ_begin( SchedGraphNode *N) {
462 return sg_succ_iterator(N->beginOutEdges());
463}
464inline sg_succ_iterator succ_end( SchedGraphNode *N) {
465 return sg_succ_iterator(N->endOutEdges());
466}
467inline sg_succ_const_iterator succ_begin(const SchedGraphNode *N) {
468 return sg_succ_const_iterator(N->beginOutEdges());
469}
470inline sg_succ_const_iterator succ_end( const SchedGraphNode *N) {
471 return sg_succ_const_iterator(N->endOutEdges());
472}
473
Chris Lattner3ff43872001-09-28 22:56:31 +0000474// Provide specializations of GraphTraits to be able to use graph iterators on
475// the scheduling graph!
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000476//
Chris Lattner3ff43872001-09-28 22:56:31 +0000477template <> struct GraphTraits<SchedGraph*> {
478 typedef SchedGraphNode NodeType;
479 typedef sg_succ_iterator ChildIteratorType;
480
481 static inline NodeType *getEntryNode(SchedGraph *SG) { return SG->getRoot(); }
482 static inline ChildIteratorType child_begin(NodeType *N) {
483 return succ_begin(N);
484 }
485 static inline ChildIteratorType child_end(NodeType *N) {
486 return succ_end(N);
487 }
488};
489
490template <> struct GraphTraits<const SchedGraph*> {
491 typedef const SchedGraphNode NodeType;
492 typedef sg_succ_const_iterator ChildIteratorType;
493
494 static inline NodeType *getEntryNode(const SchedGraph *SG) {
495 return SG->getRoot();
496 }
497 static inline ChildIteratorType child_begin(NodeType *N) {
498 return succ_begin(N);
499 }
500 static inline ChildIteratorType child_end(NodeType *N) {
501 return succ_end(N);
502 }
503};
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000504
505
Chris Lattner697954c2002-01-20 22:54:45 +0000506std::ostream &operator<<(std::ostream& os, const SchedGraphEdge& edge);
507std::ostream &operator<<(std::ostream &os, const SchedGraphNode& node);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000508
509#endif