summaryrefslogtreecommitdiff
path: root/lib/TableGen
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2016-12-04 05:48:20 +0000
committerMatthias Braun <matze@braunis.de>2016-12-04 05:48:20 +0000
commit013ca3cf779a71661cab996fcb110facd723e15a (patch)
tree6b411a65e7f8e4a43817125ef098c337f8566b41 /lib/TableGen
parent0c517c8dffadddb6cdca1195301d26b67ca388a8 (diff)
TableGen: Store Records on a BumpPtrAllocator
All these records are internalized and will live until exit. This makes them perfect candidates for a fast BumpPtrAllocator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288613 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/TableGen')
-rw-r--r--lib/TableGen/Record.cpp126
1 files changed, 70 insertions, 56 deletions
diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp
index 7fa20d115e0..e705fe8977c 100644
--- a/lib/TableGen/Record.cpp
+++ b/lib/TableGen/Record.cpp
@@ -28,6 +28,8 @@
using namespace llvm;
+static BumpPtrAllocator Allocator;
+
//===----------------------------------------------------------------------===//
// std::string wrapper for DenseMap purposes
//===----------------------------------------------------------------------===//
@@ -97,8 +99,8 @@ LLVM_DUMP_METHOD void RecTy::dump() const { print(errs()); }
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 {
@@ -115,13 +117,13 @@ bool BitRecTy::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 {
@@ -268,7 +270,7 @@ ProfileBitsInit(FoldingSetNodeID &ID, ArrayRef<Init *> Range) {
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);
@@ -277,12 +279,13 @@ BitsInit *BitsInit::get(ArrayRef<Init *> 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;
}
@@ -398,11 +401,11 @@ Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) const {
}
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 {
@@ -455,19 +458,27 @@ IntInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) 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 {
@@ -496,7 +507,7 @@ static void ProfileListInit(FoldingSetNodeID &ID,
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);
@@ -505,12 +516,13 @@ ListInit *ListInit::get(ArrayRef<Init *> Range, RecTy *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;
}
@@ -634,7 +646,7 @@ ProfileUnOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *Op, RecTy *Type) {
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);
@@ -643,9 +655,9 @@ UnOpInit *UnOpInit::get(UnaryOp Opc, Init *LHS, RecTy *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;
}
@@ -782,7 +794,7 @@ ProfileBinOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *RHS,
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);
@@ -791,9 +803,9 @@ BinOpInit *BinOpInit::get(BinaryOp Opc, Init *LHS,
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;
}
@@ -937,7 +949,7 @@ ProfileTernOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *MHS,
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);
@@ -946,9 +958,9 @@ TernOpInit *TernOpInit::get(TernaryOp Opc, Init *LHS, Init *MHS, Init *RHS,
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;
}
@@ -1289,13 +1301,14 @@ VarInit *VarInit::get(StringRef VN, RecTy *T) {
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 {
@@ -1363,13 +1376,14 @@ Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) 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 {
@@ -1394,13 +1408,13 @@ Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) 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 {
@@ -1464,13 +1478,13 @@ std::string DefInit::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 {
@@ -1528,7 +1542,7 @@ DagInit *
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);
@@ -1537,9 +1551,9 @@ DagInit::get(Init *V, StringRef VN, ArrayRef<Init *> ArgRange,
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;
}
@@ -1648,8 +1662,8 @@ void Record::checkName() {
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 {