[llvm-commits] [llvm] r68523 - in /llvm/trunk: examples/HowToUseJIT/HowToUseJIT.cpp include/llvm/AbstractTypeUser.h lib/VMCore/Type.cpp

Torok Edwin edwintorok at gmail.com
Tue Apr 7 10:23:03 PDT 2009


Author: edwin
Date: Tue Apr  7 12:23:02 2009
New Revision: 68523

URL: http://llvm.org/viewvc/llvm-project?rev=68523&view=rev
Log:
Another attempt at fixing PR2975.
Types can have references to eachother, so we can't just call destroy on them.

Modified:
    llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp
    llvm/trunk/include/llvm/AbstractTypeUser.h
    llvm/trunk/lib/VMCore/Type.cpp

Modified: llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp?rev=68523&r1=68522&r2=68523&view=diff

==============================================================================
--- llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp (original)
+++ llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp Tue Apr  7 12:23:02 2009
@@ -42,6 +42,7 @@
 #include "llvm/ExecutionEngine/JIT.h"
 #include "llvm/ExecutionEngine/Interpreter.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
+#include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
@@ -109,5 +110,8 @@
 
   // Import result of execution:
   outs() << "Result: " << gv.IntVal << "\n";
+  EE->freeMachineCodeForFunction(FooF);
+  delete EE;
+  llvm_shutdown();
   return 0;
 }

Modified: llvm/trunk/include/llvm/AbstractTypeUser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/AbstractTypeUser.h?rev=68523&r1=68522&r2=68523&view=diff

==============================================================================
--- llvm/trunk/include/llvm/AbstractTypeUser.h (original)
+++ llvm/trunk/include/llvm/AbstractTypeUser.h Tue Apr  7 12:23:02 2009
@@ -137,6 +137,7 @@
 ///
 class PATypeHolder {
   mutable const Type *Ty;
+  void destroy();
 public:
   PATypeHolder(const Type *ty) : Ty(ty) {
     addRef();
@@ -145,7 +146,7 @@
     addRef();
   }
 
-  ~PATypeHolder() { dropRef(); }
+  ~PATypeHolder() { if (Ty) dropRef(); }
 
   operator Type *() const { return get(); }
   Type *get() const;
@@ -173,6 +174,7 @@
 private:
   void addRef();
   void dropRef();
+  friend class TypeMapBase;
 };
 
 // simplify_type - Allow clients to treat uses just like values when using

Modified: llvm/trunk/lib/VMCore/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=68523&r1=68522&r2=68523&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Type.cpp (original)
+++ llvm/trunk/lib/VMCore/Type.cpp Tue Apr  7 12:23:02 2009
@@ -388,6 +388,10 @@
 #endif
 }
 
+void PATypeHolder::destroy() {
+  Ty = 0;
+}
+
 // dropAllTypeUses - When this (abstract) type is resolved to be equal to
 // another (more concrete) type, we must eliminate all references to other
 // types, to avoid some circular reference problems.
@@ -666,6 +670,27 @@
   std::multimap<unsigned, PATypeHolder> TypesByHash;
 
 public:
+  ~TypeMapBase()
+  {
+    //PATypeHolder won't destroy non-abstract types.
+    //We can't destroy them by simply iterating,  because
+    //they may contain references to each-other
+
+    for (std::multimap<unsigned, PATypeHolder>::iterator I
+         = TypesByHash.begin(), E = TypesByHash.end(); I != E; ++I) {
+      Type *Ty = const_cast<Type*>(I->second.Ty);
+      I->second.destroy();
+      // We can't invoke destroy or delete, because the type may
+      // contain references to already freed types.
+      // So we have to destruct the object the ugly way.
+      if (Ty) {
+        Ty->AbstractTypeUsers.clear();
+        static_cast<const Type*>(Ty)->Type::~Type();
+        operator delete(Ty);
+      }
+    }
+  }
+
   void RemoveFromTypesByHash(unsigned Hash, const Type *Ty) {
     std::multimap<unsigned, PATypeHolder>::iterator I =
       TypesByHash.lower_bound(Hash);





More information about the llvm-commits mailing list