summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/ConstantsContext.h
diff options
context:
space:
mode:
authorTorok Edwin <edwintorok@gmail.com>2009-08-31 16:14:59 +0000
committerTorok Edwin <edwintorok@gmail.com>2009-08-31 16:14:59 +0000
commitd18e668fbcf40951c19a908f91b74cd41ea9f21c (patch)
treed6fa21e407120c03885c652290bfca34b2674c8e /llvm/lib/VMCore/ConstantsContext.h
parent487d57602076cdb6d64a0e7931a5c01008adb7cb (diff)
downloadbcm5719-llvm-d18e668fbcf40951c19a908f91b74cd41ea9f21c.tar.gz
bcm5719-llvm-d18e668fbcf40951c19a908f91b74cd41ea9f21c.zip
Free the constants that have no uses in ~LLVMContext.
This fixes leaks from LLVMContext in multithreaded apps. Since constants are only deleted if they have no uses, it is safe to not delete a Module on shutdown, as many single-threaded tools do. Multithreaded apps should however delete the Module before destroying the Context to ensure that there are no leaks (assuming they use a different context for each thread). llvm-svn: 80590
Diffstat (limited to 'llvm/lib/VMCore/ConstantsContext.h')
-rw-r--r--llvm/lib/VMCore/ConstantsContext.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/ConstantsContext.h b/llvm/lib/VMCore/ConstantsContext.h
index 22aba7e1d35..f4a2cde5d0f 100644
--- a/llvm/lib/VMCore/ConstantsContext.h
+++ b/llvm/lib/VMCore/ConstantsContext.h
@@ -575,6 +575,14 @@ public:
// to enforce proper synchronization.
typename MapTy::iterator map_begin() { return Map.begin(); }
typename MapTy::iterator map_end() { return Map.end(); }
+
+ void freeConstants() {
+ for (typename MapTy::iterator I=Map.begin(), E=Map.end();
+ I != E; ++I) {
+ if (I->second->use_empty())
+ delete I->second;
+ }
+ }
/// InsertOrGetItem - Return an iterator for the specified element.
/// If the element exists in the map, the returned iterator points to the
OpenPOWER on IntegriCloud