diff options
author | Dan Gohman <gohman@apple.com> | 2010-03-18 16:16:38 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-03-18 16:16:38 +0000 |
commit | 6556c8962cf87d42665803429e0286f96dc2650d (patch) | |
tree | b81b267d16ce82bc4b515883e8504fd123d894b3 /llvm/lib/Support | |
parent | 1793c0711438346c03e49fa16e0cfa03acf482e9 (diff) | |
download | bcm5719-llvm-6556c8962cf87d42665803429e0286f96dc2650d.tar.gz bcm5719-llvm-6556c8962cf87d42665803429e0286f96dc2650d.zip |
Add the ability to "intern" FoldingSetNodeID data into a
BumpPtrAllocator-allocated region to allow it to be stored in a more
compact form and to avoid the need for a non-trivial destructor call.
Use this new mechanism in ScalarEvolution instead of
FastFoldingSetNode to avoid leaking memory in the case where a
FoldingSetNodeID uses heap storage, and to reduce overall memory
usage.
llvm-svn: 98829
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/FoldingSet.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Support/FoldingSet.cpp b/llvm/lib/Support/FoldingSet.cpp index 954dc77dff1..3f467fe1b69 100644 --- a/llvm/lib/Support/FoldingSet.cpp +++ b/llvm/lib/Support/FoldingSet.cpp @@ -15,6 +15,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/FoldingSet.h" +#include "llvm/Support/Allocator.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include <cassert> @@ -130,6 +131,15 @@ bool FoldingSetNodeID::operator==(const FoldingSetNodeID &RHS)const{ return memcmp(&Bits[0], &RHS.Bits[0], Bits.size()*sizeof(Bits[0])) == 0; } +/// Intern - Copy this node's data to a memory region allocated from the +/// given allocator and return a FoldingSetNodeIDRef describing the +/// interned data. +FoldingSetNodeIDRef +FoldingSetNodeID::Intern(BumpPtrAllocator &Allocator) const { + unsigned *New = Allocator.Allocate<unsigned>(Bits.size()); + std::uninitialized_copy(Bits.begin(), Bits.end(), New); + return FoldingSetNodeIDRef(New, Bits.size()); +} //===----------------------------------------------------------------------===// /// Helper functions for FoldingSetImpl. |