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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98829 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2010-03-18 16:16:38 +00:00
parent 7c4a121110
commit c93b4cff89
5 changed files with 76 additions and 40 deletions

View File

@@ -23,6 +23,7 @@
namespace llvm {
class APFloat;
class APInt;
class BumpPtrAllocator;
/// This folding set used for two purposes:
/// 1. Given information about a node we want to create, look up the unique
@@ -197,6 +198,23 @@ template<typename T> struct FoldingSetTrait {
static inline void Profile(T& X, FoldingSetNodeID& ID) { X.Profile(ID); }
};
//===--------------------------------------------------------------------===//
/// FoldingSetNodeIDRef - This class describes a reference to an interned
/// FoldingSetNodeID, which can be a useful to store node id data rather
/// than using plain FoldingSetNodeIDs, since the 32-element SmallVector
/// is often much larger than necessary, and the possibility of heap
/// allocation means it requires a non-trivial destructor call.
class FoldingSetNodeIDRef {
unsigned* Data;
size_t Size;
public:
FoldingSetNodeIDRef() : Data(0), Size(0) {}
FoldingSetNodeIDRef(unsigned *D, size_t S) : Data(D), Size(S) {}
unsigned *getData() const { return Data; }
size_t getSize() const { return Size; }
};
//===--------------------------------------------------------------------===//
/// FoldingSetNodeID - This class is used to gather all the unique data bits of
/// a node. When all the bits are gathered this class is used to produce a
@@ -210,11 +228,8 @@ class FoldingSetNodeID {
public:
FoldingSetNodeID() {}
/// getRawData - Return the ith entry in the Bits data.
///
unsigned getRawData(unsigned i) const {
return Bits[i];
}
FoldingSetNodeID(FoldingSetNodeIDRef Ref)
: Bits(Ref.getData(), Ref.getData() + Ref.getSize()) {}
/// Add* - Add various data types to Bit data.
///
@@ -242,6 +257,11 @@ public:
/// operator== - Used to compare two nodes to each other.
///
bool operator==(const FoldingSetNodeID &RHS) const;
/// Intern - Copy this node's data to a memory region allocated from the
/// given allocator and return a FoldingSetNodeIDRef describing the
/// interned data.
FoldingSetNodeIDRef Intern(BumpPtrAllocator &Allocator) const;
};
// Convenience type to hide the implementation of the folding set.