diff options
author | Volodymyr Sapsai <vsapsai@apple.com> | 2020-01-16 17:12:41 -0800 |
---|---|---|
committer | Volodymyr Sapsai <vsapsai@apple.com> | 2020-01-16 17:12:41 -0800 |
commit | 83f4c3af021cd5322ea10fd1c4e839874c1dae49 (patch) | |
tree | cc7fb88b435699c41e687eea3c1400d90e447f61 /clang/lib/Serialization/ModuleManager.cpp | |
parent | f55ab6f90b7317a6bb85303a6102702bdae1199e (diff) | |
download | llvm-83f4c3af021cd5322ea10fd1c4e839874c1dae49.zip llvm-83f4c3af021cd5322ea10fd1c4e839874c1dae49.tar.gz llvm-83f4c3af021cd5322ea10fd1c4e839874c1dae49.tar.bz2 |
[modules] Do not cache invalid state for modules that we attempted to load.
Partially reverts 0a2be46cfdb698fefcc860a56b47dde0884d5335 as it turned
out to cause redundant module rebuilds in multi-process incremental builds.
When a module was getting out of date, all compilation processes started at the
same time were marking it as `ToBuild`. So each process was building the same
module instead of checking if it was built by someone else and using that
result. In addition to the work duplication, contention on the same .pcm file
wasn't making builds faster.
Note that for a single-process build this change would cause redundant module
reads and validations. But reading a module is faster than building it and
multi-process builds are more common than single-process. So I'm willing to
make such a trade-off.
rdar://problem/54395127
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D72860
Diffstat (limited to 'clang/lib/Serialization/ModuleManager.cpp')
-rw-r--r-- | clang/lib/Serialization/ModuleManager.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index daef502..7406c87 100644 --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -163,7 +163,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type, // Load the contents of the module if (std::unique_ptr<llvm::MemoryBuffer> Buffer = lookupBuffer(FileName)) { // The buffer was already provided for us. - NewModule->Buffer = &ModuleCache->addBuiltPCM(FileName, std::move(Buffer)); + NewModule->Buffer = &ModuleCache->addFinalPCM(FileName, std::move(Buffer)); // Since the cached buffer is reused, it is safe to close the file // descriptor that was opened while stat()ing the PCM in // lookupModuleFile() above, it won't be needed any longer. @@ -173,11 +173,6 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type, NewModule->Buffer = Buffer; // As above, the file descriptor is no longer needed. Entry->closeFile(); - } else if (getModuleCache().shouldBuildPCM(FileName)) { - // Report that the module is out of date, since we tried (and failed) to - // import it earlier. - Entry->closeFile(); - return OutOfDate; } else { // Open the AST file. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buf((std::error_code())); @@ -185,7 +180,9 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type, Buf = llvm::MemoryBuffer::getSTDIN(); } else { // Get a buffer of the file and close the file descriptor when done. - Buf = FileMgr.getBufferForFile(NewModule->File, /*isVolatile=*/false); + // The file is volatile because in a parallel build we expect multiple + // compiler processes to use the same module file rebuilding it if needed. + Buf = FileMgr.getBufferForFile(NewModule->File, /*isVolatile=*/true); } if (!Buf) { |