[llvm-commits] [PATCH 10/20] [AVX] Make StringInit Unique

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


Use a StringMap to ensure the StringInits are unique.  This is
especially important for AVX where we will have many smallish
strings representing instruction prefixes, suffixes and the like.
---
 utils/TableGen/Record.cpp |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git oldutils/TableGen/Record.cpp newutils/TableGen/Record.cpp
index dda0b71..d1401c7 100644
--- oldutils/TableGen/Record.cpp
+++ newutils/TableGen/Record.cpp
@@ -20,6 +20,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
 
 using namespace llvm;
 
@@ -524,7 +525,29 @@ IntInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) const {
 }
 
 const StringInit *StringInit::get(const std::string &V) {
-  return new StringInit(V);
+  typedef StringMap<StringInit *> Pool;
+  static Pool ThePool;
+
+  typedef StringMapEntry<StringInit *> MapEntryTy;
+
+  Pool::iterator i = ThePool.find(V);
+ 
+  StringInit *Result = 0;
+
+  if (i == ThePool.end()) {
+    Result = new StringInit(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 CodeInit *CodeInit::get(const std::string &V) {
-- 
1.7.6




More information about the llvm-commits mailing list