[llvm-commits] [PATCH 20/20] [AVX] Make DagInits Unique
David Greene
dag at cray.com
Tue Jul 19 13:11:55 PDT 2011
Make sure DagInits are unique and created only once. Make DagInit
a FastFoldingSetNode to accomplish this.
---
utils/TableGen/Record.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++-
utils/TableGen/Record.h | 26 +++++++++--------------
2 files changed, 57 insertions(+), 18 deletions(-)
diff --git oldutils/TableGen/Record.cpp newutils/TableGen/Record.cpp
index cf82255..2278b40 100644
--- oldutils/TableGen/Record.cpp
+++ newutils/TableGen/Record.cpp
@@ -1563,15 +1563,60 @@ const Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) const {
const DagInit *
DagInit::get(const Init *V, const std::string &VN,
+ ArrayRef<const Init *> ArgRange,
+ ArrayRef<std::string> NameRange) {
+ typedef FoldingSet<DagInit> Pool;
+ static Pool ThePool;
+
+ FoldingSetNodeID ID;
+ ID.AddPointer(V);
+ ID.AddString(VN);
+
+ ArrayRef<const Init *>::iterator Arg = ArgRange.begin();
+ ArrayRef<std::string>::iterator Name = NameRange.begin();
+ while (Arg != ArgRange.end()) {
+ assert(Name != NameRange.end() && "Arg name underflow!");
+ ID.AddPointer(*Arg++);
+ ID.AddString(*Name++);
+ }
+ assert(Name == NameRange.end() && "Arg name overflow!");
+
+ void *IP = 0;
+ if (const DagInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
+ return I;
+
+ DagInit *I = new DagInit(ID, V, VN, ArgRange, NameRange);
+ ThePool.InsertNode(I, IP);
+
+ return I;
+}
+
+const DagInit *
+DagInit::get(const Init *V, const std::string &VN,
const std::vector<std::pair<const Init*, std::string> > &args) {
- return new DagInit(V, VN, args);
+ typedef std::pair<const Init*, std::string> PairType;
+
+ std::vector<const Init *> Args;
+ std::vector<std::string> Names;
+
+ for (std::vector<PairType>::const_iterator i = args.begin(),
+ iend = args.end();
+ i != iend;
+ ++i) {
+ Args.push_back(i->first);
+ Names.push_back(i->second);
+ }
+
+ return DagInit::get(V, VN, ArrayRef<const Init *>(Args),
+ ArrayRef<std::string>(Names));
}
const DagInit *
DagInit::get(const Init *V, const std::string &VN,
const std::vector<const Init *> &args,
const std::vector<std::string> &argNames) {
- return new DagInit(V, VN, args, argNames);
+ return DagInit::get(V, VN, ArrayRef<const Init *>(args),
+ ArrayRef<std::string>(argNames));
}
const Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) const {
diff --git oldutils/TableGen/Record.h newutils/TableGen/Record.h
index ed8f678..cdd08c4 100644
--- oldutils/TableGen/Record.h
+++ newutils/TableGen/Record.h
@@ -1250,33 +1250,27 @@ public:
/// to have at least one value then a (possibly empty) list of arguments. Each
/// argument can have a name associated with it.
///
-class DagInit : public TypedInit {
+class DagInit : public TypedInit, public FastFoldingSetNode {
const Init *Val;
std::string ValName;
std::vector<const Init*> Args;
std::vector<std::string> ArgNames;
- DagInit(const Init *V, const std::string &VN,
- const std::vector<std::pair<const Init*, std::string> > &args)
- : TypedInit(DagRecTy::get()), Val(V), ValName(VN) {
- Args.reserve(args.size());
- ArgNames.reserve(args.size());
- for (unsigned i = 0, e = args.size(); i != e; ++i) {
- Args.push_back(args[i].first);
- ArgNames.push_back(args[i].second);
- }
- }
- DagInit(const Init *V, const std::string &VN,
- const std::vector<const Init*> &args,
- const std::vector<std::string> &argNames)
- : TypedInit(DagRecTy::get()), Val(V), ValName(VN), Args(args),
- ArgNames(argNames) { }
+ DagInit(FoldingSetNodeID &ID, const Init *V, const std::string &VN,
+ ArrayRef<const Init *> ArgRange,
+ ArrayRef<std::string> NameRange)
+ : TypedInit(DagRecTy::get()), FastFoldingSetNode(ID), Val(V), ValName(VN),
+ Args(ArgRange.begin(), ArgRange.end()),
+ ArgNames(NameRange.begin(), NameRange.end()) {}
DagInit(const DagInit &Other); // Do not define.
DagInit &operator=(const DagInit &Other); // Do not define.
public:
static const DagInit *get(const Init *V, const std::string &VN,
+ ArrayRef<const Init *> ArgRange,
+ ArrayRef<std::string> NameRange);
+ static const DagInit *get(const Init *V, const std::string &VN,
const std::vector<
std::pair<const Init*, std::string> > &args);
static const DagInit *get(const Init *V, const std::string &VN,
--
1.7.6
More information about the llvm-commits
mailing list