From 78621a851ae84520de7d24a6d61e1dcf25749712 Mon Sep 17 00:00:00 2001 From: David Greene Date: Fri, 29 Jul 2011 19:07:26 +0000 Subject: [PATCH] [AVX] Make DagInits Unique Make sure DagInits are unique and created only once. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@136501 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/Record.cpp | 45 ++++++++++++++++++++++++++++++++++++++++----- utils/TableGen/Record.h | 28 ++++++++++------------------ 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index d4e60839753..ed271cbdce0 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -1531,6 +1531,44 @@ const Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) const { return this; } +void ProfileDagInit(FoldingSetNodeID &ID, + const Init *V, + const std::string &VN, + ArrayRef ArgRange, + ArrayRef NameRange) { + ID.AddPointer(V); + ID.AddString(VN); + + ArrayRef::iterator Arg = ArgRange.begin(); + ArrayRef::iterator Name = NameRange.begin(); + while (Arg != ArgRange.end()) { + assert(Name != NameRange.end() && "Arg name underflow!"); + ID.AddPointer(*Arg++); + ID.AddString(*Name++); + } + assert(Name == NameRange.end() && "Arg name overflow!"); +} + +const DagInit * +DagInit::get(const Init *V, const std::string &VN, + ArrayRef ArgRange, + ArrayRef NameRange) { + typedef FoldingSet Pool; + static Pool ThePool; + + FoldingSetNodeID ID; + ProfileDagInit(ID, V, VN, ArgRange, NameRange); + + void *IP = 0; + if (const DagInit *I = ThePool.FindNodeOrInsertPos(ID, IP)) + return I; + + DagInit *I = new DagInit(V, VN, ArgRange, NameRange); + ThePool.InsertNode(I, IP); + + return I; +} + const DagInit * DagInit::get(const Init *V, const std::string &VN, const std::vector > &args) { @@ -1550,11 +1588,8 @@ DagInit::get(const Init *V, const std::string &VN, return DagInit::get(V, VN, Args, Names); } -const DagInit * -DagInit::get(const Init *V, const std::string &VN, - const std::vector &args, - const std::vector &argNames) { - return new DagInit(V, VN, args, argNames); +void DagInit::Profile(FoldingSetNodeID &ID) const { + ProfileDagInit(ID, Val, ValName, Args, ArgNames); } const Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) const { diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index cbde0e9bdbc..351625ac4e0 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -1252,39 +1252,31 @@ public: /// to have at least one value then a (possibly empty) list of arguments. Each /// argument can have a name associated with it. /// -class DagInit : public TypedInit { +class DagInit : public TypedInit, public FoldingSetNode { const Init *Val; std::string ValName; std::vector Args; std::vector ArgNames; DagInit(const Init *V, const std::string &VN, - const std::vector > &args) - : TypedInit(DagRecTy::get()), Val(V), ValName(VN) { - Args.reserve(args.size()); - ArgNames.reserve(args.size()); - for (unsigned i = 0, e = args.size(); i != e; ++i) { - Args.push_back(args[i].first); - ArgNames.push_back(args[i].second); - } - } - DagInit(const Init *V, const std::string &VN, - const std::vector &args, - const std::vector &argNames) - : TypedInit(DagRecTy::get()), Val(V), ValName(VN), Args(args), - ArgNames(argNames) { } + ArrayRef ArgRange, + ArrayRef NameRange) + : TypedInit(DagRecTy::get()), Val(V), ValName(VN), + Args(ArgRange.begin(), ArgRange.end()), + ArgNames(NameRange.begin(), NameRange.end()) {} DagInit(const DagInit &Other); // Do not define. DagInit &operator=(const DagInit &Other); // Do not define. public: static const DagInit *get(const Init *V, const std::string &VN, + ArrayRef ArgRange, + ArrayRef NameRange); + static const DagInit *get(const Init *V, const std::string &VN, const std::vector< std::pair > &args); - static const DagInit *get(const Init *V, const std::string &VN, - const std::vector &args, - const std::vector &argNames); + void Profile(FoldingSetNodeID &ID) const; virtual const Init *convertInitializerTo(RecTy *Ty) const { return Ty->convertValue(this); -- 2.11.4.GIT