Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 1 | //===- SchedGraphCommon.cpp - Scheduling Graphs Base Class- ---------------===// |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 9 | // |
| 10 | // Scheduling graph base class that contains common information for SchedGraph |
| 11 | // and ModuloSchedGraph scheduling graphs. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/SchedGraphCommon.h" |
| 16 | #include "Support/STLExtras.h" |
| 17 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 18 | namespace llvm { |
| 19 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 20 | class SchedGraphCommon; |
| 21 | |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 22 | // |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 23 | // class SchedGraphEdge |
| 24 | // |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 25 | SchedGraphEdge::SchedGraphEdge(SchedGraphNodeCommon* _src, |
| 26 | SchedGraphNodeCommon* _sink, |
| 27 | SchedGraphEdgeDepType _depType, |
| 28 | unsigned int _depOrderType, |
| 29 | int _minDelay) |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 30 | : src(_src), sink(_sink), depType(_depType), depOrderType(_depOrderType), |
| 31 | minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()), val(NULL) { |
| 32 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 33 | iteDiff=0; |
| 34 | assert(src != sink && "Self-loop in scheduling graph!"); |
| 35 | src->addOutEdge(this); |
| 36 | sink->addInEdge(this); |
| 37 | } |
| 38 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 39 | SchedGraphEdge::SchedGraphEdge(SchedGraphNodeCommon* _src, |
| 40 | SchedGraphNodeCommon* _sink, |
| 41 | const Value* _val, |
| 42 | unsigned int _depOrderType, |
| 43 | int _minDelay) |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 44 | : src(_src), sink(_sink), depType(ValueDep), depOrderType(_depOrderType), |
| 45 | minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()), val(_val) { |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 46 | iteDiff=0; |
| 47 | assert(src != sink && "Self-loop in scheduling graph!"); |
| 48 | src->addOutEdge(this); |
| 49 | sink->addInEdge(this); |
| 50 | } |
| 51 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 52 | SchedGraphEdge::SchedGraphEdge(SchedGraphNodeCommon* _src, |
| 53 | SchedGraphNodeCommon* _sink, |
| 54 | unsigned int _regNum, |
| 55 | unsigned int _depOrderType, |
| 56 | int _minDelay) |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 57 | : src(_src), sink(_sink), depType(MachineRegister), |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 58 | depOrderType(_depOrderType), |
| 59 | minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()), |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 60 | machineRegNum(_regNum) { |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 61 | iteDiff=0; |
| 62 | assert(src != sink && "Self-loop in scheduling graph!"); |
| 63 | src->addOutEdge(this); |
| 64 | sink->addInEdge(this); |
| 65 | } |
| 66 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 67 | SchedGraphEdge::SchedGraphEdge(SchedGraphNodeCommon* _src, |
| 68 | SchedGraphNodeCommon* _sink, |
| 69 | ResourceId _resourceId, |
| 70 | int _minDelay) |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 71 | : src(_src), sink(_sink), depType(MachineResource), depOrderType(NonDataDep), |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 72 | minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()), |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 73 | resourceId(_resourceId) { |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 74 | iteDiff=0; |
| 75 | assert(src != sink && "Self-loop in scheduling graph!"); |
| 76 | src->addOutEdge(this); |
| 77 | sink->addInEdge(this); |
| 78 | } |
| 79 | |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 80 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 81 | void SchedGraphEdge::dump(int indent) const { |
| 82 | std::cerr << std::string(indent*2, ' ') << *this; |
| 83 | } |
| 84 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 85 | /*dtor*/ |
| 86 | SchedGraphNodeCommon::~SchedGraphNodeCommon() |
| 87 | { |
| 88 | // for each node, delete its out-edges |
| 89 | std::for_each(beginOutEdges(), endOutEdges(), |
| 90 | deleter<SchedGraphEdge>); |
| 91 | } |
| 92 | |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 93 | void SchedGraphNodeCommon::removeInEdge(const SchedGraphEdge* edge) { |
| 94 | assert(edge->getSink() == this); |
| 95 | |
| 96 | for (iterator I = beginInEdges(); I != endInEdges(); ++I) |
| 97 | if ((*I) == edge) { |
| 98 | inEdges.erase(I); |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | void SchedGraphNodeCommon::removeOutEdge(const SchedGraphEdge* edge) { |
| 104 | assert(edge->getSrc() == this); |
| 105 | |
| 106 | for (iterator I = beginOutEdges(); I != endOutEdges(); ++I) |
| 107 | if ((*I) == edge) { |
| 108 | outEdges.erase(I); |
| 109 | break; |
| 110 | } |
| 111 | } |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 112 | |
| 113 | void SchedGraphNodeCommon::dump(int indent) const { |
| 114 | std::cerr << std::string(indent*2, ' ') << *this; |
| 115 | } |
| 116 | |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 117 | //class SchedGraphCommon |
| 118 | |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 119 | SchedGraphCommon::~SchedGraphCommon() { |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 120 | delete graphRoot; |
| 121 | delete graphLeaf; |
| 122 | } |
| 123 | |
| 124 | |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 125 | void SchedGraphCommon::eraseIncomingEdges(SchedGraphNodeCommon* node, |
| 126 | bool addDummyEdges) { |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 127 | // Delete and disconnect all in-edges for the node |
| 128 | for (SchedGraphNodeCommon::iterator I = node->beginInEdges(); |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 129 | I != node->endInEdges(); ++I) { |
| 130 | SchedGraphNodeCommon* srcNode = (*I)->getSrc(); |
| 131 | srcNode->removeOutEdge(*I); |
| 132 | delete *I; |
| 133 | |
| 134 | if (addDummyEdges && srcNode != getRoot() && |
| 135 | srcNode->beginOutEdges() == srcNode->endOutEdges()) { |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 136 | |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 137 | // srcNode has no more out edges, so add an edge to dummy EXIT node |
| 138 | assert(node != getLeaf() && "Adding edge that was just removed?"); |
| 139 | (void) new SchedGraphEdge(srcNode, getLeaf(), |
| 140 | SchedGraphEdge::CtrlDep, |
| 141 | SchedGraphEdge::NonDataDep, 0); |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 142 | } |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 143 | } |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 144 | |
| 145 | node->inEdges.clear(); |
| 146 | } |
| 147 | |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 148 | void SchedGraphCommon::eraseOutgoingEdges(SchedGraphNodeCommon* node, |
| 149 | bool addDummyEdges) { |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 150 | // Delete and disconnect all out-edges for the node |
| 151 | for (SchedGraphNodeCommon::iterator I = node->beginOutEdges(); |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 152 | I != node->endOutEdges(); ++I) { |
| 153 | SchedGraphNodeCommon* sinkNode = (*I)->getSink(); |
| 154 | sinkNode->removeInEdge(*I); |
| 155 | delete *I; |
| 156 | |
| 157 | if (addDummyEdges && |
| 158 | sinkNode != getLeaf() && |
| 159 | sinkNode->beginInEdges() == sinkNode->endInEdges()) { |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 160 | |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 161 | //sinkNode has no more in edges, so add an edge from dummy ENTRY node |
| 162 | assert(node != getRoot() && "Adding edge that was just removed?"); |
| 163 | (void) new SchedGraphEdge(getRoot(), sinkNode, |
| 164 | SchedGraphEdge::CtrlDep, |
| 165 | SchedGraphEdge::NonDataDep, 0); |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 166 | } |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 167 | } |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 168 | |
| 169 | node->outEdges.clear(); |
| 170 | } |
| 171 | |
Tanya Lattner | c50ee55 | 2003-08-27 02:42:58 +0000 | [diff] [blame] | 172 | void SchedGraphCommon::eraseIncidentEdges(SchedGraphNodeCommon* node, |
| 173 | bool addDummyEdges) { |
Tanya Lattner | b6489f3 | 2003-08-25 22:42:20 +0000 | [diff] [blame] | 174 | this->eraseIncomingEdges(node, addDummyEdges); |
| 175 | this->eraseOutgoingEdges(node, addDummyEdges); |
| 176 | } |
| 177 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 178 | } // End llvm namespace |