[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Aug 3 21:48:11 PDT 2004



Changes in directory llvm/lib/VMCore:

Constants.cpp updated: 1.97 -> 1.98
---
Log message:

Implement a FIXME, by not searching linearly through a map to remove an
element.  This speeds up the bytecode reader from 12.86s to 8.72s on 252.eon.


---
Diffs of the changes:  (+34 -8)

Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.97 llvm/lib/VMCore/Constants.cpp:1.98
--- llvm/lib/VMCore/Constants.cpp:1.97	Thu Jul 29 12:20:21 2004
+++ llvm/lib/VMCore/Constants.cpp	Tue Aug  3 23:48:01 2004
@@ -606,13 +606,10 @@
     }
     
     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 @@
   };
 }
 
-
-
 //---- ConstantUInt::get() and ConstantSInt::get() implementations...
 //
 static ValueMap< int64_t, Type, ConstantSInt> SIntConstants;
@@ -785,6 +780,8 @@
 
 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 @@
   };
 }
 
+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 @@
 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 @@
 
 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 @@
 } // 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) {






More information about the llvm-commits mailing list