[cfe-commits] r107915 - in /cfe/trunk: docs/PCHInternals.html include/clang/Frontend/ASTConsumers.h include/clang/Frontend/CompilerInstance.h include/clang/Frontend/PCHBitCodes.h include/clang/Frontend/PCHWriter.h lib/Frontend/CompilerInstance.cpp lib/Frontend/FrontendActions.cpp lib/Frontend/GeneratePCH.cpp lib/Frontend/PCHWriter.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Thu Jul 8 15:01:51 PDT 2010


Author: cornedbee
Date: Thu Jul  8 17:01:51 2010
New Revision: 107915

URL: http://llvm.org/viewvc/llvm-project?rev=107915&view=rev
Log:
Some preparatory work for chained PCH. No functionality change.

Modified:
    cfe/trunk/docs/PCHInternals.html
    cfe/trunk/include/clang/Frontend/ASTConsumers.h
    cfe/trunk/include/clang/Frontend/CompilerInstance.h
    cfe/trunk/include/clang/Frontend/PCHBitCodes.h
    cfe/trunk/include/clang/Frontend/PCHWriter.h
    cfe/trunk/lib/Frontend/CompilerInstance.cpp
    cfe/trunk/lib/Frontend/FrontendActions.cpp
    cfe/trunk/lib/Frontend/GeneratePCH.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp

Modified: cfe/trunk/docs/PCHInternals.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/PCHInternals.html?rev=107915&r1=107914&r2=107915&view=diff
==============================================================================
--- cfe/trunk/docs/PCHInternals.html (original)
+++ cfe/trunk/docs/PCHInternals.html Thu Jul  8 17:01:51 2010
@@ -144,6 +144,15 @@
 useful to determine whether the precompiled header implementation can
 be improved by making more of the implementation lazy.</p>
 
+<p>Precompiled headers can be chained. When you create a PCH while
+including an existing PCH, Clang can create the new PCH by referencing
+the original file and only writing the new data to the new file. For
+example, you could create a PCH out of all the headers that are very
+commonly used throughout your project, and then create a PCH for every
+single source file in the project that includes the code that is
+specific to that file, so that recompiling the file itself is very fast,
+without duplicating the data from the common headers for every file.</p>
+
 <h2 id="contents">Precompiled Header Contents</h2>
 
 <img src="PCHLayout.png" align="right" alt="Precompiled header layout">
@@ -209,6 +218,27 @@
 
 </dl>
 
+<p>A chained PCH file (that is, one that references another PCH) has
+a slightly different metadata block, which contains the following
+information:</p>
+
+<dl>
+  <dt>Referenced file</dt>
+  <dd>The name of the referenced PCH file. It is looked up like a file
+specified using -include-pch.</dd>
+
+  <dt>PCH version</dt>
+  <dd>This is the same as in normal PCH files.</dd>
+
+  <dt>Original file name</dt>
+  <dd>The full path of the header that was used to generate this
+precompiled header.</dd>
+
+</dl>
+
+<p>The language options, target architecture and predefines buffer data
+is taken from the end of the chain, since they have to match anyway.</p>
+
 <h3 id="sourcemgr">Source Manager Block</h3>
 
 <p>The source manager block contains the serialized representation of

Modified: cfe/trunk/include/clang/Frontend/ASTConsumers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTConsumers.h?rev=107915&r1=107914&r2=107915&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTConsumers.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTConsumers.h Thu Jul  8 17:01:51 2010
@@ -29,6 +29,7 @@
 class Diagnostic;
 class FileManager;
 class LangOptions;
+class PCHReader;
 class Preprocessor;
 class TargetOptions;
 
