remove extraneous namespace qualifier, PR2142
[oota-llvm.git] / lib / Support / Allocator.cpp
index a31b80fcf355e698b55d98092e8693b3a1747213..5961afe04c7ffd47b046a961e5ca81b5bc3ae4a6 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Chris Lattner and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -68,14 +68,25 @@ public:
     return NewRegion->Allocate(AllocSize, Alignment, RegPtr);
   }
   
-  /// Deallocate - Release all memory for this region to the system.
-  ///
+  /// Deallocate - Recursively release all memory for this and its next regions
+  /// to the system.
   void Deallocate() {
     MemRegion *next = Next;
     free(this);
     if (next)
       next->Deallocate();
   }
+
+  /// DeallocateAllButLast - Recursively release all memory for this and its
+  /// next regions to the system stopping at the last region in the list.
+  /// Returns the pointer to the last region.
+  MemRegion *DeallocateAllButLast() {
+    MemRegion *next = Next;
+    if (!next)
+      return this;
+    free(this);
+    return next->DeallocateAllButLast();
+  }
 };
 }
 
@@ -92,8 +103,18 @@ BumpPtrAllocator::~BumpPtrAllocator() {
   ((MemRegion*)TheMemory)->Deallocate();
 }
 
+void BumpPtrAllocator::Reset() {
+  MemRegion *MRP = (MemRegion*)TheMemory;
+  MRP = MRP->DeallocateAllButLast();
+  MRP->Init(4096, 1, 0);
+  TheMemory = MRP;
+}
+
 void *BumpPtrAllocator::Allocate(unsigned Size, unsigned Align) {
-  return ((MemRegion*)TheMemory)->Allocate(Size, Align,(MemRegion**)&TheMemory);
+  MemRegion *MRP = (MemRegion*)TheMemory;
+  void *Ptr = MRP->Allocate(Size, Align, &MRP);
+  TheMemory = MRP;
+  return Ptr;
 }
 
 void BumpPtrAllocator::PrintStats() const {