[llvm-branch-commits] [cfe-branch] r125040 - in /cfe/branches/Apple/sill: include/clang/Frontend/CompilerInstance.h include/clang/Frontend/PreprocessorOptions.h include/clang/Serialization/ASTReader.h lib/Basic/FileManager.cpp lib/Frontend/ASTUnit.cpp lib/Frontend/CompilerInstance.cpp lib/Frontend/FrontendAction.cpp lib/Serialization/ASTReader.cpp

Daniel Dunbar daniel at zuster.org
Mon Feb 7 12:00:08 PST 2011


Author: ddunbar
Date: Mon Feb  7 14:00:07 2011
New Revision: 125040

URL: http://llvm.org/viewvc/llvm-project?rev=125040&view=rev
Log:
Merge r124971:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Sat Feb 5 19:42:43 2011 +0000

    Improve our uniquing of file entries when files are re-saved or are
    overridden via remapping. Thus, when we create a "virtual" file in the
    file manager, we still stat() the real file that lives behind it so
    that we can provide proper uniquing based on inodes. This helps keep
    the file manager much more consistent.

    To take advantage of this when reparsing files in libclang, we disable
    the use of the stat() cache when reparsing or performing code
    completion, since the stat() cache is very likely to be out of date in
    this use case.

*** CUSTOM MERGE ***

Modified:
    cfe/branches/Apple/sill/include/clang/Frontend/CompilerInstance.h
    cfe/branches/Apple/sill/include/clang/Frontend/PreprocessorOptions.h
    cfe/branches/Apple/sill/include/clang/Serialization/ASTReader.h
    cfe/branches/Apple/sill/lib/Basic/FileManager.cpp
    cfe/branches/Apple/sill/lib/Frontend/ASTUnit.cpp
    cfe/branches/Apple/sill/lib/Frontend/CompilerInstance.cpp
    cfe/branches/Apple/sill/lib/Frontend/FrontendAction.cpp
    cfe/branches/Apple/sill/lib/Serialization/ASTReader.cpp

Modified: cfe/branches/Apple/sill/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/sill/include/clang/Frontend/CompilerInstance.h?rev=125040&r1=125039&r2=125040&view=diff
==============================================================================
--- cfe/branches/Apple/sill/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/branches/Apple/sill/include/clang/Frontend/CompilerInstance.h Mon Feb  7 14:00:07 2011
@@ -544,6 +544,7 @@
   /// context.
   void createPCHExternalASTSource(llvm::StringRef Path,
                                   bool DisablePCHValidation,
+                                  bool DisableStatCache,
                                   void *DeserializationListener);
 
   /// Create an external AST source to read a PCH file.
@@ -552,6 +553,7 @@
   static ExternalASTSource *
   createPCHExternalASTSource(llvm::StringRef Path, const std::string &Sysroot,
                              bool DisablePCHValidation,
+                             bool DisableStatCache,
                              Preprocessor &PP, ASTContext &Context,
                              void *DeserializationListener, bool Preamble);
 

Modified: cfe/branches/Apple/sill/include/clang/Frontend/PreprocessorOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/sill/include/clang/Frontend/PreprocessorOptions.h?rev=125040&r1=125039&r2=125040&view=diff
==============================================================================
--- cfe/branches/Apple/sill/include/clang/Frontend/PreprocessorOptions.h (original)
+++ cfe/branches/Apple/sill/include/clang/Frontend/PreprocessorOptions.h Mon Feb  7 14:00:07 2011
@@ -48,6 +48,10 @@
   /// precompiled headers.
   bool DisablePCHValidation;
 
+  /// \brief When true, disables the use of the stat cache within a
+  /// precompiled header or AST file.
+  bool DisableStatCache;
+
   /// \brief Dump declarations that are deserialized from PCH, for testing.
   bool DumpDeserializedPCHDecls;
 
@@ -125,7 +129,7 @@
   
 public:
   PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
-                          DisablePCHValidation(false),
+                          DisablePCHValidation(false), DisableStatCache(false),
                           DumpDeserializedPCHDecls(false),
                           PrecompiledPreambleBytes(0, true),
                           RetainRemappedFileBuffers(false) { }

