[llvm] r206246 - Use unique_ptr to manage ownership of GCStrategy objects in GCMetadata
David Blaikie
dblaikie at gmail.com
Mon Apr 14 22:34:50 PDT 2014
Author: dblaikie
Date: Tue Apr 15 00:34:49 2014
New Revision: 206246
URL: http://llvm.org/viewvc/llvm-project?rev=206246&view=rev
Log:
Use unique_ptr to manage ownership of GCStrategy objects in GCMetadata
Modified:
llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
llvm/trunk/include/llvm/CodeGen/GCMetadata.h
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/lib/CodeGen/GCMetadata.cpp
Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=206246&r1=206245&r2=206246&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Tue Apr 15 00:34:49 2014
@@ -516,7 +516,7 @@ namespace llvm {
/// Emit llvm.ident metadata in an '.ident' directive.
void EmitModuleIdents(Module &M);
void EmitXXStructorList(const Constant *List, bool isCtor);
- GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C);
+ GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy &C);
};
}
Modified: llvm/trunk/include/llvm/CodeGen/GCMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GCMetadata.h?rev=206246&r1=206245&r2=206246&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GCMetadata.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GCMetadata.h Tue Apr 15 00:34:49 2014
@@ -38,6 +38,8 @@
#include "llvm/IR/DebugLoc.h"
#include "llvm/Pass.h"
+#include <memory>
+
namespace llvm {
class AsmPrinter;
class GCStrategy;
@@ -163,7 +165,7 @@ namespace llvm {
///
class GCModuleInfo : public ImmutablePass {
typedef StringMap<GCStrategy*> strategy_map_type;
- typedef std::vector<GCStrategy*> list_type;
+ typedef std::vector<std::unique_ptr<GCStrategy>> list_type;
typedef DenseMap<const Function*,GCFunctionInfo*> finfo_map_type;
strategy_map_type StrategyMap;
@@ -178,7 +180,6 @@ namespace llvm {
static char ID;
GCModuleInfo();
- ~GCModuleInfo();
/// clear - Resets the pass. Any pass, which uses GCModuleInfo, should
/// call it in doFinalization().
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=206246&r1=206245&r2=206246&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Apr 15 00:34:49 2014
@@ -210,7 +210,7 @@ bool AsmPrinter::doInitialization(Module
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I)
- if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
+ if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(**I))
MP->beginAssembly(*this);
// Emit module-level inline asm if it exists.
@@ -966,7 +966,7 @@ bool AsmPrinter::doFinalization(Module &
GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; )
- if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*--I))
+ if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(**--I))
MP->finishAssembly(*this);
// Emit llvm.ident metadata in an '.ident' directive.
@@ -2231,24 +2231,24 @@ isBlockOnlyReachableByFallthrough(const
-GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
- if (!S->usesMetadata())
+GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy &S) {
+ if (!S.usesMetadata())
return 0;
gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
- gcp_map_type::iterator GCPI = GCMap.find(S);
+ gcp_map_type::iterator GCPI = GCMap.find(&S);
if (GCPI != GCMap.end())
return GCPI->second;
- const char *Name = S->getName().c_str();
+ const char *Name = S.getName().c_str();
for (GCMetadataPrinterRegistry::iterator
I = GCMetadataPrinterRegistry::begin(),
E = GCMetadataPrinterRegistry::end(); I != E; ++I)
if (strcmp(Name, I->getName()) == 0) {
GCMetadataPrinter *GMP = I->instantiate();
- GMP->S = S;
- GCMap.insert(std::make_pair(S, GMP));
+ GMP->S = &S;
+ GCMap.insert(std::make_pair(&S, GMP));
return GMP;
}
Modified: llvm/trunk/lib/CodeGen/GCMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GCMetadata.cpp?rev=206246&r1=206245&r2=206246&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GCMetadata.cpp (original)
+++ llvm/trunk/lib/CodeGen/GCMetadata.cpp Tue Apr 15 00:34:49 2014
@@ -61,10 +61,6 @@ GCModuleInfo::GCModuleInfo()
initializeGCModuleInfoPass(*PassRegistry::getPassRegistry());
}
-GCModuleInfo::~GCModuleInfo() {
- clear();
-}
-
GCStrategy *GCModuleInfo::getOrCreateStrategy(const Module *M,
const std::string &Name) {
strategy_map_type::iterator NMI = StrategyMap.find(Name);
@@ -74,12 +70,12 @@ GCStrategy *GCModuleInfo::getOrCreateStr
for (GCRegistry::iterator I = GCRegistry::begin(),
E = GCRegistry::end(); I != E; ++I) {
if (Name == I->getName()) {
- GCStrategy *S = I->instantiate();
+ std::unique_ptr<GCStrategy> S(I->instantiate());
S->M = M;
S->Name = Name;
- StrategyMap.GetOrCreateValue(Name).setValue(S);
- StrategyList.push_back(S);
- return S;
+ StrategyMap.GetOrCreateValue(Name).setValue(S.get());
+ StrategyList.push_back(std::move(S));
+ return StrategyList.back().get();
}
}
@@ -104,9 +100,6 @@ GCFunctionInfo &GCModuleInfo::getFunctio
void GCModuleInfo::clear() {
FInfoMap.clear();
StrategyMap.clear();
-
- for (iterator I = begin(), E = end(); I != E; ++I)
- delete *I;
StrategyList.clear();
}
More information about the llvm-commits
mailing list