From 43f33dd550a2d165c41cbf01cae97d513dd5002c Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 2 Jul 2009 00:17:47 +0000 Subject: Fix a bunch of other places that used operator[] to test whether a key is present in a std::map or DenseMap to use find instead. llvm-svn: 74676 --- llvm/lib/Target/X86/X86FastISel.cpp | 5 +++-- llvm/lib/Transforms/Scalar/JumpThreading.cpp | 16 ++++++++++------ llvm/lib/Transforms/Scalar/TailDuplication.cpp | 14 +++++++++----- 3 files changed, 22 insertions(+), 13 deletions(-) (limited to 'llvm/lib') diff --git a/llvm/lib/Target/X86/X86FastISel.cpp b/llvm/lib/Target/X86/X86FastISel.cpp index ea29f73a066..bd994dea8f4 100644 --- a/llvm/lib/Target/X86/X86FastISel.cpp +++ b/llvm/lib/Target/X86/X86FastISel.cpp @@ -452,8 +452,9 @@ bool X86FastISel::X86SelectAddress(Value *V, X86AddressMode &AM, bool isCall) { if (Subtarget->GVRequiresExtraLoad(GV, TM, isCall)) { // Check to see if we've already materialized this // value in a register in this block. - if (unsigned Reg = LocalValueMap[V]) { - AM.Base.Reg = Reg; + DenseMap::iterator I = LocalValueMap.find(V); + if (I != LocalValueMap.end() && I->second != 0) { + AM.Base.Reg = I->second; AM.GV = 0; return true; } diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 5a70fc3bc6f..c3aee01e644 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -935,9 +935,11 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB, BasicBlock *PredBB, // Remap operands to patch up intra-block references. for (unsigned i = 0, e = New->getNumOperands(); i != e; ++i) - if (Instruction *Inst = dyn_cast(New->getOperand(i))) - if (Value *Remapped = ValueMapping[Inst]) - New->setOperand(i, Remapped); + if (Instruction *Inst = dyn_cast(New->getOperand(i))) { + DenseMap::iterator I = ValueMapping.find(Inst); + if (I != ValueMapping.end()) + New->setOperand(i, I->second); + } } // We didn't copy the terminator from BB over to NewBB, because there is now @@ -953,9 +955,11 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB, BasicBlock *PredBB, Value *IV = PN->getIncomingValueForBlock(BB); // Remap the value if necessary. - if (Instruction *Inst = dyn_cast(IV)) - if (Value *MappedIV = ValueMapping[Inst]) - IV = MappedIV; + if (Instruction *Inst = dyn_cast(IV)) { + DenseMap::iterator I = ValueMapping.find(Inst); + if (I != ValueMapping.end()) + IV = I->second; + } PN->addIncoming(IV, NewBB); } diff --git a/llvm/lib/Transforms/Scalar/TailDuplication.cpp b/llvm/lib/Transforms/Scalar/TailDuplication.cpp index 99a7dee3988..c037ee96031 100644 --- a/llvm/lib/Transforms/Scalar/TailDuplication.cpp +++ b/llvm/lib/Transforms/Scalar/TailDuplication.cpp @@ -317,9 +317,12 @@ void TailDup::eliminateUnconditionalBranch(BranchInst *Branch) { // BI = Branch; ++BI; // Get an iterator to the first new instruction for (; BI != SourceBlock->end(); ++BI) - for (unsigned i = 0, e = BI->getNumOperands(); i != e; ++i) - if (Value *Remapped = ValueMapping[BI->getOperand(i)]) - BI->setOperand(i, Remapped); + for (unsigned i = 0, e = BI->getNumOperands(); i != e; ++i) { + std::map::const_iterator I = + ValueMapping.find(BI->getOperand(i)); + if (I != ValueMapping.end()) + BI->setOperand(i, I->second); + } // Next we check to see if any of the successors of DestBlock had PHI nodes. // If so, we need to add entries to the PHI nodes for SourceBlock now. @@ -333,8 +336,9 @@ void TailDup::eliminateUnconditionalBranch(BranchInst *Branch) { Value *IV = PN->getIncomingValueForBlock(DestBlock); // Remap the value if necessary... - if (Value *MappedIV = ValueMapping[IV]) - IV = MappedIV; + std::map::const_iterator I = ValueMapping.find(IV); + if (I != ValueMapping.end()) + IV = I->second; PN->addIncoming(IV, SourceBlock); } } -- cgit v1.2.3