Modified: cfe/branches/Apple/sill/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/sill/include/clang/Serialization/ASTReader.h?rev=125040&r1=125039&r2=125040&view=diff
==============================================================================
--- cfe/branches/Apple/sill/include/clang/Serialization/ASTReader.h (original)
+++ cfe/branches/Apple/sill/include/clang/Serialization/ASTReader.h Mon Feb  7 14:00:07 2011
@@ -589,6 +589,9 @@
   /// headers when they are loaded.
   bool DisableValidation;
       
+  /// \brief Whether to disable the use of stat caches in AST files.
+  bool DisableStatCache;
+
   /// \brief Mapping from switch-case IDs in the chain to switch-case statements
   ///
   /// Statements usually don't have IDs, but switch cases need them, so that the
@@ -782,8 +785,14 @@
   /// \param DisableValidation If true, the AST reader will suppress most
   /// of its regular consistency checking, allowing the use of precompiled
   /// headers that cannot be determined to be compatible.
+  ///
+  /// \param DisableStatCache If true, the AST reader will ignore the
+  /// stat cache in the AST files. This performance pessimization can
+  /// help when an AST file is being used in cases where the
+  /// underlying files in the file system may have changed, but
+  /// parsing should still continue.
   ASTReader(Preprocessor &PP, ASTContext *Context, const char *isysroot = 0,
-            bool DisableValidation = false);
+            bool DisableValidation = false, bool DisableStatCache = false);
 
   /// \brief Load the AST file without using any pre-initialized Preprocessor.
   ///
@@ -804,10 +813,16 @@
   /// \param DisableValidation If true, the AST reader will suppress most
   /// of its regular consistency checking, allowing the use of precompiled
   /// headers that cannot be determined to be compatible.
+  ///
+  /// \param DisableStatCache If true, the AST reader will ignore the
+  /// stat cache in the AST files. This performance pessimization can
+  /// help when an AST file is being used in cases where the
+  /// underlying files in the file system may have changed, but
+  /// parsing should still continue.
   ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
             const FileSystemOptions &FileSystemOpts,
             Diagnostic &Diags, const char *isysroot = 0,
-            bool DisableValidation = false);
+            bool DisableValidation = false, bool DisableStatCache = false);
   ~ASTReader();
 
   /// \brief Load the precompiled header designated by the given file

Modified: cfe/branches/Apple/sill/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/sill/lib/Basic/FileManager.cpp?rev=125040&r1=125039&r2=125040&view=diff
==============================================================================
--- cfe/branches/Apple/sill/lib/Basic/FileManager.cpp (original)
+++ cfe/branches/Apple/sill/lib/Basic/FileManager.cpp Mon Feb  7 14:00:07 2011
@@ -361,32 +361,40 @@
   // By default, initialize it to invalid.
   NamedFileEnt.setValue(NON_EXISTENT_FILE);
 
+  // We allow the directory to not exist. If it does exist we store it.
+  FileEntry *UFE = 0;
   const DirectoryEntry *DirInfo
     = getDirectoryFromFile(*this, NameStart, NameEnd, FileSystemOpts);
-  if (DirInfo == 0)  // Directory doesn't exist, file can't exist.
-    return 0;
+  if (DirInfo) {
+    // Check to see if the file exists. If so, drop the virtual file
+    struct stat StatBuf;
+    const char *InterndFileName = NamedFileEnt.getKeyData();
+    if (stat_cached(InterndFileName, &StatBuf, FileSystemOpts) == 0 &&
+        !S_ISDIR(StatBuf.st_mode)) {
+      StatBuf.st_size = Size;
+      StatBuf.st_mtime = ModificationTime;
+      UFE = &UniqueFiles.getFile(InterndFileName, StatBuf);
+      NamedFileEnt.setValue(UFE);
+
+      // If we already have an entry with this inode, return it.
+      if (UFE->getName()) 
+        return UFE;
+    }
+  }
 
-  FileEntry *UFE = new FileEntry();
-  VirtualFileEntries.push_back(UFE);
-  NamedFileEnt.setValue(UFE);
+  if (!UFE) {
+    UFE = new FileEntry();
+    VirtualFileEntries.push_back(UFE);
+    NamedFileEnt.setValue(UFE);
+  }
 
