[llvm] r258065 - [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
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 18 11:52:38 PST 2016
Author: ctopper
Date: Mon Jan 18 13:52:37 2016
New Revision: 258065
URL: http://llvm.org/viewvc/llvm-project?rev=258065&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/TableGen/Record.h
llvm/trunk/lib/TableGen/Record.cpp
llvm/trunk/lib/TableGen/SetTheory.cpp
llvm/trunk/lib/TableGen/TGParser.cpp
llvm/trunk/utils/TableGen/CodeGenRegisters.cpp
Modified: llvm/trunk/include/llvm/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/Record.h?rev=258065&r1=258064&r2=258065&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/Record.h (original)
+++ llvm/trunk/include/llvm/TableGen/Record.h Mon Jan 18 13:52:37 2016
@@ -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
Modified: llvm/trunk/lib/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/Record.cpp?rev=258065&r1=258064&r2=258065&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/Record.cpp (original)
+++ llvm/trunk/lib/TableGen/Record.cpp Mon Jan 18 13:52:37 2016
@@ -167,8 +167,8 @@ bool RecordRecTy::typeIsConvertibleTo(co
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, Rec
// 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, Rec
}
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_ostrea
}
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";
Modified: llvm/trunk/lib/TableGen/SetTheory.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/SetTheory.cpp?rev=258065&r1=258064&r2=258065&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/SetTheory.cpp (original)
+++ llvm/trunk/lib/TableGen/SetTheory.cpp Mon Jan 18 13:52:37 2016
@@ -302,12 +302,12 @@ const RecVec *SetTheory::expand(Record *
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];
Modified: llvm/trunk/lib/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TGParser.cpp?rev=258065&r1=258064&r2=258065&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp (original)
+++ llvm/trunk/lib/TableGen/TGParser.cpp Mon Jan 18 13:52:37 2016
@@ -185,13 +185,12 @@ bool TGParser::AddSubClass(Record *CurRe
// 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))
Modified: llvm/trunk/utils/TableGen/CodeGenRegisters.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenRegisters.cpp?rev=258065&r1=258064&r2=258065&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenRegisters.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenRegisters.cpp Mon Jan 18 13:52:37 2016
@@ -587,10 +587,9 @@ struct TupleExpander : SetTheory::Expand
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) {
More information about the llvm-commits
mailing list