[llvm-commits] [PATCH 11/20] [AVX] Make CodeInit Unique

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


Use a StringMap to ensure CodeInits are unique and created only
once.
---
 utils/TableGen/Record.cpp |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git oldutils/TableGen/Record.cpp newutils/TableGen/Record.cpp
index d1401c7..726c86d 100644
--- oldutils/TableGen/Record.cpp
+++ newutils/TableGen/Record.cpp
@@ -551,7 +551,29 @@ 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;
+
+  typedef StringMapEntry<CodeInit *> MapEntryTy;
+
+  Pool::iterator i = ThePool.find(V);
+ 
+  CodeInit *Result = 0;
+
+  if (i == ThePool.end()) {
+    Result = new CodeInit(V);
+
+    MapEntryTy *NewItem = MapEntryTy::Create(V.data(), V.data() + V.size(),
+                                             ThePool.getAllocator(), Result);
+
+    bool Inserted = false;
+    Inserted = ThePool.insert(NewItem);
+    assert(Inserted && "Did not insert new Init into pool!");
+  }
+  else
+    Result = i->second;
+
+  return Result;
 }
 
 const ListInit *ListInit::get(std::vector<const Init *> &Vs, RecTy *EltTy) {
-- 
1.7.6




More information about the llvm-commits mailing list