-// ProcessNode - This method is called by ProcessInterval to add nodes to the
-// interval being constructed, and it is also called recursively as it walks
-// the source graph. A node is added to the current interval only if all of
-// its predecessors are already in the graph. This also takes care of keeping
-// the successor set of an interval up to date.
-//
-// This method is templated because it may operate on two different source
-// graphs: a basic block graph, or a preexisting interval graph.
-//
-template<class NodeTy, class OrigContainer>
-void IntervalPartition::ProcessNode(Interval *Int,
- NodeTy *Node, OrigContainer *OC) {
- assert(Int && "Null interval == bad!");
- assert(Node && "Null Node == bad!");
-
- BasicBlock *NodeHeader = getNodeHeader(Node);
- Interval *CurInt = getBlockInterval(NodeHeader);
- if (CurInt == Int) { // Already in this interval...
- return;
- } else if (CurInt != 0) { // In another interval, add as successor
- if (!Int->isSuccessor(NodeHeader)) // Add only if not already in set
- Int->Successors.push_back(NodeHeader);
- } else { // Otherwise, not in interval yet
- for (typename NodeTy::pred_iterator I = pred_begin(Node),
- E = pred_end(Node); I != E; ++I) {
- if (!Int->contains(*I)) { // If pred not in interval, we can't be
- if (!Int->isSuccessor(NodeHeader)) // Add only if not already in set
- Int->Successors.push_back(NodeHeader);
- return; // See you later
- }
- }
-
- // If we get here, then all of the predecessors of BB are in the interval
- // already. In this case, we must add BB to the interval!
- addNodeToInterval(Int, Node);
-
- if (Int->isSuccessor(NodeHeader)) {
- // If we were in the successor list from before... remove from succ list
- Int->Successors.erase(remove(Int->Successors.begin(),
- Int->Successors.end(), NodeHeader),
- Int->Successors.end());
- }
-
- // Now that we have discovered that Node is in the interval, perhaps some of
- // its successors are as well?
- for (typename NodeTy::succ_iterator It = succ_begin(Node),
- End = succ_end(Node); It != End; ++It)
- ProcessNode(Int, getSourceGraphNode(OC, *It), OC);
- }
-}