-
-
-/*ctor*/
-SchedGraph::SchedGraph(const BasicBlock* bb,
- const TargetMachine& target)
-{
- bbVec.push_back(bb);
- this->buildGraph(target);
-}
-
-
-/*dtor*/
-SchedGraph::~SchedGraph()
-{
- for (iterator I=begin(); I != end(); ++I)
- {
- SchedGraphNode* node = (*I).second;
-
- // for each node, delete its out-edges
- for (SchedGraphNode::iterator I = node->beginOutEdges();
- I != node->endOutEdges(); ++I)
- delete *I;
-
- // then delete the node itself.
- delete node;
- }
-}
-
-
-void
-SchedGraph::dump() const
-{
- cout << " Sched Graph for Basic Blocks: ";
- for (unsigned i=0, N=bbVec.size(); i < N; i++)
- {
- cout << (bbVec[i]->hasName()? bbVec[i]->getName() : "block")
- << " (" << bbVec[i] << ")"
- << ((i == N-1)? "" : ", ");
- }
-
- cout << endl << endl << " Actual Root nodes : ";
- for (unsigned i=0, N=graphRoot->outEdges.size(); i < N; i++)
- cout << graphRoot->outEdges[i]->getSink()->getNodeId()
- << ((i == N-1)? "" : ", ");
-
- cout << endl << " Graph Nodes:" << endl;
- for (const_iterator I=begin(); I != end(); ++I)
- cout << endl << * (*I).second;
-
- cout << endl;
-}
-
-
-void
-SchedGraph::eraseIncomingEdges(SchedGraphNode* node, bool addDummyEdges)
-{
- // Delete and disconnect all in-edges for the node
- for (SchedGraphNode::iterator I = node->beginInEdges();
- I != node->endInEdges(); ++I)
- {
- SchedGraphNode* srcNode = (*I)->getSrc();
- srcNode->removeOutEdge(*I);
- delete *I;
-
- if (addDummyEdges &&
- srcNode != getRoot() &&
- srcNode->beginOutEdges() == srcNode->endOutEdges())
- { // srcNode has no more out edges, so add an edge to dummy EXIT node
- assert(node != getLeaf() && "Adding edge that was just removed?");
- (void) new SchedGraphEdge(srcNode, getLeaf(),
- SchedGraphEdge::CtrlDep, SchedGraphEdge::NonDataDep, 0);
- }
- }
-
- node->inEdges.clear();
-}
-
-void
-SchedGraph::eraseOutgoingEdges(SchedGraphNode* node, bool addDummyEdges)
-{
- // Delete and disconnect all out-edges for the node
- for (SchedGraphNode::iterator I = node->beginOutEdges();
- I != node->endOutEdges(); ++I)
- {
- SchedGraphNode* sinkNode = (*I)->getSink();
- sinkNode->removeInEdge(*I);
- delete *I;
-
- if (addDummyEdges &&
- sinkNode != getLeaf() &&
- sinkNode->beginInEdges() == sinkNode->endInEdges())
- { //sinkNode has no more in edges, so add an edge from dummy ENTRY node
- assert(node != getRoot() && "Adding edge that was just removed?");
- (void) new SchedGraphEdge(getRoot(), sinkNode,
- SchedGraphEdge::CtrlDep, SchedGraphEdge::NonDataDep, 0);
- }
- }
-
- node->outEdges.clear();
-}
-
-void
-SchedGraph::eraseIncidentEdges(SchedGraphNode* node, bool addDummyEdges)
-{
- this->eraseIncomingEdges(node, addDummyEdges);
- this->eraseOutgoingEdges(node, addDummyEdges);
-}
-
-
-void
-SchedGraph::addDummyEdges()
-{
- assert(graphRoot->outEdges.size() == 0);
-
- for (const_iterator I=begin(); I != end(); ++I)
- {
- SchedGraphNode* node = (*I).second;
- assert(node != graphRoot && node != graphLeaf);
- if (node->beginInEdges() == node->endInEdges())
- (void) new SchedGraphEdge(graphRoot, node, SchedGraphEdge::CtrlDep,
- SchedGraphEdge::NonDataDep, 0);
- if (node->beginOutEdges() == node->endOutEdges())
- (void) new SchedGraphEdge(node, graphLeaf, SchedGraphEdge::CtrlDep,
- SchedGraphEdge::NonDataDep, 0);
- }
+SchedGraph::SchedGraph(MachineBasicBlock &mbb, const TargetMachine& target)
+ : MBB(mbb) {
+ buildGraph(target);
+}
+
+//
+// Method: SchedGraph Destructor
+//
+// Description:
+// This method deletes memory allocated by the SchedGraph object.
+//
+// Notes:
+// Do not delete the graphRoot or graphLeaf here. The base class handles
+// that bit of work.
+//
+SchedGraph::~SchedGraph() {
+ for (const_iterator I = begin(); I != end(); ++I)
+ delete I->second;
+}
+
+void SchedGraph::dump() const {
+ std::cerr << " Sched Graph for Basic Block: "
+ << MBB.getBasicBlock()->getName()
+ << " (" << *MBB.getBasicBlock() << ")"
+ << "\n\n Actual Root nodes: ";
+ for (SchedGraphNodeCommon::const_iterator I = graphRoot->beginOutEdges(),
+ E = graphRoot->endOutEdges();
+ I != E; ++I) {
+ std::cerr << (*I)->getSink ()->getNodeId ();
+ if (I + 1 != E) { std::cerr << ", "; }
+ }
+ std::cerr << "\n Graph Nodes:\n";
+ for (const_iterator I = begin(), E = end(); I != E; ++I)
+ std::cerr << "\n" << *I->second;
+ std::cerr << "\n";
+}
+
+void SchedGraph::addDummyEdges() {
+ assert(graphRoot->getNumOutEdges() == 0);
+
+ for (const_iterator I=begin(); I != end(); ++I) {
+ SchedGraphNode* node = (*I).second;
+ assert(node != graphRoot && node != graphLeaf);
+ if (node->beginInEdges() == node->endInEdges())
+ (void) new SchedGraphEdge(graphRoot, node, SchedGraphEdge::CtrlDep,
+ SchedGraphEdge::NonDataDep, 0);
+ if (node->beginOutEdges() == node->endOutEdges())
+ (void) new SchedGraphEdge(node, graphLeaf, SchedGraphEdge::CtrlDep,
+ SchedGraphEdge::NonDataDep, 0);
+ }