Switch inliner over to use DenseMap instead of std::map for ValueMap.  This
speeds up the inliner 16%.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33801 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp
index 371bee1..f90716c 100644
--- a/lib/Transforms/Utils/ValueMapper.cpp
+++ b/lib/Transforms/Utils/ValueMapper.cpp
@@ -18,9 +18,12 @@
 #include "llvm/Instruction.h"
 using namespace llvm;
 
-Value *llvm::MapValue(const Value *V, std::map<const Value*, Value*> &VM) {
+Value *llvm::MapValue(const Value *V, ValueMapTy &VM) {
   Value *&VMSlot = VM[V];
   if (VMSlot) return VMSlot;      // Does it exist in the map yet?
+  
+  // NOTE: VMSlot can be invalidated by any reference to VM, which can grow the
+  // DenseMap.  This includes any recursive calls to MapValue.
 
   // Global values do not need to be seeded into the ValueMap if they are using
   // the identity mapping.
@@ -46,10 +49,10 @@
           Values.push_back(cast<Constant>(MV));
           for (++i; i != e; ++i)
             Values.push_back(cast<Constant>(MapValue(CA->getOperand(i), VM)));
-          return VMSlot = ConstantArray::get(CA->getType(), Values);
+          return VM[V] = ConstantArray::get(CA->getType(), Values);
         }
       }
-      return VMSlot = C;
+      return VM[V] = C;
 
     } else if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
       for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i) {
@@ -65,16 +68,16 @@
           Values.push_back(cast<Constant>(MV));
           for (++i; i != e; ++i)
             Values.push_back(cast<Constant>(MapValue(CS->getOperand(i), VM)));
-          return VMSlot = ConstantStruct::get(CS->getType(), Values);
+          return VM[V] = ConstantStruct::get(CS->getType(), Values);
         }
       }
-      return VMSlot = C;
+      return VM[V] = C;
 
     } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
       std::vector<Constant*> Ops;
       for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i)
         Ops.push_back(cast<Constant>(MapValue(CE->getOperand(i), VM)));
-      return VMSlot = CE->getWithOperands(Ops);
+      return VM[V] = CE->getWithOperands(Ops);
     } else if (ConstantPacked *CP = dyn_cast<ConstantPacked>(C)) {
       for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i) {
         Value *MV = MapValue(CP->getOperand(i), VM);
@@ -89,7 +92,7 @@
           Values.push_back(cast<Constant>(MV));
           for (++i; i != e; ++i)
             Values.push_back(cast<Constant>(MapValue(CP->getOperand(i), VM)));
-          return VMSlot = ConstantPacked::get(Values);
+          return VM[V] = ConstantPacked::get(Values);
         }
       }
       return VMSlot = C;
@@ -105,8 +108,7 @@
 /// RemapInstruction - Convert the instruction operands from referencing the
 /// current values into those specified by ValueMap.
 ///
-void llvm::RemapInstruction(Instruction *I,
-                            std::map<const Value *, Value*> &ValueMap) {
+void llvm::RemapInstruction(Instruction *I, ValueMapTy &ValueMap) {
   for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
     const Value *Op = I->getOperand(op);
     Value *V = MapValue(Op, ValueMap);