+  // Get the null-terminated file name as stored as the key of the
+  // FileEntries map.
   UFE->Name    = NamedFileEnt.getKeyData();
   UFE->Size    = Size;
   UFE->ModTime = ModificationTime;
   UFE->Dir     = DirInfo;
   UFE->UID     = NextFileUID++;
-  
-  // If this virtual file resolves to a file, also map that file to the 
-  // newly-created file entry.
-  const char *InterndFileName = NamedFileEnt.getKeyData();
-  struct stat StatBuf;
-  if (!stat_cached(InterndFileName, &StatBuf, FileSystemOpts) &&
-      !S_ISDIR(StatBuf.st_mode)) {
-    llvm::sys::Path FilePath(InterndFileName);
-    FilePath.makeAbsolute();
-    FileEntries[FilePath.str()] = UFE;
-  }
-  
   return UFE;
 }
 

Modified: cfe/branches/Apple/sill/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/sill/lib/Frontend/ASTUnit.cpp?rev=125040&r1=125039&r2=125040&view=diff
==============================================================================
--- cfe/branches/Apple/sill/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/branches/Apple/sill/lib/Frontend/ASTUnit.cpp Mon Feb  7 14:00:07 2011
@@ -1592,6 +1592,7 @@
 
   // Remap files.
   PreprocessorOptions &PPOpts = Invocation->getPreprocessorOpts();
+  PPOpts.DisableStatCache = true;
   for (PreprocessorOptions::remapped_file_buffer_iterator 
          R = PPOpts.remapped_file_buffer_begin(),
          REnd = PPOpts.remapped_file_buffer_end();
@@ -1963,6 +1964,7 @@
 
   // If the main file has been overridden due to the use of a preamble,
   // make that override happen and introduce the preamble.
+  PreprocessorOpts.DisableStatCache = true;
   StoredDiagnostics.insert(StoredDiagnostics.end(),
                            this->StoredDiagnostics.begin(),
              this->StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver);

Modified: cfe/branches/Apple/sill/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/sill/lib/Frontend/CompilerInstance.cpp?rev=125040&r1=125039&r2=125040&view=diff
==============================================================================
--- cfe/branches/Apple/sill/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/branches/Apple/sill/lib/Frontend/CompilerInstance.cpp Mon Feb  7 14:00:07 2011
@@ -223,11 +223,13 @@
 
 void CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path,
                                                   bool DisablePCHValidation,
+                                                  bool DisableStatCache,
                                                  void *DeserializationListener){
   llvm::OwningPtr<ExternalASTSource> Source;
   bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
   Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot,
-                                          DisablePCHValidation,
+                                          DisablePCHValidation, 
+                                          DisableStatCache,
                                           getPreprocessor(), getASTContext(),
                                           DeserializationListener,
                                           Preamble));
@@ -238,6 +240,7 @@
 CompilerInstance::createPCHExternalASTSource(llvm::StringRef Path,
                                              const std::string &Sysroot,
                                              bool DisablePCHValidation,
+                                             bool DisableStatCache,
                                              Preprocessor &PP,
                                              ASTContext &Context,
                                              void *DeserializationListener,
@@ -245,7 +248,7 @@
   llvm::OwningPtr<ASTReader> Reader;
   Reader.reset(new ASTReader(PP, &Context,
                              Sysroot.empty() ? 0 : Sysroot.c_str(),
-                             DisablePCHValidation));
+                             DisablePCHValidation, DisableStatCache));
 
   Reader->setDeserializationListener(
             static_cast<ASTDeserializationListener *>(DeserializationListener));

