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

Douglas Gregor dgregor at apple.com
Wed Apr 22 12:09:20 PDT 2009


Author: dgregor
Date: Wed Apr 22 14:09:20 2009
New Revision: 69820

URL: http://llvm.org/viewvc/llvm-project?rev=69820&view=rev
Log:
Minimize the number and kind of "external definitions" that the PCH
file needs to store. CodeGen needs to see these definitions (via
HandleTopLevelDecl), otherwise it won't be able to generate code for
them. 

This patch notifies the consumer (e.g., CodeGen) about function
definitions and variable definitions when the corresponding
declarations are deserialized. Hence, we don't eagerly deserialize the
declarations for every variable or function that has a definition in
the PCH file. This gives another 5% speedup for the Carbon-prefixed
"Hello, World!", and brings our PCH statistics down to something far
more reasonable:

*** PCH Statistics:
  13/20693 types read (0.062823%)
  17/59230 declarations read (0.028702%)
  54/44914 identifiers read (0.120230%)
  0/32954 statements read (0.000000%)
  5/6187 macros read (0.080815%)


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

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

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Wed Apr 22 14:09:20 2009
@@ -39,6 +39,7 @@
 namespace clang {
 
 class AddrLabelExpr;
+class ASTConsumer;
 class ASTContext;
 class Attr;
 class Decl;
@@ -77,6 +78,9 @@
   /// \brief The AST context into which we'll read the PCH file.
   ASTContext &Context;
 
+  /// \brief The AST consumer.
+  ASTConsumer *Consumer;
+
   /// \brief The bitstream reader from which we'll read the PCH file.
   llvm::BitstreamReader Stream;
 
@@ -198,7 +202,7 @@
   typedef llvm::SmallVector<uint64_t, 64> RecordData;
 
   explicit PCHReader(Preprocessor &PP, ASTContext &Context) 
-    : SemaObj(0), PP(PP), Context(Context), 
+    : SemaObj(0), PP(PP), Context(Context), Consumer(0),
       IdentifierTableData(0), NumStatementsRead(0) { }
 
   ~PCHReader() {}

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Apr 22 14:09:20 2009
@@ -377,9 +377,7 @@
 std::pair<uint64_t, uint64_t> 
 PCHDeclReader::VisitDeclContext(DeclContext *DC) {
   uint64_t LexicalOffset = Record[Idx++];
-  uint64_t VisibleOffset = 0;
-  if (DC->getPrimaryContext() == DC)
-    VisibleOffset = Record[Idx++];
+  uint64_t VisibleOffset = Record[Idx++];
   return std::make_pair(LexicalOffset, VisibleOffset);
 }
 
@@ -2317,6 +2315,23 @@
   }
   assert(Idx == Record.size());
 
+  if (Consumer) {
+    // If we have deserialized a declaration that has a definition the
+    // AST consumer might need to know about, notify the consumer
+    // about that definition now.
+    if (VarDecl *Var = dyn_cast<VarDecl>(D)) {
+      if (Var->isFileVarDecl() && Var->getInit()) {
+        DeclGroupRef DG(Var);
+        Consumer->HandleTopLevelDecl(DG);
+      }
+    } else if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) {
+      if (Func->isThisDeclarationADefinition()) {
+        DeclGroupRef DG(Func);
+        Consumer->HandleTopLevelDecl(DG);
+      }
+    }
+  }
+
   return D;
 }
 
@@ -2458,6 +2473,8 @@
 }
 
 void PCHReader::StartTranslationUnit(ASTConsumer *Consumer) {
+  this->Consumer = Consumer;
+
   if (!Consumer)
     return;
 

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed Apr 22 14:09:20 2009
@@ -574,8 +574,7 @@
 void PCHDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset, 
                                      uint64_t VisibleOffset) {
   Record.push_back(LexicalOffset);
-  if (DC->getPrimaryContext() == DC)
-    Record.push_back(VisibleOffset);
+  Record.push_back(VisibleOffset);
 }
 
 //===----------------------------------------------------------------------===//
@@ -1728,20 +1727,6 @@
     // in the PCH file later.
     if (isa<FileScopeAsmDecl>(D))
       ExternalDefinitions.push_back(ID);
-    else if (VarDecl *Var = dyn_cast<VarDecl>(D)) {
-      if (// Non-static file-scope variables with initializers or that
-          // are tentative definitions.
-          (Var->isFileVarDecl() &&
-           (Var->getInit() || Var->getStorageClass() == VarDecl::None)) ||
-          // Out-of-line definitions of static data members (C++).
-          (Var->getDeclContext()->isRecord() && 
-           !Var->getLexicalDeclContext()->isRecord() && 
-           Var->getStorageClass() == VarDecl::Static))
-        ExternalDefinitions.push_back(ID);
-    } else if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) {
-      if (Func->isThisDeclarationADefinition())
-        ExternalDefinitions.push_back(ID);
-    }
   }
 
   // Exit the declarations block





More information about the cfe-commits mailing list