diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2025-05-07 14:02:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-07 14:02:40 -0700 |
commit | 1698beb5420f6e6f7eed5d9914ab6a10ff5f4b1f (patch) | |
tree | a007e3f26b36f6c35698ff1a599e9c758477bab9 /clang/lib/Serialization/ModuleCache.cpp | |
parent | b8461acc5eb41ced70cc5c7f5a324cfd8bf76403 (diff) | |
download | llvm-1698beb5420f6e6f7eed5d9914ab6a10ff5f4b1f.zip llvm-1698beb5420f6e6f7eed5d9914ab6a10ff5f4b1f.tar.gz llvm-1698beb5420f6e6f7eed5d9914ab6a10ff5f4b1f.tar.bz2 |
[clang][modules][deps] Optimize in-process timestamping of PCMs (#137363)
In the past, timestamps used for
`-fmodules-validate-once-per-build-session` were found to be a source of
contention in the dependency scanner
([D149802](https://reviews.llvm.org/D149802),
https://github.com/llvm/llvm-project/pull/112452). This PR is yet
another attempt to optimize these. We now make use of the new
`ModuleCache` interface to implement the in-process version in terms of
atomic `std::time_t` variables rather the mtime attribute on
`.timestamp` files.
Diffstat (limited to 'clang/lib/Serialization/ModuleCache.cpp')
-rw-r--r-- | clang/lib/Serialization/ModuleCache.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/Serialization/ModuleCache.cpp b/clang/lib/Serialization/ModuleCache.cpp index 955e5f3..4ae49c4 100644 --- a/clang/lib/Serialization/ModuleCache.cpp +++ b/clang/lib/Serialization/ModuleCache.cpp @@ -9,6 +9,7 @@ #include "clang/Serialization/ModuleCache.h" #include "clang/Serialization/InMemoryModuleCache.h" +#include "clang/Serialization/ModuleFile.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/LockFileManager.h" #include "llvm/Support/Path.h" @@ -32,6 +33,28 @@ public: return std::make_unique<llvm::LockFileManager>(ModuleFilename); } + std::time_t getModuleTimestamp(StringRef ModuleFilename) override { + std::string TimestampFilename = + serialization::ModuleFile::getTimestampFilename(ModuleFilename); + llvm::sys::fs::file_status Status; + if (llvm::sys::fs::status(ModuleFilename, Status) != std::error_code{}) + return 0; + return llvm::sys::toTimeT(Status.getLastModificationTime()); + } + + void updateModuleTimestamp(StringRef ModuleFilename) override { + // Overwrite the timestamp file contents so that file's mtime changes. + std::error_code EC; + llvm::raw_fd_ostream OS( + serialization::ModuleFile::getTimestampFilename(ModuleFilename), EC, + llvm::sys::fs::OF_TextWithCRLF); + if (EC) + return; + OS << "Timestamp file\n"; + OS.close(); + OS.clear_error(); // Avoid triggering a fatal error. + } + InMemoryModuleCache &getInMemoryModuleCache() override { return InMemory; } const InMemoryModuleCache &getInMemoryModuleCache() const override { return InMemory; |