diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2014-02-12 10:33:14 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2014-02-12 10:33:14 +0000 |
commit | f430da4de68b5569634b03df30b38d1133dc169b (patch) | |
tree | 3cbc33ed201f16def4c5052e05004820a6800b0e /clang/lib/Frontend/CompilerInstance.cpp | |
parent | ecbe18e01dc42fb5e60fdac361ce74f9ab8c5307 (diff) | |
download | bcm5719-llvm-f430da4de68b5569634b03df30b38d1133dc169b.tar.gz bcm5719-llvm-f430da4de68b5569634b03df30b38d1133dc169b.zip |
Add an option to allow Clang verify source files for a module only once during
the build
When Clang loads the module, it verifies the user source files that the module
was built from. If any file was changed, the module is rebuilt. There are two
problems with this:
1. correctness: we don't verify system files (there are too many of them, and
stat'ing all of them would take a lot of time);
2. performance: the same module file is verified again and again during a
single build.
This change allows the build system to optimize source file verification. The
idea is based on the fact that while the project is being built, the source
files don't change. This allows us to verify the module only once during a
single build session. The build system passes a flag,
-fbuild-session-timestamp=, to inform Clang of the time when the build started.
The build system also requests to enable this feature by passing
-fmodules-validate-once-per-build-session. If these flags are not passed, the
behavior is not changed. When Clang verifies the module the first time, it
writes out a timestamp file. Then, when Clang loads the module the second
time, it finds a timestamp file, so it can compare the verification timestamp
of the module with the time when the build started. If the verification
timestamp is too old, the module is verified again, and the timestamp file is
updated.
llvm-svn: 201224
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index d1211801253..61fe26c9222 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1057,41 +1057,38 @@ static void pruneModuleCache(const HeaderSearchOptions &HSOpts) { continue; // Walk all of the files within this directory. - bool RemovedAllFiles = true; for (llvm::sys::fs::directory_iterator File(Dir->path(), EC), FileEnd; File != FileEnd && !EC; File.increment(EC)) { // We only care about module and global module index files. - if (llvm::sys::path::extension(File->path()) != ".pcm" && - llvm::sys::path::filename(File->path()) != "modules.idx") { - RemovedAllFiles = false; + StringRef Extension = llvm::sys::path::extension(File->path()); + if (Extension != ".pcm" && Extension != ".timestamp" && + llvm::sys::path::filename(File->path()) != "modules.idx") continue; - } // Look at this file. If we can't stat it, there's nothing interesting // there. - if (::stat(File->path().c_str(), &StatBuf)) { - RemovedAllFiles = false; + if (::stat(File->path().c_str(), &StatBuf)) continue; - } // If the file has been used recently enough, leave it there. time_t FileAccessTime = StatBuf.st_atime; if (CurrentTime - FileAccessTime <= time_t(HSOpts.ModuleCachePruneAfter)) { - RemovedAllFiles = false; continue; } // Remove the file. - bool Existed; - if (llvm::sys::fs::remove(File->path(), Existed) || !Existed) { - RemovedAllFiles = false; - } + llvm::sys::fs::remove(File->path()); + + // Remove the timestamp file. + std::string TimpestampFilename = File->path() + ".timestamp"; + llvm::sys::fs::remove(TimpestampFilename); } // If we removed all of the files in the directory, remove the directory // itself. - if (RemovedAllFiles) + if (llvm::sys::fs::directory_iterator(Dir->path(), EC) == + llvm::sys::fs::directory_iterator() && !EC) llvm::sys::fs::remove(Dir->path()); } } |