-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[TableGen] Only store direct superclasses in Record #123072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
f12511a
2a96ff4
683fe14
e235152
e169673
2eb1354
6d74050
21492b5
9a645ee
d39a1fc
e52de29
9c70b67
834a337
2af1d81
0889f4c
e57064b
0160783
8bbe3c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1630,9 +1630,9 @@ class Record { | |
SmallVector<AssertionInfo, 0> Assertions; | ||
SmallVector<DumpInfo, 0> Dumps; | ||
|
||
// All superclasses in the inheritance forest in post-order (yes, it | ||
// Direct superclasses, which are roots of the inheritance forest (yes, it | ||
// must be a forest; diamond-shaped inheritance is not allowed). | ||
SmallVector<std::pair<const Record *, SMRange>, 0> SuperClasses; | ||
SmallVector<std::pair<const Record *, SMRange>, 0> DirectSuperClasses; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the fact that we're only storing a small number of direct super classes now, would it make more sense to use SmallVector<..., N> with N not equal to zero? N = 0 will disable any stack allocation and allocate on heap only, IIRC There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried N=1 but it seemed to increase memory usage overall. I think the problem is that |
||
|
||
// Tracks Record instances. Not owned by Record. | ||
RecordKeeper &TrackedRecords; | ||
|
@@ -1666,8 +1666,9 @@ class Record { | |
Record(const Record &O) | ||
: Name(O.Name), Locs(O.Locs), TemplateArgs(O.TemplateArgs), | ||
Values(O.Values), Assertions(O.Assertions), | ||
SuperClasses(O.SuperClasses), TrackedRecords(O.TrackedRecords), | ||
ID(getNewUID(O.getRecords())), Kind(O.Kind) {} | ||
DirectSuperClasses(O.DirectSuperClasses), | ||
TrackedRecords(O.TrackedRecords), ID(getNewUID(O.getRecords())), | ||
Kind(O.Kind) {} | ||
|
||
static unsigned getNewUID(RecordKeeper &RK); | ||
|
||
|
@@ -1718,15 +1719,23 @@ class Record { | |
ArrayRef<AssertionInfo> getAssertions() const { return Assertions; } | ||
ArrayRef<DumpInfo> getDumps() const { return Dumps; } | ||
|
||
ArrayRef<std::pair<const Record *, SMRange>> getSuperClasses() const { | ||
return SuperClasses; | ||
void getSuperClasses( | ||
s-barannikov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SmallVectorImpl<std::pair<const Record *, SMRange>> &Classes) const { | ||
for (const auto &[SC, R] : DirectSuperClasses) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Or can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I went for |
||
SC->getSuperClasses(Classes); | ||
Classes.emplace_back(SC, R); | ||
} | ||
} | ||
|
||
/// Determine whether this record has the specified direct superclass. | ||
bool hasDirectSuperClass(const Record *SuperClass) const; | ||
bool hasDirectSuperClass(const Record *SuperClass) const { | ||
return is_contained(make_first_range(DirectSuperClasses), SuperClass); | ||
} | ||
|
||
/// Append the direct superclasses of this record to Classes. | ||
void getDirectSuperClasses(SmallVectorImpl<const Record *> &Classes) const; | ||
/// Return the direct superclasses of this record. | ||
ArrayRef<std::pair<const Record *, SMRange>> getDirectSuperClasses() const { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (idea for a future patch) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh I see, it is copied around but ultimately never used for anything. I can do a follow up to remove it completely. Or maybe doing that change first, before landing this one, would be less disruptive (in case there are any out-of-tree users of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure location should be removed completely as it might be used for diagnostics. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Though unfortunately we're not doing it at this moment, I think we should make good uses of this location (where the superclass was reference) to show a nice backtrace. Personally I feel like if it doesn't take a lot of efforts we should probably keep the location. |
||
return DirectSuperClasses; | ||
} | ||
|
||
bool isTemplateArg(const Init *Name) const { | ||
return llvm::is_contained(TemplateArgs, Name); | ||
|
@@ -1794,29 +1803,32 @@ class Record { | |
void checkUnusedTemplateArgs(); | ||
|
||
bool isSubClassOf(const Record *R) const { | ||
for (const auto &[SC, _] : SuperClasses) | ||
if (SC == R) | ||
for (const auto &[SC, _] : DirectSuperClasses) { | ||
if (SC == R || SC->isSubClassOf(R)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool isSubClassOf(StringRef Name) const { | ||
for (const auto &[SC, _] : SuperClasses) { | ||
for (const auto &[SC, _] : DirectSuperClasses) { | ||
if (const auto *SI = dyn_cast<StringInit>(SC->getNameInit())) { | ||
if (SI->getValue() == Name) | ||
return true; | ||
} else if (SC->getNameInitAsString() == Name) { | ||
return true; | ||
} | ||
if (SC->isSubClassOf(Name)) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void addSuperClass(const Record *R, SMRange Range) { | ||
void addDirectSuperClass(const Record *R, SMRange Range) { | ||
assert(!CorrespondingDefInit && | ||
"changing type of record after it has been referenced"); | ||
assert(!isSubClassOf(R) && "Already subclassing record!"); | ||
SuperClasses.push_back(std::make_pair(R, Range)); | ||
DirectSuperClasses.emplace_back(R, Range); | ||
} | ||
|
||
/// If there are any field references that refer to fields that have been | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR, but since you are changing the comment:
Is this true?
TGParser::AddSubClass
seems to pass the location of a superclass reference in the inheritance list.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I noticed this too, and I think you're probably right and the documentation is wrong, but I didn't want to go down the rabbit hole of fact-checking the documentation just now.