[cfe-commits] r120030 - in /cfe/trunk: include/clang/Basic/FileManager.h include/clang/Basic/FileSystemStatCache.h include/clang/Lex/PTHManager.h lib/Basic/CMakeLists.txt lib/Basic/FileManager.cpp lib/Basic/FileSystemStatCache.cpp lib/Frontend/CacheTokens.cpp lib/Lex/PTHLexer.cpp lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp lib/Serialization/GeneratePCH.cpp
Chris Lattner
sabre at nondot.org
Tue Nov 23 11:19:34 PST 2010
Author: lattner
Date: Tue Nov 23 13:19:34 2010
New Revision: 120030
URL: http://llvm.org/viewvc/llvm-project?rev=120030&view=rev
Log:
rework the stat cache, pulling it out of FileManager.h into
its own header and giving it some more structure. No
functionality change.
Added:
cfe/trunk/include/clang/Basic/FileSystemStatCache.h
cfe/trunk/lib/Basic/FileSystemStatCache.cpp
Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/include/clang/Lex/PTHManager.h
cfe/trunk/lib/Basic/CMakeLists.txt
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Frontend/CacheTokens.cpp
cfe/trunk/lib/Lex/PTHLexer.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/GeneratePCH.cpp
Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=120030&r1=120029&r2=120030&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Tue Nov 23 13:19:34 2010
@@ -23,18 +23,18 @@
#include "llvm/Config/config.h" // for mode_t
// FIXME: Enhance libsystem to support inode and other fields in stat.
#include <sys/types.h>
-#include <sys/stat.h>
+
+struct stat;
namespace llvm {
class MemoryBuffer;
-namespace sys {
-class Path;
-}
+namespace sys { class Path; }
}
namespace clang {
class FileManager;
-
+class FileSystemStatCache;
+
/// DirectoryEntry - Cached information about one directory on the disk.
///
class DirectoryEntry {
@@ -80,61 +80,6 @@
}
};
-/// \brief Abstract interface for introducing a FileManager cache for 'stat'
-/// system calls, which is used by precompiled and pretokenized headers to
-/// improve performance.
-class StatSysCallCache {
-protected:
- llvm::OwningPtr<StatSysCallCache> NextStatCache;
-
-public:
- virtual ~StatSysCallCache() {}
- virtual int stat(const char *path, struct stat *buf) {
- if (getNextStatCache())
- return getNextStatCache()->stat(path, buf);
-
- return ::stat(path, buf);
- }
-
- /// \brief Sets the next stat call cache in the chain of stat caches.
- /// Takes ownership of the given stat cache.
- void setNextStatCache(StatSysCallCache *Cache) {
- NextStatCache.reset(Cache);
- }
-
- /// \brief Retrieve the next stat call cache in the chain.
- StatSysCallCache *getNextStatCache() { return NextStatCache.get(); }
-
- /// \brief Retrieve the next stat call cache in the chain, transferring
- /// ownership of this cache (and, transitively, all of the remaining caches)
- /// to the caller.
- StatSysCallCache *takeNextStatCache() { return NextStatCache.take(); }
-};
-
-/// \brief A stat "cache" that can be used by FileManager to keep
-/// track of the results of stat() calls that occur throughout the
-/// execution of the front end.
-class MemorizeStatCalls : public StatSysCallCache {
-public:
- /// \brief The result of a stat() call.
- ///
- /// The first member is the result of calling stat(). If stat()
- /// found something, the second member is a copy of the stat
- /// structure.
- typedef std::pair<int, struct stat> StatResult;
-
- /// \brief The set of stat() calls that have been
- llvm::StringMap<StatResult, llvm::BumpPtrAllocator> StatCalls;
-
- typedef llvm::StringMap<StatResult, llvm::BumpPtrAllocator>::const_iterator
- iterator;
-
- iterator begin() const { return StatCalls.begin(); }
- iterator end() const { return StatCalls.end(); }
-
- virtual int stat(const char *path, struct stat *buf);
-};
-
/// FileManager - Implements support for file system lookup, file system
/// caching, and directory search management. This also handles more advanced
/// properties, such as uniquing files based on "inode", so that a file with two
@@ -162,22 +107,21 @@
unsigned NextFileUID;
/// \brief The virtual files that we have allocated.
- llvm::SmallVector<FileEntry *, 4> VirtualFileEntries;
+ llvm::SmallVector<FileEntry*, 4> VirtualFileEntries;
// Statistics.
unsigned NumDirLookups, NumFileLookups;
unsigned NumDirCacheMisses, NumFileCacheMisses;
// Caching.
- llvm::OwningPtr<StatSysCallCache> StatCache;
-
- int stat_cached(const char *path, struct stat *buf);
+ llvm::OwningPtr<FileSystemStatCache> StatCache;
+ bool getStatValue(const char *Path, struct stat &StatBuf);
public:
FileManager(const FileSystemOptions &FileSystemOpts);
~FileManager();
- /// \brief Installs the provided StatSysCallCache object within
+ /// \brief Installs the provided FileSystemStatCache object within
/// the FileManager.
///
/// Ownership of this object is transferred to the FileManager.
@@ -188,10 +132,10 @@
/// \param AtBeginning whether this new stat cache must be installed at the
/// beginning of the chain of stat caches. Otherwise, it will be added to
/// the end of the chain.
- void addStatCache(StatSysCallCache *statCache, bool AtBeginning = false);
+ void addStatCache(FileSystemStatCache *statCache, bool AtBeginning = false);
- /// \brief Removes the provided StatSysCallCache object from the file manager.
- void removeStatCache(StatSysCallCache *statCache);
+ /// \brief Removes the specified FileSystemStatCache object from the manager.
+ void removeStatCache(FileSystemStatCache *statCache);
/// getDirectory - Lookup, cache, and verify the specified directory. This
/// returns null if the directory doesn't exist.
Added: cfe/trunk/include/clang/Basic/FileSystemStatCache.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileSystemStatCache.h?rev=120030&view=auto
==============================================================================
--- cfe/trunk/include/clang/Basic/FileSystemStatCache.h (added)
+++ cfe/trunk/include/clang/Basic/FileSystemStatCache.h Tue Nov 23 13:19:34 2010
@@ -0,0 +1,91 @@
+//===--- FileSystemStatCache.h - Caching for 'stat' calls -------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the FileSystemStatCache interface.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_FILESYSTEMSTATCACHE_H
+#define LLVM_CLANG_FILESYSTEMSTATCACHE_H
+
+#include "llvm/ADT/OwningPtr.h"
+#include "llvm/ADT/StringMap.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+
+namespace clang {
+
+/// \brief Abstract interface for introducing a FileManager cache for 'stat'
+/// system calls, which is used by precompiled and pretokenized headers to
+/// improve performance.
+class FileSystemStatCache {
+protected:
+ llvm::OwningPtr<FileSystemStatCache> NextStatCache;
+
+public:
+ virtual ~FileSystemStatCache() {}
+
+ enum LookupResult {
+ CacheHitExists, //< We know the file exists and its cached stat data.
+ CacheHitMissing, //< We know that the file doesn't exist.
+ CacheMiss //< We don't know anything about the file.
+ };
+
+ virtual LookupResult getStat(const char *Path, struct stat &StatBuf) = 0;
+
+ /// \brief Sets the next stat call cache in the chain of stat caches.
+ /// Takes ownership of the given stat cache.
+ void setNextStatCache(FileSystemStatCache *Cache) {
+ NextStatCache.reset(Cache);
+ }
+
+ /// \brief Retrieve the next stat call cache in the chain.
+ FileSystemStatCache *getNextStatCache() { return NextStatCache.get(); }
+
+ /// \brief Retrieve the next stat call cache in the chain, transferring
+ /// ownership of this cache (and, transitively, all of the remaining caches)
+ /// to the caller.
+ FileSystemStatCache *takeNextStatCache() { return NextStatCache.take(); }
+
+protected:
+ LookupResult statChained(const char *Path, struct stat &StatBuf) {
+ if (FileSystemStatCache *Next = getNextStatCache())
+ return Next->getStat(Path, StatBuf);
+
+ return CacheMiss;
+ }
+};
+
+/// \brief A stat "cache" that can be used by FileManager to keep
+/// track of the results of stat() calls that occur throughout the
+/// execution of the front end.
+class MemorizeStatCalls : public FileSystemStatCache {
+public:
+ /// \brief The result of a stat() call.
+ ///
+ /// The first member is the result of calling stat(). If stat()
+ /// found something, the second member is a copy of the stat
+ /// structure.
+ typedef std::pair<int, struct stat> StatResult;
+
+ /// \brief The set of stat() calls that have been
+ llvm::StringMap<StatResult, llvm::BumpPtrAllocator> StatCalls;
+
+ typedef llvm::StringMap<StatResult, llvm::BumpPtrAllocator>::const_iterator
+ iterator;
+
+ iterator begin() const { return StatCalls.begin(); }
+ iterator end() const { return StatCalls.end(); }
+
+ virtual LookupResult getStat(const char *Path, struct stat &StatBuf);
+};
+
+} // end namespace clang
+
+#endif
Modified: cfe/trunk/include/clang/Lex/PTHManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PTHManager.h?rev=120030&r1=120029&r2=120030&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PTHManager.h (original)
+++ cfe/trunk/include/clang/Lex/PTHManager.h Tue Nov 23 13:19:34 2010
@@ -31,7 +31,7 @@
class FileEntry;
class PTHLexer;
class Diagnostic;
-class StatSysCallCache;
+class FileSystemStatCache;
class PTHManager : public IdentifierInfoLookup {
friend class PTHLexer;
@@ -128,11 +128,11 @@
/// It is the responsibility of the caller to 'delete' the returned object.
PTHLexer *CreateLexer(FileID FID);
- /// createStatCache - Returns a StatSysCallCache object for use with
+ /// createStatCache - Returns a FileSystemStatCache object for use with
/// FileManager objects. These objects use the PTH data to speed up
/// calls to stat by memoizing their results from when the PTH file
/// was generated.
- StatSysCallCache *createStatCache();
+ FileSystemStatCache *createStatCache();
};
} // end namespace clang
Modified: cfe/trunk/lib/Basic/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/CMakeLists.txt?rev=120030&r1=120029&r2=120030&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/CMakeLists.txt (original)
+++ cfe/trunk/lib/Basic/CMakeLists.txt Tue Nov 23 13:19:34 2010
@@ -6,6 +6,7 @@
Diagnostic.cpp
DiagnosticIDs.cpp
FileManager.cpp
+ FileSystemStatCache.cpp
IdentifierTable.cpp
SourceLocation.cpp
SourceManager.cpp
Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=120030&r1=120029&r2=120030&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Tue Nov 23 13:19:34 2010
@@ -1,4 +1,4 @@
-///===--- FileManager.cpp - File System Probing and Caching ----------------===//
+//===--- FileManager.cpp - File System Probing and Caching ----------------===//
//
// The LLVM Compiler Infrastructure
//
@@ -18,7 +18,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Basic/FileManager.h"
-#include "clang/Basic/FileSystemOptions.h"
+#include "clang/Basic/FileSystemStatCache.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -162,7 +162,8 @@
delete *V;
}
-void FileManager::addStatCache(StatSysCallCache *statCache, bool AtBeginning) {
+void FileManager::addStatCache(FileSystemStatCache *statCache,
+ bool AtBeginning) {
assert(statCache && "No stat cache provided?");
if (AtBeginning || StatCache.get() == 0) {
statCache->setNextStatCache(StatCache.take());
@@ -170,14 +171,14 @@
return;
}
- StatSysCallCache *LastCache = StatCache.get();
+ FileSystemStatCache *LastCache = StatCache.get();
while (LastCache->getNextStatCache())
LastCache = LastCache->getNextStatCache();
LastCache->setNextStatCache(statCache);
}
-void FileManager::removeStatCache(StatSysCallCache *statCache) {
+void FileManager::removeStatCache(FileSystemStatCache *statCache) {
if (!statCache)
return;
@@ -188,7 +189,7 @@
}
// Find the stat cache in the list.
- StatSysCallCache *PrevCache = StatCache.get();
+ FileSystemStatCache *PrevCache = StatCache.get();
while (PrevCache && PrevCache->getNextStatCache() != statCache)
PrevCache = PrevCache->getNextStatCache();
if (PrevCache)
@@ -249,8 +250,8 @@
// Check to see if the directory exists.
struct stat StatBuf;
- if (stat_cached(InterndDirName, &StatBuf) || // Error stat'ing.
- !S_ISDIR(StatBuf.st_mode)) // Not a directory?
+ if (getStatValue(InterndDirName, StatBuf) || // Error stat'ing.
+ !S_ISDIR(StatBuf.st_mode)) // Not a directory?
return 0;
// It exists. See if we have already opened a directory with the same inode.
@@ -306,8 +307,8 @@
// Nope, there isn't. Check to see if the file exists.
struct stat StatBuf;
//llvm::errs() << "STATING: " << Filename;
- if (stat_cached(InterndFileName, &StatBuf) || // Error stat'ing.
- S_ISDIR(StatBuf.st_mode)) { // A directory?
+ if (getStatValue(InterndFileName, StatBuf) || // Error stat'ing.
+ S_ISDIR(StatBuf.st_mode)) { // A directory?
// If this file doesn't exist, we leave a null in FileEntries for this path.
//llvm::errs() << ": Not existing\n";
return 0;
@@ -370,7 +371,7 @@
// newly-created file entry.
const char *InterndFileName = NamedFileEnt.getKeyData();
struct stat StatBuf;
- if (!stat_cached(InterndFileName, &StatBuf) &&
+ if (!getStatValue(InterndFileName, StatBuf) &&
!S_ISDIR(StatBuf.st_mode)) {
llvm::sys::Path FilePath(InterndFileName);
FilePath.makeAbsolute();
@@ -410,17 +411,36 @@
return llvm::MemoryBuffer::getFile(FilePath.c_str(), ErrorStr);
}
-int FileManager::stat_cached(const char *path, struct stat *buf) {
- if (FileSystemOpts.WorkingDir.empty())
- return StatCache.get() ? StatCache->stat(path, buf) : stat(path, buf);
-
- llvm::sys::Path FilePath(path);
+/// getStatValue - Get the 'stat' information for the specified path, using the
+/// cache to accellerate it if possible. This returns true if the path does not
+/// exist or false if it exists.
+bool FileManager::getStatValue(const char *Path, struct stat &StatBuf) {
+ FileSystemStatCache::LookupResult Result = FileSystemStatCache::CacheMiss;
+
+ // FIXME: FileSystemOpts shouldn't be passed in here, all paths should be
+ // absolute!
+ if (FileSystemOpts.WorkingDir.empty()) {
+ if (StatCache.get())
+ Result = StatCache->getStat(Path, StatBuf);
+
+ if (Result == FileSystemStatCache::CacheMiss)
+ return ::stat(Path, &StatBuf);
+ return Result == FileSystemStatCache::CacheHitMissing;
+ }
+
+ llvm::sys::Path FilePath(Path);
FixupRelativePath(FilePath, FileSystemOpts);
-
- return StatCache.get() ? StatCache->stat(FilePath.c_str(), buf)
- : stat(FilePath.c_str(), buf);
+
+ if (StatCache.get())
+ Result = StatCache->getStat(FilePath.c_str(), StatBuf);
+
+ if (Result == FileSystemStatCache::CacheMiss)
+ return ::stat(FilePath.c_str(), &StatBuf);
+ return Result == FileSystemStatCache::CacheHitMissing;
}
+
+
void FileManager::PrintStats() const {
llvm::errs() << "\n*** File Manager Stats:\n";
llvm::errs() << UniqueFiles.size() << " files found, "
@@ -433,19 +453,3 @@
//llvm::errs() << PagesMapped << BytesOfPagesMapped << FSLookups;
}
-int MemorizeStatCalls::stat(const char *path, struct stat *buf) {
- int result = StatSysCallCache::stat(path, buf);
-
- // Do not cache failed stats, it is easy to construct common inconsistent
- // situations if we do, and they are not important for PCH performance (which
- // currently only needs the stats to construct the initial FileManager
- // entries).
- if (result != 0)
- return result;
-
- // Cache file 'stat' results and directories with absolutely paths.
- if (!S_ISDIR(buf->st_mode) || llvm::sys::Path(path).isAbsolute())
- StatCalls[path] = StatResult(result, *buf);
-
- return result;
-}
Added: cfe/trunk/lib/Basic/FileSystemStatCache.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileSystemStatCache.cpp?rev=120030&view=auto
==============================================================================
--- cfe/trunk/lib/Basic/FileSystemStatCache.cpp (added)
+++ cfe/trunk/lib/Basic/FileSystemStatCache.cpp Tue Nov 23 13:19:34 2010
@@ -0,0 +1,40 @@
+//===--- FileSystemStatCache.cpp - Caching for 'stat' calls ---------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the FileSystemStatCache interface.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Basic/FileSystemStatCache.h"
+#include "llvm/System/Path.h"
+using namespace clang;
+
+MemorizeStatCalls::LookupResult
+MemorizeStatCalls::getStat(const char *Path, struct stat &StatBuf) {
+ LookupResult Result = statChained(Path, StatBuf);
+
+ // If the chained cache didn't know anything about the file, do the stat now
+ // so we can record the result.
+ if (Result == CacheMiss)
+ Result = ::stat(Path, &StatBuf) ? CacheHitMissing : CacheHitExists;
+
+
+ // Do not cache failed stats, it is easy to construct common inconsistent
+ // situations if we do, and they are not important for PCH performance (which
+ // currently only needs the stats to construct the initial FileManager
+ // entries).
+ if (Result == CacheHitMissing)
+ return Result;
+
+ // Cache file 'stat' results and directories with absolutely paths.
+ if (!S_ISDIR(StatBuf.st_mode) || llvm::sys::Path(Path).isAbsolute())
+ StatCalls[Path] = StatResult(Result, StatBuf);
+
+ return Result;
+}
Modified: cfe/trunk/lib/Frontend/CacheTokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CacheTokens.cpp?rev=120030&r1=120029&r2=120030&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CacheTokens.cpp (original)
+++ cfe/trunk/lib/Frontend/CacheTokens.cpp Tue Nov 23 13:19:34 2010
@@ -13,11 +13,12 @@
//===----------------------------------------------------------------------===//
#include "clang/Frontend/Utils.h"
+#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/FileManager.h"
-#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/FileSystemStatCache.h"
#include "clang/Basic/IdentifierTable.h"
-#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/OnDiskHashTable.h"
+#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/StringExtras.h"
@@ -510,26 +511,31 @@
/// as input to PTH generation. StatListener populates the PTHWriter's
/// file map with stat information for directories as well as negative stats.
/// Stat information for files are populated elsewhere.
-class StatListener : public StatSysCallCache {
+class StatListener : public FileSystemStatCache {
PTHMap &PM;
public:
StatListener(PTHMap &pm) : PM(pm) {}
~StatListener() {}
- int stat(const char *path, struct stat *buf) {
- int result = StatSysCallCache::stat(path, buf);
+ LookupResult getStat(const char *Path, struct stat &StatBuf) {
+ LookupResult Result = FileSystemStatCache::statChained(Path, StatBuf);
- if (result != 0) // Failed 'stat'.
- PM.insert(PTHEntryKeyVariant(path), PTHEntry());
- else if (S_ISDIR(buf->st_mode)) {
+ // If the chained cache didn't know anything about the file, do the stat now
+ // so we can record the result.
+ if (Result == CacheMiss)
+ Result = ::stat(Path, &StatBuf) ? CacheHitMissing : CacheHitExists;
+
+ if (Result == CacheHitMissing) // Failed 'stat'.
+ PM.insert(PTHEntryKeyVariant(Path), PTHEntry());
+ else if (S_ISDIR(StatBuf.st_mode)) {
// Only cache directories with absolute paths.
- if (!llvm::sys::Path(path).isAbsolute())
- return result;
+ if (!llvm::sys::Path(Path).isAbsolute())
+ return Result;
- PM.insert(PTHEntryKeyVariant(buf, path), PTHEntry());
+ PM.insert(PTHEntryKeyVariant(&StatBuf, Path), PTHEntry());
}
- return result;
+ return Result;
}
};
} // end anonymous namespace
Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=120030&r1=120029&r2=120030&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Tue Nov 23 13:19:34 2010
@@ -13,6 +13,7 @@
#include "clang/Basic/TokenKinds.h"
#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemStatCache.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/OnDiskHashTable.h"
#include "clang/Lex/LexDiagnostic.h"
@@ -667,7 +668,7 @@
}
};
-class PTHStatCache : public StatSysCallCache {
+class PTHStatCache : public FileSystemStatCache {
typedef OnDiskChainedHashTable<PTHStatLookupTrait> CacheTy;
CacheTy Cache;
@@ -678,29 +679,29 @@
~PTHStatCache() {}
- int stat(const char *path, struct stat *buf) {
+ LookupResult getStat(const char *Path, struct stat &StatBuf) {
// Do the lookup for the file's data in the PTH file.
- CacheTy::iterator I = Cache.find(path);
+ CacheTy::iterator I = Cache.find(Path);
// If we don't get a hit in the PTH file just forward to 'stat'.
if (I == Cache.end())
- return StatSysCallCache::stat(path, buf);
+ return statChained(Path, StatBuf);
- const PTHStatData& Data = *I;
+ const PTHStatData &Data = *I;
if (!Data.hasStat)
- return 1;
+ return CacheHitMissing;
- buf->st_ino = Data.ino;
- buf->st_dev = Data.dev;
- buf->st_mtime = Data.mtime;
- buf->st_mode = Data.mode;
- buf->st_size = Data.size;
- return 0;
+ StatBuf.st_ino = Data.ino;
+ StatBuf.st_dev = Data.dev;
+ StatBuf.st_mtime = Data.mtime;
+ StatBuf.st_mode = Data.mode;
+ StatBuf.st_size = Data.size;
+ return CacheHitExists;
}
};
} // end anonymous namespace
-StatSysCallCache *PTHManager::createStatCache() {
+FileSystemStatCache *PTHManager::createStatCache() {
return new PTHStatCache(*((PTHFileLookup*) FileLookup));
}
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=120030&r1=120029&r2=120030&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Nov 23 13:19:34 2010
@@ -33,6 +33,7 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/SourceManagerInternals.h"
#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemStatCache.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/Version.h"
#include "llvm/ADT/StringExtras.h"
@@ -1066,7 +1067,7 @@
///
/// This cache is very similar to the stat cache used by pretokenized
/// headers.
-class ASTStatCache : public StatSysCallCache {
+class ASTStatCache : public FileSystemStatCache {
typedef OnDiskChainedHashTable<ASTStatLookupTrait> CacheTy;
CacheTy *Cache;
@@ -1082,28 +1083,28 @@
~ASTStatCache() { delete Cache; }
- int stat(const char *path, struct stat *buf) {
+ LookupResult getStat(const char *Path, struct stat &StatBuf) {
// Do the lookup for the file's data in the AST file.
- CacheTy::iterator I = Cache->find(path);
+ CacheTy::iterator I = Cache->find(Path);
// If we don't get a hit in the AST file just forward to 'stat'.
if (I == Cache->end()) {
++NumStatMisses;
- return StatSysCallCache::stat(path, buf);
+ return statChained(Path, StatBuf);
}
++NumStatHits;
ASTStatData Data = *I;
if (!Data.hasStat)
- return 1;
+ return CacheHitMissing;
- buf->st_ino = Data.ino;
- buf->st_dev = Data.dev;
- buf->st_mtime = Data.mtime;
- buf->st_mode = Data.mode;
- buf->st_size = Data.size;
- return 0;
+ StatBuf.st_ino = Data.ino;
+ StatBuf.st_dev = Data.dev;
+ StatBuf.st_mtime = Data.mtime;
+ StatBuf.st_mode = Data.mode;
+ StatBuf.st_size = Data.size;
+ return CacheHitExists;
}
};
} // end anonymous namespace
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=120030&r1=120029&r2=120030&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Tue Nov 23 13:19:34 2010
@@ -30,6 +30,7 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemStatCache.h"
#include "clang/Basic/OnDiskHashTable.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/SourceManagerInternals.h"
Modified: cfe/trunk/lib/Serialization/GeneratePCH.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/GeneratePCH.cpp?rev=120030&r1=120029&r2=120030&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/GeneratePCH.cpp (original)
+++ cfe/trunk/lib/Serialization/GeneratePCH.cpp Tue Nov 23 13:19:34 2010
@@ -19,6 +19,7 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemStatCache.h"
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/Support/raw_ostream.h"
#include <string>
@@ -34,7 +35,7 @@
// Install a stat() listener to keep track of all of the stat()
// calls.
- StatCalls = new MemorizeStatCalls;
+ StatCalls = new MemorizeStatCalls();
// If we have a chain, we want new stat calls only, so install the memorizer
// *after* the already installed ASTReader's stat cache.
PP.getFileManager().addStatCache(StatCalls,
More information about the cfe-commits
mailing list