diff options
author | Chris Lattner <sabre@nondot.org> | 2003-10-09 23:10:14 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-10-09 23:10:14 +0000 |
commit | 97330cf287660a60c6c25f04328c2c201d235f59 (patch) | |
tree | 1a8163e9d5e41426a9294efdda6bed0c80e90fcc /lib/Bytecode/Reader | |
parent | 4c52392ba35a763a3113f373bfb102791f8ac520 (diff) | |
download | external_llvm-97330cf287660a60c6c25f04328c2c201d235f59.zip external_llvm-97330cf287660a60c6c25f04328c2c201d235f59.tar.gz external_llvm-97330cf287660a60c6c25f04328c2c201d235f59.tar.bz2 |
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
Diffstat (limited to 'lib/Bytecode/Reader')
-rw-r--r-- | lib/Bytecode/Reader/Reader.cpp | 33 |
1 files changed, 20 insertions, 13 deletions
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<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 (Argument *A = dyn_cast<Argument>(I->getOperand(i))) { + std::map<Value*, Value*>::iterator It = ForwardRefMapping.find(A); + if (It != ForwardRefMapping.end()) I->setOperand(i, It->second); + } - // Resolve forward references while (!ForwardReferences.empty()) { std::map<std::pair<unsigned,unsigned>, 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! |