[llvm-commits] [PATCH 18/20] [AVX] Make VarListElementInit Unique

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


Make sure VarListElementInits are unique and created only once.
---
 utils/TableGen/Record.cpp |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git oldutils/TableGen/Record.cpp newutils/TableGen/Record.cpp
index 6b51ac1..ef1601e 100644
--- oldutils/TableGen/Record.cpp
+++ newutils/TableGen/Record.cpp
@@ -1432,7 +1432,22 @@ const Init *VarBitInit::resolveReferences(Record &R,
 
 const VarListElementInit *VarListElementInit::get(const TypedInit *T,
                                                   unsigned E) {
-  return new VarListElementInit(T, E);
+  typedef std::pair<const TypedInit *, unsigned> Key;
+  typedef DenseMap<Key, VarListElementInit *> Pool;
+
+  static Pool ThePool;
+
+  Key TheKey(std::make_pair(T, E));
+  Pool::iterator Result = ThePool.find(TheKey);
+ 
+  if (Result == ThePool.end()) {
+    VarListElementInit *New = new VarListElementInit(T, E);
+    bool Inserted = false;
+    tie(Result, Inserted) = ThePool.insert(std::make_pair(TheKey, New));
+    assert(Inserted && "Did not insert new Init into pool!");
+  }
+    
+  return Result->second;
 }
 
 std::string VarListElementInit::getAsString() const {
-- 
1.7.6




More information about the llvm-commits mailing list