[llvm-commits] [llvm] r136489 - in /llvm/trunk/utils/TableGen: Record.cpp Record.h

David Greene greened at obbligato.org
Fri Jul 29 12:07:11 PDT 2011


Author: greened
Date: Fri Jul 29 14:07:11 2011
New Revision: 136489

URL: http://llvm.org/viewvc/llvm-project?rev=136489&view=rev
Log:
[AVX] Make BitsInit Unique

Make BitsInit a FoldingSetNode so we can unique it.

Modified:
    llvm/trunk/utils/TableGen/Record.cpp
    llvm/trunk/utils/TableGen/Record.h

Modified: llvm/trunk/utils/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.cpp?rev=136489&r1=136488&r2=136489&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.cpp (original)
+++ llvm/trunk/utils/TableGen/Record.cpp Fri Jul 29 14:07:11 2011
@@ -16,6 +16,8 @@
 #include "Error.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Format.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
@@ -455,8 +457,36 @@
   return V ? &True : &False;
 }
 
+static void
+ProfileBitsInit(FoldingSetNodeID &ID, ArrayRef<const Init *> Range) {
+  ID.AddInteger(Range.size());
+
+  for (ArrayRef<const Init *>::iterator i = Range.begin(),
+         iend = Range.end();
+       i != iend;
+       ++i)
+    ID.AddPointer(*i);
+}
+
 const BitsInit *BitsInit::get(ArrayRef<const Init *> Range) {
-  return new BitsInit(Range);
+  typedef FoldingSet<BitsInit> Pool;
+  static Pool ThePool;  
+
+  FoldingSetNodeID ID;
+  ProfileBitsInit(ID, Range);
+
+  void *IP = 0;
+  if (const BitsInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
+    return I;
+
+  BitsInit *I = new BitsInit(Range);
+  ThePool.InsertNode(I, IP);
+
+  return I;
+}
+
+void BitsInit::Profile(FoldingSetNodeID &ID) const {
+  ProfileBitsInit(ID, Bits);
 }
 
 const Init *

Modified: llvm/trunk/utils/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.h?rev=136489&r1=136488&r2=136489&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.h (original)
+++ llvm/trunk/utils/TableGen/Record.h Fri Jul 29 14:07:11 2011
@@ -16,6 +16,7 @@
 #define RECORD_H
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/FoldingSet.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/DataTypes.h"
@@ -648,11 +649,9 @@
 /// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value.
 /// It contains a vector of bits, whose size is determined by the type.
 ///
-class BitsInit : public Init {
+class BitsInit : public Init, public FoldingSetNode {
   std::vector<const Init*> Bits;
 
-  BitsInit(unsigned Size) : Bits(Size) {}
-
   BitsInit(ArrayRef<const Init *> Range) : Bits(Range.begin(), Range.end()) {}
 
   BitsInit(const BitsInit &Other);  // Do not define.
@@ -661,6 +660,8 @@
 public:
   static const BitsInit *get(ArrayRef<const Init *> Range);
 
+  void Profile(FoldingSetNodeID &ID) const;
+
   unsigned getNumBits() const { return Bits.size(); }
 
   const Init *getBit(unsigned Bit) const {





More information about the llvm-commits mailing list