Implement caching of stat() calls for precompiled headers, which is
essentially the same thing we do with pretokenized headers. stat()
caching improves performance of the Cocoa-prefixed "Hello, World" by
45%.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70223 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/GeneratePCH.cpp b/tools/clang-cc/GeneratePCH.cpp
index 4265c81..9bc5ded 100644
--- a/tools/clang-cc/GeneratePCH.cpp
+++ b/tools/clang-cc/GeneratePCH.cpp
@@ -18,6 +18,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/Lex/Preprocessor.h"
+#include "clang/Basic/FileManager.h"
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/System/Path.h"
#include "llvm/Support/Compiler.h"
@@ -33,16 +34,24 @@
const Preprocessor &PP;
std::string OutFile;
Sema *SemaPtr;
+ MemorizeStatCalls *StatCalls; // owned by the FileManager
public:
- explicit PCHGenerator(const Preprocessor &PP, const std::string &OutFile)
- : PP(PP), OutFile(OutFile), SemaPtr(0) { }
-
+ explicit PCHGenerator(const Preprocessor &PP, const std::string &OutFile);
virtual void InitializeSema(Sema &S) { SemaPtr = &S; }
virtual void HandleTranslationUnit(ASTContext &Ctx);
};
}
+PCHGenerator::PCHGenerator(const Preprocessor &PP, const std::string &OutFile)
+ : PP(PP), OutFile(OutFile), SemaPtr(0), StatCalls(0) {
+
+ // Install a stat() listener to keep track of all of the stat()
+ // calls.
+ StatCalls = new MemorizeStatCalls;
+ PP.getFileManager().setStatCache(StatCalls);
+}
+
void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
if (PP.getDiagnostics().hasErrorOccurred())
return;
@@ -54,7 +63,7 @@
// Emit the PCH file
assert(SemaPtr && "No Sema?");
- Writer.WritePCH(*SemaPtr);
+ Writer.WritePCH(*SemaPtr, StatCalls);
// Open up the PCH file.
std::string ErrMsg;
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index ab72d6b..bba5723 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -1919,7 +1919,7 @@
// Create a file manager object to provide access to and cache the filesystem.
FileManager FileMgr;
-
+
for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
const std::string &InFile = InputFilenames[i];