1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

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.

llvm-svn: 288613
This commit is contained in:
Matthias Braun 2016-12-04 05:48:20 +00:00
parent 9e5ef1c46f
commit 3fb138a4a5
2 changed files with 76 additions and 67 deletions

View File

@ -63,7 +63,7 @@ public:
private:
RecTyKind Kind;
std::unique_ptr<ListRecTy> ListTy;
ListRecTy *ListTy = nullptr;
public:
RecTy(RecTyKind K) : Kind(K) {}
@ -408,11 +408,6 @@ class TypedInit : public Init {
protected:
explicit TypedInit(InitKind K, RecTy *T, uint8_t Opc = 0)
: Init(K, Opc), Ty(T) {}
~TypedInit() override {
// If this is a DefInit we need to delete the RecordRecTy.
if (getKind() == IK_DefInit)
delete Ty;
}
public:
TypedInit(const TypedInit &Other) = delete;
@ -602,7 +597,7 @@ public:
/// "foo" - Represent an initialization by a string value.
///
class StringInit : public TypedInit {
std::string Value;
StringRef Value;
explicit StringInit(StringRef V)
: TypedInit(IK_StringInit, StringRecTy::get()), Value(V) {}
@ -621,7 +616,7 @@ public:
Init *convertInitializerTo(RecTy *Ty) const override;
std::string getAsString() const override { return "\"" + Value + "\""; }
std::string getAsString() const override { return "\"" + Value.str() + "\""; }
std::string getAsUnquotedString() const override { return Value; }
@ -639,7 +634,7 @@ public:
};
class CodeInit : public TypedInit {
std::string Value;
StringRef Value;
explicit CodeInit(StringRef V)
: TypedInit(IK_CodeInit, static_cast<RecTy *>(CodeRecTy::get())),
@ -660,7 +655,7 @@ public:
Init *convertInitializerTo(RecTy *Ty) const override;
std::string getAsString() const override {
return "[{" + Value + "}]";
return "[{" + Value.str() + "}]";
}
std::string getAsUnquotedString() const override { return Value; }
@ -1276,7 +1271,7 @@ class Record {
// Tracks Record instances. Not owned by Record.
RecordKeeper &TrackedRecords;
std::unique_ptr<DefInit> TheInit;
DefInit *TheInit = nullptr;
// Unique record ID.
unsigned ID;

View File

@ -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 {