summaryrefslogtreecommitdiff
path: root/lib/Bytecode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-12-09 04:51:50 +0000
committerChris Lattner <sabre@nondot.org>2004-12-09 04:51:50 +0000
commitc4d69165081237eb951509d74b1816601834a3e7 (patch)
tree12aa0e8bebc45d6b44bb5c3312752233248b1823 /lib/Bytecode
parentc49741d047f7cf1143aa34a3a97379a8d1b5f0e5 (diff)
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
Diffstat (limited to 'lib/Bytecode')
-rw-r--r--lib/Bytecode/Reader/Reader.cpp36
1 files changed, 6 insertions, 30 deletions
diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp
index 8f0a7f8a8dc..9880ac405ae 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 @@ void BytecodeReader::ParseFunctionBody(Function* F) {
// 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;
}