From a618f82c9fdbe869b41581f00ae357e1b22302d1 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 11 Feb 2008 23:11:12 +0000 Subject: [PATCH] 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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46975 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/ImmutableMap.h | 3 +++ include/llvm/ADT/ImmutableSet.h | 31 +++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/include/llvm/ADT/ImmutableMap.h b/include/llvm/ADT/ImmutableMap.h index 6e309c0db8a..27148e6083d 100644 --- a/include/llvm/ADT/ImmutableMap.h +++ b/include/llvm/ADT/ImmutableMap.h @@ -84,6 +84,9 @@ public: 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) { diff --git a/include/llvm/ADT/ImmutableSet.h b/include/llvm/ADT/ImmutableSet.h index c339e3d4f96..717ec98ba99 100644 --- a/include/llvm/ADT/ImmutableSet.h +++ b/include/llvm/ADT/ImmutableSet.h @@ -16,6 +16,7 @@ #include "llvm/Support/Allocator.h" #include "llvm/ADT/FoldingSet.h" +#include "llvm/Support/DataTypes.h" #include namespace llvm { @@ -334,15 +335,31 @@ class ImutAVLFactory { typedef FoldingSet CacheTy; - CacheTy Cache; - BumpPtrAllocator Allocator; + CacheTy Cache; + uintptr_t Allocator; + + bool ownsAllocator() const { + return Allocator & 0x1 ? false : true; + } + + BumpPtrAllocator& getAllocator() const { + return *reinterpret_cast(Allocator & ~0x1); + } //===--------------------------------------------------===// // Public interface. //===--------------------------------------------------===// public: - ImutAVLFactory() {} + ImutAVLFactory() + : Allocator(reinterpret_cast(new BumpPtrAllocator())) {} + + ImutAVLFactory(BumpPtrAllocator& Alloc) + : Allocator(reinterpret_cast(&Alloc) | 0x1) {} + + ~ImutAVLFactory() { + if (ownsAllocator()) delete &getAllocator(); + } TreeTy* Add(TreeTy* T, value_type_ref V) { T = Add_internal(V,T); @@ -358,8 +375,6 @@ public: 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 @@ private: // Create it. // Allocate the new tree node and insert it into the cache. - TreeTy* T = (TreeTy*) Allocator.Allocate(); + BumpPtrAllocator& A = getAllocator(); + TreeTy* T = (TreeTy*) A.Allocate(); 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: public: Factory() {} + Factory(BumpPtrAllocator& Alloc) + : F(Alloc) {} + /// GetEmptySet - Returns an immutable set that contains no elements. ImmutableSet GetEmptySet() { return ImmutableSet(F.GetEmptyTree()); } -- 2.11.0