From aad4c9fc37b38cae21343173084c81d789535446 Mon Sep 17 00:00:00 2001 From: David Greene Date: Fri, 29 Jul 2011 19:07:16 +0000 Subject: [PATCH] [AVX] Make ListInits Unique Ensure ListInits are unique and only created once. This will be important for AVX as lists will be used extensively to pass generic patterns, prefix information and other things to lower-level pattern-generation classes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136493 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/Record.cpp | 37 ++++++++++++++++++++++++++++++++++++- utils/TableGen/Record.h | 10 +++++----- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 133a1581c0e..4608d7aa149 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -583,8 +583,43 @@ const CodeInit *CodeInit::get(const std::string &V) { return I; } +static void ProfileListInit(FoldingSetNodeID &ID, + ArrayRef Range, + RecTy *EltTy) { + ID.AddInteger(Range.size()); + ID.AddPointer(EltTy); + + for (ArrayRef::iterator i = Range.begin(), + iend = Range.end(); + i != iend; + ++i) + ID.AddPointer(*i); +} + const ListInit *ListInit::get(ArrayRef Range, RecTy *EltTy) { - return new ListInit(Range, EltTy); + typedef FoldingSet Pool; + static Pool ThePool; + + // Just use the FoldingSetNodeID to compute a hash. Use a DenseMap + // for actual storage. + FoldingSetNodeID ID; + ProfileListInit(ID, Range, EltTy); + + void *IP = 0; + if (const ListInit *I = ThePool.FindNodeOrInsertPos(ID, IP)) + return I; + + ListInit *I = new ListInit(Range, EltTy); + ThePool.InsertNode(I, IP); + return I; +} + +void ListInit::Profile(FoldingSetNodeID &ID) const { + ListRecTy *ListType = dynamic_cast(getType()); + assert(ListType && "Bad type for ListInit!"); + RecTy *EltTy = ListType->getElementType(); + + ProfileListInit(ID, Values, EltTy); } const Init * diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index e70cad1a324..cbde0e9bdbc 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -1,3 +1,4 @@ + //===- Record.h - Classes to represent Table Records ------------*- C++ -*-===// // // The LLVM Compiler Infrastructure @@ -801,15 +802,12 @@ public: /// ListInit - [AL, AH, CL] - Represent a list of defs /// -class ListInit : public TypedInit { +class ListInit : public TypedInit, public FoldingSetNode { std::vector Values; public: typedef std::vector::const_iterator const_iterator; - explicit ListInit(std::vector &Vs, RecTy *EltTy) - : TypedInit(ListRecTy::get(EltTy)) { - Values.swap(Vs); - } +private: explicit ListInit(ArrayRef Range, RecTy *EltTy) : TypedInit(ListRecTy::get(EltTy)), Values(Range.begin(), Range.end()) {} @@ -819,6 +817,8 @@ public: public: static const ListInit *get(ArrayRef Range, RecTy *EltTy); + void Profile(FoldingSetNodeID &ID) const; + unsigned getSize() const { return Values.size(); } const Init *getElement(unsigned i) const { assert(i < Values.size() && "List element index out of range!"); -- 2.34.1