Author: kremenek Date: Mon Feb 11 17:11:12 2008 New Revision: 46975 URL: http://llvm.org/viewvc/llvm-project?rev=46975&view=rev Log: The factories for ImutAVLTree/ImmutableSet/ImmutableMap now take an (optional) BumpPtrAllocator argument to their constructors. This BumpPtrAllocator will be used to allocate trees. If no BumpPtrAllocator is provided, one is created (as before).
Modified: llvm/trunk/include/llvm/ADT/ImmutableMap.h llvm/trunk/include/llvm/ADT/ImmutableSet.h Modified: llvm/trunk/include/llvm/ADT/ImmutableMap.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ImmutableMap.h?rev=46975&r1=46974&r2=46975&view=diff ============================================================================== --- llvm/trunk/include/llvm/ADT/ImmutableMap.h (original) +++ llvm/trunk/include/llvm/ADT/ImmutableMap.h Mon Feb 11 17:11:12 2008 @@ -84,6 +84,9 @@ public: Factory() {} + Factory(BumpPtrAllocator& Alloc) + : F(Alloc) {} + ImmutableMap GetEmptyMap() { return ImmutableMap(F.GetEmptyTree()); } ImmutableMap Add(ImmutableMap Old, key_type_ref K, data_type_ref D) { Modified: llvm/trunk/include/llvm/ADT/ImmutableSet.h URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/ImmutableSet.h?rev=46975&r1=46974&r2=46975&view=diff ============================================================================== --- llvm/trunk/include/llvm/ADT/ImmutableSet.h (original) +++ llvm/trunk/include/llvm/ADT/ImmutableSet.h Mon Feb 11 17:11:12 2008 @@ -16,6 +16,7 @@ #include "llvm/Support/Allocator.h" #include "llvm/ADT/FoldingSet.h" +#include "llvm/Support/DataTypes.h" #include <cassert> namespace llvm { @@ -334,15 +335,31 @@ typedef FoldingSet<TreeTy> CacheTy; - CacheTy Cache; - BumpPtrAllocator Allocator; + CacheTy Cache; + uintptr_t Allocator; + + bool ownsAllocator() const { + return Allocator & 0x1 ? false : true; + } + + BumpPtrAllocator& getAllocator() const { + return *reinterpret_cast<BumpPtrAllocator*>(Allocator & ~0x1); + } //===--------------------------------------------------===// // Public interface. //===--------------------------------------------------===// public: - ImutAVLFactory() {} + ImutAVLFactory() + : Allocator(reinterpret_cast<uintptr_t>(new BumpPtrAllocator())) {} + + ImutAVLFactory(BumpPtrAllocator& Alloc) + : Allocator(reinterpret_cast<uintptr_t>(&Alloc) | 0x1) {} + + ~ImutAVLFactory() { + if (ownsAllocator()) delete &getAllocator(); + } TreeTy* Add(TreeTy* T, value_type_ref V) { T = Add_internal(V,T); @@ -358,8 +375,6 @@ TreeTy* GetEmptyTree() const { return NULL; } - BumpPtrAllocator& getAllocator() { return Allocator; } - //===--------------------------------------------------===// // A bunch of quick helper functions used for reasoning // about the properties of trees and their children. @@ -450,7 +465,8 @@ // Create it. // Allocate the new tree node and insert it into the cache. - TreeTy* T = (TreeTy*) Allocator.Allocate<TreeTy>(); + BumpPtrAllocator& A = getAllocator(); + TreeTy* T = (TreeTy*) A.Allocate<TreeTy>(); new (T) TreeTy(L,R,V,IncrementHeight(L,R)); // We do not insert 'T' into the FoldingSet here. This is because @@ -930,6 +946,9 @@ public: Factory() {} + Factory(BumpPtrAllocator& Alloc) + : F(Alloc) {} + /// GetEmptySet - Returns an immutable set that contains no elements. ImmutableSet GetEmptySet() { return ImmutableSet(F.GetEmptyTree()); } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits