From d6f611198089b78e32d3a15fe8bc986204aee1aa Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 23 Nov 2010 20:05:15 +0000 Subject: [PATCH] simplify the cache miss handling code, eliminating CacheMissing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120038 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/FileSystemStatCache.h | 17 +++++++---------- lib/Basic/FileSystemStatCache.cpp | 7 +------ lib/Frontend/CacheTokens.cpp | 11 +++-------- lib/Lex/PTHLexer.cpp | 5 ++--- lib/Serialization/ASTReader.cpp | 2 +- 5 files changed, 14 insertions(+), 28 deletions(-) diff --git a/include/clang/Basic/FileSystemStatCache.h b/include/clang/Basic/FileSystemStatCache.h index 7bb3706793..e9da8cf15c 100644 --- a/include/clang/Basic/FileSystemStatCache.h +++ b/include/clang/Basic/FileSystemStatCache.h @@ -32,9 +32,8 @@ 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. + CacheExists, //< We know the file exists and its cached stat data. + CacheMissing //< We know that the file doesn't exist. }; /// FileSystemStatCache::get - Get the 'stat' information for the specified @@ -42,14 +41,10 @@ public: /// the path does not exist or false if it exists. static bool get(const char *Path, struct stat &StatBuf, FileSystemStatCache *Cache) { - LookupResult R = CacheMiss; - if (Cache) - R = Cache->getStat(Path, StatBuf); + return Cache->getStat(Path, StatBuf) == CacheMissing; - if (R == FileSystemStatCache::CacheMiss) - return ::stat(Path, &StatBuf); - return R == FileSystemStatCache::CacheHitMissing; + return ::stat(Path, &StatBuf) != 0; } /// \brief Sets the next stat call cache in the chain of stat caches. @@ -73,7 +68,9 @@ protected: if (FileSystemStatCache *Next = getNextStatCache()) return Next->getStat(Path, StatBuf); - return CacheMiss; + // If we hit the end of the list of stat caches to try, just compute and + // return it without a cache. + return get(Path, StatBuf, 0) ? CacheMissing : CacheExists; } }; diff --git a/lib/Basic/FileSystemStatCache.cpp b/lib/Basic/FileSystemStatCache.cpp index 738af41a9e..26e9d2f150 100644 --- a/lib/Basic/FileSystemStatCache.cpp +++ b/lib/Basic/FileSystemStatCache.cpp @@ -19,16 +19,11 @@ 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) + if (Result == CacheMissing) return Result; // Cache file 'stat' results and directories with absolutely paths. diff --git a/lib/Frontend/CacheTokens.cpp b/lib/Frontend/CacheTokens.cpp index 94bee6b868..2a7af8a8c3 100644 --- a/lib/Frontend/CacheTokens.cpp +++ b/lib/Frontend/CacheTokens.cpp @@ -518,14 +518,9 @@ public: ~StatListener() {} LookupResult getStat(const char *Path, struct stat &StatBuf) { - LookupResult Result = FileSystemStatCache::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; - - if (Result == CacheHitMissing) // Failed 'stat'. + LookupResult Result = statChained(Path, StatBuf); + + if (Result == CacheMissing) // Failed 'stat'. PM.insert(PTHEntryKeyVariant(Path), PTHEntry()); else if (S_ISDIR(StatBuf.st_mode)) { // Only cache directories with absolute paths. diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp index 0dd30f6d70..ed068675fe 100644 --- a/lib/Lex/PTHLexer.cpp +++ b/lib/Lex/PTHLexer.cpp @@ -26,7 +26,6 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/MemoryBuffer.h" -#include using namespace clang; using namespace clang::io; @@ -690,14 +689,14 @@ public: const PTHStatData &Data = *I; if (!Data.hasStat) - return CacheHitMissing; + return CacheMissing; 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; + return CacheExists; } }; } // end anonymous namespace diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 0c0e4fffc0..dc719a1f93 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1092,7 +1092,7 @@ public: StatBuf.st_mtime = Data.mtime; StatBuf.st_mode = Data.mode; StatBuf.st_size = Data.size; - return CacheHitExists; + return CacheExists; } }; } // end anonymous namespace -- 2.40.0