blob: 8a8a523f004ea37e8d1458e19a4830289fd5080d [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/NonCopyable.h"
24#include "Support/HashExtras.h"
25#include "Support/GraphTraits.h"
Vikram S. Adve78ef1392001-08-28 23:06:02 +000026
27class Value;
28class Instruction;
Chris Lattner3ff43872001-09-28 22:56:31 +000029class TerminatorInst;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000030class BasicBlock;
Chris Lattnere7506a32002-03-23 22:51:58 +000031class Function;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000032class TargetMachine;
33class SchedGraphEdge;
34class SchedGraphNode;
35class SchedGraph;
Vikram S. Adve4a87b382001-09-30 23:37:26 +000036class RegToRefVecMap;
Vikram S. Advec352d2c2001-11-05 04:04:23 +000037class ValueToDefVecMap;
38class RefVec;
Chris Lattnerc0c77082001-09-14 17:55:51 +000039class MachineInstr;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000040class MachineCodeForBasicBlock;
41
Vikram S. Adve78ef1392001-08-28 23:06:02 +000042
43/******************** Exported Data Types and Constants ********************/
44
45typedef int ResourceId;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000046const ResourceId InvalidRID = -1;
47const ResourceId MachineCCRegsRID = -2; // use +ve numbers for actual regs
48const ResourceId MachineIntRegsRID = -3; // use +ve numbers for actual regs
49const ResourceId MachineFPRegsRID = -4; // use +ve numbers for actual regs
Vikram S. Adve78ef1392001-08-28 23:06:02 +000050
51
52//*********************** Public Class Declarations ************************/
53
54class SchedGraphEdge: public NonCopyable {
55public:
56 enum SchedGraphEdgeDepType {
Vikram S. Adve200a4352001-11-12 18:53:43 +000057 CtrlDep, MemoryDep, ValueDep, MachineRegister, MachineResource
Vikram S. Adve78ef1392001-08-28 23:06:02 +000058 };
59 enum DataDepOrderType {
Vikram S. Adved0d79c02001-10-28 21:45:02 +000060 TrueDep = 0x1, AntiDep=0x2, OutputDep=0x4, NonDataDep=0x8
Vikram S. Adve78ef1392001-08-28 23:06:02 +000061 };
62
63protected:
64 SchedGraphNode* src;
65 SchedGraphNode* sink;
66 SchedGraphEdgeDepType depType;
Vikram S. Adved0d79c02001-10-28 21:45:02 +000067 unsigned int depOrderType;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000068 int minDelay; // cached latency (assumes fixed target arch)
69
70 union {
Vikram S. Adve4a87b382001-09-30 23:37:26 +000071 const Value* val;
72 int machineRegNum;
73 ResourceId resourceId;
Vikram S. Adve78ef1392001-08-28 23:06:02 +000074 };
75
76public:
77 // For all constructors, if minDelay is unspecified, minDelay is
78 // set to _src->getLatency().
79 // constructor for CtrlDep or MemoryDep edges, selected by 3rd argument
80 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
81 SchedGraphNode* _sink,
82 SchedGraphEdgeDepType _depType,
Vikram S. Adve200a4352001-11-12 18:53:43 +000083 unsigned int _depOrderType,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000084 int _minDelay = -1);
85
Vikram S. Adve200a4352001-11-12 18:53:43 +000086 // constructor for explicit value dependence (may be true/anti/output)
Vikram S. Adve78ef1392001-08-28 23:06:02 +000087 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
88 SchedGraphNode* _sink,
Vikram S. Adve4a87b382001-09-30 23:37:26 +000089 const Value* _val,
Vikram S. Adve200a4352001-11-12 18:53:43 +000090 unsigned int _depOrderType,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000091 int _minDelay = -1);
92
93 // constructor for machine register dependence
94 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
95 SchedGraphNode* _sink,
96 unsigned int _regNum,
Vikram S. Adve200a4352001-11-12 18:53:43 +000097 unsigned int _depOrderType,
Vikram S. Adve78ef1392001-08-28 23:06:02 +000098 int _minDelay = -1);
99
100 // constructor for any other machine resource dependences.
101 // DataDepOrderType is always NonDataDep. It it not an argument to
102 // avoid overloading ambiguity with previous constructor.
103 /*ctor*/ SchedGraphEdge(SchedGraphNode* _src,
104 SchedGraphNode* _sink,
105 ResourceId _resourceId,
106 int _minDelay = -1);
107
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000108 /*dtor*/ ~SchedGraphEdge();
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000109
110 SchedGraphNode* getSrc () const { return src; }
111 SchedGraphNode* getSink () const { return sink; }
112 int getMinDelay () const { return minDelay; }
113 SchedGraphEdgeDepType getDepType () const { return depType; }
114
115 const Value* getValue () const {
Vikram S. Adve200a4352001-11-12 18:53:43 +0000116 assert(depType == ValueDep); return val;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000117 }
118 int getMachineReg () const {
119 assert(depType == MachineRegister); return machineRegNum;
120 }
121 int getResourceId () const {
122 assert(depType == MachineResource); return resourceId;
123 }
124
125public:
126 //
127 // Debugging support
128 //
Chris Lattner697954c2002-01-20 22:54:45 +0000129 friend std::ostream& operator<<(std::ostream& os, const SchedGraphEdge& edge);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000130
Chris Lattnercffebdc2001-09-07 21:07:10 +0000131 void dump (int indent=0) const;
132
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000133private:
134 // disable default ctor
135 /*ctor*/ SchedGraphEdge(); // DO NOT IMPLEMENT
136};
137
138
139
140class SchedGraphNode: public NonCopyable {
141private:
142 unsigned int nodeId;
Vikram S. Adveaf00d482001-11-12 14:18:01 +0000143 const BasicBlock* bb;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000144 const MachineInstr* minstr;
Chris Lattner697954c2002-01-20 22:54:45 +0000145 std::vector<SchedGraphEdge*> inEdges;
146 std::vector<SchedGraphEdge*> outEdges;
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000147 int origIndexInBB; // original position of machine instr in BB
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000148 int latency;
149
150public:
Chris Lattner697954c2002-01-20 22:54:45 +0000151 typedef std::vector<SchedGraphEdge*>:: iterator iterator;
152 typedef std::vector<SchedGraphEdge*>::const_iterator const_iterator;
153 typedef std::vector<SchedGraphEdge*>:: reverse_iterator reverse_iterator;
154 typedef std::vector<SchedGraphEdge*>::const_reverse_iterator const_reverse_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000155
156public:
157 //
158 // Accessor methods
159 //
160 unsigned int getNodeId () const { return nodeId; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000161 const MachineInstr* getMachineInstr () const { return minstr; }
Vikram S. Advee64574c2001-11-08 05:20:23 +0000162 const MachineOpCode getOpCode () const { return minstr->getOpCode();}
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000163 int getLatency () const { return latency; }
164 unsigned int getNumInEdges () const { return inEdges.size(); }
165 unsigned int getNumOutEdges () const { return outEdges.size(); }
166 bool isDummyNode () const { return (minstr == NULL); }
Vikram S. Adveaf00d482001-11-12 14:18:01 +0000167 const BasicBlock* getBB () const { return bb; }
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000168 int getOrigIndexInBB() const { return origIndexInBB; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000169
170 //
171 // Iterators
172 //
173 iterator beginInEdges () { return inEdges.begin(); }
174 iterator endInEdges () { return inEdges.end(); }
175 iterator beginOutEdges () { return outEdges.begin(); }
176 iterator endOutEdges () { return outEdges.end(); }
177
178 const_iterator beginInEdges () const { return inEdges.begin(); }
179 const_iterator endInEdges () const { return inEdges.end(); }
180 const_iterator beginOutEdges () const { return outEdges.begin(); }
181 const_iterator endOutEdges () const { return outEdges.end(); }
182
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000183public:
184 //
185 // Debugging support
186 //
Chris Lattner697954c2002-01-20 22:54:45 +0000187 friend std::ostream& operator<<(std::ostream& os, const SchedGraphNode& node);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000188
Chris Lattnercffebdc2001-09-07 21:07:10 +0000189 void dump (int indent=0) const;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000190
191private:
192 friend class SchedGraph; // give access for ctor and dtor
193 friend class SchedGraphEdge; // give access for adding edges
194
195 void addInEdge (SchedGraphEdge* edge);
196 void addOutEdge (SchedGraphEdge* edge);
197
198 void removeInEdge (const SchedGraphEdge* edge);
199 void removeOutEdge (const SchedGraphEdge* edge);
200
201 // disable default constructor and provide a ctor for single-block graphs
202 /*ctor*/ SchedGraphNode(); // DO NOT IMPLEMENT
203 /*ctor*/ SchedGraphNode (unsigned int _nodeId,
Vikram S. Adveaf00d482001-11-12 14:18:01 +0000204 const BasicBlock* _bb,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000205 const MachineInstr* _minstr,
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000206 int indexInBB,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000207 const TargetMachine& _target);
208 /*dtor*/ ~SchedGraphNode ();
209};
210
211
212
213class SchedGraph :
214 public NonCopyable,
Chris Lattner697954c2002-01-20 22:54:45 +0000215 private std::hash_map<const MachineInstr*, SchedGraphNode*>
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000216{
217private:
Chris Lattner697954c2002-01-20 22:54:45 +0000218 std::vector<const BasicBlock*> bbVec; // basic blocks included in the graph
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000219 SchedGraphNode* graphRoot; // the root and leaf are not inserted
220 SchedGraphNode* graphLeaf; // in the hash_map (see getNumNodes())
221
Chris Lattner697954c2002-01-20 22:54:45 +0000222 typedef std::hash_map<const MachineInstr*, SchedGraphNode*> map_base;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000223public:
Chris Lattner697954c2002-01-20 22:54:45 +0000224 using map_base::iterator;
225 using map_base::const_iterator;
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000226
227public:
228 //
229 // Accessor methods
230 //
Chris Lattner697954c2002-01-20 22:54:45 +0000231 const std::vector<const BasicBlock*>& getBasicBlocks() const { return bbVec; }
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000232 const unsigned int getNumNodes() const { return size()+2; }
233 SchedGraphNode* getRoot() const { return graphRoot; }
234 SchedGraphNode* getLeaf() const { return graphLeaf; }
235
236 SchedGraphNode* getGraphNodeForInstr(const MachineInstr* minstr) const {
237 const_iterator onePair = this->find(minstr);
238 return (onePair != this->end())? (*onePair).second : NULL;
239 }
240
241 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000242 // Delete nodes or edges from the graph.
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000243 //
Vikram S. Advef0b6d792001-09-18 12:49:26 +0000244 void eraseNode (SchedGraphNode* node);
245
246 void eraseIncomingEdges (SchedGraphNode* node,
247 bool addDummyEdges = true);
248
249 void eraseOutgoingEdges (SchedGraphNode* node,
250 bool addDummyEdges = true);
251
252 void eraseIncidentEdges (SchedGraphNode* node,
253 bool addDummyEdges = true);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000254
255 //
256 // Unordered iterators.
257 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
258 //
Chris Lattner697954c2002-01-20 22:54:45 +0000259 using map_base::begin;
260 using map_base::end;
261
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000262 //
263 // Ordered iterators.
264 // Return values is pair<const MachineIntr*,SchedGraphNode*>.
265 //
266 // void postord_init();
267 // postorder_iterator postord_begin();
268 // postorder_iterator postord_end();
269 // const_postorder_iterator postord_begin() const;
270 // const_postorder_iterator postord_end() const;
271
272 //
273 // Debugging support
274 //
275 void dump () const;
276
277private:
278 friend class SchedGraphSet; // give access to ctor
279
280 // disable default constructor and provide a ctor for single-block graphs
281 /*ctor*/ SchedGraph (); // DO NOT IMPLEMENT
282 /*ctor*/ SchedGraph (const BasicBlock* bb,
283 const TargetMachine& target);
284 /*dtor*/ ~SchedGraph ();
285
286 inline void noteGraphNodeForInstr (const MachineInstr* minstr,
287 SchedGraphNode* node)
288 {
289 assert((*this)[minstr] == NULL);
290 (*this)[minstr] = node;
291 }
292
293 //
294 // Graph builder
295 //
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000296 void buildGraph (const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000297
Vikram S. Adve5b43af92001-11-11 01:23:27 +0000298 void buildNodesforBB (const TargetMachine& target,
299 const BasicBlock* bb,
Chris Lattner697954c2002-01-20 22:54:45 +0000300 std::vector<SchedGraphNode*>& memNod,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000301 RegToRefVecMap& regToRefVecMap,
302 ValueToDefVecMap& valueToDefVecMap);
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000303
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000304 void findDefUseInfoAtInstr (const TargetMachine& target,
305 SchedGraphNode* node,
Chris Lattner697954c2002-01-20 22:54:45 +0000306 std::vector<SchedGraphNode*>& memNode,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000307 RegToRefVecMap& regToRefVecMap,
308 ValueToDefVecMap& valueToDefVecMap);
309
Vikram S. Advee64574c2001-11-08 05:20:23 +0000310 void addEdgesForInstruction(const MachineInstr& minstr,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000311 const ValueToDefVecMap& valueToDefVecMap,
312 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000313
314 void addCDEdges (const TerminatorInst* term,
315 const TargetMachine& target);
316
Chris Lattner697954c2002-01-20 22:54:45 +0000317 void addMemEdges (const std::vector<SchedGraphNode*>& memNod,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000318 const TargetMachine& target);
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000319
Chris Lattner697954c2002-01-20 22:54:45 +0000320 void addCallCCEdges (const std::vector<SchedGraphNode*>& memNod,
Vikram S. Advee64574c2001-11-08 05:20:23 +0000321 MachineCodeForBasicBlock& bbMvec,
322 const TargetMachine& target);
Vikram S. Adved0d79c02001-10-28 21:45:02 +0000323
Vikram S. Adve4a87b382001-09-30 23:37:26 +0000324 void addMachineRegEdges (RegToRefVecMap& regToRefVecMap,
Vikram S. Adve78ef1392001-08-28 23:06:02 +0000325 const TargetMachine& target);
326
Vikram S. Adve200a4352001-11-12 18:53:43 +0000327 void addEdgesForValue (SchedGraphNode* refNode,
Vikram S. Advec352d2c2001-11-05 04:04:23 +0000328 const RefVec& defVec,
Vikram S. Advef43e3362001-10-17 23:55:16 +0000329 const Value* defValue,
Vikram S. Adve200a4352001-11-12 18:53:43 +0000330 bool refNodeIsDef,
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