Add PCH statistics for the number/percent of lexical/visible declcontexts read
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69835 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Frontend/PCHReader.h b/include/clang/Frontend/PCHReader.h
index 72ca6ad..107779a 100644
--- a/include/clang/Frontend/PCHReader.h
+++ b/include/clang/Frontend/PCHReader.h
@@ -185,9 +185,16 @@
/// \brief The number of macros de-serialized from the PCH file.
unsigned NumMacrosRead;
+
/// \brief The total number of macros stored in the PCH file.
unsigned TotalNumMacros;
+ /// Number of lexical decl contexts read/total.
+ unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts;
+
+ /// Number of visible decl contexts read/total.
+ unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
+
/// \brief FIXME: document!
llvm::SmallVector<uint64_t, 4> SpecialTypes;
@@ -211,7 +218,8 @@
explicit PCHReader(Preprocessor &PP, ASTContext &Context)
: SemaObj(0), PP(PP), Context(Context), Consumer(0),
- IdentifierTableData(0), NumStatementsRead(0) { }
+ IdentifierTableData(0), NumStatementsRead(0), NumMacrosRead(0),
+ NumLexicalDeclContextsRead(0), NumVisibleDeclContextsRead(0) { }
~PCHReader() {}
diff --git a/include/clang/Frontend/PCHWriter.h b/include/clang/Frontend/PCHWriter.h
index d721f10..e3d0603 100644
--- a/include/clang/Frontend/PCHWriter.h
+++ b/include/clang/Frontend/PCHWriter.h
@@ -136,6 +136,14 @@
/// \brief The number of macros written to the PCH file.
unsigned NumMacros;
+ /// \brief The number of lexical declcontexts written to the PCH
+ /// file.
+ unsigned NumLexicalDeclContexts;
+
+ /// \brief The number of visible declcontexts written to the PCH
+ /// file.
+ unsigned NumVisibleDeclContexts;
+
void WriteTargetTriple(const TargetInfo &Target);
void WriteLanguageOptions(const LangOptions &LangOpts);
void WriteSourceManagerBlock(SourceManager &SourceMgr);
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index 66a849d..3ade493 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -1711,6 +1711,8 @@
case pch::STATISTICS:
TotalNumStatements = Record[0];
TotalNumMacros = Record[1];
+ TotalLexicalDeclContexts = Record[2];
+ TotalVisibleDeclContexts = Record[3];
break;
case pch::TENTATIVE_DEFINITIONS:
@@ -2439,6 +2441,7 @@
// Load all of the declaration IDs
Decls.clear();
Decls.insert(Decls.end(), Record.begin(), Record.end());
+ ++NumLexicalDeclContextsRead;
return false;
}
@@ -2479,6 +2482,7 @@
LoadedDecls.push_back(Record[Idx++]);
}
+ ++NumVisibleDeclContextsRead;
return false;
}
@@ -2525,6 +2529,14 @@
std::fprintf(stderr, " %u/%u macros read (%f%%)\n",
NumMacrosRead, TotalNumMacros,
((float)NumMacrosRead/TotalNumMacros * 100));
+ std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n",
+ NumLexicalDeclContextsRead, TotalLexicalDeclContexts,
+ ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts
+ * 100));
+ std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n",
+ NumVisibleDeclContextsRead, TotalVisibleDeclContexts,
+ ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts
+ * 100));
std::fprintf(stderr, "\n");
}
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 0aada62..6557ca5 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -1616,6 +1616,7 @@
D != DEnd; ++D)
AddDeclRef(*D, Record);
+ ++NumLexicalDeclContexts;
Stream.EmitRecord(pch::DECL_CONTEXT_LEXICAL, Record);
return Offset;
}
@@ -1664,6 +1665,7 @@
return 0;
Stream.EmitRecord(pch::DECL_CONTEXT_VISIBLE, Record);
+ ++NumVisibleDeclContexts;
return Offset;
}
@@ -1997,7 +1999,8 @@
PCHWriter::PCHWriter(llvm::BitstreamWriter &Stream)
: Stream(Stream), NextTypeID(pch::NUM_PREDEF_TYPE_IDS),
- NumStatements(0), NumMacros(0) { }
+ NumStatements(0), NumMacros(0), NumLexicalDeclContexts(0),
+ NumVisibleDeclContexts(0) { }
void PCHWriter::WritePCH(Sema &SemaRef) {
ASTContext &Context = SemaRef.Context;
@@ -2078,6 +2081,8 @@
Record.clear();
Record.push_back(NumStatements);
Record.push_back(NumMacros);
+ Record.push_back(NumLexicalDeclContexts);
+ Record.push_back(NumVisibleDeclContexts);
Stream.EmitRecord(pch::STATISTICS, Record);
Stream.ExitBlock();
}