Implement a new mergeInGraph method, which basically factors code out of
the BU class.

This will be used by the IPModRef class to do stuff, eventually perhaps the
TD pass will use it also.

Speaking of the TD pass, this also eliminates the self recursive case, which
was broken, and couldn't occur anyway.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4599 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/DataStructure/TopDownClosure.cpp b/lib/Analysis/DataStructure/TopDownClosure.cpp
index 69422ca..817e734 100644
--- a/lib/Analysis/DataStructure/TopDownClosure.cpp
+++ b/lib/Analysis/DataStructure/TopDownClosure.cpp
@@ -149,36 +149,36 @@
     DEBUG(std::cerr << "\t [TD] Inlining caller #" << c << " '"
           << Caller.getName() << "' into callee: " << F.getName() << "\n");
     
-    if (&Caller == &F) {
-      // Self-recursive call: this can happen after a cycle of calls is inlined.
-      ResolveCallSite(*Graph, CallSite);
-    } else {
+    // Self recursion is not tracked in BU pass...
+    assert(&Caller != &F && "This cannot happen!\n");
 
-      // Recursively compute the graph for the Caller.  It should be fully
-      // resolved except if there is mutual recursion...
-      //
-      DSGraph &CG = calculateGraph(Caller);  // Graph to inline
-      
-      DEBUG(std::cerr << "\t\t[TD] Got graph for " << Caller.getName()
-                      << " in: " << F.getName() << "\n");
+    // Recursively compute the graph for the Caller.  It should be fully
+    // resolved except if there is mutual recursion...
+    //
+    DSGraph &CG = calculateGraph(Caller);  // Graph to inline
+    
+    DEBUG(std::cerr << "\t\t[TD] Got graph for " << Caller.getName()
+          << " in: " << F.getName() << "\n");
+    
+    // Translate call site from having links into the BU graph
+    DSCallSite CallSiteInCG(CallSite, BUMaps[&Caller]);
 
-      // These two maps keep track of where scalars in the old graph _used_
-      // to point to, and of new nodes matching nodes of the old graph.
-      std::map<Value*, DSNodeHandle> OldValMap;
-      std::map<const DSNode*, DSNode*> OldNodeMap;
+    // These two maps keep track of where scalars in the old graph _used_
+    // to point to, and of new nodes matching nodes of the old graph.
+    std::map<Value*, DSNodeHandle> OldValMap;
+    std::map<const DSNode*, DSNode*> OldNodeMap;
 
-      // Translate call site from having links into the BU graph
-      DSCallSite CallSiteInCG(CallSite, BUMaps[&Caller]);
-
-      // Clone the Caller's graph into the current graph, keeping
-      // track of where scalars in the old graph _used_ to point...
-      // Do this here because it only needs to happens once for each Caller!
-      // Strip scalars but not allocas since they are alive in callee.
-      // 
-      DSNodeHandle RetVal = Graph->cloneInto(CG, OldValMap, OldNodeMap,
-                                             /*StripAllocas*/ false);
-      ResolveCallSite(*Graph, DSCallSite(CallSiteInCG, OldNodeMap));
-    }
+    // FIXME: Eventually use DSGraph::mergeInGraph here...
+    // Graph->mergeInGraph(CallSiteInCG, CG, false);
+    
+    // Clone the Caller's graph into the current graph, keeping
+    // track of where scalars in the old graph _used_ to point...
+    // Do this here because it only needs to happens once for each Caller!
+    // Strip scalars but not allocas since they are alive in callee.
+    // 
+    DSNodeHandle RetVal = Graph->cloneInto(CG, OldValMap, OldNodeMap,
+                                           /*StripAllocas*/ false);
+    ResolveCallSite(*Graph, DSCallSite(CallSiteInCG, OldNodeMap));
   }
 
   // Recompute the Incomplete markers and eliminate unreachable nodes.