[llvm] r206297 - Use unique_ptr to manage PassInfo instances in the PassRegistry

David Blaikie dblaikie at gmail.com
Tue Apr 15 08:17:14 PDT 2014


Author: dblaikie
Date: Tue Apr 15 10:17:14 2014
New Revision: 206297

URL: http://llvm.org/viewvc/llvm-project?rev=206297&view=rev
Log:
Use unique_ptr to manage PassInfo instances in the PassRegistry

Modified:
    llvm/trunk/lib/IR/PassRegistry.cpp

Modified: llvm/trunk/lib/IR/PassRegistry.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/PassRegistry.cpp?rev=206297&r1=206296&r2=206297&view=diff
==============================================================================
--- llvm/trunk/lib/IR/PassRegistry.cpp (original)
+++ llvm/trunk/lib/IR/PassRegistry.cpp Tue Apr 15 10:17:14 2014
@@ -57,7 +57,7 @@ struct PassRegistryImpl {
   };
   DenseMap<const PassInfo*, AnalysisGroupInfo> AnalysisGroupInfoMap;
   
-  std::vector<const PassInfo*> ToFree;
+  std::vector<std::unique_ptr<const PassInfo>> ToFree;
   std::vector<PassRegistrationListener*> Listeners;
 };
 } // end anonymous namespace
@@ -75,11 +75,6 @@ void *PassRegistry::getImpl() const {
 PassRegistry::~PassRegistry() {
   sys::SmartScopedWriter<true> Guard(*Lock);
   PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(pImpl);
-  
-  for (std::vector<const PassInfo*>::iterator I = Impl->ToFree.begin(),
-       E = Impl->ToFree.end(); I != E; ++I)
-    delete *I;
-  
   delete Impl;
   pImpl = nullptr;
 }
@@ -117,7 +112,7 @@ void PassRegistry::registerPass(const Pa
        I = Impl->Listeners.begin(), E = Impl->Listeners.end(); I != E; ++I)
     (*I)->passRegistered(&PI);
   
-  if (ShouldFree) Impl->ToFree.push_back(&PI);
+  if (ShouldFree) Impl->ToFree.push_back(std::unique_ptr<const PassInfo>(&PI));
 }
 
 void PassRegistry::unregisterPass(const PassInfo &PI) {
@@ -185,7 +180,8 @@ void PassRegistry::registerAnalysisGroup
   }
   
   PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
-  if (ShouldFree) Impl->ToFree.push_back(&Registeree);
+  if (ShouldFree)
+    Impl->ToFree.push_back(std::unique_ptr<const PassInfo>(&Registeree));
 }
 
 void PassRegistry::addRegistrationListener(PassRegistrationListener *L) {





More information about the llvm-commits mailing list