[llvm-commits] [llvm] r136493 - in /llvm/trunk/utils/TableGen: Record.cpp Record.h
David Greene
greened at obbligato.org
Fri Jul 29 12:07:16 PDT 2011
Author: greened
Date: Fri Jul 29 14:07:16 2011
New Revision: 136493
URL: http://llvm.org/viewvc/llvm-project?rev=136493&view=rev
Log:
[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.
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=136493&r1=136492&r2=136493&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.cpp (original)
+++ llvm/trunk/utils/TableGen/Record.cpp Fri Jul 29 14:07:16 2011
@@ -583,8 +583,43 @@
return I;
}
+static void ProfileListInit(FoldingSetNodeID &ID,
+ ArrayRef<const Init *> Range,
+ RecTy *EltTy) {
+ ID.AddInteger(Range.size());
+ ID.AddPointer(EltTy);
+
+ for (ArrayRef<const Init *>::iterator i = Range.begin(),
+ iend = Range.end();
+ i != iend;
+ ++i)
+ ID.AddPointer(*i);
+}
+
const ListInit *ListInit::get(ArrayRef<const Init *> Range, RecTy *EltTy) {
- return new ListInit(Range, EltTy);
+ typedef FoldingSet<ListInit> 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<ListRecTy *>(getType());
+ assert(ListType && "Bad type for ListInit!");
+ RecTy *EltTy = ListType->getElementType();
+
+ ProfileListInit(ID, Values, EltTy);
}
const Init *
Modified: llvm/trunk/utils/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.h?rev=136493&r1=136492&r2=136493&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.h (original)
+++ llvm/trunk/utils/TableGen/Record.h Fri Jul 29 14:07:16 2011
@@ -1,3 +1,4 @@
+
//===- Record.h - Classes to represent Table Records ------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
@@ -801,15 +802,12 @@
/// ListInit - [AL, AH, CL] - Represent a list of defs
///
-class ListInit : public TypedInit {
+class ListInit : public TypedInit, public FoldingSetNode {
std::vector<const Init*> Values;
public:
typedef std::vector<const Init*>::const_iterator const_iterator;
- explicit ListInit(std::vector<const Init*> &Vs, RecTy *EltTy)
- : TypedInit(ListRecTy::get(EltTy)) {
- Values.swap(Vs);
- }
+private:
explicit ListInit(ArrayRef<const Init *> Range, RecTy *EltTy)
: TypedInit(ListRecTy::get(EltTy)), Values(Range.begin(), Range.end()) {}
@@ -819,6 +817,8 @@
public:
static const ListInit *get(ArrayRef<const Init *> 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!");
More information about the llvm-commits
mailing list