[llvm-commits] [PATCH 15/20] [AVX] Make TernOpInit Unique

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


Make sure TernOpInits are unique and created only once.  This will be
important for AVX/SIMD as many operators will be used to generate
patterns and other relevant data.
---
 utils/TableGen/Record.cpp |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)

diff --git oldutils/TableGen/Record.cpp newutils/TableGen/Record.cpp
index d2ae02a..64ddced 100644
--- oldutils/TableGen/Record.cpp
+++ newutils/TableGen/Record.cpp
@@ -973,7 +973,33 @@ std::string BinOpInit::getAsString() const {
 const TernOpInit *TernOpInit::get(TernaryOp opc, const Init *lhs,
                                   const Init *mhs, const Init *rhs,
                                   RecTy *Type) {
-  return new TernOpInit(opc, lhs, mhs, rhs, Type);
+  typedef std::pair<
+    std::pair<
+      std::pair<std::pair<unsigned, RecTy *>, const Init *>,
+      const Init *
+      >,
+    const Init *
+    > Key;
+
+  typedef DenseMap<Key, TernOpInit *> Pool;
+  static Pool ThePool;
+
+  Key TheKey(std::make_pair(std::make_pair(std::make_pair(std::make_pair(opc,
+                                                                         Type),
+                                                          lhs),
+                                           mhs),
+                            rhs));
+
+  Pool::iterator Result = ThePool.find(TheKey);
+
+  if (Result == ThePool.end()) {
+    TernOpInit *New = new TernOpInit(opc, lhs, mhs, rhs, Type);
+    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;
 }
 
 static const Init *ForeachHelper(const Init *LHS, const Init *MHS,
-- 
1.7.6




More information about the llvm-commits mailing list