Do map insert+find in one step. TODO -= 2.
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 5 Nov 2009 14:33:27 +0000 (14:33 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 5 Nov 2009 14:33:27 +0000 (14:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86133 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/SCCP.cpp

index d515c130e991b5f5689b705963581a55317850aa..509a6dbc12f055c87a4f36180acf8f9c78c5b1bb 100644 (file)
@@ -370,13 +370,13 @@ private:
   /// by properly seeding constants etc.
   LatticeVal &getValueState(Value *V) {
     assert(!isa<StructType>(V->getType()) && "Should use getStructValueState");
-    
-    // TODO: Change to do insert+find in one operation.
-    DenseMap<Value*, LatticeVal>::iterator I = ValueState.find(V);
-    if (I != ValueState.end())
-      return I->second;  // Common case, already in the map.
 
-    LatticeVal &LV = ValueState[V];
+    std::pair<DenseMap<Value*, LatticeVal>::iterator, bool> I =
+      ValueState.insert(std::make_pair(V, LatticeVal()));
+    LatticeVal &LV = I.first->second;
+
+    if (!I.second)
+      return LV;  // Common case, already in the map.
 
     if (Constant *C = dyn_cast<Constant>(V)) {
       // Undef values remain undefined.
@@ -395,15 +395,15 @@ private:
     assert(isa<StructType>(V->getType()) && "Should use getValueState");
     assert(i < cast<StructType>(V->getType())->getNumElements() &&
            "Invalid element #");
-    
-    // TODO: Change to do insert+find in one operation.
-    DenseMap<std::pair<Value*, unsigned>, LatticeVal>::iterator
-      I = StructValueState.find(std::make_pair(V, i));
-    if (I != StructValueState.end())
-      return I->second;  // Common case, already in the map.
-    
-    LatticeVal &LV = StructValueState[std::make_pair(V, i)];
-    
+
+    std::pair<DenseMap<std::pair<Value*, unsigned>, LatticeVal>::iterator,
+              bool> I = StructValueState.insert(
+                        std::make_pair(std::make_pair(V, i), LatticeVal()));
+    LatticeVal &LV = I.first->second;
+
+    if (!I.second)
+      return LV;  // Common case, already in the map.
+
     if (Constant *C = dyn_cast<Constant>(V)) {
       if (isa<UndefValue>(C))
         ; // Undef values remain undefined.