diff options
author | Chris Lattner <sabre@nondot.org> | 2004-11-19 16:39:44 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-11-19 16:39:44 +0000 |
commit | 8a7ad2d2c5940fd3bf1a0a6f2a0271e57df2d005 (patch) | |
tree | ba4f675ef4dbc8d183d1a106d103f7afa70b5913 /lib/VMCore/Constants.cpp | |
parent | 5b2d43aad08a1f8f6f48a946b5c587524b171ac9 (diff) | |
download | external_llvm-8a7ad2d2c5940fd3bf1a0a6f2a0271e57df2d005.zip external_llvm-8a7ad2d2c5940fd3bf1a0a6f2a0271e57df2d005.tar.gz external_llvm-8a7ad2d2c5940fd3bf1a0a6f2a0271e57df2d005.tar.bz2 |
Add hooks to free all memory allocated by the singleton factories in these
files. Patch contributed by Morten Ofstad!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17995 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Constants.cpp')
-rw-r--r-- | lib/VMCore/Constants.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index b5831ae..97e4fa5 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -612,6 +612,16 @@ namespace { typedef std::map<const TypeClass*, MapIterator> AbstractTypeMapTy; AbstractTypeMapTy AbstractTypeMap; + + friend void Constant::clearAllValueMaps(); + private: + void clear(std::vector<Constant *> &Constants) { + for(MapIterator I = Map.begin(); I != Map.end(); ++I) + Constants.push_back(I->second); + Map.clear(); + AbstractTypeMap.clear(); + } + public: // getOrCreate - Return the specified constant from the map, creating it if // necessary. @@ -1401,3 +1411,29 @@ const char *ConstantExpr::getOpcodeName() const { return Instruction::getOpcodeName(getOpcode()); } +/// clearAllValueMaps - This method frees all internal memory used by the +/// constant subsystem, which can be used in environments where this memory +/// is otherwise reported as a leak. +void Constant::clearAllValueMaps() { + std::vector<Constant *> Constants; + + DoubleConstants.clear(Constants); + FloatConstants.clear(Constants); + SIntConstants.clear(Constants); + UIntConstants.clear(Constants); + AggZeroConstants.clear(Constants); + ArrayConstants.clear(Constants); + StructConstants.clear(Constants); + PackedConstants.clear(Constants); + NullPtrConstants.clear(Constants); + UndefValueConstants.clear(Constants); + ExprConstants.clear(Constants); + + for (std::vector<Constant *>::iterator I = Constants.begin(), + E = Constants.end(); I != E; ++I) + (*I)->dropAllReferences(); + for (std::vector<Constant *>::iterator I = Constants.begin(), + E = Constants.end(); I != E; ++I) + (*I)->destroyConstantImpl(); + Constants.clear(); +} |