[llvm-commits] [PATCH 17/20] [AVX] Make VarBitInit Unique

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


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

diff --git oldutils/TableGen/Record.cpp newutils/TableGen/Record.cpp
index 6b37898..6b51ac1 100644
--- oldutils/TableGen/Record.cpp
+++ newutils/TableGen/Record.cpp
@@ -1400,7 +1400,23 @@ const Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) const {
 }
 
 const VarBitInit *VarBitInit::get(const TypedInit *T, unsigned B) {
-  return new VarBitInit(T, B);
+  typedef std::pair<const TypedInit *, unsigned> Key;
+  typedef DenseMap<Key, VarBitInit *> Pool;
+
+  static Pool ThePool;
+
+  Key TheKey(std::make_pair(T, B));
+
+  Pool::iterator Result = ThePool.find(TheKey);
+ 
+  if (Result == ThePool.end()) {
+    VarBitInit *New = new VarBitInit(T, B);
+    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 VarBitInit::getAsString() const {
-- 
1.7.6




More information about the llvm-commits mailing list