[cfe-commits] r120001 - in /cfe/trunk: include/clang/Basic/FileManager.h include/clang/Frontend/ASTUnit.h lib/Basic/FileManager.cpp lib/Basic/SourceManager.cpp lib/Frontend/ASTUnit.cpp

Chris Lattner sabre at nondot.org
Mon Nov 22 22:09:11 PST 2010


Author: lattner
Date: Tue Nov 23 00:09:11 2010
New Revision: 120001

URL: http://llvm.org/viewvc/llvm-project?rev=120001&view=rev
Log:
Partially revert Doug's PCH validation patch (r98585).

This patch completely defeated the "passing in a prestat'd size 
to MemoryBuffer" optimization, leading to an extra fstat call for
every buffer opened, in order to find out if the datestamp and size 
of the file on disk matches what is in the stat cache.

I fully admit that I don't completely understand what is going on here:
why punish code when a stat cache isn't in use?  what is the point of a
stat cache if you have to turn around and stat stuff to validate it?

To resolve both these issues, just drop the modtime check and check the
file size, which is the important thing anyway.  This should also resolve
PR6812, because presumably windows is stable when it comes to file sizes.
If the modtime is actually important, we should get it and keep it on the
first stat.

This eliminates 833 fstat syscalls when processing Cocoa.h, speeding up
system time on -Eonly Cocoa.h  from 0.041 to 0.038s.


Modified:
    cfe/trunk/include/clang/Basic/FileManager.h
    cfe/trunk/include/clang/Frontend/ASTUnit.h
    cfe/trunk/lib/Basic/FileManager.cpp
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/Frontend/ASTUnit.cpp

Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=120001&r1=120000&r2=120001&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Tue Nov 23 00:09:11 2010
@@ -216,16 +216,14 @@
   /// MemoryBuffer if successful, otherwise returning null.
   llvm::MemoryBuffer *getBufferForFile(const FileEntry *Entry,
                                        const FileSystemOptions &FileSystemOpts,
-                                       std::string *ErrorStr = 0,
-                                       struct stat *FileInfo = 0) {
+                                       std::string *ErrorStr = 0) {
     return getBufferForFile(Entry->getName(), FileSystemOpts,
-                            ErrorStr, Entry->getSize(), FileInfo);
+                            ErrorStr, Entry->getSize());
   }
   llvm::MemoryBuffer *getBufferForFile(llvm::StringRef Filename,
                                        const FileSystemOptions &FileSystemOpts,
                                        std::string *ErrorStr = 0,
-                                       int64_t FileSize = -1,
-                                       struct stat *FileInfo = 0);
+                                       int64_t FileSize = -1);
 
   /// \brief If path is not absolute and FileSystemOptions set the working
   /// directory, the path is modified to be relative to the given

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=120001&r1=120000&r2=120001&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Tue Nov 23 00:09:11 2010
@@ -463,8 +463,7 @@
 
   llvm::MemoryBuffer *getBufferForFile(llvm::StringRef Filename,
                                        std::string *ErrorStr = 0,
-                                       int64_t FileSize = -1,
-                                       struct stat *FileInfo = 0);
+                                       int64_t FileSize = -1);
 
   /// \brief Whether this AST represents a complete translation unit.
   ///

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=120001&r1=120000&r2=120001&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Tue Nov 23 00:09:11 2010
@@ -399,15 +399,13 @@
 llvm::MemoryBuffer *FileManager::
 getBufferForFile(llvm::StringRef Filename,
                  const FileSystemOptions &FileSystemOpts,
-                 std::string *ErrorStr, int64_t FileSize,
-                 struct stat *FileInfo) {
+                 std::string *ErrorStr, int64_t FileSize) {
   if (FileSystemOpts.WorkingDir.empty())
-    return llvm::MemoryBuffer::getFile(Filename, ErrorStr, FileSize, FileInfo);
+    return llvm::MemoryBuffer::getFile(Filename, ErrorStr, FileSize);
   
   llvm::sys::Path FilePath(Filename);
   FixupRelativePath(FilePath, FileSystemOpts);
-  return llvm::MemoryBuffer::getFile(FilePath.c_str(), ErrorStr,
-                                     FileSize, FileInfo);
+  return llvm::MemoryBuffer::getFile(FilePath.c_str(), ErrorStr, FileSize);
 }
 
 int FileManager::stat_cached(const char *path, struct stat *buf,

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=120001&r1=120000&r2=120001&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Nov 23 00:09:11 2010
@@ -73,10 +73,9 @@
   // Lazily create the Buffer for ContentCaches that wrap files.
   if (!Buffer.getPointer() && Entry) {
     std::string ErrorStr;
-    struct stat FileInfo;
     Buffer.setPointer(SM.getFileManager().getBufferForFile(Entry,
                                                          SM.getFileSystemOpts(),
-                                                         &ErrorStr, &FileInfo));
+                                                         &ErrorStr));
 
     // If we were unable to open the file, then we are in an inconsistent
     // situation where the content cache referenced a file which no longer
@@ -105,17 +104,9 @@
 
       Buffer.setInt(Buffer.getInt() | InvalidFlag);
 
-    // FIXME: This conditionalization is horrible, but we see spurious failures
-    // in the test suite due to this warning and no one has had time to hunt it
-    // down. So for now, we just don't emit this diagnostic on Win32, and hope
-    // nothing bad happens.
-    //
-    // PR6812.
-#if !defined(LLVM_ON_WIN32)
-    } else if (FileInfo.st_size != Entry->getSize() ||
-               FileInfo.st_mtime != Entry->getModificationTime()) {
-      // Check that the file's size and modification time are the same
-      // as in the file entry (which may have come from a stat cache).
+    } else if (getRawBuffer()->getBufferSize() != (size_t)Entry->getSize()) {
+      // Check that the file's size is the same as in the file entry (which may
+      // have come from a stat cache).
       if (Diag.isDiagnosticInFlight())
         Diag.SetDelayedDiagnostic(diag::err_file_modified,
                                   Entry->getName());
@@ -124,7 +115,6 @@
           << Entry->getName();
 
       Buffer.setInt(Buffer.getInt() | InvalidFlag);
-#endif
     }
     
     // If the buffer is valid, check to see if it has a UTF Byte Order Mark

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=120001&r1=120000&r2=120001&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Tue Nov 23 00:09:11 2010
@@ -457,10 +457,9 @@
 
 llvm::MemoryBuffer *ASTUnit::getBufferForFile(llvm::StringRef Filename,
                                               std::string *ErrorStr,
-                                              int64_t FileSize,
-                                              struct stat *FileInfo) {
+                                              int64_t FileSize) {
   return FileMgr->getBufferForFile(Filename, FileSystemOpts,
-                                   ErrorStr, FileSize, FileInfo);
+                                   ErrorStr, FileSize);
 }
 
 /// \brief Configure the diagnostics object for use with ASTUnit.





More information about the cfe-commits mailing list