зеркало из https://github.com/microsoft/clang-1.git
Keep track of the number of statements/expressions written to and read
from a PCH file. It turns out that "Hello, World!" is bringing in 19% of all of the statements in Carbon.h, so we need to be lazy. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69393 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
96508e1fea
Коммит
3e1af84bb0
|
@ -140,7 +140,11 @@ namespace clang {
|
|||
/// reported to the AST consumer after the PCH file has been
|
||||
/// read, since their presence can affect the semantics of the
|
||||
/// program (e.g., for code generation).
|
||||
EXTERNAL_DEFINITIONS = 7
|
||||
EXTERNAL_DEFINITIONS = 7,
|
||||
|
||||
/// \brief Record code for the block of extra statistics we
|
||||
/// gather while generating a PCH file.
|
||||
STATISTICS = 8
|
||||
};
|
||||
|
||||
/// \brief Record types used within a source manager block.
|
||||
|
|
|
@ -149,6 +149,14 @@ private:
|
|||
/// been de-serialized.
|
||||
std::multimap<unsigned, AddrLabelExpr *> UnresolvedAddrLabelExprs;
|
||||
|
||||
/// \brief The number of statements (and expressions) de-serialized
|
||||
/// from the PCH file.
|
||||
unsigned NumStatementsRead;
|
||||
|
||||
/// \brief The total number of statements (and expressions) stored
|
||||
/// in the PCH file.
|
||||
unsigned TotalNumStatements;
|
||||
|
||||
PCHReadResult ReadPCHBlock();
|
||||
bool CheckPredefinesBuffer(const char *PCHPredef,
|
||||
unsigned PCHPredefLen,
|
||||
|
@ -168,7 +176,7 @@ public:
|
|||
typedef llvm::SmallVector<uint64_t, 64> RecordData;
|
||||
|
||||
PCHReader(Preprocessor &PP, ASTContext &Context)
|
||||
: PP(PP), Context(Context), IdentifierTable(0) { }
|
||||
: PP(PP), Context(Context), IdentifierTable(0), NumStatementsRead(0) { }
|
||||
|
||||
~PCHReader() {}
|
||||
|
||||
|
|
|
@ -117,6 +117,9 @@ private:
|
|||
/// \brief Mapping from LabelStmt statements to IDs.
|
||||
std::map<LabelStmt *, unsigned> LabelIDs;
|
||||
|
||||
/// \brief The number of statements written to the PCH file.
|
||||
unsigned NumStatements;
|
||||
|
||||
void WriteTargetTriple(const TargetInfo &Target);
|
||||
void WriteLanguageOptions(const LangOptions &LangOpts);
|
||||
void WriteSourceManagerBlock(SourceManager &SourceMgr);
|
||||
|
|
|
@ -1173,7 +1173,7 @@ PCHReader::PCHReadResult PCHReader::ReadPCHBlock() {
|
|||
}
|
||||
|
||||
uint64_t PreprocessorBlockBit = 0;
|
||||
|
||||
|
||||
// Read all of the records and blocks for the PCH file.
|
||||
RecordData Record;
|
||||
while (!Stream.AtEndOfStream()) {
|
||||
|
@ -1315,6 +1315,11 @@ PCHReader::PCHReadResult PCHReader::ReadPCHBlock() {
|
|||
}
|
||||
ExternalDefinitions.swap(Record);
|
||||
break;
|
||||
|
||||
case pch::STATISTICS:
|
||||
TotalNumStatements = Record[0];
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1976,6 +1981,9 @@ void PCHReader::PrintStats() {
|
|||
std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n",
|
||||
NumIdentifiersLoaded, (unsigned)IdentifierData.size(),
|
||||
((float)NumIdentifiersLoaded/IdentifierData.size() * 100));
|
||||
std::fprintf(stderr, " %u/%u statements read (%f%%)\n",
|
||||
NumStatementsRead, TotalNumStatements,
|
||||
((float)NumStatementsRead/TotalNumStatements * 100));
|
||||
std::fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
|
@ -2450,6 +2458,8 @@ Stmt *PCHReader::ReadStmt() {
|
|||
if (Finished)
|
||||
break;
|
||||
|
||||
++NumStatementsRead;
|
||||
|
||||
if (S) {
|
||||
unsigned NumSubStmts = Reader.Visit(S);
|
||||
while (NumSubStmts > 0) {
|
||||
|
|
|
@ -1723,7 +1723,7 @@ void PCHWriter::AddString(const std::string &Str, RecordData &Record) {
|
|||
}
|
||||
|
||||
PCHWriter::PCHWriter(llvm::BitstreamWriter &Stream)
|
||||
: Stream(Stream), NextTypeID(pch::NUM_PREDEF_TYPE_IDS) { }
|
||||
: Stream(Stream), NextTypeID(pch::NUM_PREDEF_TYPE_IDS), NumStatements(0) { }
|
||||
|
||||
void PCHWriter::WritePCH(ASTContext &Context, const Preprocessor &PP) {
|
||||
// Emit the file header.
|
||||
|
@ -1749,6 +1749,11 @@ void PCHWriter::WritePCH(ASTContext &Context, const Preprocessor &PP) {
|
|||
Stream.EmitRecord(pch::DECL_OFFSET, DeclOffsets);
|
||||
if (!ExternalDefinitions.empty())
|
||||
Stream.EmitRecord(pch::EXTERNAL_DEFINITIONS, ExternalDefinitions);
|
||||
|
||||
// Some simple statistics
|
||||
RecordData Record;
|
||||
Record.push_back(NumStatements);
|
||||
Stream.EmitRecord(pch::STATISTICS, Record);
|
||||
Stream.ExitBlock();
|
||||
}
|
||||
|
||||
|
@ -1880,6 +1885,7 @@ void PCHWriter::AddDeclarationName(DeclarationName Name, RecordData &Record) {
|
|||
void PCHWriter::WriteSubStmt(Stmt *S) {
|
||||
RecordData Record;
|
||||
PCHStmtWriter Writer(*this, Record);
|
||||
++NumStatements;
|
||||
|
||||
if (!S) {
|
||||
Stream.EmitRecord(pch::STMT_NULL_PTR, Record);
|
||||
|
@ -1900,6 +1906,7 @@ void PCHWriter::FlushStmts() {
|
|||
PCHStmtWriter Writer(*this, Record);
|
||||
|
||||
for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
|
||||
++NumStatements;
|
||||
Stmt *S = StmtsToEmit[I];
|
||||
|
||||
if (!S) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче