mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-27 13:40:30 +00:00
Use unique_ptr for the result of Registry entries.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206248 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5a21a893c0
commit
9c94042083
@ -14,24 +14,27 @@
|
||||
#ifndef LLVM_SUPPORT_REGISTRY_H
|
||||
#define LLVM_SUPPORT_REGISTRY_H
|
||||
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace llvm {
|
||||
/// A simple registry entry which provides only a name, description, and
|
||||
/// no-argument constructor.
|
||||
template <typename T>
|
||||
class SimpleRegistryEntry {
|
||||
const char *Name, *Desc;
|
||||
T *(*Ctor)();
|
||||
std::unique_ptr<T> (*Ctor)();
|
||||
|
||||
public:
|
||||
SimpleRegistryEntry(const char *N, const char *D, T *(*C)())
|
||||
SimpleRegistryEntry(const char *N, const char *D, std::unique_ptr<T> (*C)())
|
||||
: Name(N), Desc(D), Ctor(C)
|
||||
{}
|
||||
|
||||
const char *getName() const { return Name; }
|
||||
const char *getDesc() const { return Desc; }
|
||||
T *instantiate() const { return Ctor(); }
|
||||
std::unique_ptr<T> instantiate() const { return Ctor(); }
|
||||
};
|
||||
|
||||
|
||||
@ -195,7 +198,7 @@ namespace llvm {
|
||||
entry Entry;
|
||||
node Node;
|
||||
|
||||
static T *CtorFn() { return new V(); }
|
||||
static std::unique_ptr<T> CtorFn() { return make_unique<V>(); }
|
||||
|
||||
public:
|
||||
Add(const char *Name, const char *Desc)
|
||||
|
@ -62,7 +62,7 @@ STATISTIC(EmittedInsts, "Number of machine instrs printed");
|
||||
|
||||
char AsmPrinter::ID = 0;
|
||||
|
||||
typedef DenseMap<GCStrategy*,GCMetadataPrinter*> gcp_map_type;
|
||||
typedef DenseMap<GCStrategy*, std::unique_ptr<GCMetadataPrinter>> gcp_map_type;
|
||||
static gcp_map_type &getGCMap(void *&P) {
|
||||
if (P == 0)
|
||||
P = new gcp_map_type();
|
||||
@ -114,8 +114,6 @@ AsmPrinter::~AsmPrinter() {
|
||||
if (GCMetadataPrinters != 0) {
|
||||
gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
|
||||
|
||||
for (gcp_map_type::iterator I = GCMap.begin(), E = GCMap.end(); I != E; ++I)
|
||||
delete I->second;
|
||||
delete &GCMap;
|
||||
GCMetadataPrinters = 0;
|
||||
}
|
||||
@ -2238,7 +2236,7 @@ GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy &S) {
|
||||
gcp_map_type &GCMap = getGCMap(GCMetadataPrinters);
|
||||
gcp_map_type::iterator GCPI = GCMap.find(&S);
|
||||
if (GCPI != GCMap.end())
|
||||
return GCPI->second;
|
||||
return GCPI->second.get();
|
||||
|
||||
const char *Name = S.getName().c_str();
|
||||
|
||||
@ -2246,10 +2244,10 @@ GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy &S) {
|
||||
I = GCMetadataPrinterRegistry::begin(),
|
||||
E = GCMetadataPrinterRegistry::end(); I != E; ++I)
|
||||
if (strcmp(Name, I->getName()) == 0) {
|
||||
GCMetadataPrinter *GMP = I->instantiate();
|
||||
std::unique_ptr<GCMetadataPrinter> GMP = I->instantiate();
|
||||
GMP->S = &S;
|
||||
GCMap.insert(std::make_pair(&S, GMP));
|
||||
return GMP;
|
||||
auto IterBool = GCMap.insert(std::make_pair(&S, std::move(GMP)));
|
||||
return IterBool.first->second.get();
|
||||
}
|
||||
|
||||
report_fatal_error("no GCMetadataPrinter registered for GC: " + Twine(Name));
|
||||
|
@ -70,7 +70,7 @@ GCStrategy *GCModuleInfo::getOrCreateStrategy(const Module *M,
|
||||
for (GCRegistry::iterator I = GCRegistry::begin(),
|
||||
E = GCRegistry::end(); I != E; ++I) {
|
||||
if (Name == I->getName()) {
|
||||
std::unique_ptr<GCStrategy> S(I->instantiate());
|
||||
std::unique_ptr<GCStrategy> S = I->instantiate();
|
||||
S->M = M;
|
||||
S->Name = Name;
|
||||
StrategyMap.GetOrCreateValue(Name).setValue(S.get());
|
||||
|
Loading…
Reference in New Issue
Block a user