blob: 514e5654774a7818c79354d715c91a66a47b7569 [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 {
135private:
136 unsigned int nodeId;
Vikram S. Adveaf00d482001-11-12 14:18:01 +0000137 const BasicBlock* bb;
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 //
154 unsigned int getNodeId () const { return nodeId; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000155 const MachineInstr* getMachineInstr () const { return minstr; }
Vikram S. Advee64574c2001-11-08 05:20:23 +0000156 const MachineOpCode getOpCode () const { return minstr->getOpCode();}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000157 int getLatency () const { return latency; }
158 unsigned int getNumInEdges () const { return inEdges.size(); }
159 unsigned int getNumOutEdges () const { return outEdges.size(); }
160 bool isDummyNode () const { return (minstr == NULL); }
Vikram S. Adveaf00d482001-11-12 14:18:01 +0000161 const BasicBlock* getBB () const { return bb; }
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
197 /*ctor*/ SchedGraphNode (unsigned int _nodeId,
Vikram S. Adveaf00d482001-11-12 14:18:01 +0000198 const BasicBlock* _bb,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000199 const MachineInstr* _minstr,
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000200 int indexInBB,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000201 const TargetMachine& _target);
202 /*dtor*/ ~SchedGraphNode ();
203};
204
205
206
207class SchedGraph :
208 public NonCopyable,
Chris Lattner09ff1122002-07-24 21:21:32 +0000209 private hash_map<const MachineInstr*, SchedGraphNode*>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000210{
211private:
Chris Lattner697954c2002-01-20 22:54:45 +0000212 std::vector<const BasicBlock*> bbVec; // basic blocks included in the graph
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000213 SchedGraphNode* graphRoot; // the root and leaf are not inserted
214 SchedGraphNode* graphLeaf; // in the hash_map (see getNumNodes())
215
Chris Lattner09ff1122002-07-24 21:21:32 +0000216 typedef hash_map<const MachineInstr*, SchedGraphNode*> map_base;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000217public:
Chris Lattner697954c2002-01-20 22:54:45 +0000218 using map_base::iterator;
219 using map_base::const_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000220
221public:
222 //
223 // Accessor methods
224 //
Chris Lattner697954c2002-01-20 22:54:45 +0000225 const std::vector<const BasicBlock*>& getBasicBlocks() const { return bbVec; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000226 const unsigned int getNumNodes() const { return size()+2; }
227 SchedGraphNode* getRoot() const { return graphRoot; }
228 SchedGraphNode* getLeaf() const { return graphLeaf; }
229
230 SchedGraphNode* getGraphNodeForInstr(const MachineInstr* minstr) const {
231 const_iterator onePair = this->find(minstr);
232 return (onePair != this->end())? (*onePair).second : NULL;
233 }
234
235 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000236 // Delete nodes or edges from the graph.
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000237 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000238 void eraseNode (SchedGraphNode* node);
239
240 void eraseIncomingEdges (SchedGraphNode* node,
241 bool addDummyEdges = true);
242
243 void eraseOutgoingEdges (SchedGraphNode* node,
244 bool addDummyEdges = true);
245
246 void eraseIncidentEdges (SchedGraphNode* node,
247 bool addDummyEdges = true);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000248
249 //
250 // Unordered iterators.
251 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
252 //
Chris Lattner697954c2002-01-20 22:54:45 +0000253 using map_base::begin;
254 using map_base::end;
255
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000256 //
257 // Ordered iterators.
258 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
259 //
260 // void postord_init();
261 // postorder_iterator postord_begin();
262 // postorder_iterator postord_end();
263 // const_postorder_iterator postord_begin() const;
264 // const_postorder_iterator postord_end() const;
265
266 //
267 // Debugging support
268 //
269 void dump () const;
270
271private:
272 friend class SchedGraphSet; // give access to ctor
273
274 // disable default constructor and provide a ctor for single-block graphs
275 /*ctor*/ SchedGraph (); // DO NOT IMPLEMENT
276 /*ctor*/ SchedGraph (const BasicBlock* bb,
277 const TargetMachine& target);
278 /*dtor*/ ~SchedGraph ();
279
280 inline void noteGraphNodeForInstr (const MachineInstr* minstr,
281 SchedGraphNode* node)
282 {
283 assert((*this)[minstr] == NULL);
284 (*this)[minstr] = node;
285 }
286
287 //
288 // Graph builder
289 //
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000290 void buildGraph (const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000291
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000292 void buildNodesforBB (const TargetMachine& target,
293 const BasicBlock* bb,
Chris Lattner697954c2002-01-20 22:54:45 +0000294 std::vector<SchedGraphNode*>& memNod,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000295 RegToRefVecMap& regToRefVecMap,
296 ValueToDefVecMap& valueToDefVecMap);
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000297
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000298 void findDefUseInfoAtInstr (const TargetMachine& target,
299 SchedGraphNode* node,
Chris Lattner697954c2002-01-20 22:54:45 +0000300 std::vector<SchedGraphNode*>& memNode,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000301 RegToRefVecMap& regToRefVecMap,
302 ValueToDefVecMap& valueToDefVecMap);
303
Vikram S. Advee64574c2001-11-08 05:20:23 +0000304 void addEdgesForInstruction(const MachineInstr& minstr,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000305 const ValueToDefVecMap& valueToDefVecMap,
306 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000307
308 void addCDEdges (const TerminatorInst* term,
309 const TargetMachine& target);
310
Chris Lattner697954c2002-01-20 22:54:45 +0000311 void addMemEdges (const std::vector<SchedGraphNode*>& memNod,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000312 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000313
Chris Lattner697954c2002-01-20 22:54:45 +0000314 void addCallCCEdges (const std::vector<SchedGraphNode*>& memNod,
Misha Brukmanfce11432002-10-28 00:28:31 +0000315 MachineBasicBlock& bbMvec,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000316 const TargetMachine& target);
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000317
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000318 void addMachineRegEdges (RegToRefVecMap& regToRefVecMap,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000319 const TargetMachine& target);
320
Vikram S. Adve200a4352001-11-12 18:53:43 +0000321 void addEdgesForValue (SchedGraphNode* refNode,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000322 const RefVec& defVec,
Vikram S. Advef43e3362001-10-17 23:55:16 +0000323 const Value* defValue,
Vikram S. Adve200a4352001-11-12 18:53:43 +0000324 bool refNodeIsDef,
Vikram S. Adve0baf1c02002-07-08 22:59:23 +0000325 bool refNodeIsDefAndUse,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000326 const TargetMachine& target);
327
328 void addDummyEdges ();
329};
330
331
332class SchedGraphSet :
333 public NonCopyable,
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000334 private std::vector<SchedGraph*>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000335{
336private:
Chris Lattnere7506a32002-03-23 22:51:58 +0000337 const Function* method;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000338
339public:
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000340 typedef std::vector<SchedGraph*> baseVector;
341 using baseVector::iterator;
342 using baseVector::const_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000343
344public:
Chris Lattnere7506a32002-03-23 22:51:58 +0000345 /*ctor*/ SchedGraphSet (const Function * function,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000346 const TargetMachine& target);
347 /*dtor*/ ~SchedGraphSet ();
348
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000349 // Iterators
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000350 using baseVector::begin;
351 using baseVector::end;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000352
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000353 // Debugging support
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000354 void dump () const;
355
356private:
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000357 inline void addGraph(SchedGraph* graph) {
358 assert(graph != NULL);
359 this->push_back(graph);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000360 }
Vikram S. Adve97fb99b2002-03-24 03:53:03 +0000361
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000362 // Graph builder
Chris Lattnere7506a32002-03-23 22:51:58 +0000363 void buildGraphsForMethod (const Function *F,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000364 const TargetMachine& target);
365};
366
367
368//********************** Sched Graph Iterators *****************************/
369
370// Ok to make it a template because it shd get instantiated at most twice:
371// for <SchedGraphNode, SchedGraphNode::iterator> and
372// for <const SchedGraphNode, SchedGraphNode::const_iterator>.
373//
374template <class _NodeType, class _EdgeType, class _EdgeIter>
Chris Lattner0c0edf82002-07-25 06:17:51 +0000375class SGPredIterator: public bidirectional_iterator<_NodeType, ptrdiff_t> {
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000376protected:
377 _EdgeIter oi;
378public:
Chris Lattner455889a2002-02-12 22:39:50 +0000379 typedef SGPredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000380
Chris Lattner455889a2002-02-12 22:39:50 +0000381 inline SGPredIterator(_EdgeIter startEdge) : oi(startEdge) {}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000382
383 inline bool operator==(const _Self& x) const { return oi == x.oi; }
384 inline bool operator!=(const _Self& x) const { return !operator==(x); }
385
386 // operator*() differs for pred or succ iterator
Chris Lattnercffebdc2001-09-07 21:07:10 +0000387 inline _NodeType* operator*() const { return (*oi)->getSrc(); }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000388 inline _NodeType* operator->() const { return operator*(); }
389
390 inline _EdgeType* getEdge() const { return *(oi); }
391
Chris Lattnercffebdc2001-09-07 21:07:10 +0000392 inline _Self &operator++() { ++oi; return *this; } // Preincrement
393 inline _Self operator++(int) { // Postincrement
394 _Self tmp(*this); ++*this; return tmp;
395 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000396
Chris Lattnercffebdc2001-09-07 21:07:10 +0000397 inline _Self &operator--() { --oi; return *this; } // Predecrement
398 inline _Self operator--(int) { // Postdecrement
399 _Self tmp = *this; --*this; return tmp;
400 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000401};
402
403template <class _NodeType, class _EdgeType, class _EdgeIter>
Chris Lattner0c0edf82002-07-25 06:17:51 +0000404class SGSuccIterator : public bidirectional_iterator<_NodeType, ptrdiff_t> {
Chris Lattnercffebdc2001-09-07 21:07:10 +0000405protected:
406 _EdgeIter oi;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000407public:
Chris Lattner455889a2002-02-12 22:39:50 +0000408 typedef SGSuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000409
Chris Lattner455889a2002-02-12 22:39:50 +0000410 inline SGSuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000411
Chris Lattnercffebdc2001-09-07 21:07:10 +0000412 inline bool operator==(const _Self& x) const { return oi == x.oi; }
413 inline bool operator!=(const _Self& x) const { return !operator==(x); }
414
415 inline _NodeType* operator*() const { return (*oi)->getSink(); }
416 inline _NodeType* operator->() const { return operator*(); }
417
418 inline _EdgeType* getEdge() const { return *(oi); }
419
420 inline _Self &operator++() { ++oi; return *this; } // Preincrement
421 inline _Self operator++(int) { // Postincrement
422 _Self tmp(*this); ++*this; return tmp;
423 }
424
425 inline _Self &operator--() { --oi; return *this; } // Predecrement
426 inline _Self operator--(int) { // Postdecrement
427 _Self tmp = *this; --*this; return tmp;
428 }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000429};
430
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000431//
432// sg_pred_iterator
433// sg_pred_const_iterator
434//
Chris Lattner455889a2002-02-12 22:39:50 +0000435typedef SGPredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000436 sg_pred_iterator;
Chris Lattner455889a2002-02-12 22:39:50 +0000437typedef SGPredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000438 sg_pred_const_iterator;
439
440inline sg_pred_iterator pred_begin( SchedGraphNode *N) {
441 return sg_pred_iterator(N->beginInEdges());
442}
443inline sg_pred_iterator pred_end( SchedGraphNode *N) {
444 return sg_pred_iterator(N->endInEdges());
445}
446inline sg_pred_const_iterator pred_begin(const SchedGraphNode *N) {
447 return sg_pred_const_iterator(N->beginInEdges());
448}
449inline sg_pred_const_iterator pred_end( const SchedGraphNode *N) {
450 return sg_pred_const_iterator(N->endInEdges());
451}
452
453
454//
455// sg_succ_iterator
456// sg_succ_const_iterator
457//
Chris Lattner455889a2002-02-12 22:39:50 +0000458typedef SGSuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000459 sg_succ_iterator;
Chris Lattner455889a2002-02-12 22:39:50 +0000460typedef SGSuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000461 sg_succ_const_iterator;
462
463inline sg_succ_iterator succ_begin( SchedGraphNode *N) {
464 return sg_succ_iterator(N->beginOutEdges());
465}
466inline sg_succ_iterator succ_end( SchedGraphNode *N) {
467 return sg_succ_iterator(N->endOutEdges());
468}
469inline sg_succ_const_iterator succ_begin(const SchedGraphNode *N) {
470 return sg_succ_const_iterator(N->beginOutEdges());
471}
472inline sg_succ_const_iterator succ_end( const SchedGraphNode *N) {
473 return sg_succ_const_iterator(N->endOutEdges());
474}
475
Chris Lattner3ff43872001-09-28 22:56:31 +0000476// Provide specializations of GraphTraits to be able to use graph iterators on
477// the scheduling graph!
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000478//
Chris Lattner3ff43872001-09-28 22:56:31 +0000479template <> struct GraphTraits<SchedGraph*> {
480 typedef SchedGraphNode NodeType;
481 typedef sg_succ_iterator ChildIteratorType;
482
483 static inline NodeType *getEntryNode(SchedGraph *SG) { return SG->getRoot(); }
484 static inline ChildIteratorType child_begin(NodeType *N) {
485 return succ_begin(N);
486 }
487 static inline ChildIteratorType child_end(NodeType *N) {
488 return succ_end(N);
489 }
490};
491
492template <> struct GraphTraits<const SchedGraph*> {
493 typedef const SchedGraphNode NodeType;
494 typedef sg_succ_const_iterator ChildIteratorType;
495
496 static inline NodeType *getEntryNode(const SchedGraph *SG) {
497 return SG->getRoot();
498 }
499 static inline ChildIteratorType child_begin(NodeType *N) {
500 return succ_begin(N);
501 }
502 static inline ChildIteratorType child_end(NodeType *N) {
503 return succ_end(N);
504 }
505};
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000506
507
Chris Lattner697954c2002-01-20 22:54:45 +0000508std::ostream &operator<<(std::ostream& os, const SchedGraphEdge& edge);
509std::ostream &operator<<(std::ostream &os, const SchedGraphNode& node);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000510
511#endif