[AVX] Make UnOpInit Unique
authorDavid Greene <greened@obbligato.org>
Fri, 29 Jul 2011 19:07:18 +0000 (19:07 +0000)
committerDavid Greene <greened@obbligato.org>
Fri, 29 Jul 2011 19:07:18 +0000 (19:07 +0000)
Make sure UnOpInits 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@136494 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/Record.cpp

index 4608d7aa149674690db316115e99a65caac795c5..8fc0c18cd4b520a113422fad83158e48be8becbb 100644 (file)
@@ -714,7 +714,16 @@ const Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV,
 }
 
 const UnOpInit *UnOpInit::get(UnaryOp opc, const Init *lhs, RecTy *Type) {
 }
 
 const UnOpInit *UnOpInit::get(UnaryOp opc, const Init *lhs, RecTy *Type) {
-  return new UnOpInit(opc, lhs, Type);
+  typedef std::pair<std::pair<unsigned, const Init *>, RecTy *> Key;
+
+  typedef DenseMap<Key, UnOpInit *> Pool;
+  static Pool ThePool;  
+
+  Key TheKey(std::make_pair(std::make_pair(opc, lhs), Type));
+
+  UnOpInit *&I = ThePool[TheKey];
+  if (!I) I = new UnOpInit(opc, lhs, Type);
+  return I;
 }
 
 const Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {
 }
 
 const Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) const {