[llvm] r258071 - [TableGen] Use FoldingSets instead of DenseMaps to unique UnOpInit, BinOpInit and TernOpInit. This remove the memory needed to store the key for the DenseMap. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 18 12:36:06 PST 2016
Author: ctopper
Date: Mon Jan 18 14:36:06 2016
New Revision: 258071
URL: http://llvm.org/viewvc/llvm-project?rev=258071&view=rev
Log:
[TableGen] Use FoldingSets instead of DenseMaps to unique UnOpInit, BinOpInit and TernOpInit. This remove the memory needed to store the key for the DenseMap. NFC
Modified:
llvm/trunk/include/llvm/TableGen/Record.h
llvm/trunk/lib/TableGen/Record.cpp
Modified: llvm/trunk/include/llvm/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/Record.h?rev=258071&r1=258070&r2=258071&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/Record.h (original)
+++ llvm/trunk/include/llvm/TableGen/Record.h Mon Jan 18 14:36:06 2016
@@ -683,7 +683,7 @@ public:
/// UnOpInit - !op (X) - Transform an init.
///
-class UnOpInit : public OpInit {
+class UnOpInit : public OpInit, public FoldingSetNode {
public:
enum UnaryOp : uint8_t { CAST, HEAD, TAIL, EMPTY };
@@ -702,6 +702,8 @@ public:
}
static UnOpInit *get(UnaryOp opc, Init *lhs, RecTy *Type);
+ void Profile(FoldingSetNodeID &ID) const;
+
// Clone - Clone this operator, replacing arguments with the new list
OpInit *clone(std::vector<Init *> &Operands) const override {
assert(Operands.size() == 1 &&
@@ -729,7 +731,7 @@ public:
/// BinOpInit - !op (X, Y) - Combine two inits.
///
-class BinOpInit : public OpInit {
+class BinOpInit : public OpInit, public FoldingSetNode {
public:
enum BinaryOp : uint8_t { ADD, AND, SHL, SRA, SRL, LISTCONCAT,
STRCONCAT, CONCAT, EQ };
@@ -750,6 +752,8 @@ public:
static BinOpInit *get(BinaryOp opc, Init *lhs, Init *rhs,
RecTy *Type);
+ void Profile(FoldingSetNodeID &ID) const;
+
// Clone - Clone this operator, replacing arguments with the new list
OpInit *clone(std::vector<Init *> &Operands) const override {
assert(Operands.size() == 2 &&
@@ -781,7 +785,7 @@ public:
/// TernOpInit - !op (X, Y, Z) - Combine two inits.
///
-class TernOpInit : public OpInit {
+class TernOpInit : public OpInit, public FoldingSetNode {
public:
enum TernaryOp : uint8_t { SUBST, FOREACH, IF };
@@ -803,6 +807,8 @@ public:
Init *mhs, Init *rhs,
RecTy *Type);
+ void Profile(FoldingSetNodeID &ID) const;
+
// Clone - Clone this operator, replacing arguments with the new list
OpInit *clone(std::vector<Init *> &Operands) const override {
assert(Operands.size() == 3 &&
Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=258071&r1=258070&r2=258071&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Mon Jan 18 14:36:06 2016
@@ -609,15 +609,32 @@ Init *OpInit::getBit(unsigned Bit) const
return VarBitInit::get(const_cast<OpInit*>(this), Bit);
}
-UnOpInit *UnOpInit::get(UnaryOp opc, Init *lhs, RecTy *Type) {
- typedef std::pair<std::pair<unsigned, Init *>, RecTy *> Key;
- static DenseMap<Key, std::unique_ptr<UnOpInit>> ThePool;
-
- Key TheKey(std::make_pair(std::make_pair(opc, lhs), Type));
-
- std::unique_ptr<UnOpInit> &I = ThePool[TheKey];
- if (!I) I.reset(new UnOpInit(opc, lhs, Type));
- return I.get();
+static void
+ProfileUnOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *Op, RecTy *Type) {
+ ID.AddInteger(Opcode);
+ ID.AddPointer(Op);
+ ID.AddPointer(Type);
+}
+
+UnOpInit *UnOpInit::get(UnaryOp Opc, Init *LHS, RecTy *Type) {
+ static FoldingSet<UnOpInit> ThePool;
+ static std::vector<std::unique_ptr<UnOpInit>> TheActualPool;
+
+ FoldingSetNodeID ID;
+ ProfileUnOpInit(ID, Opc, LHS, Type);
+
+ void *IP = nullptr;
+ if (UnOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
+ return I;
+
+ UnOpInit *I = new UnOpInit(Opc, LHS, Type);
+ ThePool.InsertNode(I, IP);
+ TheActualPool.push_back(std::unique_ptr<UnOpInit>(I));
+ return I;
+}
+
+void UnOpInit::Profile(FoldingSetNodeID &ID) const {
+ ProfileUnOpInit(ID, getOpcode(), getOperand(), getType());
}
Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
@@ -737,21 +754,35 @@ std::string UnOpInit::getAsString() cons
return Result + "(" + LHS->getAsString() + ")";
}
-BinOpInit *BinOpInit::get(BinaryOp opc, Init *lhs,
- Init *rhs, RecTy *Type) {
- typedef std::pair<
- std::pair<std::pair<unsigned, Init *>, Init *>,
- RecTy *
- > Key;
-
- static DenseMap<Key, std::unique_ptr<BinOpInit>> ThePool;
-
- Key TheKey(std::make_pair(std::make_pair(std::make_pair(opc, lhs), rhs),
- Type));
-
- std::unique_ptr<BinOpInit> &I = ThePool[TheKey];
- if (!I) I.reset(new BinOpInit(opc, lhs, rhs, Type));
- return I.get();
+static void
+ProfileBinOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *RHS,
+ RecTy *Type) {
+ ID.AddInteger(Opcode);
+ ID.AddPointer(LHS);
+ ID.AddPointer(RHS);
+ ID.AddPointer(Type);
+}
+
+BinOpInit *BinOpInit::get(BinaryOp Opc, Init *LHS,
+ Init *RHS, RecTy *Type) {
+ static FoldingSet<BinOpInit> ThePool;
+ static std::vector<std::unique_ptr<BinOpInit>> TheActualPool;
+
+ FoldingSetNodeID ID;
+ ProfileBinOpInit(ID, Opc, LHS, RHS, Type);
+
+ void *IP = nullptr;
+ if (BinOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
+ return I;
+
+ BinOpInit *I = new BinOpInit(Opc, LHS, RHS, Type);
+ ThePool.InsertNode(I, IP);
+ TheActualPool.push_back(std::unique_ptr<BinOpInit>(I));
+ return I;
+}
+
+void BinOpInit::Profile(FoldingSetNodeID &ID) const {
+ ProfileBinOpInit(ID, getOpcode(), getLHS(), getRHS(), getType());
}
Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
@@ -870,27 +901,36 @@ std::string BinOpInit::getAsString() con
return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
}
-TernOpInit *TernOpInit::get(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
+static void
+ProfileTernOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *MHS,
+ Init *RHS, RecTy *Type) {
+ ID.AddInteger(Opcode);
+ ID.AddPointer(LHS);
+ ID.AddPointer(MHS);
+ ID.AddPointer(RHS);
+ ID.AddPointer(Type);
+}
+
+TernOpInit *TernOpInit::get(TernaryOp Opc, Init *LHS, Init *MHS, Init *RHS,
RecTy *Type) {
- typedef std::pair<
- std::pair<
- std::pair<std::pair<unsigned, RecTy *>, Init *>,
- Init *
- >,
- Init *
- > Key;
-
- static DenseMap<Key, std::unique_ptr<TernOpInit>> ThePool;
-
- Key TheKey(std::make_pair(std::make_pair(std::make_pair(std::make_pair(opc,
- Type),
- lhs),
- mhs),
- rhs));
-
- std::unique_ptr<TernOpInit> &I = ThePool[TheKey];
- if (!I) I.reset(new TernOpInit(opc, lhs, mhs, rhs, Type));
- return I.get();
+ static FoldingSet<TernOpInit> ThePool;
+ static std::vector<std::unique_ptr<TernOpInit>> TheActualPool;
+
+ FoldingSetNodeID ID;
+ ProfileTernOpInit(ID, Opc, LHS, MHS, RHS, Type);
+
+ void *IP = nullptr;
+ if (TernOpInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
+ return I;
+
+ TernOpInit *I = new TernOpInit(Opc, LHS, MHS, RHS, Type);
+ ThePool.InsertNode(I, IP);
+ TheActualPool.push_back(std::unique_ptr<TernOpInit>(I));
+ return I;
+}
+
+void TernOpInit::Profile(FoldingSetNodeID &ID) const {
+ ProfileTernOpInit(ID, getOpcode(), getLHS(), getMHS(), getRHS(), getType());
}
static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
More information about the llvm-commits
mailing list