Change the ActualCallees callgraph from hash_multimap<Instruction,Function>
to std::set<std::pair<Inst,Func>> to avoid duplicate entries.

This speeds up the CompleteBU pass from 1.99s to .15s on povray and the
eqgraph passes from 1.5s to .16s on the same.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21031 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/DataStructure/CompleteBottomUp.cpp b/lib/Analysis/DataStructure/CompleteBottomUp.cpp
index 3cb0b6e..834ae97 100644
--- a/lib/Analysis/DataStructure/CompleteBottomUp.cpp
+++ b/lib/Analysis/DataStructure/CompleteBottomUp.cpp
@@ -13,6 +13,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#define DEBUG_TYPE "cbudatastructure"
 #include "llvm/Analysis/DataStructure/DataStructure.h"
 #include "llvm/Module.h"
 #include "llvm/Analysis/DataStructure/DSGraph.h"
@@ -37,39 +38,8 @@
   GlobalsGraph = new DSGraph(BU.getGlobalsGraph(), GlobalECs);
   GlobalsGraph->setPrintAuxCalls();
 
-#if 1   // REMOVE ME EVENTUALLY
-  // FIXME: TEMPORARY (remove once finalization of indirect call sites in the
-  // globals graph has been implemented in the BU pass)
-  TDDataStructures &TD = getAnalysis<TDDataStructures>();
-
-  ActualCallees.clear();
-
-  // The call graph extractable from the TD pass is _much more complete_ and
-  // trustable than that generated by the BU pass so far.  Until this is fixed,
-  // we hack it like this:
-  for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI) {
-    if (MI->isExternal()) continue;
-    const std::list<DSCallSite> &CSs = TD.getDSGraph(*MI).getFunctionCalls();
-
-    for (std::list<DSCallSite>::const_iterator CSI = CSs.begin(), E = CSs.end();
-         CSI != E; ++CSI) {
-      Instruction *TheCall = CSI->getCallSite().getInstruction();
-
-      if (CSI->isIndirectCall()) { // indirect call: insert all callees
-        std::vector<Function*> Callees;
-        CSI->getCalleeNode()->addFullFunctionList(Callees);
-        for (unsigned i = 0, e = Callees.size(); i != e; ++i)
-          ActualCallees.insert(std::make_pair(TheCall, Callees[i]));
-      } else {        // direct call: insert the single callee directly
-        ActualCallees.insert(std::make_pair(TheCall,
-                                            CSI->getCalleeFunc()));
-      }
-    }
-  }
-#else
   // Our call graph is the same as the BU data structures call graph
   ActualCallees = BU.getActualCallees();
-#endif
 
   std::vector<DSGraph*> Stack;
   hash_map<DSGraph*, unsigned> ValMap;
@@ -150,8 +120,9 @@
     Instruction *Call = CI->getCallSite().getInstruction();
 
     // Loop over all of the actually called functions...
-    ActualCalleesTy::iterator I, E;
-    for (tie(I, E) = ActualCallees.equal_range(Call); I != E; ++I)
+    ActualCalleesTy::iterator I = callee_begin(Call), E = callee_end(Call);
+    for (; I != E && I->first == Call; ++I) {
+      assert(I->first == Call && "Bad callee construction!");
       if (!I->second->isExternal()) {
         DSGraph &Callee = getOrCreateGraph(*I->second);
         unsigned M;
@@ -163,6 +134,7 @@
           M = It->second;
         if (M < Min) Min = M;
       }
+    }
   }
 
   assert(ValMap[&FG] == MyID && "SCC construction assumption wrong!");
@@ -225,10 +197,11 @@
     // Inline direct calls as well as indirect calls because the direct
     // callee may have indirect callees and so may have changed.
     // 
-    ActualCalleesTy::iterator I, E;
-    tie(I, E) = ActualCallees.equal_range(TheCall);
-    unsigned TNum = 0, Num = std::distance(I, E);
+    ActualCalleesTy::iterator I = callee_begin(TheCall),E = callee_end(TheCall);
+    unsigned TNum = 0, Num = 0;
+    DEBUG(Num = std::distance(I, E));
     for (; I != E; ++I, ++TNum) {
+      assert(I->first == TheCall && "Bad callee construction!");
       Function *CalleeFunc = I->second;
       if (!CalleeFunc->isExternal()) {
         // Merge the callee's graph into this graph.  This works for normal