[llvm-commits] [PATCH 08/20] [AVX] Make BitsInit Unique
David Greene
dag at cray.com
Tue Jul 19 13:11:43 PDT 2011
Make BitsInit a FastFoldingSetNode so we can unique it.
---
utils/TableGen/Record.cpp | 23 ++++++++++++++++++++++-
utils/TableGen/Record.h | 8 ++++----
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git oldutils/TableGen/Record.cpp newutils/TableGen/Record.cpp
index 68ac572..4c019d3 100644
--- oldutils/TableGen/Record.cpp
+++ newutils/TableGen/Record.cpp
@@ -15,6 +15,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"
@@ -417,7 +419,26 @@ const BitInit *BitInit::get(bool V) {
}
const BitsInit *BitsInit::get(ArrayRef<const Init *> Range) {
- return new BitsInit(Range);
+ typedef FoldingSet<BitsInit> Pool;
+ static Pool ThePool;
+
+ FoldingSetNodeID ID;
+ ID.AddInteger(Range.size());
+
+ for (ArrayRef<const Init *>::iterator i = Range.begin(),
+ iend = Range.end();
+ i != iend;
+ ++i)
+ ID.AddPointer(*i);
+
+ void *IP = 0;
+ if (const BitsInit *I = ThePool.FindNodeOrInsertPos(ID, IP))
+ return I;
+
+ BitsInit *I = new BitsInit(ID, Range);
+ ThePool.InsertNode(I, IP);
+
+ return I;
}
const Init *
diff --git oldutils/TableGen/Record.h newutils/TableGen/Record.h
index 4b4a2c6..468d31f 100644
--- oldutils/TableGen/Record.h
+++ newutils/TableGen/Record.h
@@ -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,12 +649,11 @@ public:
/// 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 FastFoldingSetNode {
std::vector<const Init*> Bits;
- BitsInit(unsigned Size) : Bits(Size) {}
-
- BitsInit(ArrayRef<const Init *> Range) : Bits(Range.begin(), Range.end()) {}
+ BitsInit(FoldingSetNodeID &ID, ArrayRef<const Init *> Range)
+ : FastFoldingSetNode(ID), Bits(Range.begin(), Range.end()) {}
BitsInit(const BitsInit &Other); // Do not define.
BitsInit &operator=(const BitsInit &Other); // Do not define.
--
1.7.6
More information about the llvm-commits
mailing list