Modified: cfe/branches/Apple/sill/lib/Frontend/FrontendAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/sill/lib/Frontend/FrontendAction.cpp?rev=125040&r1=125039&r2=125040&view=diff
==============================================================================
--- cfe/branches/Apple/sill/lib/Frontend/FrontendAction.cpp (original)
+++ cfe/branches/Apple/sill/lib/Frontend/FrontendAction.cpp Mon Feb  7 14:00:07 2011
@@ -187,6 +187,7 @@
       CI.createPCHExternalASTSource(
                                 CI.getPreprocessorOpts().ImplicitPCHInclude,
                                 CI.getPreprocessorOpts().DisablePCHValidation,
+                                CI.getPreprocessorOpts().DisableStatCache,
                                 DeserialListener);
       if (!CI.getASTContext().getExternalSource())
         goto failure;

Modified: cfe/branches/Apple/sill/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/sill/lib/Serialization/ASTReader.cpp?rev=125040&r1=125039&r2=125040&view=diff
==============================================================================
--- cfe/branches/Apple/sill/lib/Serialization/ASTReader.cpp (original)
+++ cfe/branches/Apple/sill/lib/Serialization/ASTReader.cpp Mon Feb  7 14:00:07 2011
@@ -2037,12 +2037,14 @@
       break;
 
     case STAT_CACHE: {
-      ASTStatCache *MyStatCache =
-        new ASTStatCache((const unsigned char *)BlobStart + Record[0],
-                         (const unsigned char *)BlobStart,
-                         NumStatHits, NumStatMisses);
-      FileMgr.addStatCache(MyStatCache);
-      F.StatCache = MyStatCache;
+      if (!DisableStatCache) {
+        ASTStatCache *MyStatCache =
+          new ASTStatCache((const unsigned char *)BlobStart + Record[0],
+                           (const unsigned char *)BlobStart,
+                           NumStatHits, NumStatMisses);
+        FileMgr.addStatCache(MyStatCache);
+        F.StatCache = MyStatCache;
+      }
       break;
     }
 
@@ -4524,31 +4526,35 @@
 }
 
 ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context,
-                     const char *isysroot, bool DisableValidation)
+                     const char *isysroot, bool DisableValidation,
+                     bool DisableStatCache)
   : Listener(new PCHValidator(PP, *this)), DeserializationListener(0),
     SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()),
     FileSystemOpts(PP.getFileSystemOpts()),
     Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context),
     Consumer(0), isysroot(isysroot), DisableValidation(DisableValidation),
-    NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0),
-    TotalNumSLocEntries(0), NextSLocOffset(0), NumStatementsRead(0),
-    TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0),
-    NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0),
-    TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0),
-    TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0),
-    TotalVisibleDeclContexts(0), NumCurrentElementsDeserializing(0) {
+    DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), 
+    NumSLocEntriesRead(0), TotalNumSLocEntries(0), NextSLocOffset(0), 
+    NumStatementsRead(0), TotalNumStatements(0), NumMacrosRead(0), 
+    TotalNumMacros(0), NumSelectorsRead(0), NumMethodPoolEntriesRead(0), 
+    NumMethodPoolMisses(0), TotalNumMethodPoolEntries(0), 
+    NumLexicalDeclContextsRead(0), TotalLexicalDeclContexts(0), 
+    NumVisibleDeclContextsRead(0), TotalVisibleDeclContexts(0), 
+    NumCurrentElementsDeserializing(0) 
+{
   RelocatablePCH = false;
 }
 
 ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr,
                      const FileSystemOptions &FileSystemOpts,
                      Diagnostic &Diags, const char *isysroot,
-                     bool DisableValidation)
+                     bool DisableValidation, bool DisableStatCache)
   : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr),
     FileSystemOpts(FileSystemOpts),
     Diags(Diags), SemaObj(0), PP(0), Context(0), Consumer(0),
-    isysroot(isysroot), DisableValidation(DisableValidation), NumStatHits(0),
-    NumStatMisses(0), NumSLocEntriesRead(0), TotalNumSLocEntries(0),
+    isysroot(isysroot), DisableValidation(DisableValidation), 
+    DisableStatCache(DisableStatCache), NumStatHits(0), NumStatMisses(0), 
+    NumSLocEntriesRead(0), TotalNumSLocEntries(0),
     NextSLocOffset(0), NumStatementsRead(0), TotalNumStatements(0),
     NumMacrosRead(0), TotalNumMacros(0), NumSelectorsRead(0),
     NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0),





More information about the llvm-branch-commits mailing list