[clang] [clang][deps] Keep module cache in memory (PR #192347)
Michael Spencer via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 24 09:55:28 PDT 2026
================
@@ -134,22 +139,39 @@ class InProcessModuleCache : public ModuleCache {
std::error_code write(StringRef Path, llvm::MemoryBufferRef Buffer,
off_t &Size, time_t &ModTime) override {
- // This is a compiler-internal input/output, let's bypass the sandbox.
- auto BypassSandbox = llvm::sys::sandbox::scopedDisable();
-
- // FIXME: This could use an in-memory cache to avoid IO, and only write to
- // disk at the end of the scan.
- return writeImpl(Path, Buffer, Size, ModTime);
+ ModuleCacheEntry &Entry = getOrCreateEntry(Path);
+ std::lock_guard<std::mutex> Lock(Entry.Mutex);
+ if (Entry.State == ModuleCacheEntry::S_Written) {
+ assert(Entry.Buffer && *Entry.Buffer == Buffer &&
+ "Wrote the same PCM with different contents");
+ return {};
+ }
+ Entry.Buffer =
+ llvm::MemoryBuffer::getMemBufferCopy(Buffer.getBuffer(), Path);
+ Entry.ModTime = llvm::sys::toTimeT(std::chrono::system_clock::now());
----------------
Bigcheese wrote:
Ah, I forgot that only applies to explicitly built pcms. I think that's fine then as this only impacts IBM. May be good to have a comment there.
https://github.com/llvm/llvm-project/pull/192347
More information about the cfe-commits
mailing list