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
This commit is contained in:
Chris Lattner 2004-08-04 04:48:01 +00:00
parent b6197611d5
commit 6823c9f9ff

View 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) {