1 #include "llvm/CodeGen/SchedGraphCommon.h"
2 #include "Support/STLExtras.h"
4 class SchedGraphCommon;
7 // class SchedGraphEdge
11 SchedGraphEdge::SchedGraphEdge(SchedGraphNodeCommon* _src,
12 SchedGraphNodeCommon* _sink,
13 SchedGraphEdgeDepType _depType,
14 unsigned int _depOrderType,
19 depOrderType(_depOrderType),
20 minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()),
24 assert(src != sink && "Self-loop in scheduling graph!");
25 src->addOutEdge(this);
26 sink->addInEdge(this);
31 SchedGraphEdge::SchedGraphEdge(SchedGraphNodeCommon* _src,
32 SchedGraphNodeCommon* _sink,
34 unsigned int _depOrderType,
39 depOrderType(_depOrderType),
40 minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()),
44 assert(src != sink && "Self-loop in scheduling graph!");
45 src->addOutEdge(this);
46 sink->addInEdge(this);
51 SchedGraphEdge::SchedGraphEdge(SchedGraphNodeCommon* _src,
52 SchedGraphNodeCommon* _sink,
54 unsigned int _depOrderType,
58 depType(MachineRegister),
59 depOrderType(_depOrderType),
60 minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()),
61 machineRegNum(_regNum)
64 assert(src != sink && "Self-loop in scheduling graph!");
65 src->addOutEdge(this);
66 sink->addInEdge(this);
71 SchedGraphEdge::SchedGraphEdge(SchedGraphNodeCommon* _src,
72 SchedGraphNodeCommon* _sink,
73 ResourceId _resourceId,
77 depType(MachineResource),
78 depOrderType(NonDataDep),
79 minDelay((_minDelay >= 0)? _minDelay : _src->getLatency()),
80 resourceId(_resourceId)
83 assert(src != sink && "Self-loop in scheduling graph!");
84 src->addOutEdge(this);
85 sink->addInEdge(this);
89 SchedGraphEdge::~SchedGraphEdge()
93 void SchedGraphEdge::dump(int indent) const {
94 std::cerr << std::string(indent*2, ' ') << *this;
101 SchedGraphNodeCommon::SchedGraphNodeCommon(unsigned _nodeId)
108 SchedGraphNodeCommon::~SchedGraphNodeCommon()
110 // for each node, delete its out-edges
111 std::for_each(beginOutEdges(), endOutEdges(),
112 deleter<SchedGraphEdge>);
116 void SchedGraphNodeCommon::dump(int indent) const {
117 std::cerr << std::string(indent*2, ' ') << *this;
122 SchedGraphNodeCommon::addInEdge(SchedGraphEdge* edge)
124 inEdges.push_back(edge);
129 SchedGraphNodeCommon::addOutEdge(SchedGraphEdge* edge)
131 outEdges.push_back(edge);
135 SchedGraphNodeCommon::removeInEdge(const SchedGraphEdge* edge)
137 assert(edge->getSink() == this);
139 for (iterator I = beginInEdges(); I != endInEdges(); ++I)
148 SchedGraphNodeCommon::removeOutEdge(const SchedGraphEdge* edge)
150 assert(edge->getSrc() == this);
152 for (iterator I = beginOutEdges(); I != endOutEdges(); ++I)
161 //class SchedGraphCommon
164 SchedGraphCommon::SchedGraphCommon()
170 SchedGraphCommon::~SchedGraphCommon()
179 SchedGraphCommon::eraseIncomingEdges(SchedGraphNodeCommon* node, bool addDummyEdges)
181 // Delete and disconnect all in-edges for the node
182 for (SchedGraphNodeCommon::iterator I = node->beginInEdges();
183 I != node->endInEdges(); ++I)
185 SchedGraphNodeCommon* srcNode = (*I)->getSrc();
186 srcNode->removeOutEdge(*I);
190 srcNode != getRoot() &&
191 srcNode->beginOutEdges() == srcNode->endOutEdges())
192 { // srcNode has no more out edges, so add an edge to dummy EXIT node
193 assert(node != getLeaf() && "Adding edge that was just removed?");
194 (void) new SchedGraphEdge(srcNode, getLeaf(),
195 SchedGraphEdge::CtrlDep, SchedGraphEdge::NonDataDep, 0);
199 node->inEdges.clear();
203 SchedGraphCommon::eraseOutgoingEdges(SchedGraphNodeCommon* node, bool addDummyEdges)
205 // Delete and disconnect all out-edges for the node
206 for (SchedGraphNodeCommon::iterator I = node->beginOutEdges();
207 I != node->endOutEdges(); ++I)
209 SchedGraphNodeCommon* sinkNode = (*I)->getSink();
210 sinkNode->removeInEdge(*I);
214 sinkNode != getLeaf() &&
215 sinkNode->beginInEdges() == sinkNode->endInEdges())
216 { //sinkNode has no more in edges, so add an edge from dummy ENTRY node
217 assert(node != getRoot() && "Adding edge that was just removed?");
218 (void) new SchedGraphEdge(getRoot(), sinkNode,
219 SchedGraphEdge::CtrlDep, SchedGraphEdge::NonDataDep, 0);
223 node->outEdges.clear();
227 SchedGraphCommon::eraseIncidentEdges(SchedGraphNodeCommon* node, bool addDummyEdges)
229 this->eraseIncomingEdges(node, addDummyEdges);
230 this->eraseOutgoingEdges(node, addDummyEdges);
233 std::ostream &operator<<(std::ostream &os, const SchedGraphNodeCommon& node)