From 6823c9f9ff8ea83ae8daba9769485ba492541d57 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 4 Aug 2004 04:48:01 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15463 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Constants.cpp | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'lib/VMCore') diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index eed9cf1..6800bdf 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -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 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 getValType(ConstantArray *CA) { + std::vector Elements; + Elements.reserve(CA->getNumOperands()); + for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i) + Elements.push_back(cast(CA->getOperand(i))); + return Elements; +} + static ValueMap, ArrayType, ConstantArray> ArrayConstants; @@ -914,6 +919,14 @@ namespace llvm { static ValueMap, StructType, ConstantStruct> StructConstants; +static std::vector getValType(ConstantStruct *CS) { + std::vector Elements; + Elements.reserve(CS->getNumOperands()); + for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i) + Elements.push_back(cast(CS->getOperand(i))); + return Elements; +} + Constant *ConstantStruct::get(const StructType *Ty, const std::vector &V) { // Create a ConstantAggregateZero value if all elements are zeros... @@ -965,6 +978,11 @@ namespace llvm { static ValueMap 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 Operands; + Operands.reserve(CE->getNumOperands()); + for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) + Operands.push_back(cast(CE->getOperand(i))); + return ExprMapKeyType(CE->getOpcode(), Operands); +} + static ValueMap ExprConstants; Constant *ConstantExpr::getCast(Constant *C, const Type *Ty) { -- cgit v1.1