diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-04-15 05:34:49 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-04-15 05:34:49 +0000 |
commit | 88368bae4cbf9cca6f8148e5397cf0cf805ebd57 (patch) | |
tree | 668da32ea792d4e39bac18ebaaec42c8a169296f | |
parent | f564ab62677c17775603465dbd7c1668d27bae20 (diff) | |
download | bcm5719-llvm-88368bae4cbf9cca6f8148e5397cf0cf805ebd57.tar.gz bcm5719-llvm-88368bae4cbf9cca6f8148e5397cf0cf805ebd57.zip |
Use unique_ptr to manage ownership of GCStrategy objects in GCMetadata
llvm-svn: 206246
-rw-r--r-- | llvm/include/llvm/CodeGen/AsmPrinter.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/CodeGen/GCMetadata.h | 5 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 16 | ||||
-rw-r--r-- | llvm/lib/CodeGen/GCMetadata.cpp | 15 |
4 files changed, 16 insertions, 22 deletions
diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h index 3126fa618cc..654b72982a1 100644 --- a/llvm/include/llvm/CodeGen/AsmPrinter.h +++ b/llvm/include/llvm/CodeGen/AsmPrinter.h @@ -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); }; } diff --git a/llvm/include/llvm/CodeGen/GCMetadata.h b/llvm/include/llvm/CodeGen/GCMetadata.h index ea9454259ef..ddcc823ecd9 100644 --- a/llvm/include/llvm/CodeGen/GCMetadata.h +++ b/llvm/include/llvm/CodeGen/GCMetadata.h @@ -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(). diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index c3afc8ba8c2..7d64cdd03f9 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -210,7 +210,7 @@ bool AsmPrinter::doInitialization(Module &M) { 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 &M) { 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 MachineBasicBlock *MBB) 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; } diff --git a/llvm/lib/CodeGen/GCMetadata.cpp b/llvm/lib/CodeGen/GCMetadata.cpp index c47450ea735..19f21864562 100644 --- a/llvm/lib/CodeGen/GCMetadata.cpp +++ b/llvm/lib/CodeGen/GCMetadata.cpp @@ -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::getOrCreateStrategy(const Module *M, 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::getFunctionInfo(const Function &F) { void GCModuleInfo::clear() { FInfoMap.clear(); StrategyMap.clear(); - - for (iterator I = begin(), E = end(); I != E; ++I) - delete *I; StrategyList.clear(); } |