[TableGen] Merge the SuperClass Record and SMRange vector into a single vector. This removes the state needed to manage the extra vector thus reducing the size of the Record class. NFC

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258065 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Craig Topper 2016-01-18 19:52:37 +00:00
parent 83f897b505
commit 401ee722ee
5 changed files with 32 additions and 35 deletions

View File

@ -1157,8 +1157,7 @@ class Record {
SmallVector<SMLoc, 4> Locs;
std::vector<Init *> TemplateArgs;
std::vector<RecordVal> Values;
std::vector<Record *> SuperClasses;
std::vector<SMRange> SuperClassRanges;
std::vector<std::pair<Record *, SMRange>> SuperClasses;
// Tracks Record instances. Not owned by Record.
RecordKeeper &TrackedRecords;
@ -1204,8 +1203,8 @@ public:
Record(const Record &O) :
Name(O.Name), Locs(O.Locs), TemplateArgs(O.TemplateArgs),
Values(O.Values), SuperClasses(O.SuperClasses),
SuperClassRanges(O.SuperClassRanges), TrackedRecords(O.TrackedRecords),
ID(LastID++), IsAnonymous(O.IsAnonymous), ResolveFirst(O.ResolveFirst) { }
TrackedRecords(O.TrackedRecords), ID(LastID++),
IsAnonymous(O.IsAnonymous), ResolveFirst(O.ResolveFirst) { }
static unsigned getNewUID() { return LastID++; }
@ -1231,8 +1230,9 @@ public:
return TemplateArgs;
}
ArrayRef<RecordVal> getValues() const { return Values; }
ArrayRef<Record *> getSuperClasses() const { return SuperClasses; }
ArrayRef<SMRange> getSuperClassRanges() const { return SuperClassRanges; }
ArrayRef<std::pair<Record *, SMRange>> getSuperClasses() const {
return SuperClasses;
}
bool isTemplateArg(Init *Name) const {
for (Init *TA : TemplateArgs)
@ -1294,23 +1294,22 @@ public:
}
bool isSubClassOf(const Record *R) const {
for (const Record *SC : SuperClasses)
if (SC == R)
for (const auto &SCPair : SuperClasses)
if (SCPair.first == R)
return true;
return false;
}
bool isSubClassOf(StringRef Name) const {
for (const Record *SC : SuperClasses)
if (SC->getNameInitAsString() == Name)
for (const auto &SCPair : SuperClasses)
if (SCPair.first->getNameInitAsString() == Name)
return true;
return false;
}
void addSuperClass(Record *R, SMRange Range) {
assert(!isSubClassOf(R) && "Already subclassing record!");
SuperClasses.push_back(R);
SuperClassRanges.push_back(Range);
SuperClasses.push_back(std::make_pair(R, Range));
}
/// resolveReferences - If there are any field references that refer to fields

View File

