From bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6 Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Thu, 23 Feb 2012 09:17:40 +0000 Subject: Reinstate r151049 now that GeneralHash is fixed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@151248 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/LLVMContextImpl.h | 109 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 106 insertions(+), 3 deletions(-) (limited to 'lib/VMCore/LLVMContextImpl.h') diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index a27afc08b9..9aba73781c 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -29,6 +29,7 @@ #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/StringMap.h" +#include "llvm/ADT/Hashing.h" #include namespace llvm { @@ -89,6 +90,107 @@ struct DenseMapAPFloatKeyInfo { } }; +struct AnonStructTypeKeyInfo { + struct KeyTy { + ArrayRef ETypes; + bool isPacked; + KeyTy(const ArrayRef& E, bool P) : + ETypes(E), isPacked(P) {} + KeyTy(const KeyTy& that) : + ETypes(that.ETypes), isPacked(that.isPacked) {} + KeyTy(const StructType* ST) : + ETypes(ArrayRef(ST->element_begin(), ST->element_end())), + isPacked(ST->isPacked()) {} + bool operator==(const KeyTy& that) const { + if (isPacked != that.isPacked) + return false; + if (ETypes != that.ETypes) + return false; + return true; + } + bool operator!=(const KeyTy& that) const { + return !this->operator==(that); + } + }; + static inline StructType* getEmptyKey() { + return DenseMapInfo::getEmptyKey(); + } + static inline StructType* getTombstoneKey() { + return DenseMapInfo::getTombstoneKey(); + } + static unsigned getHashValue(const KeyTy& Key) { + GeneralHash Hash; + Hash.add(Key.ETypes); + Hash.add(Key.isPacked); + return Hash.finish(); + } + static unsigned getHashValue(const StructType *ST) { + return getHashValue(KeyTy(ST)); + } + static bool isEqual(const KeyTy& LHS, const StructType *RHS) { + if (RHS == getEmptyKey() || RHS == getTombstoneKey()) + return false; + return LHS == KeyTy(RHS); + } + static bool isEqual(const StructType *LHS, const StructType *RHS) { + return LHS == RHS; + } +}; + +struct FunctionTypeKeyInfo { + struct KeyTy { + const Type *ReturnType; + ArrayRef Params; + bool isVarArg; + KeyTy(const Type* R, const ArrayRef& P, bool V) : + ReturnType(R), Params(P), isVarArg(V) {} + KeyTy(const KeyTy& that) : + ReturnType(that.ReturnType), + Params(that.Params), + isVarArg(that.isVarArg) {} + KeyTy(const FunctionType* FT) : + ReturnType(FT->getReturnType()), + Params(ArrayRef(FT->param_begin(), FT->param_end())), + isVarArg(FT->isVarArg()) {} + bool operator==(const KeyTy& that) const { + if (ReturnType != that.ReturnType) + return false; + if (isVarArg != that.isVarArg) + return false; + if (Params != that.Params) + return false; + return true; + } + bool operator!=(const KeyTy& that) const { + return !this->operator==(that); + } + }; + static inline FunctionType* getEmptyKey() { + return DenseMapInfo::getEmptyKey(); + } + static inline FunctionType* getTombstoneKey() { + return DenseMapInfo::getTombstoneKey(); + } + static unsigned getHashValue(const KeyTy& Key) { + GeneralHash Hash; + Hash.add(Key.ReturnType); + Hash.add(Key.Params); + Hash.add(Key.isVarArg); + return Hash.finish(); + } + static unsigned getHashValue(const FunctionType *FT) { + return getHashValue(KeyTy(FT)); + } + static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) { + if (RHS == getEmptyKey() || RHS == getTombstoneKey()) + return false; + return LHS == KeyTy(RHS); + } + static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) { + return LHS == RHS; + } +}; + /// DebugRecVH - This is a CallbackVH used to keep the Scope -> index maps /// up to date as MDNodes mutate. This class is implemented in DebugLoc.cpp. class DebugRecVH : public CallbackVH { @@ -180,9 +282,10 @@ public: DenseMap IntegerTypes; - // TODO: Optimize FunctionTypes/AnonStructTypes! - std::map, FunctionType*> FunctionTypes; - std::map, StructType*> AnonStructTypes; + typedef DenseMap FunctionTypeMap; + FunctionTypeMap FunctionTypes; + typedef DenseMap StructTypeMap; + StructTypeMap AnonStructTypes; StringMap NamedStructTypes; unsigned NamedStructTypesUniqueID; -- cgit v1.2.3