[AVX] Make CodeInit Unique
authorDavid Greene <greened@obbligato.org>
Fri, 29 Jul 2011 19:07:15 +0000 (19:07 +0000)
committerDavid Greene <greened@obbligato.org>
Fri, 29 Jul 2011 19:07:15 +0000 (19:07 +0000)
Use a StringMap to ensure CodeInits are unique and created only
once.

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

utils/TableGen/Record.cpp

index ee5db4713dcf00698e127d5dd054beba33c77905..133a1581c0e3dfd083f6e091aaf8e65fa8df57a9 100644 (file)
@@ -575,7 +575,12 @@ const StringInit *StringInit::get(const std::string &V) {
 }
 
 const CodeInit *CodeInit::get(const std::string &V) {
-  return new CodeInit(V);
+  typedef StringMap<CodeInit *> Pool;
+  static Pool ThePool;
+
+  CodeInit *&I = ThePool[V];
+  if (!I) I = new CodeInit(V);
+  return I;
 }
 
 const ListInit *ListInit::get(ArrayRef<const Init *> Range, RecTy *EltTy) {