summaryrefslogtreecommitdiff
path: root/utils/TableGen/Record.cpp
diff options
context:
space:
mode:
authorDavid Greene <greened@obbligato.org>2011-07-29 19:07:16 +0000
committerDavid Greene <greened@obbligato.org>2011-07-29 19:07:16 +0000
commitaad4c9fc37b38cae21343173084c81d789535446 (patch)
treea89ed5dd8b537809a3353409ec6edda0ff0f5b26 /utils/TableGen/Record.cpp
parent637b4ffa01f42a6df598d4fc367d645a600128e1 (diff)
downloadllvm-aad4c9fc37b38cae21343173084c81d789535446.tar.gz
llvm-aad4c9fc37b38cae21343173084c81d789535446.tar.bz2
llvm-aad4c9fc37b38cae21343173084c81d789535446.tar.xz
[AVX] Make ListInits Unique
Ensure ListInits are unique and only created once. This will be important for AVX as lists will be used extensively to pass generic patterns, prefix information and other things to lower-level pattern-generation classes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136493 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/Record.cpp')
-rw-r--r--utils/TableGen/Record.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index 133a1581c0..4608d7aa14 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -583,8 +583,43 @@ const CodeInit *CodeInit::get(const std::string &V) {
return I;
}
+static void ProfileListInit(FoldingSetNodeID &ID,
+ ArrayRef<const Init *> Range,
+ RecTy *EltTy) {
+ ID.AddInteger(Range.size());
+ ID.AddPointer(EltTy);
+
+ for (ArrayRef<const Init *>::iterator i = Range.begin(),
+ iend = Range.end();
+ i != iend;
+ ++i)
+ ID.AddPointer(*i);
+}
+
const ListInit *ListInit::get(ArrayRef<const Init *> Range, RecTy *EltTy) {
- return new ListInit(Range, EltTy);
+ typedef FoldingSet<ListInit> Pool;
+ static Pool ThePool;
+
+ // Just use the FoldingSetNodeID to compute a hash. Use a DenseMap
+ // for actual storage.
+ FoldingSetNodeID ID;
+ ProfileListInit(ID, Range, EltTy);
+
+ void *IP = 0;
+ if (const ListInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
+ return I;
+
+ ListInit *I = new ListInit(Range, EltTy);
+ ThePool.InsertNode(I, IP);
+ return I;
+}
+
+void ListInit::Profile(FoldingSetNodeID &ID) const {
+ ListRecTy *ListType = dynamic_cast<ListRecTy *>(getType());
+ assert(ListType && "Bad type for ListInit!");
+ RecTy *EltTy = ListType->getElementType();
+
+ ProfileListInit(ID, Values, EltTy);
}
const Init *