@ -167,8 +167,8 @@ bool RecordRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
if (RTy->getRecord() == Rec || Rec->isSubClassOf(RTy->getRecord()))
return true;
for (Record *SC : RTy->getRecord()->getSuperClasses())
if (Rec->isSubClassOf(SC))
for (const auto &SCPair : RTy->getRecord()->getSuperClasses())
if (Rec->isSubClassOf(SCPair.first))
return true;
return false;
@ -186,8 +186,8 @@ RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) {
// If one is a Record type, check superclasses
if (RecordRecTy *RecTy1 = dyn_cast<RecordRecTy>(T1)) {
// See if T2 inherits from a type T1 also inherits from
for (Record *SuperRec1 : RecTy1->getRecord()->getSuperClasses()) {
RecordRecTy *SuperRecTy1 = RecordRecTy::get(SuperRec1);
for (const auto &SuperPair1 : RecTy1->getRecord()->getSuperClasses()) {
RecordRecTy *SuperRecTy1 = RecordRecTy::get(SuperPair1.first);
RecTy *NewType1 = resolveTypes(SuperRecTy1, T2);
if (NewType1)
return NewType1;
@ -195,8 +195,8 @@ RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) {
}
if (RecordRecTy *RecTy2 = dyn_cast<RecordRecTy>(T2)) {
// See if T1 inherits from a type T2 also inherits from
for (Record *SuperRec2 : RecTy2->getRecord()->getSuperClasses()) {
RecordRecTy *SuperRecTy2 = RecordRecTy::get(SuperRec2);
for (const auto &SuperPair2 : RecTy2->getRecord()->getSuperClasses()) {
RecordRecTy *SuperRecTy2 = RecordRecTy::get(SuperPair2.first);
RecTy *NewType2 = resolveTypes(T1, SuperRecTy2);
if (NewType2)
return NewType2;
@ -1662,11 +1662,11 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const Record &R) {
}
OS << " {";
ArrayRef<Record *> SC = R.getSuperClasses();
ArrayRef<std::pair<Record *, SMRange>> SC = R.getSuperClasses();
if (!SC.empty()) {
OS << "\t//";
for (const Record *Super : SC)
OS << " " << Super->getNameInitAsString();
for (const auto &SuperPair : SC)
OS << " " << SuperPair.first->getNameInitAsString();
}
OS << "\n";

View File

@ -302,12 +302,12 @@ const RecVec *SetTheory::expand(Record *Set) {
return &I->second;
// This is the first time we see Set. Find a suitable expander.
ArrayRef<Record *> SC = Set->getSuperClasses();
for (unsigned i = 0, e = SC.size(); i != e; ++i) {
ArrayRef<std::pair<Record *, SMRange>> SC = Set->getSuperClasses();
for (const auto &SCPair : SC) {
// Skip unnamed superclasses.
if (!dyn_cast<StringInit>(SC[i]->getNameInit()))
if (!isa<StringInit>(SCPair.first->getNameInit()))
continue;
auto I = Expanders.find(SC[i]->getName());
auto I = Expanders.find(SCPair.first->getName());
if (I != Expanders.end()) {
// This breaks recursive definitions.
RecVec &EltVec = Expansions[Set];

View File

@ -185,13 +185,12 @@ bool TGParser::AddSubClass(Record *CurRec, SubClassReference &SubClass) {
// Since everything went well, we can now set the "superclass" list for the
// current record.
ArrayRef<Record *> SCs = SC->getSuperClasses();
ArrayRef<SMRange> SCRanges = SC->getSuperClassRanges();
for (unsigned i = 0, e = SCs.size(); i != e; ++i) {
if (CurRec->isSubClassOf(SCs[i]))
ArrayRef<std::pair<Record *, SMRange>> SCs = SC->getSuperClasses();
for (const auto &SCPair : SCs) {
if (CurRec->isSubClassOf(SCPair.first))
return Error(SubClass.RefRange.Start,
"Already subclass of '" + SCs[i]->getName() + "'!\n");
CurRec->addSuperClass(SCs[i], SCRanges[i]);
"Already subclass of '" + SCPair.first->getName() + "'!\n");
CurRec->addSuperClass(SCPair.first, SCPair.second);
}
if (CurRec->isSubClassOf(SC))

View File

@ -587,10 +587,9 @@ struct TupleExpander : SetTheory::Expander {
Elts.insert(NewReg);
// Copy Proto super-classes.
ArrayRef<Record *> Supers = Proto->getSuperClasses();
ArrayRef<SMRange> Ranges = Proto->getSuperClassRanges();
for (unsigned i = 0, e = Supers.size(); i != e; ++i)
NewReg->addSuperClass(Supers[i], Ranges[i]);
ArrayRef<std::pair<Record *, SMRange>> Supers = Proto->getSuperClasses();
for (const auto &SuperPair : Supers)
NewReg->addSuperClass(SuperPair.first, SuperPair.second);
// Copy Proto fields.
for (unsigned i = 0, e = Proto->getValues().size(); i != e; ++i) {