[llvm-commits] [PATCH 12/20] [AVX] Make ListInits Unique

David Greene dag at cray.com
Tue Jul 19 13:11:47 PDT 2011


Make ListInit a FastFoldingSetNode to 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.
---
 utils/TableGen/Record.cpp |   25 +++++++++++++++++++++++--
 utils/TableGen/Record.h   |   14 +++++++-------
 2 files changed, 30 insertions(+), 9 deletions(-)

diff --git oldutils/TableGen/Record.cpp newutils/TableGen/Record.cpp
index 726c86d..5d1ec3a 100644
--- oldutils/TableGen/Record.cpp
+++ newutils/TableGen/Record.cpp
@@ -577,11 +577,32 @@ const CodeInit *CodeInit::get(const std::string &V) {
 }
 
 const ListInit *ListInit::get(std::vector<const Init *> &Vs, RecTy *EltTy) {
-  return new ListInit(Vs, EltTy);
+  return ListInit::get(ArrayRef<const Init*>(Vs), EltTy);
 }
 
 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;
+  ID.AddInteger(Range.size());
+  ID.AddPointer(EltTy);
+
+  for (ArrayRef<const Init *>::iterator i = Range.begin(),
+         iend = Range.end();
+       i != iend;
+       ++i)
+    ID.AddPointer(*i);
+
+  void *IP = 0;
+  if (const ListInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
+    return I;
+
+  ListInit *I = new ListInit(ID, Range, EltTy);
+  ThePool.InsertNode(I, IP);
+  return I;
 }
 
 const Init *
diff --git oldutils/TableGen/Record.h newutils/TableGen/Record.h
index 468d31f..ed8f678 100644
--- oldutils/TableGen/Record.h
+++ newutils/TableGen/Record.h
@@ -1,3 +1,4 @@
+
 //===- Record.h - Classes to represent Table Records ------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
@@ -800,17 +801,16 @@ public:
 
 /// ListInit - [AL, AH, CL] - Represent a list of defs
 ///
-class ListInit : public TypedInit {
+class ListInit : public TypedInit, public FastFoldingSetNode {
   std::vector<const Init*> Values;
 public:
   typedef std::vector<const Init*>::const_iterator const_iterator;
 
-  explicit ListInit(std::vector<const Init*> &Vs, RecTy *EltTy)
-    : TypedInit(ListRecTy::get(EltTy)) {
-    Values.swap(Vs);
-  }
-  explicit ListInit(ArrayRef<const Init *> Range, RecTy *EltTy)
-      : TypedInit(ListRecTy::get(EltTy)), Values(Range.begin(), Range.end()) {}
+private:
+  explicit ListInit(FoldingSetNodeID &ID, ArrayRef<const Init *> Range,
+                    RecTy *EltTy)
+      : TypedInit(ListRecTy::get(EltTy)), FastFoldingSetNode(ID),
+          Values(Range.begin(), Range.end()) {}
 
   ListInit(const ListInit &Other);  // Do not define.
   ListInit &operator=(const ListInit &Other);  // Do not define.
-- 
1.7.6




More information about the llvm-commits mailing list