@@ -62,6 +63,7 @@
 // times.
 ASTConsumer *CreatePCHGenerator(const Preprocessor &PP,
                                 llvm::raw_ostream *OS,
+                                const PCHReader *Chain,
                                 const char *isysroot = 0);
 
 // Inheritance viewer: for C++ code, creates a graph of the inheritance

Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=107915&r1=107914&r2=107915&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Thu Jul  8 17:01:51 2010
@@ -34,6 +34,7 @@
 class ExternalASTSource;
 class FileManager;
 class FrontendAction;
+class PCHReader;
 class Preprocessor;
 class SourceManager;
 class TargetInfo;
@@ -96,6 +97,9 @@
   /// The list of active output files.
   std::list< std::pair<std::string, llvm::raw_ostream*> > OutputFiles;
 
+  /// The PCH reader. Not owned; the ASTContext owns this.
+  PCHReader *Reader;
+
   void operator=(const CompilerInstance &);  // DO NOT IMPLEMENT
   CompilerInstance(const CompilerInstance&); // DO NOT IMPLEMENT
 public:
@@ -507,6 +511,9 @@
   createPCHExternalASTSource(llvm::StringRef Path, const std::string &Sysroot,
                              Preprocessor &PP, ASTContext &Context);
 
+  /// Get the PCH reader, if any.
+  PCHReader *getPCHReader() { return Reader; }
+
   /// Create a code completion consumer using the invocation; note that this
   /// will cause the source manager to truncate the input source file at the
   /// completion point.

Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=107915&r1=107914&r2=107915&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Thu Jul  8 17:01:51 2010
@@ -30,10 +30,10 @@
     /// designed for the previous version could not support reading
     /// the new version), this number should be increased.
     ///
-    /// Version 3 of PCH files also requires that the version control branch and
+    /// Version 4 of PCH files also requires that the version control branch and
     /// revision match exactly, since there is no backward compatibility of
     /// PCH files at this time.
-    const unsigned VERSION_MAJOR = 3;
+    const unsigned VERSION_MAJOR = 4;
 
     /// \brief PCH minor version number supported by this version of
     /// Clang.
@@ -47,7 +47,7 @@
 
     /// \brief An ID number that refers to a declaration in a PCH file.
     ///
-    /// The ID numbers of types are consecutive (in order of
+    /// The ID numbers of declarations are consecutive (in order of
     /// discovery) and start at 2. 0 is reserved for NULL, and 1 is
     /// reserved for the translation unit declaration.
     typedef uint32_t DeclID;
@@ -232,7 +232,11 @@
       VTABLE_USES = 24,
 
       /// \brief Record code for the array of dynamic classes.
-      DYNAMIC_CLASSES = 25
+      DYNAMIC_CLASSES = 25,
+
+      /// \brief Record code for the chained PCH metadata, including the
+      /// PCH version and the name of the PCH this is chained to.
+      CHAINED_METADATA = 26
 
     };
 

Modified: cfe/trunk/include/clang/Frontend/PCHWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHWriter.h?rev=107915&r1=107914&r2=107915&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHWriter.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHWriter.h Thu Jul  8 17:01:51 2010
@@ -39,6 +39,7 @@
 class LabelStmt;
 class MacroDefinition;
 class MemorizeStatCalls;
+class PCHReader;
 class Preprocessor;
 class Sema;
 class SourceManager;
@@ -257,7 +258,7 @@
   /// \param PPRec Record of the preprocessing actions that occurred while
   /// preprocessing this file, e.g., macro instantiations
   void WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
-                const char* isysroot);
+                const PCHReader *Chain, const char* isysroot);
 
   /// \brief Emit a source location.
   void AddSourceLocation(SourceLocation Loc, RecordData &Record);

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=107915&r1=107914&r2=107915&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Jul  8 17:01:51 2010
@@ -255,6 +255,8 @@
   llvm::OwningPtr<ExternalASTSource> Source;
   Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot,
                                           getPreprocessor(), getASTContext()));
