[AVX] Make BinOpInit Unique
[oota-llvm.git] / utils / TableGen / Record.cpp
index 8fc0c18cd4b520a113422fad83158e48be8becbb..56a46e195b477d852a74bbb0448357e66b05d2f1 100644 (file)
@@ -860,7 +860,20 @@ std::string UnOpInit::getAsString() const {
 
 const BinOpInit *BinOpInit::get(BinaryOp opc, const Init *lhs,
                                 const Init *rhs, RecTy *Type) {
-  return new BinOpInit(opc, lhs, rhs, Type);
+  typedef std::pair<
+    std::pair<std::pair<unsigned, const Init *>, const Init *>,
+    RecTy *
+    > Key;
+
+  typedef DenseMap<Key, BinOpInit *> Pool;
+  static Pool ThePool;  
+
+  Key TheKey(std::make_pair(std::make_pair(std::make_pair(opc, lhs), rhs),
+                            Type));
+
+  BinOpInit *&I = ThePool[TheKey];
+  if (!I) I = new BinOpInit(opc, lhs, rhs, Type);
+  return I;
 }
 
 const Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {