From 458ad3e2cb136d469dbdadfbdd1265b33dd56b8f Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Wed, 22 Apr 2015 02:20:44 +0000 Subject: [PATCH] [TableGen] Remove Pool helper class and just use unique_ptr in the maps. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235467 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/Record.cpp | 65 +++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 21680baf941..17f78e286a9 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -570,27 +570,12 @@ Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) const { return const_cast(this); } -namespace { - template - class Pool : public T { - public: - ~Pool(); - }; - template - Pool::~Pool() { - for (typename T::iterator I = this->begin(), E = this->end(); I != E; ++I) { - typename T::value_type &Item = *I; - delete Item.second; - } - } -} - IntInit *IntInit::get(int64_t V) { - static Pool > ThePool; + static DenseMap> ThePool; - IntInit *&I = ThePool[V]; - if (!I) I = new IntInit(V); - return I; + std::unique_ptr &I = ThePool[V]; + if (!I) I.reset(new IntInit(V)); + return I.get(); } std::string IntInit::getAsString() const { @@ -613,11 +598,11 @@ IntInit::convertInitializerBitRange(const std::vector &Bits) const { void StringInit::anchor() { } StringInit *StringInit::get(StringRef V) { - static Pool > ThePool; + static StringMap> ThePool; - StringInit *&I = ThePool[V]; - if (!I) I = new StringInit(V); - return I; + std::unique_ptr &I = ThePool[V]; + if (!I) I.reset(new StringInit(V)); + return I.get(); } static void ProfileListInit(FoldingSetNodeID &ID, @@ -752,13 +737,13 @@ Init *OpInit::getBit(unsigned Bit) const { UnOpInit *UnOpInit::get(UnaryOp opc, Init *lhs, RecTy *Type) { typedef std::pair, RecTy *> Key; - static Pool > ThePool; + static DenseMap> ThePool; Key TheKey(std::make_pair(std::make_pair(opc, lhs), Type)); - UnOpInit *&I = ThePool[TheKey]; - if (!I) I = new UnOpInit(opc, lhs, Type); - return I; + std::unique_ptr &I = ThePool[TheKey]; + if (!I) I.reset(new UnOpInit(opc, lhs, Type)); + return I.get(); } Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { @@ -891,14 +876,14 @@ BinOpInit *BinOpInit::get(BinaryOp opc, Init *lhs, RecTy * > Key; - static Pool > ThePool; + static DenseMap> ThePool; Key TheKey(std::make_pair(std::make_pair(std::make_pair(opc, lhs), rhs), Type)); - BinOpInit *&I = ThePool[TheKey]; - if (!I) I = new BinOpInit(opc, lhs, rhs, Type); - return I; + std::unique_ptr &I = ThePool[TheKey]; + if (!I) I.reset(new BinOpInit(opc, lhs, rhs, Type)); + return I.get(); } Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const { @@ -1326,13 +1311,13 @@ VarInit *VarInit::get(const std::string &VN, RecTy *T) { VarInit *VarInit::get(Init *VN, RecTy *T) { typedef std::pair Key; - static Pool > ThePool; + static DenseMap> ThePool; Key TheKey(std::make_pair(T, VN)); - VarInit *&I = ThePool[TheKey]; - if (!I) I = new VarInit(VN, T); - return I; + std::unique_ptr &I = ThePool[TheKey]; + if (!I) I.reset(new VarInit(VN, T)); + return I.get(); } const std::string &VarInit::getName() const { @@ -1411,15 +1396,13 @@ Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) const { VarBitInit *VarBitInit::get(TypedInit *T, unsigned B) { typedef std::pair Key; - typedef DenseMap Pool; - - static Pool ThePool; + static DenseMap> ThePool; Key TheKey(std::make_pair(T, B)); - VarBitInit *&I = ThePool[TheKey]; - if (!I) I = new VarBitInit(T, B); - return I; + std::unique_ptr &I = ThePool[TheKey]; + if (!I) I.reset(new VarBitInit(T, B)); + return I.get(); } std::string VarBitInit::getAsString() const {