Fix a bunch of other places that used operator[] to test whether
authorDan Gohman <gohman@apple.com>
Thu, 2 Jul 2009 00:17:47 +0000 (00:17 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 2 Jul 2009 00:17:47 +0000 (00:17 +0000)
a key is present in a std::map or DenseMap to use find instead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74676 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/Dominators.h
lib/Target/X86/X86FastISel.cpp
lib/Transforms/Scalar/JumpThreading.cpp
lib/Transforms/Scalar/TailDuplication.cpp
tools/llvm-prof/llvm-prof.cpp

index 347e239d8ea7fc943102e3414e5c35be5d72b9f9..366d492b11456d374f69d039b63aa982c92b4d38 100644 (file)
@@ -618,8 +618,9 @@ protected:
   }
   
   DomTreeNodeBase<NodeT> *getNodeForBlock(NodeT *BB) {
-    if (DomTreeNodeBase<NodeT> *BBNode = this->DomTreeNodes[BB])
-      return BBNode;
+    typename DomTreeNodeMapType::iterator I = this->DomTreeNodes.find(BB);
+    if (I != this->DomTreeNodes.end() && I->second)
+      return I->second;
 
     // Haven't calculated this node yet?  Get or calculate the node for the
     // immediate dominator.
index ea29f73a066a090861b09aeee7b1db3f0dbe2b92..bd994dea8f414af491e42798d035aca01d162963 100644 (file)
@@ -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<const Value *, unsigned>::iterator I = LocalValueMap.find(V);
+      if (I != LocalValueMap.end() && I->second != 0) {
+        AM.Base.Reg = I->second;
         AM.GV = 0;
         return true;
       }
index 5a70fc3bc6f761381dd0242d784fc52df7cc13f0..c3aee01e64464ca0e4dc6dd35229d164f1924abd 100644 (file)
@@ -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<Instruction>(New->getOperand(i)))
-        if (Value *Remapped = ValueMapping[Inst])
-          New->setOperand(i, Remapped);
+      if (Instruction *Inst = dyn_cast<Instruction>(New->getOperand(i))) {
+        DenseMap<Instruction*, Value*>::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<Instruction>(IV))
-      if (Value *MappedIV = ValueMapping[Inst])
-        IV = MappedIV;
+    if (Instruction *Inst = dyn_cast<Instruction>(IV)) {
+      DenseMap<Instruction*, Value*>::iterator I = ValueMapping.find(Inst);
+      if (I != ValueMapping.end())
+        IV = I->second;
+    }
     PN->addIncoming(IV, NewBB);
   }
   
index 99a7dee39887dc51e33a3839779fc4b11b44b47c..c037ee960317754e15a36a5e2cf1c292b74f988c 100644 (file)
@@ -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<Value*, Value*>::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<Value*, Value*>::const_iterator I = ValueMapping.find(IV);
+      if (I != ValueMapping.end())
+        IV = I->second;
       PN->addIncoming(IV, SourceBlock);
     }
   }
index cab87e7305827b883c3759b68257a6f0d6eb63d9..2cff296ba99c06dbaff5e980cf08bc1685928eb8 100644 (file)
@@ -81,8 +81,10 @@ namespace {
     virtual void emitBasicBlockStartAnnot(const BasicBlock *BB,
                                           raw_ostream &OS) {
       if (BlockFreqs.empty()) return;
-      if (unsigned Count = BlockFreqs[BB])
-        OS << "\t;;; Basic block executed " << Count << " times.\n";
+      std::map<const BasicBlock *, unsigned>::const_iterator I =
+        BlockFreqs.find(BB);
+      if (I != BlockFreqs.end())
+        OS << "\t;;; Basic block executed " << I->second << " times.\n";
       else
         OS << "\t;;; Never executed!\n";
     }