Skip to content

Commit 30f1cfb

Browse files
authored
[TableGen] Print memory stats in detailed record emitter (#106990)
Print memory allocation and related statistics when dumping detailed record information.
1 parent 1b0a802 commit 30f1cfb

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

llvm/include/llvm/TableGen/Record.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ class Record {
17571757
ArrayRef<AssertionInfo> getAssertions() const { return Assertions; }
17581758
ArrayRef<DumpInfo> getDumps() const { return Dumps; }
17591759

1760-
ArrayRef<std::pair<Record *, SMRange>> getSuperClasses() const {
1760+
ArrayRef<std::pair<Record *, SMRange>> getSuperClasses() const {
17611761
return SuperClasses;
17621762
}
17631763

@@ -2073,6 +2073,8 @@ class RecordKeeper {
20732073

20742074
void dump() const;
20752075

2076+
void dumpAllocationStats(raw_ostream &OS) const;
2077+
20762078
private:
20772079
RecordKeeper(RecordKeeper &&) = delete;
20782080
RecordKeeper(const RecordKeeper &) = delete;

llvm/lib/TableGen/DetailedRecordsBackend.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class DetailedRecordsEmitter {
4141
void printVariables(raw_ostream &OS);
4242
void printClasses(raw_ostream &OS);
4343
void printRecords(raw_ostream &OS);
44+
void printAllocationStats(raw_ostream &OS);
4445
void printDefms(const Record &Rec, raw_ostream &OS);
4546
void printTemplateArgs(const Record &Rec, raw_ostream &OS);
4647
void printSuperclasses(const Record &Rec, raw_ostream &OS);
@@ -55,15 +56,15 @@ void DetailedRecordsEmitter::run(raw_ostream &OS) {
5556
printVariables(OS);
5657
printClasses(OS);
5758
printRecords(OS);
59+
printAllocationStats(OS);
5860
}
5961

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

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

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

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

112+
// Print memory allocation related stats.
113+
void DetailedRecordsEmitter::printAllocationStats(raw_ostream &OS) {
114+
OS << formatv("\n{0} Memory Allocation Stats {0}\n", "--------------------");
115+
Records.dumpAllocationStats(OS);
116+
}
117+
113118
// Print the record's defm source locations, if any. Note that they
114119
// are stored in the reverse order of their invocation.
115120
void DetailedRecordsEmitter::printDefms(const Record &Rec, raw_ostream &OS) {

llvm/lib/TableGen/Record.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,39 @@ struct RecordKeeperImpl {
9292

9393
unsigned AnonCounter;
9494
unsigned LastRecordID;
95+
96+
void dumpAllocationStats(raw_ostream &OS) const;
9597
};
9698
} // namespace detail
9799
} // namespace llvm
98100

101+
void detail::RecordKeeperImpl::dumpAllocationStats(raw_ostream &OS) const {
102+
// Dump memory allocation related stats.
103+
OS << "TheArgumentInitPool size = " << TheArgumentInitPool.size() << '\n';
104+
OS << "TheBitsInitPool size = " << TheBitsInitPool.size() << '\n';
105+
OS << "TheIntInitPool size = " << TheIntInitPool.size() << '\n';
106+
OS << "TheBitsInitPool size = " << TheBitsInitPool.size() << '\n';
107+
OS << "TheListInitPool size = " << TheListInitPool.size() << '\n';
108+
OS << "TheUnOpInitPool size = " << TheUnOpInitPool.size() << '\n';
109+
OS << "TheBinOpInitPool size = " << TheBinOpInitPool.size() << '\n';
110+
OS << "TheTernOpInitPool size = " << TheTernOpInitPool.size() << '\n';
111+
OS << "TheFoldOpInitPool size = " << TheFoldOpInitPool.size() << '\n';
112+
OS << "TheIsAOpInitPool size = " << TheIsAOpInitPool.size() << '\n';
113+
OS << "TheExistsOpInitPool size = " << TheExistsOpInitPool.size() << '\n';
114+
OS << "TheCondOpInitPool size = " << TheCondOpInitPool.size() << '\n';
115+
OS << "TheDagInitPool size = " << TheDagInitPool.size() << '\n';
116+
OS << "RecordTypePool size = " << RecordTypePool.size() << '\n';
117+
OS << "TheVarInitPool size = " << TheVarInitPool.size() << '\n';
118+
OS << "TheVarBitInitPool size = " << TheVarBitInitPool.size() << '\n';
119+
OS << "TheVarDefInitPool size = " << TheVarDefInitPool.size() << '\n';
120+
OS << "TheFieldInitPool size = " << TheFieldInitPool.size() << '\n';
121+
OS << "Bytes allocated = " << Allocator.getBytesAllocated() << '\n';
122+
OS << "Total allocator memory = " << Allocator.getTotalMemory() << "\n\n";
123+
124+
OS << "Number of records instantiated = " << LastRecordID << '\n';
125+
OS << "Number of anonymous records = " << AnonCounter << '\n';
126+
}
127+
99128
//===----------------------------------------------------------------------===//
100129
// Type implementations
101130
//===----------------------------------------------------------------------===//
@@ -3261,6 +3290,10 @@ RecordKeeper::getAllDerivedDefinitionsIfDefined(StringRef ClassName) const {
32613290
: std::vector<Record *>();
32623291
}
32633292

3293+
void RecordKeeper::dumpAllocationStats(raw_ostream &OS) const {
3294+
Impl->dumpAllocationStats(OS);
3295+
}
3296+
32643297
Init *MapResolver::resolve(Init *VarName) {
32653298
auto It = Map.find(VarName);
32663299
if (It == Map.end())

0 commit comments

Comments
 (0)