Chris Lattner | 179cdfb | 2002-08-09 20:08:03 +0000 | [diff] [blame] | 1 | //===-- 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. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 13 | |
| 14 | #ifndef LLVM_CODEGEN_SCHEDGRAPH_H |
| 15 | #define LLVM_CODEGEN_SCHEDGRAPH_H |
| 16 | |
Vikram S. Adve | e64574c | 2001-11-08 05:20:23 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineInstr.h" |
Chris Lattner | cee8f9a | 2001-11-27 00:03:19 +0000 | [diff] [blame] | 18 | #include "Support/GraphTraits.h" |
Chris Lattner | e5a61cc | 2003-07-26 23:22:19 +0000 | [diff] [blame] | 19 | #include "Support/hash_map" |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 20 | #include "llvm/Transforms/Scalar.h" |
| 21 | #include "llvm/CodeGen/SchedGraphCommon.h" |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 22 | |
Vikram S. Adve | 4a87b38 | 2001-09-30 23:37:26 +0000 | [diff] [blame] | 23 | class RegToRefVecMap; |
Vikram S. Adve | c352d2c | 2001-11-05 04:04:23 +0000 | [diff] [blame] | 24 | class ValueToDefVecMap; |
| 25 | class RefVec; |
Vikram S. Adve | d0d79c0 | 2001-10-28 21:45:02 +0000 | [diff] [blame] | 26 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 27 | class SchedGraphNode : public SchedGraphNodeCommon { |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 28 | |
Vikram S. Adve | 5b43af9 | 2001-11-11 01:23:27 +0000 | [diff] [blame] | 29 | int origIndexInBB; // original position of machine instr in BB |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 30 | MachineBasicBlock *MBB; |
| 31 | const MachineInstr *MI; |
Chris Lattner | 9efc4d6 | 2003-06-02 22:45:07 +0000 | [diff] [blame] | 32 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 33 | |
| 34 | SchedGraphNode (unsigned nodeId, MachineBasicBlock *mbb, |
| 35 | int indexInBB, const TargetMachine& Target); |
| 36 | ~SchedGraphNode (); |
| 37 | |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 38 | friend class SchedGraph; // give access for ctor and dtor |
| 39 | friend class SchedGraphEdge; // give access for adding edges |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 40 | |
| 41 | public: |
| 42 | // Accessor methods |
| 43 | const MachineInstr* getMachineInstr () const { return MI; } |
| 44 | const MachineOpCode getOpCode () const { return MI->getOpCode(); } |
| 45 | bool isDummyNode () const { return (MI == NULL); } |
| 46 | MachineBasicBlock &getMachineBasicBlock() const { return *MBB; } |
| 47 | |
| 48 | int getOrigIndexInBB() const { return origIndexInBB; } |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 51 | class SchedGraph : public SchedGraphCommon { |
| 52 | MachineBasicBlock &MBB; |
| 53 | hash_map<const MachineInstr*, SchedGraphNode*> GraphMap; |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 54 | |
| 55 | public: |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 56 | typedef hash_map<const MachineInstr*, SchedGraphNode*>::const_iterator iterator; |
| 57 | typedef hash_map<const MachineInstr*, SchedGraphNode*>::const_iterator const_iterator; |
| 58 | |
| 59 | MachineBasicBlock& getBasicBlock() const{return MBB;} |
| 60 | const unsigned int getNumNodes() const { return GraphMap.size()+2; } |
| 61 | SchedGraphNode* getGraphNodeForInstr(const MachineInstr* MI) const { |
| 62 | const_iterator onePair = find(MI); |
| 63 | return (onePair != end())? onePair->second : NULL; |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 66 | // Debugging support |
| 67 | void dump () const; |
Vikram S. Adve | f0b6d79 | 2001-09-18 12:49:26 +0000 | [diff] [blame] | 68 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 69 | protected: |
| 70 | SchedGraph(MachineBasicBlock& mbb, const TargetMachine& TM); |
| 71 | ~SchedGraph(); |
| 72 | |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 73 | // Unordered iterators. |
| 74 | // Return values is pair<const MachineIntr*,SchedGraphNode*>. |
| 75 | // |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 76 | hash_map<const MachineInstr*, SchedGraphNode*>::const_iterator begin() const { |
| 77 | return GraphMap.begin(); |
| 78 | } |
| 79 | hash_map<const MachineInstr*, SchedGraphNode*>::const_iterator end() const { |
| 80 | return GraphMap.end(); |
| 81 | } |
| 82 | |
| 83 | unsigned size() { return GraphMap.size(); } |
| 84 | iterator find(const MachineInstr *MI) const { return GraphMap.find(MI); } |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 85 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 86 | SchedGraphNode *&operator[](const MachineInstr *MI) { |
| 87 | return GraphMap[MI]; |
| 88 | } |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 89 | |
| 90 | private: |
| 91 | friend class SchedGraphSet; // give access to ctor |
| 92 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 93 | |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 94 | |
| 95 | inline void noteGraphNodeForInstr (const MachineInstr* minstr, |
| 96 | SchedGraphNode* node) |
| 97 | { |
| 98 | assert((*this)[minstr] == NULL); |
| 99 | (*this)[minstr] = node; |
| 100 | } |
| 101 | |
| 102 | // |
| 103 | // Graph builder |
| 104 | // |
Vikram S. Adve | d0d79c0 | 2001-10-28 21:45:02 +0000 | [diff] [blame] | 105 | void buildGraph (const TargetMachine& target); |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 106 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 107 | void buildNodesForBB (const TargetMachine& target, |
Chris Lattner | fb3a0aed | 2002-10-28 18:50:08 +0000 | [diff] [blame] | 108 | MachineBasicBlock &MBB, |
Vikram S. Adve | 7952d60 | 2003-05-31 07:37:05 +0000 | [diff] [blame] | 109 | std::vector<SchedGraphNode*>& memNV, |
| 110 | std::vector<SchedGraphNode*>& callNV, |
Vikram S. Adve | c352d2c | 2001-11-05 04:04:23 +0000 | [diff] [blame] | 111 | RegToRefVecMap& regToRefVecMap, |
| 112 | ValueToDefVecMap& valueToDefVecMap); |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 113 | |
Vikram S. Adve | 4a87b38 | 2001-09-30 23:37:26 +0000 | [diff] [blame] | 114 | |
Vikram S. Adve | c352d2c | 2001-11-05 04:04:23 +0000 | [diff] [blame] | 115 | void findDefUseInfoAtInstr (const TargetMachine& target, |
| 116 | SchedGraphNode* node, |
Vikram S. Adve | 7952d60 | 2003-05-31 07:37:05 +0000 | [diff] [blame] | 117 | std::vector<SchedGraphNode*>& memNV, |
| 118 | std::vector<SchedGraphNode*>& callNV, |
Vikram S. Adve | c352d2c | 2001-11-05 04:04:23 +0000 | [diff] [blame] | 119 | RegToRefVecMap& regToRefVecMap, |
| 120 | ValueToDefVecMap& valueToDefVecMap); |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 121 | |
Vikram S. Adve | c352d2c | 2001-11-05 04:04:23 +0000 | [diff] [blame] | 122 | |
Vikram S. Adve | e64574c | 2001-11-08 05:20:23 +0000 | [diff] [blame] | 123 | void addEdgesForInstruction(const MachineInstr& minstr, |
Vikram S. Adve | c352d2c | 2001-11-05 04:04:23 +0000 | [diff] [blame] | 124 | const ValueToDefVecMap& valueToDefVecMap, |
| 125 | const TargetMachine& target); |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 126 | |
| 127 | void addCDEdges (const TerminatorInst* term, |
| 128 | const TargetMachine& target); |
| 129 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 130 | void addMemEdges (const std::vector<SchedGraphNode*>& memNod, |
Vikram S. Adve | e64574c | 2001-11-08 05:20:23 +0000 | [diff] [blame] | 131 | const TargetMachine& target); |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 132 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 133 | void addCallCCEdges (const std::vector<SchedGraphNode*>& memNod, |
| 134 | MachineBasicBlock& bbMvec, |
| 135 | const TargetMachine& target); |
Vikram S. Adve | 7952d60 | 2003-05-31 07:37:05 +0000 | [diff] [blame] | 136 | void addCallDepEdges (const std::vector<SchedGraphNode*>& callNV, |
Vikram S. Adve | e64574c | 2001-11-08 05:20:23 +0000 | [diff] [blame] | 137 | const TargetMachine& target); |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 138 | |
Vikram S. Adve | 4a87b38 | 2001-09-30 23:37:26 +0000 | [diff] [blame] | 139 | void addMachineRegEdges (RegToRefVecMap& regToRefVecMap, |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 140 | const TargetMachine& target); |
| 141 | |
Vikram S. Adve | 200a435 | 2001-11-12 18:53:43 +0000 | [diff] [blame] | 142 | void addEdgesForValue (SchedGraphNode* refNode, |
Vikram S. Adve | c352d2c | 2001-11-05 04:04:23 +0000 | [diff] [blame] | 143 | const RefVec& defVec, |
Vikram S. Adve | f43e336 | 2001-10-17 23:55:16 +0000 | [diff] [blame] | 144 | const Value* defValue, |
Vikram S. Adve | 200a435 | 2001-11-12 18:53:43 +0000 | [diff] [blame] | 145 | bool refNodeIsDef, |
Vikram S. Adve | 0baf1c0 | 2002-07-08 22:59:23 +0000 | [diff] [blame] | 146 | bool refNodeIsDefAndUse, |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 147 | const TargetMachine& target); |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 148 | void addDummyEdges(); |
| 149 | |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | |
Chris Lattner | 9efc4d6 | 2003-06-02 22:45:07 +0000 | [diff] [blame] | 153 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 154 | class SchedGraphSet { |
| 155 | const Function* function; |
| 156 | std::vector<SchedGraph*> Graphs; |
| 157 | |
| 158 | // Graph builder |
| 159 | void buildGraphsForMethod (const Function *F, const TargetMachine& target); |
| 160 | |
| 161 | inline void addGraph(SchedGraph* graph) { |
| 162 | assert(graph != NULL); |
| 163 | Graphs.push_back(graph); |
| 164 | } |
| 165 | |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 166 | public: |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 167 | SchedGraphSet(const Function * function, const TargetMachine& target); |
Chris Lattner | 9efc4d6 | 2003-06-02 22:45:07 +0000 | [diff] [blame] | 168 | ~SchedGraphSet(); |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 169 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 170 | //iterators |
| 171 | typedef std::vector<SchedGraph*>::const_iterator iterator; |
| 172 | typedef std::vector<SchedGraph*>::const_iterator const_iterator; |
| 173 | |
| 174 | std::vector<SchedGraph*>::const_iterator begin() const { return Graphs.begin(); } |
| 175 | std::vector<SchedGraph*>::const_iterator end() const { return Graphs.end(); } |
| 176 | |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 177 | // Debugging support |
Chris Lattner | 9efc4d6 | 2003-06-02 22:45:07 +0000 | [diff] [blame] | 178 | void dump() const; |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 182 | |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 183 | //********************** Sched Graph Iterators *****************************/ |
| 184 | |
| 185 | // Ok to make it a template because it shd get instantiated at most twice: |
| 186 | // for <SchedGraphNode, SchedGraphNode::iterator> and |
| 187 | // for <const SchedGraphNode, SchedGraphNode::const_iterator>. |
| 188 | // |
| 189 | template <class _NodeType, class _EdgeType, class _EdgeIter> |
Chris Lattner | 0c0edf8 | 2002-07-25 06:17:51 +0000 | [diff] [blame] | 190 | class SGPredIterator: public bidirectional_iterator<_NodeType, ptrdiff_t> { |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 191 | protected: |
| 192 | _EdgeIter oi; |
| 193 | public: |
Chris Lattner | 455889a | 2002-02-12 22:39:50 +0000 | [diff] [blame] | 194 | typedef SGPredIterator<_NodeType, _EdgeType, _EdgeIter> _Self; |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 195 | |
Chris Lattner | 455889a | 2002-02-12 22:39:50 +0000 | [diff] [blame] | 196 | inline SGPredIterator(_EdgeIter startEdge) : oi(startEdge) {} |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 197 | |
| 198 | inline bool operator==(const _Self& x) const { return oi == x.oi; } |
| 199 | inline bool operator!=(const _Self& x) const { return !operator==(x); } |
| 200 | |
| 201 | // operator*() differs for pred or succ iterator |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 202 | inline _NodeType* operator*() const { return (_NodeType*)(*oi)->getSrc(); } |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 203 | inline _NodeType* operator->() const { return operator*(); } |
| 204 | |
| 205 | inline _EdgeType* getEdge() const { return *(oi); } |
| 206 | |
Chris Lattner | cffebdc | 2001-09-07 21:07:10 +0000 | [diff] [blame] | 207 | inline _Self &operator++() { ++oi; return *this; } // Preincrement |
| 208 | inline _Self operator++(int) { // Postincrement |
| 209 | _Self tmp(*this); ++*this; return tmp; |
| 210 | } |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 211 | |
Chris Lattner | cffebdc | 2001-09-07 21:07:10 +0000 | [diff] [blame] | 212 | inline _Self &operator--() { --oi; return *this; } // Predecrement |
| 213 | inline _Self operator--(int) { // Postdecrement |
| 214 | _Self tmp = *this; --*this; return tmp; |
| 215 | } |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | template <class _NodeType, class _EdgeType, class _EdgeIter> |
Chris Lattner | 0c0edf8 | 2002-07-25 06:17:51 +0000 | [diff] [blame] | 219 | class SGSuccIterator : public bidirectional_iterator<_NodeType, ptrdiff_t> { |
Chris Lattner | cffebdc | 2001-09-07 21:07:10 +0000 | [diff] [blame] | 220 | protected: |
| 221 | _EdgeIter oi; |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 222 | public: |
Chris Lattner | 455889a | 2002-02-12 22:39:50 +0000 | [diff] [blame] | 223 | typedef SGSuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self; |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 224 | |
Chris Lattner | 455889a | 2002-02-12 22:39:50 +0000 | [diff] [blame] | 225 | inline SGSuccIterator(_EdgeIter startEdge) : oi(startEdge) {} |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 226 | |
Chris Lattner | cffebdc | 2001-09-07 21:07:10 +0000 | [diff] [blame] | 227 | inline bool operator==(const _Self& x) const { return oi == x.oi; } |
| 228 | inline bool operator!=(const _Self& x) const { return !operator==(x); } |
| 229 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 230 | inline _NodeType* operator*() const { return (_NodeType*)(*oi)->getSink(); } |
Chris Lattner | cffebdc | 2001-09-07 21:07:10 +0000 | [diff] [blame] | 231 | inline _NodeType* operator->() const { return operator*(); } |
| 232 | |
| 233 | inline _EdgeType* getEdge() const { return *(oi); } |
| 234 | |
| 235 | inline _Self &operator++() { ++oi; return *this; } // Preincrement |
| 236 | inline _Self operator++(int) { // Postincrement |
| 237 | _Self tmp(*this); ++*this; return tmp; |
| 238 | } |
| 239 | |
| 240 | inline _Self &operator--() { --oi; return *this; } // Predecrement |
| 241 | inline _Self operator--(int) { // Postdecrement |
| 242 | _Self tmp = *this; --*this; return tmp; |
| 243 | } |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 244 | }; |
| 245 | |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 246 | // |
| 247 | // sg_pred_iterator |
| 248 | // sg_pred_const_iterator |
| 249 | // |
Chris Lattner | 455889a | 2002-02-12 22:39:50 +0000 | [diff] [blame] | 250 | typedef SGPredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator> |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 251 | sg_pred_iterator; |
Chris Lattner | 455889a | 2002-02-12 22:39:50 +0000 | [diff] [blame] | 252 | typedef SGPredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator> |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 253 | sg_pred_const_iterator; |
| 254 | |
| 255 | inline sg_pred_iterator pred_begin( SchedGraphNode *N) { |
| 256 | return sg_pred_iterator(N->beginInEdges()); |
| 257 | } |
| 258 | inline sg_pred_iterator pred_end( SchedGraphNode *N) { |
| 259 | return sg_pred_iterator(N->endInEdges()); |
| 260 | } |
| 261 | inline sg_pred_const_iterator pred_begin(const SchedGraphNode *N) { |
| 262 | return sg_pred_const_iterator(N->beginInEdges()); |
| 263 | } |
| 264 | inline sg_pred_const_iterator pred_end( const SchedGraphNode *N) { |
| 265 | return sg_pred_const_iterator(N->endInEdges()); |
| 266 | } |
| 267 | |
| 268 | |
| 269 | // |
| 270 | // sg_succ_iterator |
| 271 | // sg_succ_const_iterator |
| 272 | // |
Chris Lattner | 455889a | 2002-02-12 22:39:50 +0000 | [diff] [blame] | 273 | typedef SGSuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator> |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 274 | sg_succ_iterator; |
Chris Lattner | 455889a | 2002-02-12 22:39:50 +0000 | [diff] [blame] | 275 | typedef SGSuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator> |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 276 | sg_succ_const_iterator; |
| 277 | |
| 278 | inline sg_succ_iterator succ_begin( SchedGraphNode *N) { |
| 279 | return sg_succ_iterator(N->beginOutEdges()); |
| 280 | } |
| 281 | inline sg_succ_iterator succ_end( SchedGraphNode *N) { |
| 282 | return sg_succ_iterator(N->endOutEdges()); |
| 283 | } |
| 284 | inline sg_succ_const_iterator succ_begin(const SchedGraphNode *N) { |
| 285 | return sg_succ_const_iterator(N->beginOutEdges()); |
| 286 | } |
| 287 | inline sg_succ_const_iterator succ_end( const SchedGraphNode *N) { |
| 288 | return sg_succ_const_iterator(N->endOutEdges()); |
| 289 | } |
| 290 | |
Chris Lattner | 3ff4387 | 2001-09-28 22:56:31 +0000 | [diff] [blame] | 291 | // Provide specializations of GraphTraits to be able to use graph iterators on |
| 292 | // the scheduling graph! |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 293 | // |
Chris Lattner | 3ff4387 | 2001-09-28 22:56:31 +0000 | [diff] [blame] | 294 | template <> struct GraphTraits<SchedGraph*> { |
| 295 | typedef SchedGraphNode NodeType; |
| 296 | typedef sg_succ_iterator ChildIteratorType; |
| 297 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 298 | static inline NodeType *getEntryNode(SchedGraph *SG) { return (NodeType*)SG->getRoot(); } |
Chris Lattner | 3ff4387 | 2001-09-28 22:56:31 +0000 | [diff] [blame] | 299 | static inline ChildIteratorType child_begin(NodeType *N) { |
| 300 | return succ_begin(N); |
| 301 | } |
| 302 | static inline ChildIteratorType child_end(NodeType *N) { |
| 303 | return succ_end(N); |
| 304 | } |
| 305 | }; |
| 306 | |
| 307 | template <> struct GraphTraits<const SchedGraph*> { |
| 308 | typedef const SchedGraphNode NodeType; |
| 309 | typedef sg_succ_const_iterator ChildIteratorType; |
| 310 | |
| 311 | static inline NodeType *getEntryNode(const SchedGraph *SG) { |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 312 | return (NodeType*)SG->getRoot(); |
Chris Lattner | 3ff4387 | 2001-09-28 22:56:31 +0000 | [diff] [blame] | 313 | } |
| 314 | static inline ChildIteratorType child_begin(NodeType *N) { |
| 315 | return succ_begin(N); |
| 316 | } |
| 317 | static inline ChildIteratorType child_end(NodeType *N) { |
| 318 | return succ_end(N); |
| 319 | } |
| 320 | }; |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 321 | |
| 322 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 323 | std::ostream &operator<<(std::ostream& os, const SchedGraphEdge& edge); |
| 324 | std::ostream &operator<<(std::ostream &os, const SchedGraphNode& node); |
Vikram S. Adve | 78ef139 | 2001-08-28 23:06:02 +0000 | [diff] [blame] | 325 | |
| 326 | #endif |