Eliminate this ugly hack.  This was put back in when replaceAllUsesOf used
a different algorithm that was extremely inefficient for instructions with
many operands.

This reduces the time of this code snippet from .23s for 176.gcc to 0.03s
in a debug build, which speeds up total llvm-dis time just barely.

It's more of a code cleanup than a speedup.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18685 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index 8f0a7f8..9880ac4 100644
--- a/lib/Bytecode/Reader/Reader.cpp
+++ b/lib/Bytecode/Reader/Reader.cpp
@@ -30,6 +30,8 @@
 #include <algorithm>
 using namespace llvm;
 
+#include "llvm/Support/Timer.h"
+
 namespace {
 
 /// @brief A class for maintaining the slot number definition
@@ -1690,39 +1692,13 @@
 
   // Resolve forward references.  Replace any uses of a forward reference value
   // with the real value.
-
-  // replaceAllUsesWith is very inefficient for instructions which have a LARGE
-  // number of operands.  PHI nodes often have forward references, and can also
-  // often have a very large number of operands.
-  //
-  // FIXME: REEVALUATE.  replaceAllUsesWith is _much_ faster now, and this code
-  // should be simplified back to using it!
-  //
-  std::map<Value*, Value*> ForwardRefMapping;
-  for (std::map<std::pair<unsigned,unsigned>, Value*>::iterator 
-         I = ForwardReferences.begin(), E = ForwardReferences.end();
-       I != E; ++I)
-    ForwardRefMapping[I->second] = getValue(I->first.first, I->first.second,
-                                            false);
-
-  for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
-    for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
-      for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
-        if (Value* V = I->getOperand(i))
-          if (Argument *A = dyn_cast<Argument>(V)) {
-            std::map<Value*, Value*>::iterator It = ForwardRefMapping.find(A);
-            if (It != ForwardRefMapping.end()) I->setOperand(i, It->second);
-          }
-
   while (!ForwardReferences.empty()) {
-    std::map<std::pair<unsigned,unsigned>, Value*>::iterator I =
-      ForwardReferences.begin();
+    std::map<std::pair<unsigned,unsigned>, Value*>::iterator
+      I = ForwardReferences.begin();
+    Value *V = getValue(I->first.first, I->first.second, false);
     Value *PlaceHolder = I->second;
+    PlaceHolder->replaceAllUsesWith(V);
     ForwardReferences.erase(I);
-
-    // Now that all the uses are gone, delete the placeholder...
-    // If we couldn't find a def (error case), then leak a little
-    // memory, because otherwise we can't remove all uses!
     delete PlaceHolder;
   }