From 188b5224fd9c8573713665c77f9d2f415bcc4ff1 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Wed, 5 Sep 2007 21:41:34 +0000 Subject: [PATCH] Added Reset() to free all allocated memory regions and reset state to be the same as right after ctor. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41728 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Allocator.h | 2 ++ lib/Support/Allocator.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/include/llvm/Support/Allocator.h b/include/llvm/Support/Allocator.h index 527d4c6e2cb..f23a41f17fa 100644 --- a/include/llvm/Support/Allocator.h +++ b/include/llvm/Support/Allocator.h @@ -23,6 +23,7 @@ public: MallocAllocator() {} ~MallocAllocator() {} + void Reset() {} void *Allocate(unsigned Size, unsigned Alignment) { return malloc(Size); } void Deallocate(void *Ptr) { free(Ptr); } void PrintStats() const {} @@ -38,6 +39,7 @@ public: BumpPtrAllocator(); ~BumpPtrAllocator(); + void Reset(); void *Allocate(unsigned Size, unsigned Alignment); void Deallocate(void *Ptr) {} void PrintStats() const; diff --git a/lib/Support/Allocator.cpp b/lib/Support/Allocator.cpp index 234fd41b738..e68c3e26c7d 100644 --- a/lib/Support/Allocator.cpp +++ b/lib/Support/Allocator.cpp @@ -92,6 +92,12 @@ BumpPtrAllocator::~BumpPtrAllocator() { ((MemRegion*)TheMemory)->Deallocate(); } +void BumpPtrAllocator::Reset() { + ((MemRegion*)TheMemory)->Deallocate(); + TheMemory = malloc(4096); + ((MemRegion*)TheMemory)->Init(4096, 1, 0); +} + void *BumpPtrAllocator::Allocate(unsigned Size, unsigned Align) { MemRegion *MRP = (MemRegion*)TheMemory; void *Ptr = MRP->Allocate(Size, Align, &MRP);