+  // Remember the PCHReader, but in a non-owning way.
+  Reader = static_cast<PCHReader*>(Source.get());
   getASTContext().setExternalSource(Source);
 }
 

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=107915&r1=107914&r2=107915&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Thu Jul  8 17:01:51 2010
@@ -81,9 +81,10 @@
     return 0;
 
   if (CI.getFrontendOpts().RelocatablePCH)
-    return CreatePCHGenerator(CI.getPreprocessor(), OS, Sysroot.c_str());
+    return CreatePCHGenerator(CI.getPreprocessor(), OS,
+                              CI.getPCHReader(), Sysroot.c_str());
 
-  return CreatePCHGenerator(CI.getPreprocessor(), OS);
+  return CreatePCHGenerator(CI.getPreprocessor(), OS, CI.getPCHReader());
 }
 
 ASTConsumer *InheritanceViewAction::CreateASTConsumer(CompilerInstance &CI,

Modified: cfe/trunk/lib/Frontend/GeneratePCH.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/GeneratePCH.cpp?rev=107915&r1=107914&r2=107915&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/GeneratePCH.cpp (original)
+++ cfe/trunk/lib/Frontend/GeneratePCH.cpp Thu Jul  8 17:01:51 2010
@@ -28,6 +28,7 @@
 namespace {
   class PCHGenerator : public SemaConsumer {
     const Preprocessor &PP;
+    const PCHReader *Chain;
     const char *isysroot;
     llvm::raw_ostream *Out;
     Sema *SemaPtr;
@@ -35,6 +36,7 @@
 
   public:
     explicit PCHGenerator(const Preprocessor &PP,
+                          const PCHReader *Chain,
                           const char *isysroot,
                           llvm::raw_ostream *Out);
     virtual void InitializeSema(Sema &S) { SemaPtr = &S; }
@@ -43,9 +45,11 @@
 }
 
 PCHGenerator::PCHGenerator(const Preprocessor &PP,
+                           const PCHReader *Chain,
                            const char *isysroot,
                            llvm::raw_ostream *OS)
-  : PP(PP), isysroot(isysroot), Out(OS), SemaPtr(0), StatCalls(0) {
+  : PP(PP), Chain(Chain), isysroot(isysroot), Out(OS), SemaPtr(0),
+    StatCalls(0) {
 
   // Install a stat() listener to keep track of all of the stat()
   // calls.
@@ -64,7 +68,7 @@
 
   // Emit the PCH file
   assert(SemaPtr && "No Sema?");
-  Writer.WritePCH(*SemaPtr, StatCalls, isysroot);
+  Writer.WritePCH(*SemaPtr, StatCalls, Chain, isysroot);
 
   // Write the generated bitstream to "Out".
   Out->write((char *)&Buffer.front(), Buffer.size());
@@ -75,6 +79,7 @@
 
 ASTConsumer *clang::CreatePCHGenerator(const Preprocessor &PP,
                                        llvm::raw_ostream *OS,
+                                       const PCHReader *Chain,
                                        const char *isysroot) {
-  return new PCHGenerator(PP, isysroot, OS);
+  return new PCHGenerator(PP, Chain, isysroot, OS);
 }

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=107915&r1=107914&r2=107915&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Thu Jul  8 17:01:51 2010
@@ -628,6 +628,7 @@
   RECORD(VERSION_CONTROL_BRANCH_REVISION);
   RECORD(UNUSED_STATIC_FUNCS);
   RECORD(MACRO_DEFINITION_OFFSETS);
+  RECORD(CHAINED_METADATA);
   
   // SourceManager Block.
   BLOCK(SOURCE_MANAGER_BLOCK);
@@ -2075,7 +2076,7 @@
     NumLexicalDeclContexts(0), NumVisibleDeclContexts(0) { }
 
 void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
-                         const char *isysroot) {
+                         const PCHReader *Chain, const char *isysroot) {
   using namespace llvm;
 
   ASTContext &Context = SemaRef.Context;





More information about the cfe-commits mailing list