[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
This commit is contained in:
David Greene 2011-07-29 19:07:26 +00:00
parent 65bf3ca9aa
commit 78621a851a
2 changed files with 50 additions and 23 deletions

View File

@ -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<const Init *> ArgRange,
ArrayRef<std::string> NameRange) {
ID.AddPointer(V);
ID.AddString(VN);
ArrayRef<const Init *>::iterator Arg = ArgRange.begin();
ArrayRef<std::string>::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<const Init *> ArgRange,
ArrayRef<std::string> NameRange) {
typedef FoldingSet<DagInit> 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<std::pair<const Init*, std::string> > &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<const Init*> &args,
const std::vector<std::string> &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 {

View File

@ -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<const Init*> Args;
std::vector<std::string> ArgNames;
DagInit(const Init *V, const std::string &VN,
const std::vector<std::pair<const Init*, std::string> > &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<const Init*> &args,
const std::vector<std::string> &argNames)
: TypedInit(DagRecTy::get()), Val(V), ValName(VN), Args(args),
ArgNames(argNames) { }
ArrayRef<const Init *> ArgRange,
ArrayRef<std::string> 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<const Init *> ArgRange,
ArrayRef<std::string> NameRange);
static const DagInit *get(const Init *V, const std::string &VN,
const std::vector<
std::pair<const Init*, std::string> > &args);
static const DagInit *get(const Init *V, const std::string &VN,
const std::vector<const Init*> &args,
const std::vector<std::string> &argNames);
void Profile(FoldingSetNodeID &ID) const;
virtual const Init *convertInitializerTo(RecTy *Ty) const {
return Ty->convertValue(this);