using namespace llvm;
+static BumpPtrAllocator Allocator;
+
//===----------------------------------------------------------------------===//
// std::string wrapper for DenseMap purposes
//===----------------------------------------------------------------------===//
ListRecTy *RecTy::getListTy() {
if (!ListTy)
- ListTy.reset(new ListRecTy(this));
- return ListTy.get();
+ ListTy = new(Allocator) ListRecTy(this);
+ return ListTy;
}
bool RecTy::typeIsConvertibleTo(const RecTy *RHS) const {
}
BitsRecTy *BitsRecTy::get(unsigned Sz) {
- static std::vector<std::unique_ptr<BitsRecTy>> Shared;
+ static std::vector<BitsRecTy*> Shared;
if (Sz >= Shared.size())
Shared.resize(Sz + 1);
- std::unique_ptr<BitsRecTy> &Ty = Shared[Sz];
+ BitsRecTy *&Ty = Shared[Sz];
if (!Ty)
- Ty.reset(new BitsRecTy(Sz));
- return Ty.get();
+ Ty = new(Allocator) BitsRecTy(Sz);
+ return Ty;
}
std::string BitsRecTy::getAsString() const {
BitsInit *BitsInit::get(ArrayRef<Init *> Range) {
static FoldingSet<BitsInit> ThePool;
- static std::vector<std::unique_ptr<BitsInit>> TheActualPool;
+ static std::vector<BitsInit*> TheActualPool;
FoldingSetNodeID ID;
ProfileBitsInit(ID, Range);
if (BitsInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
return I;
- void *Mem = ::operator new (totalSizeToAlloc<Init *>(Range.size()));
- BitsInit *I = new (Mem) BitsInit(Range.size());
+ void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(Range.size()),
+ alignof(BitsInit));
+ BitsInit *I = new(Mem) BitsInit(Range.size());
std::uninitialized_copy(Range.begin(), Range.end(),
I->getTrailingObjects<Init *>());
ThePool.InsertNode(I, IP);
- TheActualPool.push_back(std::unique_ptr<BitsInit>(I));
+ TheActualPool.push_back(I);
return I;
}
}
IntInit *IntInit::get(int64_t V) {
- static DenseMap<int64_t, std::unique_ptr<IntInit>> ThePool;
+ static DenseMap<int64_t, IntInit*> ThePool;
- std::unique_ptr<IntInit> &I = ThePool[V];
- if (!I) I.reset(new IntInit(V));
- return I.get();
+ IntInit *&I = ThePool[V];
+ if (!I) I = new(Allocator) IntInit(V);
+ return I;
}
std::string IntInit::getAsString() const {
}
CodeInit *CodeInit::get(StringRef V) {
- static StringMap<std::unique_ptr<CodeInit>> ThePool;
+ static DenseMap<StringRef, CodeInit*> ThePool;
- std::unique_ptr<CodeInit> &I = ThePool[V];
- if (!I) I.reset(new CodeInit(V));
- return I.get();
+ auto I = ThePool.insert(std::make_pair(V, nullptr));
+ if (I.second) {
+ StringRef VCopy = V.copy(Allocator);
+ I.first->first = VCopy;
+ I.first->second = new(Allocator) CodeInit(VCopy);
+ }
+ return I.first->second;
}
StringInit *StringInit::get(StringRef V) {
- static StringMap<std::unique_ptr<StringInit>> ThePool;
+ static DenseMap<StringRef, StringInit*> ThePool;
- std::unique_ptr<StringInit> &I = ThePool[V];
- if (!I) I.reset(new StringInit(V));
- return I.get();
+ auto I = ThePool.insert(std::make_pair(V, nullptr));
+ if (I.second) {
+ StringRef VCopy = V.copy(Allocator);
+ I.first->first = VCopy;
+ I.first->second = new(Allocator) StringInit(VCopy);
+ }
+ return I.first->second;
}
Init *StringInit::convertInitializerTo(RecTy *Ty) const {
ListInit *ListInit::get(ArrayRef<Init *> Range, RecTy *EltTy) {
static FoldingSet<ListInit> ThePool;
- static std::vector<std::unique_ptr<ListInit>> TheActualPool;
+ static std::vector<ListInit*> TheActualPool;
FoldingSetNodeID ID;
ProfileListInit(ID, Range, EltTy);
if (ListInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
return I;
- void *Mem = ::operator new (totalSizeToAlloc<Init *>(Range.size()));
- ListInit *I = new (Mem) ListInit(Range.size(), EltTy);
+ void *Mem = Allocator.Allocate(totalSizeToAlloc<Init *>(Range.size()),
+ alignof(ListInit));
+ ListInit *I = new(Mem) ListInit(Range.size(), EltTy);
std::uninitialized_copy(Range.begin(), Range.end(),
I->getTrailingObjects<Init *>());
ThePool.InsertNode(I, IP);
- TheActualPool.push_back(std::unique_ptr<ListInit>(I));
+ TheActualPool.push_back(I);
return I;
}
UnOpInit *UnOpInit::get(UnaryOp Opc, Init *LHS, RecTy *Type) {
static FoldingSet<UnOpInit> ThePool;
- static std::vector<std::unique_ptr<UnOpInit>> TheActualPool;
+ static std::vector<UnOpInit*> TheActualPool;
FoldingSetNodeID ID;
ProfileUnOpInit(ID, Opc, LHS, Type);
if (UnOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
return I;
- UnOpInit *I = new UnOpInit(Opc, LHS, Type);
+ UnOpInit *I = new(Allocator) UnOpInit(Opc, LHS, Type);
ThePool.InsertNode(I, IP);
- TheActualPool.push_back(std::unique_ptr<UnOpInit>(I));
+ TheActualPool.push_back(I);
return I;
}
BinOpInit *BinOpInit::get(BinaryOp Opc, Init *LHS,
Init *RHS, RecTy *Type) {
static FoldingSet<BinOpInit> ThePool;
- static std::vector<std::unique_ptr<BinOpInit>> TheActualPool;
+ static std::vector<BinOpInit*> TheActualPool;
FoldingSetNodeID ID;
ProfileBinOpInit(ID, Opc, LHS, RHS, Type);
if (BinOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
return I;
- BinOpInit *I = new BinOpInit(Opc, LHS, RHS, Type);
+ BinOpInit *I = new(Allocator) BinOpInit(Opc, LHS, RHS, Type);
ThePool.InsertNode(I, IP);
- TheActualPool.push_back(std::unique_ptr<BinOpInit>(I));
+ TheActualPool.push_back(I);
return I;
}
TernOpInit *TernOpInit::get(TernaryOp Opc, Init *LHS, Init *MHS, Init *RHS,
RecTy *Type) {
static FoldingSet<TernOpInit> ThePool;
- static std::vector<std::unique_ptr<TernOpInit>> TheActualPool;
+ static std::vector<TernOpInit*> TheActualPool;
FoldingSetNodeID ID;
ProfileTernOpInit(ID, Opc, LHS, MHS, RHS, Type);
if (TernOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
return I;
- TernOpInit *I = new TernOpInit(Opc, LHS, MHS, RHS, Type);
+ TernOpInit *I = new(Allocator) TernOpInit(Opc, LHS, MHS, RHS, Type);
ThePool.InsertNode(I, IP);
- TheActualPool.push_back(std::unique_ptr<TernOpInit>(I));
+ TheActualPool.push_back(I);
return I;
}
VarInit *VarInit::get(Init *VN, RecTy *T) {
typedef std::pair<RecTy *, Init *> Key;
- static DenseMap<Key, std::unique_ptr<VarInit>> ThePool;
+ static DenseMap<Key, VarInit*> ThePool;
Key TheKey(std::make_pair(T, VN));
- std::unique_ptr<VarInit> &I = ThePool[TheKey];
- if (!I) I.reset(new VarInit(VN, T));
- return I.get();
+ VarInit *&I = ThePool[TheKey];
+ if (!I)
+ I = new(Allocator) VarInit(VN, T);
+ return I;
}
StringRef VarInit::getName() const {
VarBitInit *VarBitInit::get(TypedInit *T, unsigned B) {
typedef std::pair<TypedInit *, unsigned> Key;
- static DenseMap<Key, std::unique_ptr<VarBitInit>> ThePool;
+ static DenseMap<Key, VarBitInit*> ThePool;
Key TheKey(std::make_pair(T, B));
- std::unique_ptr<VarBitInit> &I = ThePool[TheKey];
- if (!I) I.reset(new VarBitInit(T, B));
- return I.get();
+ VarBitInit *&I = ThePool[TheKey];
+ if (!I)
+ I = new(Allocator) VarBitInit(T, B);
+ return I;
}
Init *VarBitInit::convertInitializerTo(RecTy *Ty) const {
VarListElementInit *VarListElementInit::get(TypedInit *T,
unsigned E) {
typedef std::pair<TypedInit *, unsigned> Key;
- static DenseMap<Key, std::unique_ptr<VarListElementInit>> ThePool;
+ static DenseMap<Key, VarListElementInit*> ThePool;
Key TheKey(std::make_pair(T, E));
- std::unique_ptr<VarListElementInit> &I = ThePool[TheKey];
- if (!I) I.reset(new VarListElementInit(T, E));
- return I.get();
+ VarListElementInit *&I = ThePool[TheKey];
+ if (!I) I = new(Allocator) VarListElementInit(T, E);
+ return I;
}
std::string VarListElementInit::getAsString() const {
FieldInit *FieldInit::get(Init *R, StringRef FN) {
typedef std::pair<Init *, TableGenStringKey> Key;
- static DenseMap<Key, std::unique_ptr<FieldInit>> ThePool;
+ static DenseMap<Key, FieldInit*> ThePool;
Key TheKey(std::make_pair(R, FN));
- std::unique_ptr<FieldInit> &I = ThePool[TheKey];
- if (!I) I.reset(new FieldInit(R, FN));
- return I.get();
+ FieldInit *&I = ThePool[TheKey];
+ if (!I) I = new(Allocator) FieldInit(R, FN);
+ return I;
}
Init *FieldInit::getBit(unsigned Bit) const {
DagInit::get(Init *V, StringRef VN, ArrayRef<Init *> ArgRange,
ArrayRef<std::string> NameRange) {
static FoldingSet<DagInit> ThePool;
- static std::vector<std::unique_ptr<DagInit>> TheActualPool;
+ static std::vector<DagInit*> TheActualPool;
FoldingSetNodeID ID;
ProfileDagInit(ID, V, VN, ArgRange, NameRange);
if (DagInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
return I;
- DagInit *I = new DagInit(V, VN, ArgRange, NameRange);
+ DagInit *I = new(Allocator) DagInit(V, VN, ArgRange, NameRange);
ThePool.InsertNode(I, IP);
- TheActualPool.push_back(std::unique_ptr<DagInit>(I));
+ TheActualPool.push_back(I);
return I;
}
DefInit *Record::getDefInit() {
if (!TheInit)
- TheInit.reset(new DefInit(this, new RecordRecTy(this)));
- return TheInit.get();
+ TheInit = new(Allocator) DefInit(this, new(Allocator) RecordRecTy(this));
+ return TheInit;
}
StringRef Record::getName() const {