diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-04-17 22:13:46 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-04-17 22:13:46 +0000 |
commit | 3e1af84bb0092a1aafb49deaa4ab6664c9a9071b (patch) | |
tree | 8bd3ab39182cefb3f3e8ca16debf47c739716b6e | |
parent | 96508e1fea58347b6401ca9a4728c0b268174603 (diff) |
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
-rw-r--r-- | include/clang/Frontend/PCHBitCodes.h | 6 | ||||
-rw-r--r-- | include/clang/Frontend/PCHReader.h | 10 | ||||
-rw-r--r-- | include/clang/Frontend/PCHWriter.h | 3 | ||||
-rw-r--r-- | lib/Frontend/PCHReader.cpp | 12 | ||||
-rw-r--r-- | lib/Frontend/PCHWriter.cpp | 9 |
5 files changed, 36 insertions, 4 deletions
diff --git a/include/clang/Frontend/PCHBitCodes.h b/include/clang/Frontend/PCHBitCodes.h index 70b44b8448..8bb81676bd 100644 --- a/include/clang/Frontend/PCHBitCodes.h +++ b/include/clang/Frontend/PCHBitCodes.h @@ -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. diff --git a/include/clang/Frontend/PCHReader.h b/include/clang/Frontend/PCHReader.h index 0507cfa5f5..1352908ef1 100644 --- a/include/clang/Frontend/PCHReader.h +++ b/include/clang/Frontend/PCHReader.h @@ -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() {} diff --git a/include/clang/Frontend/PCHWriter.h b/include/clang/Frontend/PCHWriter.h index 07fb3d3a2c..ee101b54f7 100644 --- a/include/clang/Frontend/PCHWriter.h +++ b/include/clang/Frontend/PCHWriter.h @@ -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); diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index da7b4229aa..5ea1f7c6c2 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -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) { diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index 5775ac4c13..64bf3833b4 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -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) { |