mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-23 14:25:07 +00:00
[TableGen] Fix all remaining memory leaks of Init and RecTy objects.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235696 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -81,7 +81,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
RecTyKind Kind;
|
RecTyKind Kind;
|
||||||
ListRecTy *ListTy;
|
std::unique_ptr<ListRecTy> ListTy;
|
||||||
virtual void anchor();
|
virtual void anchor();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -566,6 +566,11 @@ class TypedInit : public Init {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit TypedInit(InitKind K, RecTy *T) : Init(K), Ty(T) {}
|
explicit TypedInit(InitKind K, RecTy *T) : Init(K), Ty(T) {}
|
||||||
|
~TypedInit() {
|
||||||
|
// If this is a DefInit we need to delete the RecordRecTy.
|
||||||
|
if (getKind() == IK_DefInit)
|
||||||
|
delete Ty;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static bool classof(const Init *I) {
|
static bool classof(const Init *I) {
|
||||||
|
@@ -91,8 +91,8 @@ void RecTy::dump() const { print(errs()); }
|
|||||||
|
|
||||||
ListRecTy *RecTy::getListTy() {
|
ListRecTy *RecTy::getListTy() {
|
||||||
if (!ListTy)
|
if (!ListTy)
|
||||||
ListTy = new ListRecTy(this);
|
ListTy.reset(new ListRecTy(this));
|
||||||
return ListTy;
|
return ListTy.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RecTy::baseClassOf(const RecTy *RHS) const{
|
bool RecTy::baseClassOf(const RecTy *RHS) const{
|
||||||
@@ -141,13 +141,13 @@ bool BitRecTy::baseClassOf(const RecTy *RHS) const{
|
|||||||
}
|
}
|
||||||
|
|
||||||
BitsRecTy *BitsRecTy::get(unsigned Sz) {
|
BitsRecTy *BitsRecTy::get(unsigned Sz) {
|
||||||
static std::vector<BitsRecTy*> Shared;
|
static std::vector<std::unique_ptr<BitsRecTy>> Shared;
|
||||||
if (Sz >= Shared.size())
|
if (Sz >= Shared.size())
|
||||||
Shared.resize(Sz + 1);
|
Shared.resize(Sz + 1);
|
||||||
BitsRecTy *&Ty = Shared[Sz];
|
std::unique_ptr<BitsRecTy> &Ty = Shared[Sz];
|
||||||
if (!Ty)
|
if (!Ty)
|
||||||
Ty = new BitsRecTy(Sz);
|
Ty.reset(new BitsRecTy(Sz));
|
||||||
return Ty;
|
return Ty.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BitsRecTy::getAsString() const {
|
std::string BitsRecTy::getAsString() const {
|
||||||
@@ -451,8 +451,8 @@ ProfileBitsInit(FoldingSetNodeID &ID, ArrayRef<Init *> Range) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BitsInit *BitsInit::get(ArrayRef<Init *> Range) {
|
BitsInit *BitsInit::get(ArrayRef<Init *> Range) {
|
||||||
typedef FoldingSet<BitsInit> Pool;
|
static FoldingSet<BitsInit> ThePool;
|
||||||
static Pool ThePool;
|
static std::vector<std::unique_ptr<BitsInit>> TheActualPool;
|
||||||
|
|
||||||
FoldingSetNodeID ID;
|
FoldingSetNodeID ID;
|
||||||
ProfileBitsInit(ID, Range);
|
ProfileBitsInit(ID, Range);
|
||||||
@@ -463,7 +463,7 @@ BitsInit *BitsInit::get(ArrayRef<Init *> Range) {
|
|||||||
|
|
||||||
BitsInit *I = new BitsInit(Range);
|
BitsInit *I = new BitsInit(Range);
|
||||||
ThePool.InsertNode(I, IP);
|
ThePool.InsertNode(I, IP);
|
||||||
|
TheActualPool.push_back(std::unique_ptr<BitsInit>(I));
|
||||||
return I;
|
return I;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,8 +601,7 @@ static void ProfileListInit(FoldingSetNodeID &ID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ListInit *ListInit::get(ArrayRef<Init *> Range, RecTy *EltTy) {
|
ListInit *ListInit::get(ArrayRef<Init *> Range, RecTy *EltTy) {
|
||||||
typedef FoldingSet<ListInit> Pool;
|
static FoldingSet<ListInit> ThePool;
|
||||||
static Pool ThePool;
|
|
||||||
static std::vector<std::unique_ptr<ListInit>> TheActualPool;
|
static std::vector<std::unique_ptr<ListInit>> TheActualPool;
|
||||||
|
|
||||||
FoldingSetNodeID ID;
|
FoldingSetNodeID ID;
|
||||||
@@ -995,8 +994,7 @@ TernOpInit *TernOpInit::get(TernaryOp opc, Init *lhs,
|
|||||||
Init *
|
Init *
|
||||||
> Key;
|
> Key;
|
||||||
|
|
||||||
typedef DenseMap<Key, TernOpInit *> Pool;
|
static DenseMap<Key, std::unique_ptr<TernOpInit>> ThePool;
|
||||||
static Pool ThePool;
|
|
||||||
|
|
||||||
Key TheKey(std::make_pair(std::make_pair(std::make_pair(std::make_pair(opc,
|
Key TheKey(std::make_pair(std::make_pair(std::make_pair(std::make_pair(opc,
|
||||||
Type),
|
Type),
|
||||||
@@ -1004,9 +1002,9 @@ TernOpInit *TernOpInit::get(TernaryOp opc, Init *lhs,
|
|||||||
mhs),
|
mhs),
|
||||||
rhs));
|
rhs));
|
||||||
|
|
||||||
TernOpInit *&I = ThePool[TheKey];
|
std::unique_ptr<TernOpInit> &I = ThePool[TheKey];
|
||||||
if (!I) I = new TernOpInit(opc, lhs, mhs, rhs, Type);
|
if (!I) I.reset(new TernOpInit(opc, lhs, mhs, rhs, Type));
|
||||||
return I;
|
return I.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
|
static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
|
||||||
@@ -1402,15 +1400,13 @@ Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) const {
|
|||||||
VarListElementInit *VarListElementInit::get(TypedInit *T,
|
VarListElementInit *VarListElementInit::get(TypedInit *T,
|
||||||
unsigned E) {
|
unsigned E) {
|
||||||
typedef std::pair<TypedInit *, unsigned> Key;
|
typedef std::pair<TypedInit *, unsigned> Key;
|
||||||
typedef DenseMap<Key, VarListElementInit *> Pool;
|
static DenseMap<Key, std::unique_ptr<VarListElementInit>> ThePool;
|
||||||
|
|
||||||
static Pool ThePool;
|
|
||||||
|
|
||||||
Key TheKey(std::make_pair(T, E));
|
Key TheKey(std::make_pair(T, E));
|
||||||
|
|
||||||
VarListElementInit *&I = ThePool[TheKey];
|
std::unique_ptr<VarListElementInit> &I = ThePool[TheKey];
|
||||||
if (!I) I = new VarListElementInit(T, E);
|
if (!I) I.reset(new VarListElementInit(T, E));
|
||||||
return I;
|
return I.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string VarListElementInit::getAsString() const {
|
std::string VarListElementInit::getAsString() const {
|
||||||
@@ -1440,7 +1436,7 @@ Init *VarListElementInit:: resolveListElementReference(Record &R,
|
|||||||
if (TypedInit *TInit = dyn_cast<TypedInit>(Result)) {
|
if (TypedInit *TInit = dyn_cast<TypedInit>(Result)) {
|
||||||
Init *Result2 = TInit->resolveListElementReference(R, RV, Elt);
|
Init *Result2 = TInit->resolveListElementReference(R, RV, Elt);
|
||||||
if (Result2) return Result2;
|
if (Result2) return Result2;
|
||||||
return new VarListElementInit(TInit, Elt);
|
return VarListElementInit::get(TInit, Elt);
|
||||||
}
|
}
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
@@ -1470,14 +1466,13 @@ std::string DefInit::getAsString() const {
|
|||||||
|
|
||||||
FieldInit *FieldInit::get(Init *R, const std::string &FN) {
|
FieldInit *FieldInit::get(Init *R, const std::string &FN) {
|
||||||
typedef std::pair<Init *, TableGenStringKey> Key;
|
typedef std::pair<Init *, TableGenStringKey> Key;
|
||||||
typedef DenseMap<Key, FieldInit *> Pool;
|
static DenseMap<Key, std::unique_ptr<FieldInit>> ThePool;
|
||||||
static Pool ThePool;
|
|
||||||
|
|
||||||
Key TheKey(std::make_pair(R, FN));
|
Key TheKey(std::make_pair(R, FN));
|
||||||
|
|
||||||
FieldInit *&I = ThePool[TheKey];
|
std::unique_ptr<FieldInit> &I = ThePool[TheKey];
|
||||||
if (!I) I = new FieldInit(R, FN);
|
if (!I) I.reset(new FieldInit(R, FN));
|
||||||
return I;
|
return I.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Init *FieldInit::getBit(unsigned Bit) const {
|
Init *FieldInit::getBit(unsigned Bit) const {
|
||||||
@@ -1537,8 +1532,8 @@ DagInit *
|
|||||||
DagInit::get(Init *V, const std::string &VN,
|
DagInit::get(Init *V, const std::string &VN,
|
||||||
ArrayRef<Init *> ArgRange,
|
ArrayRef<Init *> ArgRange,
|
||||||
ArrayRef<std::string> NameRange) {
|
ArrayRef<std::string> NameRange) {
|
||||||
typedef FoldingSet<DagInit> Pool;
|
static FoldingSet<DagInit> ThePool;
|
||||||
static Pool ThePool;
|
static std::vector<std::unique_ptr<DagInit>> TheActualPool;
|
||||||
|
|
||||||
FoldingSetNodeID ID;
|
FoldingSetNodeID ID;
|
||||||
ProfileDagInit(ID, V, VN, ArgRange, NameRange);
|
ProfileDagInit(ID, V, VN, ArgRange, NameRange);
|
||||||
@@ -1549,7 +1544,7 @@ DagInit::get(Init *V, const std::string &VN,
|
|||||||
|
|
||||||
DagInit *I = new DagInit(V, VN, ArgRange, NameRange);
|
DagInit *I = new DagInit(V, VN, ArgRange, NameRange);
|
||||||
ThePool.InsertNode(I, IP);
|
ThePool.InsertNode(I, IP);
|
||||||
|
TheActualPool.push_back(std::unique_ptr<DagInit>(I));
|
||||||
return I;
|
return I;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1661,9 +1656,13 @@ void Record::checkName() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DefInit *Record::getDefInit() {
|
DefInit *Record::getDefInit() {
|
||||||
if (!TheInit)
|
static DenseMap<Record *, std::unique_ptr<DefInit>> ThePool;
|
||||||
TheInit = new DefInit(this, new RecordRecTy(this));
|
if (TheInit)
|
||||||
return TheInit;
|
return TheInit;
|
||||||
|
|
||||||
|
std::unique_ptr<DefInit> &I = ThePool[this];
|
||||||
|
if (!I) I.reset(new DefInit(this, new RecordRecTy(this)));
|
||||||
|
return I.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &Record::getName() const {
|
const std::string &Record::getName() const {
|
||||||
|
Reference in New Issue
Block a user