diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2025-03-14 11:32:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-14 11:32:39 -0700 |
commit | c84d8e8f1c406ab34d56efd4a9f8c5fbce70af2d (patch) | |
tree | 869fe558fc328f610628c697c2006a91f7581ec1 /clang/lib/Serialization/ModuleManager.cpp | |
parent | d0a0de50f7dc6f116863ea9e8ca11efc2dc9f71e (diff) | |
download | llvm-c84d8e8f1c406ab34d56efd4a9f8c5fbce70af2d.zip llvm-c84d8e8f1c406ab34d56efd4a9f8c5fbce70af2d.tar.gz llvm-c84d8e8f1c406ab34d56efd4a9f8c5fbce70af2d.tar.bz2 |
[clang][modules] Introduce new `ModuleCache` interface (#131193)
This PR adds new `ModuleCache` interface to Clang's implicitly-built
modules machinery. The main motivation for this change is to create a
second implementation that uses a more efficient kind of
`llvm::AdvisoryLock` during dependency scanning.
In addition to the lock abstraction, the `ModuleCache` interface also
manages the existing `InMemoryModuleCache` instance. I found that
compared to keeping these separate/independent, the code is a bit
simpler now, since these are two tightly coupled concepts. I can
envision a more efficient implementation of the `InMemoryModuleCache`
for the single-process case too, which will be much easier to implement
with the current setup.
This is not intended to be a functional change.
Diffstat (limited to 'clang/lib/Serialization/ModuleManager.cpp')
-rw-r--r-- | clang/lib/Serialization/ModuleManager.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index 4ecb776..61c4e9e 100644 --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -18,6 +18,7 @@ #include "clang/Lex/ModuleMap.h" #include "clang/Serialization/GlobalModuleIndex.h" #include "clang/Serialization/InMemoryModuleCache.h" +#include "clang/Serialization/ModuleCache.h" #include "clang/Serialization/ModuleFile.h" #include "clang/Serialization/PCHContainerOperations.h" #include "llvm/ADT/STLExtras.h" @@ -182,17 +183,20 @@ 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 = &getModuleCache().getInMemoryModuleCache().addBuiltPCM( + 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. Entry->closeFile(); } else if (llvm::MemoryBuffer *Buffer = - getModuleCache().lookupPCM(FileName)) { + getModuleCache().getInMemoryModuleCache().lookupPCM( + FileName)) { NewModule->Buffer = Buffer; // As above, the file descriptor is no longer needed. Entry->closeFile(); - } else if (getModuleCache().shouldBuildPCM(FileName)) { + } else if (getModuleCache().getInMemoryModuleCache().shouldBuildPCM( + FileName)) { // Report that the module is out of date, since we tried (and failed) to // import it earlier. Entry->closeFile(); @@ -213,7 +217,8 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type, return Missing; } - NewModule->Buffer = &getModuleCache().addPCM(FileName, std::move(*Buf)); + NewModule->Buffer = &getModuleCache().getInMemoryModuleCache().addPCM( + FileName, std::move(*Buf)); } // Initialize the stream. @@ -324,12 +329,11 @@ void ModuleManager::moduleFileAccepted(ModuleFile *MF) { ModulesInCommonWithGlobalIndex.push_back(MF); } -ModuleManager::ModuleManager(FileManager &FileMgr, - InMemoryModuleCache &ModuleCache, +ModuleManager::ModuleManager(FileManager &FileMgr, ModuleCache &ModCache, const PCHContainerReader &PCHContainerRdr, const HeaderSearch &HeaderSearchInfo) - : FileMgr(FileMgr), ModuleCache(&ModuleCache), - PCHContainerRdr(PCHContainerRdr), HeaderSearchInfo(HeaderSearchInfo) {} + : FileMgr(FileMgr), ModCache(&ModCache), PCHContainerRdr(PCHContainerRdr), + HeaderSearchInfo(HeaderSearchInfo) {} void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor, llvm::SmallPtrSetImpl<ModuleFile *> *ModuleFilesHit) { |