Add support for a chain of stat caches in the FileManager, rather than
only supporting a single stat cache. The immediate benefit of this
change is that we can now generate a PCH/AST file when including
another PCH file; in the future, the chain of stat caches will likely
be useful with multiple levels of PCH files.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84263 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/CacheTokens.cpp b/lib/Frontend/CacheTokens.cpp
index e7fc566..169fd5e 100644
--- a/lib/Frontend/CacheTokens.cpp
+++ b/lib/Frontend/CacheTokens.cpp
@@ -516,7 +516,7 @@
~StatListener() {}
int stat(const char *path, struct stat *buf) {
- int result = ::stat(path, buf);
+ int result = StatSysCallCache::stat(path, buf);
if (result != 0) // Failed 'stat'.
PM.insert(path, PTHEntry());
@@ -553,7 +553,8 @@
PTHWriter PW(*OS, PP);
// Install the 'stat' system call listener in the FileManager.
- PP.getFileManager().setStatCache(new StatListener(PW.getPM()));
+ StatListener *StatCache = new StatListener(PW.getPM());
+ PP.getFileManager().addStatCache(StatCache, /*AtBeginning=*/true);
// Lex through the entire file. This will populate SourceManager with
// all of the header information.
@@ -562,7 +563,7 @@
do { PP.Lex(Tok); } while (Tok.isNot(tok::eof));
// Generate the PTH file.
- PP.getFileManager().setStatCache(0);
+ PP.getFileManager().removeStatCache(StatCache);
PW.GeneratePTH(&MainFileName);
}
diff --git a/lib/Frontend/GeneratePCH.cpp b/lib/Frontend/GeneratePCH.cpp
index bc45cc4..0e4f83f 100644
--- a/lib/Frontend/GeneratePCH.cpp
+++ b/lib/Frontend/GeneratePCH.cpp
@@ -53,7 +53,7 @@
// Install a stat() listener to keep track of all of the stat()
// calls.
StatCalls = new MemorizeStatCalls;
- PP.getFileManager().setStatCache(StatCalls);
+ PP.getFileManager().addStatCache(StatCalls, /*AtBeginning=*/true);
}
void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp
index d9d3960..141f7c8 100644
--- a/lib/Frontend/PCHReader.cpp
+++ b/lib/Frontend/PCHReader.cpp
@@ -335,8 +335,6 @@
PP.setCounterValue(Value);
}
-
-
//===----------------------------------------------------------------------===//
// PCH reader implementation
//===----------------------------------------------------------------------===//
@@ -345,7 +343,7 @@
const char *isysroot)
: Listener(new PCHValidator(PP, *this)), SourceMgr(PP.getSourceManager()),
FileMgr(PP.getFileManager()), Diags(PP.getDiagnostics()),
- SemaObj(0), PP(&PP), Context(Context), Consumer(0),
+ SemaObj(0), PP(&PP), Context(Context), StatCache(0), Consumer(0),
IdentifierTableData(0), IdentifierLookupTable(0),
IdentifierOffsets(0),
MethodPoolLookupTable(0), MethodPoolLookupTableData(0),
@@ -362,7 +360,7 @@
PCHReader::PCHReader(SourceManager &SourceMgr, FileManager &FileMgr,
Diagnostic &Diags, const char *isysroot)
: SourceMgr(SourceMgr), FileMgr(FileMgr), Diags(Diags),
- SemaObj(0), PP(0), Context(0), Consumer(0),
+ SemaObj(0), PP(0), Context(0), StatCache(0), Consumer(0),
IdentifierTableData(0), IdentifierLookupTable(0),
IdentifierOffsets(0),
MethodPoolLookupTable(0), MethodPoolLookupTableData(0),
@@ -794,7 +792,7 @@
// If we don't get a hit in the PCH file just forward to 'stat'.
if (I == Cache->end()) {
++NumStatMisses;
- return ::stat(path, buf);
+ return StatSysCallCache::stat(path, buf);
}
++NumStatHits;
@@ -1352,13 +1350,16 @@
}
break;
- case pch::STAT_CACHE:
- FileMgr.setStatCache(
- new PCHStatCache((const unsigned char *)BlobStart + Record[0],
- (const unsigned char *)BlobStart,
- NumStatHits, NumStatMisses));
+ case pch::STAT_CACHE: {
+ PCHStatCache *MyStatCache =
+ new PCHStatCache((const unsigned char *)BlobStart + Record[0],
+ (const unsigned char *)BlobStart,
+ NumStatHits, NumStatMisses);
+ FileMgr.addStatCache(MyStatCache);
+ StatCache = MyStatCache;
break;
-
+ }
+
case pch::EXT_VECTOR_DECLS:
if (!ExtVectorDecls.empty()) {
Error("duplicate EXT_VECTOR_DECLS record in PCH file");
@@ -1466,7 +1467,8 @@
SourceMgr.ClearPreallocatedSLocEntries();
// Remove the stat cache.
- FileMgr.setStatCache(0);
+ if (StatCache)
+ FileMgr.removeStatCache((PCHStatCache*)StatCache);
return IgnorePCH;
}