[llvm-commits] [llvm] r135031 - in /llvm/trunk/lib/VMCore: LLVMContextImpl.cpp LLVMContextImpl.h Type.cpp

Chris Lattner sabre at nondot.org
Tue Jul 12 21:22:39 PDT 2011


Author: lattner
Date: Tue Jul 12 23:22:39 2011
New Revision: 135031

URL: http://llvm.org/viewvc/llvm-project?rev=135031&view=rev
Log:
stop leaking all named struct types with an empty name.  Thanks
to Benjamin Kramer for steering me in the right direction here.


Modified:
    llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
    llvm/trunk/lib/VMCore/LLVMContextImpl.h
    llvm/trunk/lib/VMCore/Type.cpp

Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.cpp?rev=135031&r1=135030&r2=135031&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.cpp Tue Jul 12 23:22:39 2011
@@ -81,14 +81,12 @@
   SmallVector<MDNode*, 8> MDNodes;
   MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size());
   for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end();
-       I != E; ++I) {
+       I != E; ++I)
     MDNodes.push_back(&*I);
-  }
   MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end());
   for (SmallVectorImpl<MDNode *>::iterator I = MDNodes.begin(),
-         E = MDNodes.end(); I != E; ++I) {
+         E = MDNodes.end(); I != E; ++I)
     (*I)->destroy();
-  }
   assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() &&
          "Destroying all MDNodes didn't empty the Context's sets.");
   // Destroy MDStrings.
@@ -103,7 +101,10 @@
   DeleteContainerSeconds(PointerTypes);
   DeleteContainerSeconds(ASPointerTypes);
 
-  for (StringMap<StructType *>::iterator I = NamedStructTypes.begin(), E = NamedStructTypes.end(); I != E; ++I) {
+  for (StringMap<StructType *>::iterator I = NamedStructTypes.begin(),
+       E = NamedStructTypes.end(); I != E; ++I)
     delete I->getValue();
-  }
+  for (SmallPtrSet<StructType*, 16>::iterator I = EmptyNamedStructTypes.begin(),
+       E = EmptyNamedStructTypes.end(); I != E; ++I)
+    delete *I;
 }

Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.h?rev=135031&r1=135030&r2=135031&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Tue Jul 12 23:22:39 2011
@@ -179,6 +179,7 @@
   std::map<std::vector<Type*>, FunctionType*> FunctionTypes;
   std::map<std::vector<Type*>, StructType*> AnonStructTypes;
   StringMap<StructType*> NamedStructTypes;
+  SmallPtrSet<StructType*, 16> EmptyNamedStructTypes;
   unsigned NamedStructTypesUniqueID;
     
   DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;

Modified: llvm/trunk/lib/VMCore/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=135031&r1=135030&r2=135031&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Type.cpp (original)
+++ llvm/trunk/lib/VMCore/Type.cpp Tue Jul 12 23:22:39 2011
@@ -412,7 +412,10 @@
 
 StructType *StructType::createNamed(LLVMContext &Context, StringRef Name) {
   StructType *ST = new StructType(Context);
-  ST->setName(Name);
+  if (!Name.empty())
+    ST->setName(Name);
+  else
+    Context.pImpl->EmptyNamedStructTypes.insert(ST);
   return ST;
 }
 
@@ -423,11 +426,16 @@
   if (SymbolTableEntry) {
     getContext().pImpl->NamedStructTypes.erase(getName());
     SymbolTableEntry = 0;
+  } else {
+    getContext().pImpl->EmptyNamedStructTypes.erase(this);
   }
   
   // If this is just removing the name, we're done.
-  if (Name.empty())
+  if (Name.empty()) {
+    // Keep track of types with no names so we can free them.
+    getContext().pImpl->EmptyNamedStructTypes.insert(this);
     return;
+  }
   
   // Look up the entry for the name.
   StringMapEntry<StructType*> *Entry =





More information about the llvm-commits mailing list