diff options
author | Chris Lattner <sabre@nondot.org> | 2004-08-04 04:48:01 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-08-04 04:48:01 +0000 |
commit | 6823c9f9ff8ea83ae8daba9769485ba492541d57 (patch) | |
tree | 3e9df01070770ed738ab44e0522d914eda812056 /lib/VMCore | |
parent | b6197611d54de7f0ba50b185aa4fe6eea9ceb8ff (diff) | |
download | external_llvm-6823c9f9ff8ea83ae8daba9769485ba492541d57.zip external_llvm-6823c9f9ff8ea83ae8daba9769485ba492541d57.tar.gz external_llvm-6823c9f9ff8ea83ae8daba9769485ba492541d57.tar.bz2 |
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
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Constants.cpp | 42 |
1 files changed, 34 insertions, 8 deletions
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<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) { |