mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 00:32:55 +00:00
Changed profiling method for ImmutableMap to once again just use its
unique ImutAVLTree* for profiling. Modified ImutAVLTree: (1) changed ComputeHash() to ComputeDigest() and (2) changed Profile() to use the computed digest and (3) modified insertion of IMutAVLTree into the FoldingSet owned by the ImutAVLTreeFactory object to use profiling instead of computing a direct hash. This fixes a bug where our abuse of the FoldingSet would not work when the FoldingSet was resized. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46753 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5a804e3e21
commit
95da16e288
@ -206,7 +206,7 @@ public:
|
|||||||
inline unsigned getHeight() const { return Root ? Root->getHeight() : 0; }
|
inline unsigned getHeight() const { return Root ? Root->getHeight() : 0; }
|
||||||
|
|
||||||
static inline void Profile(FoldingSetNodeID& ID, const ImmutableMap& M) {
|
static inline void Profile(FoldingSetNodeID& ID, const ImmutableMap& M) {
|
||||||
M.Root->Profile(ID);
|
ID.AddPointer(M.Root);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Profile(FoldingSetNodeID& ID) const {
|
inline void Profile(FoldingSetNodeID& ID) const {
|
||||||
|
@ -203,13 +203,10 @@ public:
|
|||||||
return getHeight();
|
return getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Profile - Profiling for ImutAVLTree. This is not used by the
|
/// Profile - Profiling for ImutAVLTree.
|
||||||
// Factory object (which internally uses a FoldingSet), but can
|
void Profile(llvm::FoldingSetNodeID& ID) {
|
||||||
// be used by external clients that wish to insert an ImutAVLTree
|
ID.AddInteger(ComputeDigest());
|
||||||
// object into a FoldingSet.
|
}
|
||||||
void Profile(llvm::FoldingSetNodeID& ID) const {
|
|
||||||
ID.AddPointer(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
//===----------------------------------------------------===//
|
//===----------------------------------------------------===//
|
||||||
// Internal Values.
|
// Internal Values.
|
||||||
@ -220,7 +217,7 @@ private:
|
|||||||
ImutAVLTree* Right;
|
ImutAVLTree* Right;
|
||||||
unsigned Height;
|
unsigned Height;
|
||||||
value_type Value;
|
value_type Value;
|
||||||
unsigned Hash;
|
unsigned Digest;
|
||||||
|
|
||||||
//===----------------------------------------------------===//
|
//===----------------------------------------------------===//
|
||||||
// Internal methods (node manipulation; used by Factory).
|
// Internal methods (node manipulation; used by Factory).
|
||||||
@ -234,7 +231,7 @@ private:
|
|||||||
/// ImutAVLFactory.
|
/// ImutAVLFactory.
|
||||||
ImutAVLTree(ImutAVLTree* l, ImutAVLTree* r, value_type_ref v, unsigned height)
|
ImutAVLTree(ImutAVLTree* l, ImutAVLTree* r, value_type_ref v, unsigned height)
|
||||||
: Left(reinterpret_cast<uintptr_t>(l) | Mutable),
|
: Left(reinterpret_cast<uintptr_t>(l) | Mutable),
|
||||||
Right(r), Height(height), Value(v), Hash(0) {}
|
Right(r), Height(height), Value(v), Digest(0) {}
|
||||||
|
|
||||||
|
|
||||||
/// isMutable - Returns true if the left and right subtree references
|
/// isMutable - Returns true if the left and right subtree references
|
||||||
@ -299,27 +296,27 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
unsigned ComputeHash(ImutAVLTree* L, ImutAVLTree* R, value_type_ref V) {
|
unsigned ComputeDigest(ImutAVLTree* L, ImutAVLTree* R, value_type_ref V) {
|
||||||
unsigned hash = 0;
|
unsigned digest = 0;
|
||||||
|
|
||||||
if (L) hash += L->ComputeHash();
|
if (L) digest += L->ComputeDigest();
|
||||||
|
|
||||||
{ // Compute hash of stored data.
|
{ // Compute digest of stored data.
|
||||||
FoldingSetNodeID ID;
|
FoldingSetNodeID ID;
|
||||||
ImutInfo::Profile(ID,V);
|
ImutInfo::Profile(ID,V);
|
||||||
hash += ID.ComputeHash();
|
digest += ID.ComputeHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R) hash += R->ComputeHash();
|
if (R) digest += R->ComputeDigest();
|
||||||
|
|
||||||
return hash;
|
return digest;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned ComputeHash() {
|
inline unsigned ComputeDigest() {
|
||||||
if (Hash) return Hash;
|
if (Digest) return Digest;
|
||||||
|
|
||||||
unsigned X = ComputeHash(getSafeLeft(), getRight(), getValue());
|
unsigned X = ComputeDigest(getSafeLeft(), getRight(), getValue());
|
||||||
if (!isMutable()) Hash = X;
|
if (!isMutable()) Digest = X;
|
||||||
|
|
||||||
return X;
|
return X;
|
||||||
}
|
}
|
||||||
@ -408,15 +405,19 @@ private:
|
|||||||
//===--------------------------------------------------===//
|
//===--------------------------------------------------===//
|
||||||
|
|
||||||
TreeTy* CreateNode(TreeTy* L, value_type_ref V, TreeTy* R) {
|
TreeTy* CreateNode(TreeTy* L, value_type_ref V, TreeTy* R) {
|
||||||
// Search the FoldingSet bucket for a Tree with the same hash.
|
// Search the FoldingSet bucket for a Tree with the same digest.
|
||||||
unsigned hash = TreeTy::ComputeHash(L, R, V);
|
FoldingSetNodeID ID;
|
||||||
|
unsigned digest = TreeTy::ComputeDigest(L, R, V);
|
||||||
|
ID.AddInteger(digest);
|
||||||
|
unsigned hash = ID.ComputeHash();
|
||||||
|
|
||||||
typename CacheTy::bucket_iterator I = Cache.bucket_begin(hash);
|
typename CacheTy::bucket_iterator I = Cache.bucket_begin(hash);
|
||||||
typename CacheTy::bucket_iterator E = Cache.bucket_end(hash);
|
typename CacheTy::bucket_iterator E = Cache.bucket_end(hash);
|
||||||
|
|
||||||
for (; I != E; ++I) {
|
for (; I != E; ++I) {
|
||||||
TreeTy* T = &*I;
|
TreeTy* T = &*I;
|
||||||
|
|
||||||
if (T->ComputeHash() != hash)
|
if (T->ComputeDigest() != digest)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// We found a collision. Perform a comparison of Contents('T')
|
// We found a collision. Perform a comparison of Contents('T')
|
||||||
@ -454,7 +455,7 @@ private:
|
|||||||
|
|
||||||
// We do not insert 'T' into the FoldingSet here. This is because
|
// We do not insert 'T' into the FoldingSet here. This is because
|
||||||
// this tree is still mutable and things may get rebalanced.
|
// this tree is still mutable and things may get rebalanced.
|
||||||
// Because our hash is associative and based on the contents of
|
// Because our digest is associative and based on the contents of
|
||||||
// the set, this should hopefully not cause any strange bugs.
|
// the set, this should hopefully not cause any strange bugs.
|
||||||
// 'T' is inserted by 'MarkImmutable'.
|
// 'T' is inserted by 'MarkImmutable'.
|
||||||
|
|
||||||
@ -592,7 +593,9 @@ private:
|
|||||||
|
|
||||||
// Now that the node is immutable it can safely be inserted
|
// Now that the node is immutable it can safely be inserted
|
||||||
// into the node cache.
|
// into the node cache.
|
||||||
Cache.InsertNode(T, (void*) &*Cache.bucket_end(T->ComputeHash()));
|
llvm::FoldingSetNodeID ID;
|
||||||
|
ID.AddInteger(T->ComputeDigest());
|
||||||
|
Cache.InsertNode(T, (void*) &*Cache.bucket_end(ID.ComputeHash()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user