From 97330cf287660a60c6c25f04328c2c201d235f59 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 9 Oct 2003 23:10:14 +0000 Subject: Another 10% performance improvement by not using replaceAllUsesWith git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8994 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bytecode/Reader/Reader.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'lib/Bytecode/Reader') diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index 7bb09d7..bff0b12 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -269,7 +269,6 @@ void BytecodeParser::ResolveReferencesToValue(Value *NewV, unsigned Slot) { BCR_TRACE(3, "Mutating forward refs!\n"); Value *VPH = I->second; // Get the placeholder... - VPH->replaceAllUsesWith(NewV); // If this is a global variable being resolved, remove the placeholder from @@ -382,25 +381,33 @@ void BytecodeParser::materializeFunction(Function* F) { throw std::string("Illegal basic block operand reference"); ParsedBasicBlocks.clear(); + // 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. + std::map ForwardRefMapping; + for (std::map, 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 (Argument *A = dyn_cast(I->getOperand(i))) { + std::map::iterator It = ForwardRefMapping.find(A); + if (It != ForwardRefMapping.end()) I->setOperand(i, It->second); + } - // Resolve forward references while (!ForwardReferences.empty()) { std::map, Value*>::iterator I = ForwardReferences.begin(); - unsigned type = I->first.first; - unsigned Slot = I->first.second; Value *PlaceHolder = I->second; ForwardReferences.erase(I); - Value *NewVal = getValue(type, Slot, false); - if (NewVal == 0) - throw std::string("Unresolvable reference found: <" + - PlaceHolder->getType()->getDescription() + ">:" + - utostr(Slot) + "."); - - // Fixup all of the uses of this placeholder def... - PlaceHolder->replaceAllUsesWith(NewVal); - // 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! -- cgit v1.1