Implement a FIXME, by not searching linearly through a map to remove an
authorChris Lattner <sabre@nondot.org>
Wed, 4 Aug 2004 04:48:01 +0000 (04:48 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 4 Aug 2004 04:48:01 +0000 (04:48 +0000)
element.  This speeds up the bytecode reader from 12.86s to 8.72s on 252.eon.

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

lib/VMCore/Constants.cpp

index eed9cf11e6796043a0cbb99c874ced23d97662fc..6800bdf68f5f6bba5306061007a7ceaee839c6cb 100644 (file)
@@ -606,13 +606,10 @@ namespace {
     }
     
     void remove(ConstantClass *CP) {
-      // FIXME: This should not use a linear scan.  If this gets to be a
-      // performance problem, someone should look at this.
-      MapIterator I = Map.begin();
-      for (MapIterator E = Map.end(); I != E && I->second != CP; ++I)
-        /* empty */;
-      
+      MapIterator I = Map.find(MapKey((TypeClass*)CP->getRawType(),
+                                      getValType(CP)));
       assert(I != Map.end() && "Constant not found in constant table!");
+      assert(I->second == CP && "Didn't find correct element?");
 
       // Now that we found the entry, make sure this isn't the entry that
       // the AbstractTypeMap points to.
@@ -687,8 +684,6 @@ namespace {
   };
 }
 
-
-
 //---- ConstantUInt::get() and ConstantSInt::get() implementations...
 //
 static ValueMap< int64_t, Type, ConstantSInt> SIntConstants;
@@ -785,6 +780,8 @@ namespace llvm {
 
 static ValueMap<char, Type, ConstantAggregateZero> AggZeroConstants;
 
+static char getValType(ConstantAggregateZero *CPZ) { return 0; }
+
 Constant *ConstantAggregateZero::get(const Type *Ty) {
   return AggZeroConstants.getOrCreate(Ty, 0);
 }
@@ -822,6 +819,14 @@ namespace llvm {
   };
 }
 
+static std::vector<Constant*> getValType(ConstantArray *CA) {
+  std::vector<Constant*> Elements;
+  Elements.reserve(CA->getNumOperands());
+  for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i)
+    Elements.push_back(cast<Constant>(CA->getOperand(i)));
+  return Elements;
+}
+
 static ValueMap<std::vector<Constant*>, ArrayType,
                 ConstantArray> ArrayConstants;
 
@@ -914,6 +919,14 @@ namespace llvm {
 static ValueMap<std::vector<Constant*>, StructType, 
                 ConstantStruct> StructConstants;
 
+static std::vector<Constant*> getValType(ConstantStruct *CS) {
+  std::vector<Constant*> Elements;
+  Elements.reserve(CS->getNumOperands());
+  for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i)
+    Elements.push_back(cast<Constant>(CS->getOperand(i)));
+  return Elements;
+}
+
 Constant *ConstantStruct::get(const StructType *Ty,
                               const std::vector<Constant*> &V) {
   // Create a ConstantAggregateZero value if all elements are zeros...
@@ -965,6 +978,11 @@ namespace llvm {
 
 static ValueMap<char, PointerType, ConstantPointerNull> NullPtrConstants;
 
+static char getValType(ConstantPointerNull *) {
+  return 0;
+}
+
+
 ConstantPointerNull *ConstantPointerNull::get(const PointerType *Ty) {
   return NullPtrConstants.getOrCreate(Ty, 0);
 }
@@ -1042,6 +1060,14 @@ namespace llvm {
 } // end namespace llvm
 
 
+static ExprMapKeyType getValType(ConstantExpr *CE) {
+  std::vector<Constant*> Operands;
+  Operands.reserve(CE->getNumOperands());
+  for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i)
+    Operands.push_back(cast<Constant>(CE->getOperand(i)));
+  return ExprMapKeyType(CE->getOpcode(), Operands);
+}
+
 static ValueMap<ExprMapKeyType, Type, ConstantExpr> ExprConstants;
 
 Constant *ConstantExpr::getCast(Constant *C, const Type *Ty) {