Skip to content

[TableGen] Print memory stats in detailed record emitter #106990

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/include/llvm/TableGen/Record.h
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ class Record {
ArrayRef<AssertionInfo> getAssertions() const { return Assertions; }
ArrayRef<DumpInfo> getDumps() const { return Dumps; }

ArrayRef<std::pair<Record *, SMRange>> getSuperClasses() const {
ArrayRef<std::pair<Record *, SMRange>> getSuperClasses() const {
return SuperClasses;
}

Expand Down Expand Up @@ -2073,6 +2073,8 @@ class RecordKeeper {

void dump() const;

void dumpAllocationStats(raw_ostream &OS) const;

private:
RecordKeeper(RecordKeeper &&) = delete;
RecordKeeper(const RecordKeeper &) = delete;
Expand Down
17 changes: 11 additions & 6 deletions llvm/lib/TableGen/DetailedRecordsBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class DetailedRecordsEmitter {
void printVariables(raw_ostream &OS);
void printClasses(raw_ostream &OS);
void printRecords(raw_ostream &OS);
void printAllocationStats(raw_ostream &OS);
void printDefms(const Record &Rec, raw_ostream &OS);
void printTemplateArgs(const Record &Rec, raw_ostream &OS);
void printSuperclasses(const Record &Rec, raw_ostream &OS);
Expand All @@ -55,15 +56,15 @@ void DetailedRecordsEmitter::run(raw_ostream &OS) {
printVariables(OS);
printClasses(OS);
printRecords(OS);
printAllocationStats(OS);
}

// Print the report heading, including the source file name.
void DetailedRecordsEmitter::printReportHeading(raw_ostream &OS) {
OS << formatv("DETAILED RECORDS for file {0}\n", Records.getInputFilename());
}

// Print a section heading with the name of the section and
// the item count.
// Print a section heading with the name of the section and the item count.
void DetailedRecordsEmitter::printSectionHeading(StringRef Title, int Count,
raw_ostream &OS) {
OS << formatv("\n{0} {1} ({2}) {0}\n", "--------------------", Title, Count);
Expand All @@ -79,8 +80,7 @@ void DetailedRecordsEmitter::printVariables(raw_ostream &OS) {
OS << Var.first << " = " << Var.second->getAsString() << '\n';
}

// Print the classes, including the template arguments, superclasses,
// and fields.
// Print classes, including the template arguments, superclasses, and fields.
void DetailedRecordsEmitter::printClasses(raw_ostream &OS) {
const auto &ClassList = Records.getClasses();
printSectionHeading("Classes", ClassList.size(), OS);
Expand All @@ -94,8 +94,7 @@ void DetailedRecordsEmitter::printClasses(raw_ostream &OS) {
}
}

// Print the records, including the defm sequences, supercasses,
// and fields.
// Print the records, including the defm sequences, supercasses, and fields.
void DetailedRecordsEmitter::printRecords(raw_ostream &OS) {
const auto &RecordList = Records.getDefs();
printSectionHeading("Records", RecordList.size(), OS);
Expand All @@ -110,6 +109,12 @@ void DetailedRecordsEmitter::printRecords(raw_ostream &OS) {
}
}

// Print memory allocation related stats.
void DetailedRecordsEmitter::printAllocationStats(raw_ostream &OS) {
OS << formatv("\n{0} Memory Allocation Stats {0}\n", "--------------------");
Records.dumpAllocationStats(OS);
}

// Print the record's defm source locations, if any. Note that they
// are stored in the reverse order of their invocation.
void DetailedRecordsEmitter::printDefms(const Record &Rec, raw_ostream &OS) {
Expand Down
33 changes: 33 additions & 0 deletions llvm/lib/TableGen/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,39 @@ struct RecordKeeperImpl {

unsigned AnonCounter;
unsigned LastRecordID;

void dumpAllocationStats(raw_ostream &OS) const;
};
} // namespace detail
} // namespace llvm

void detail::RecordKeeperImpl::dumpAllocationStats(raw_ostream &OS) const {
// Dump memory allocation related stats.
OS << "TheArgumentInitPool size = " << TheArgumentInitPool.size() << '\n';
OS << "TheBitsInitPool size = " << TheBitsInitPool.size() << '\n';
OS << "TheIntInitPool size = " << TheIntInitPool.size() << '\n';
OS << "TheBitsInitPool size = " << TheBitsInitPool.size() << '\n';
OS << "TheListInitPool size = " << TheListInitPool.size() << '\n';
OS << "TheUnOpInitPool size = " << TheUnOpInitPool.size() << '\n';
OS << "TheBinOpInitPool size = " << TheBinOpInitPool.size() << '\n';
OS << "TheTernOpInitPool size = " << TheTernOpInitPool.size() << '\n';
OS << "TheFoldOpInitPool size = " << TheFoldOpInitPool.size() << '\n';
OS << "TheIsAOpInitPool size = " << TheIsAOpInitPool.size() << '\n';
OS << "TheExistsOpInitPool size = " << TheExistsOpInitPool.size() << '\n';
OS << "TheCondOpInitPool size = " << TheCondOpInitPool.size() << '\n';
OS << "TheDagInitPool size = " << TheDagInitPool.size() << '\n';
OS << "RecordTypePool size = " << RecordTypePool.size() << '\n';
OS << "TheVarInitPool size = " << TheVarInitPool.size() << '\n';
OS << "TheVarBitInitPool size = " << TheVarBitInitPool.size() << '\n';
OS << "TheVarDefInitPool size = " << TheVarDefInitPool.size() << '\n';
OS << "TheFieldInitPool size = " << TheFieldInitPool.size() << '\n';
OS << "Bytes allocated = " << Allocator.getBytesAllocated() << '\n';
OS << "Total allocator memory = " << Allocator.getTotalMemory() << "\n\n";

OS << "Number of records instantiated = " << LastRecordID << '\n';
OS << "Number of anonymous records = " << AnonCounter << '\n';
}

//===----------------------------------------------------------------------===//
// Type implementations
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -3261,6 +3290,10 @@ RecordKeeper::getAllDerivedDefinitionsIfDefined(StringRef ClassName) const {
: std::vector<Record *>();
}

void RecordKeeper::dumpAllocationStats(raw_ostream &OS) const {
Impl->dumpAllocationStats(OS);
}

Init *MapResolver::resolve(Init *VarName) {
auto It = Map.find(VarName);
if (It == Map.end())
Expand Down
Loading