[cfe-commits] r117457 - in /cfe/trunk: include/clang-c/Index.h include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp tools/libclang/CIndex.cpp

Douglas Gregor dgregor at apple.com
Wed Oct 27 10:24:54 PDT 2010


Author: dgregor
Date: Wed Oct 27 12:24:53 2010
New Revision: 117457

URL: http://llvm.org/viewvc/llvm-project?rev=117457&view=rev
Log:
Introduce libclang-level options for C++ precompiled preambles,
separating out chaining precompiled preambles from non-chaining ones.

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/include/clang/Frontend/ASTUnit.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=117457&r1=117456&r2=117457&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Wed Oct 27 12:24:53 2010
@@ -713,7 +713,22 @@
    * introduces some overhead to reparsing but improves the performance of
    * code-completion operations.
    */
-  CXTranslationUnit_CacheCompletionResults = 0x08
+  CXTranslationUnit_CacheCompletionResults = 0x08,
+  /**
+   * \brief Enable precompiled preambles in C++.
+   *
+   * Note: this is a *temporary* option that is available only while
+   * we are testing C++ precompiled preamble support.
+   */
+  CXTranslationUnit_CXXPrecompiledPreamble = 0x10,
+
+  /**
+   * \brief Enabled chained precompiled preambles in C++.
+   *
+   * Note: this is a *temporary* option that is available only while
+   * we are testing C++ precompiled preamble support.
+   */
+  CXTranslationUnit_CXXChainedPCH = 0x20
 };
 
 /**

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=117457&r1=117456&r2=117457&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Wed Oct 27 12:24:53 2010
@@ -546,7 +546,9 @@
                                       bool CaptureDiagnostics = false,
                                       bool PrecompilePreamble = false,
                                       bool CompleteTranslationUnit = true,
-                                      bool CacheCodeCompletionResults = false);
+                                      bool CacheCodeCompletionResults = false,
+                                      bool CXXPrecompilePreamble = false,
+                                      bool CXXChainedPCH = false);
   
   /// \brief Reparse the source files using the same command-line options that
   /// were originally used to produce this translation unit.

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=117457&r1=117456&r2=117457&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Wed Oct 27 12:24:53 2010
@@ -1328,8 +1328,7 @@
   
   
   llvm::MemoryBuffer *OverrideMainBuffer = 0;
-  // FIXME: When C++ PCH is ready, allow use of it for a precompiled preamble.
-  if (PrecompilePreamble && !Invocation->getLangOpts().CPlusPlus) {
+  if (PrecompilePreamble) {
     PreambleRebuildCounter = 1;
     OverrideMainBuffer
       = getMainBufferWithPrecompiledPreamble(*Invocation);
@@ -1386,7 +1385,9 @@
                                       bool CaptureDiagnostics,
                                       bool PrecompilePreamble,
                                       bool CompleteTranslationUnit,
-                                      bool CacheCodeCompletionResults) {
+                                      bool CacheCodeCompletionResults,
+                                      bool CXXPrecompilePreamble,
+                                      bool CXXChainedPCH) {
   bool CreatedDiagnosticsObject = false;
   
   if (!Diags.getPtr()) {
@@ -1457,6 +1458,16 @@
   // Override the resources path.
   CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
 
+  // Check whether we should precompile the preamble and/or use chained PCH.
+  // FIXME: This is a temporary hack while we debug C++ chained PCH.
+  if (CI->getLangOpts().CPlusPlus) {
+    PrecompilePreamble = PrecompilePreamble && CXXPrecompilePreamble;
+    
+    if (PrecompilePreamble && !CXXChainedPCH &&
+        !CI->getPreprocessorOpts().ImplicitPCHInclude.empty())
+      PrecompilePreamble = false;
+  }
+  
   // Create the AST unit.
   llvm::OwningPtr<ASTUnit> AST;
   AST.reset(new ASTUnit(false));

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=117457&r1=117456&r2=117457&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Oct 27 12:24:53 2010
@@ -1972,7 +1972,8 @@
 
 unsigned clang_defaultEditingTranslationUnitOptions() {
   return CXTranslationUnit_PrecompiledPreamble | 
-         CXTranslationUnit_CacheCompletionResults;
+         CXTranslationUnit_CacheCompletionResults |
+         CXTranslationUnit_CXXPrecompiledPreamble;
 }
   
 CXTranslationUnit
@@ -2020,6 +2021,10 @@
     = ((options & CXTranslationUnit_Incomplete) == 0);
   bool CacheCodeCompetionResults
     = options & CXTranslationUnit_CacheCompletionResults;
+  bool CXXPrecompilePreamble
+    = options & CXTranslationUnit_CXXPrecompiledPreamble;
+  bool CXXChainedPCH
+    = options & CXTranslationUnit_CXXChainedPCH;
   
   // Configure the diagnostics.
   DiagnosticOptions DiagOpts;
@@ -2084,7 +2089,9 @@
                                  /*CaptureDiagnostics=*/true,
                                  PrecompilePreamble,
                                  CompleteTranslationUnit,
-                                 CacheCodeCompetionResults));
+                                 CacheCodeCompetionResults,
+                                 CXXPrecompilePreamble,
+                                 CXXChainedPCH));
 
   if (NumErrors != Diags->getNumErrors()) {
     // Make sure to check that 'Unit' is non-NULL.





More information about the cfe-commits mailing list