[cfe-commits] r69393 - in /cfe/trunk: include/clang/Frontend/PCHBitCodes.h include/clang/Frontend/PCHReader.h include/clang/Frontend/PCHWriter.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp

Douglas Gregor dgregor at apple.com
Fri Apr 17 15:13:46 PDT 2009


Author: dgregor
Date: Fri Apr 17 17:13:46 2009
New Revision: 69393

URL: http://llvm.org/viewvc/llvm-project?rev=69393&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Frontend/PCHBitCodes.h
    cfe/trunk/include/clang/Frontend/PCHReader.h
    cfe/trunk/include/clang/Frontend/PCHWriter.h
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp

Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69393&r1=69392&r2=69393&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Fri Apr 17 17:13:46 2009
@@ -140,7 +140,11 @@
       /// 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.

Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=69393&r1=69392&r2=69393&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Fri Apr 17 17:13:46 2009
@@ -149,6 +149,14 @@
   /// 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 @@
   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() {}
 

Modified: cfe/trunk/include/clang/Frontend/PCHWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHWriter.h?rev=69393&r1=69392&r2=69393&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHWriter.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHWriter.h Fri Apr 17 17:13:46 2009
@@ -117,6 +117,9 @@
   /// \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);

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69393&r1=69392&r2=69393&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Apr 17 17:13:46 2009
@@ -1173,7 +1173,7 @@
   }
 
   uint64_t PreprocessorBlockBit = 0;
-  
+
   // Read all of the records and blocks for the PCH file.
   RecordData Record;
   while (!Stream.AtEndOfStream()) {
@@ -1315,6 +1315,11 @@
       }
       ExternalDefinitions.swap(Record);
       break;
+
+    case pch::STATISTICS:
+      TotalNumStatements = Record[0];
+      break;
+
     }
   }
 
@@ -1976,6 +1981,9 @@
   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 @@
     if (Finished)
       break;
 
+    ++NumStatementsRead;
+
     if (S) {
       unsigned NumSubStmts = Reader.Visit(S);
       while (NumSubStmts > 0) {

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69393&r1=69392&r2=69393&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Fri Apr 17 17:13:46 2009
@@ -1723,7 +1723,7 @@
 }
 
 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 @@
   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::WriteSubStmt(Stmt *S) {
   RecordData Record;
   PCHStmtWriter Writer(*this, Record);
+  ++NumStatements;
 
   if (!S) {
     Stream.EmitRecord(pch::STMT_NULL_PTR, Record);
@@ -1900,6 +1906,7 @@
   PCHStmtWriter Writer(*this, Record);
 
   for (unsigned I = 0, N = StmtsToEmit.size(); I != N; ++I) {
+    ++NumStatements;
     Stmt *S = StmtsToEmit[I];
 
     if (!S) {





More information about the cfe-commits mailing list