[AVX] Make TernOpInit Unique
authorDavid Greene <greened@obbligato.org>
Fri, 29 Jul 2011 19:07:20 +0000 (19:07 +0000)
committerDavid Greene <greened@obbligato.org>
Fri, 29 Jul 2011 19:07:20 +0000 (19:07 +0000)
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.

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

utils/TableGen/Record.cpp

index 56a46e195b477d852a74bbb0448357e66b05d2f1..a6b5c4b884d93e5a48523783b4acc63c46731c7a 100644 (file)
@@ -975,7 +975,26 @@ 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));
+
+  TernOpInit *&I = ThePool[TheKey];
+  if (!I) I = new TernOpInit(opc, lhs, mhs, rhs, Type);
+  return I;
 }
 
 static const Init *ForeachHelper(const Init *LHS, const Init *MHS,