[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Reader.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Dec 8 20:52:05 PST 2004
Changes in directory llvm/lib/Bytecode/Reader:
Reader.cpp updated: 1.146 -> 1.147
---
Log message:
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.
---
Diffs of the changes: (+6 -30)
Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.146 llvm/lib/Bytecode/Reader/Reader.cpp:1.147
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.146 Sat Dec 4 16:19:53 2004
+++ llvm/lib/Bytecode/Reader/Reader.cpp Wed Dec 8 22:51:50 2004
@@ -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;
}
More information about the llvm-commits
mailing list