From 726bbde3c4ac5a279c86d1632b7b94498b01854a Mon Sep 17 00:00:00 2001 From: David Greene Date: Fri, 29 Jul 2011 19:07:11 +0000 Subject: [PATCH] [AVX] Make BitsInit Unique Make BitsInit a FoldingSetNode so we can unique it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136489 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/Record.cpp | 32 +++++++++++++++++++++++++++++++- utils/TableGen/Record.h | 7 ++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 3e0038c9e67..77c0d1a491d 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -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 @@ const BitInit *BitInit::get(bool V) { return V ? &True : &False; } +static void +ProfileBitsInit(FoldingSetNodeID &ID, ArrayRef Range) { + ID.AddInteger(Range.size()); + + for (ArrayRef::iterator i = Range.begin(), + iend = Range.end(); + i != iend; + ++i) + ID.AddPointer(*i); +} + const BitsInit *BitsInit::get(ArrayRef Range) { - return new BitsInit(Range); + typedef FoldingSet 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 * diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index c3ce2dd6046..e70cad1a324 100644 --- a/utils/TableGen/Record.h +++ b/utils/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,11 +649,9 @@ 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 FoldingSetNode { std::vector Bits; - BitsInit(unsigned Size) : Bits(Size) {} - BitsInit(ArrayRef Range) : Bits(Range.begin(), Range.end()) {} BitsInit(const BitsInit &Other); // Do not define. @@ -661,6 +660,8 @@ class BitsInit : public Init { public: static const BitsInit *get(ArrayRef Range); + void Profile(FoldingSetNodeID &ID) const; + unsigned getNumBits() const { return Bits.size(); } const Init *getBit(unsigned Bit) const {