[AVX] Make VarListElementInit Unique
authorDavid Greene <greened@obbligato.org>
Fri, 29 Jul 2011 19:07:23 +0000 (19:07 +0000)
committerDavid Greene <greened@obbligato.org>
Fri, 29 Jul 2011 19:07:23 +0000 (19:07 +0000)
Make sure VarListElementInits are unique and created only once.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136499 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/Record.cpp

index 3a022fc151e4965079f05f42d05967a7fff54ea9..89de3edfd192a607a8f9d442222c2149ec5082d6 100644 (file)
@@ -1414,7 +1414,16 @@ 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));
+
+  VarListElementInit *&I = ThePool[TheKey];
+  if (!I) I = new VarListElementInit(T, E);
+  return I;
 }
 
 std::string VarListElementInit::getAsString() const {