From: Benjamin Kramer Date: Sat, 6 Dec 2014 19:22:54 +0000 (+0000) Subject: Turn some DenseMaps that are only used for set operations into DenseSets. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2991725fe2982e0fc2c28e9f53cd9a2bec90a9d9;p=oota-llvm.git Turn some DenseMaps that are only used for set operations into DenseSets. DenseSet has better memory efficiency now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223589 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Linker/Linker.h b/include/llvm/Linker/Linker.h index 9e452453210..1de4488b33b 100644 --- a/include/llvm/Linker/Linker.h +++ b/include/llvm/Linker/Linker.h @@ -47,8 +47,7 @@ public: static bool isEqual(const StructType *LHS, const StructType *RHS); }; - typedef DenseMap - NonOpaqueStructTypeSet; + typedef DenseSet NonOpaqueStructTypeSet; typedef DenseSet OpaqueStructTypeSet; struct IdentifiedStructTypeSet { diff --git a/lib/IR/LLVMContextImpl.h b/lib/IR/LLVMContextImpl.h index 31f5fe83d68..09102b1d56b 100644 --- a/lib/IR/LLVMContextImpl.h +++ b/lib/IR/LLVMContextImpl.h @@ -313,11 +313,11 @@ public: BumpPtrAllocator TypeAllocator; DenseMap IntegerTypes; - - typedef DenseMap FunctionTypeMap; - FunctionTypeMap FunctionTypes; - typedef DenseMap StructTypeMap; - StructTypeMap AnonStructTypes; + + typedef DenseSet FunctionTypeSet; + FunctionTypeSet FunctionTypes; + typedef DenseSet StructTypeSet; + StructTypeSet AnonStructTypes; StringMap NamedStructTypes; unsigned NamedStructTypesUniqueID; diff --git a/lib/IR/Type.cpp b/lib/IR/Type.cpp index 0458b5f35ba..889705e95fc 100644 --- a/lib/IR/Type.cpp +++ b/lib/IR/Type.cpp @@ -360,8 +360,7 @@ FunctionType *FunctionType::get(Type *ReturnType, ArrayRef 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::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 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 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; diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index de62c3b94d0..87f195ead2f 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -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 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) {