Turn some DenseMaps that are only used for set operations into DenseSets.

DenseSet has better memory efficiency now.

llvm-svn: 223589
This commit is contained in:
Benjamin Kramer 2014-12-06 19:22:54 +00:00
parent 89e5306f43
commit 3280a5d9f5
4 changed files with 15 additions and 19 deletions

View File

@ -47,8 +47,7 @@ public:
static bool isEqual(const StructType *LHS, const StructType *RHS);
};
typedef DenseMap<StructType *, bool, StructTypeKeyInfo>
NonOpaqueStructTypeSet;
typedef DenseSet<StructType *, StructTypeKeyInfo> NonOpaqueStructTypeSet;
typedef DenseSet<StructType *> OpaqueStructTypeSet;
struct IdentifiedStructTypeSet {

View File

@ -313,11 +313,11 @@ public:
BumpPtrAllocator TypeAllocator;
DenseMap<unsigned, IntegerType*> IntegerTypes;
typedef DenseMap<FunctionType*, bool, FunctionTypeKeyInfo> FunctionTypeMap;
FunctionTypeMap FunctionTypes;
typedef DenseMap<StructType*, bool, AnonStructTypeKeyInfo> StructTypeMap;
StructTypeMap AnonStructTypes;
typedef DenseSet<FunctionType *, FunctionTypeKeyInfo> FunctionTypeSet;
FunctionTypeSet FunctionTypes;
typedef DenseSet<StructType *, AnonStructTypeKeyInfo> StructTypeSet;
StructTypeSet AnonStructTypes;
StringMap<StructType*> NamedStructTypes;
unsigned NamedStructTypesUniqueID;

View File

@ -360,8 +360,7 @@ FunctionType *FunctionType::get(Type *ReturnType,
ArrayRef<Type*> Params, bool isVarArg) {
LLVMContextImpl *pImpl = ReturnType->getContext().pImpl;
FunctionTypeKeyInfo::KeyTy Key(ReturnType, Params, isVarArg);
LLVMContextImpl::FunctionTypeMap::iterator I =
pImpl->FunctionTypes.find_as(Key);
auto I = pImpl->FunctionTypes.find_as(Key);
FunctionType *FT;
if (I == pImpl->FunctionTypes.end()) {
@ -369,9 +368,9 @@ FunctionType *FunctionType::get(Type *ReturnType,
Allocate(sizeof(FunctionType) + sizeof(Type*) * (Params.size() + 1),
AlignOf<FunctionType>::Alignment);
new (FT) FunctionType(ReturnType, Params, isVarArg);
pImpl->FunctionTypes[FT] = true;
pImpl->FunctionTypes.insert(FT);
} else {
FT = I->first;
FT = *I;
}
return FT;
@ -404,8 +403,7 @@ StructType *StructType::get(LLVMContext &Context, ArrayRef<Type*> ETypes,
bool isPacked) {
LLVMContextImpl *pImpl = Context.pImpl;
AnonStructTypeKeyInfo::KeyTy Key(ETypes, isPacked);
LLVMContextImpl::StructTypeMap::iterator I =
pImpl->AnonStructTypes.find_as(Key);
auto I = pImpl->AnonStructTypes.find_as(Key);
StructType *ST;
if (I == pImpl->AnonStructTypes.end()) {
@ -413,9 +411,9 @@ StructType *StructType::get(LLVMContext &Context, ArrayRef<Type*> ETypes,
ST = new (Context.pImpl->TypeAllocator) StructType(Context);
ST->setSubclassData(SCDB_IsLiteral); // Literal struct.
ST->setBody(ETypes, isPacked);
Context.pImpl->AnonStructTypes[ST] = true;
Context.pImpl->AnonStructTypes.insert(ST);
} else {
ST = I->first;
ST = *I;
}
return ST;

View File

@ -1593,8 +1593,7 @@ bool Linker::StructTypeKeyInfo::isEqual(const StructType *LHS,
void Linker::IdentifiedStructTypeSet::addNonOpaque(StructType *Ty) {
assert(!Ty->isOpaque());
bool &Entry = NonOpaqueStructTypes[Ty];
Entry = true;
NonOpaqueStructTypes.insert(Ty);
}
void Linker::IdentifiedStructTypeSet::addOpaque(StructType *Ty) {
@ -1609,7 +1608,7 @@ Linker::IdentifiedStructTypeSet::findNonOpaque(ArrayRef<Type *> ETypes,
auto I = NonOpaqueStructTypes.find_as(Key);
if (I == NonOpaqueStructTypes.end())
return nullptr;
return I->first;
return *I;
}
bool Linker::IdentifiedStructTypeSet::hasType(StructType *Ty) {
@ -1618,7 +1617,7 @@ bool Linker::IdentifiedStructTypeSet::hasType(StructType *Ty) {
auto I = NonOpaqueStructTypes.find(Ty);
if (I == NonOpaqueStructTypes.end())
return false;
return I->first == Ty;
return *I == Ty;
}
void Linker::init(Module *M, DiagnosticHandlerFunction DiagnosticHandler) {