aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2025-04-29 10:24:38 -0700
committerGitHub <noreply@github.com>2025-04-29 10:24:38 -0700
commit0f90a7b323bcaa087be31aa135b71694db2d5ff9 (patch)
tree113c832b4b549d1a0cb7b8ba3451c7353417ab1e
parent82c036e2de4eba0e286a94c9b3240e4b14d8aee4 (diff)
downloadllvm-0f90a7b323bcaa087be31aa135b71694db2d5ff9.zip
llvm-0f90a7b323bcaa087be31aa135b71694db2d5ff9.tar.gz
llvm-0f90a7b323bcaa087be31aa135b71694db2d5ff9.tar.bz2
[clang] Enable making the `CompilerInstance` module dependency collector thread-safe (#137227)
The same principle as #135473, #135737, #136178, #136601 & #137059.
-rw-r--r--clang/include/clang/Frontend/CompilerInstance.h13
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp12
2 files changed, 18 insertions, 7 deletions
diff --git a/clang/include/clang/Frontend/CompilerInstance.h b/clang/include/clang/Frontend/CompilerInstance.h
index 7de4fb5..ee15b10 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -839,16 +839,23 @@ public:
class ThreadSafeCloneConfig {
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
DiagnosticConsumer &DiagConsumer;
+ std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
public:
- ThreadSafeCloneConfig(IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
- DiagnosticConsumer &DiagConsumer)
- : VFS(std::move(VFS)), DiagConsumer(DiagConsumer) {
+ ThreadSafeCloneConfig(
+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
+ DiagnosticConsumer &DiagConsumer,
+ std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector = nullptr)
+ : VFS(std::move(VFS)), DiagConsumer(DiagConsumer),
+ ModuleDepCollector(std::move(ModuleDepCollector)) {
assert(this->VFS && "Clone config requires non-null VFS");
}
IntrusiveRefCntPtr<llvm::vfs::FileSystem> getVFS() const { return VFS; }
DiagnosticConsumer &getDiagConsumer() const { return DiagConsumer; }
+ std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector() const {
+ return ModuleDepCollector;
+ }
};
private:
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 2d6ab87..cbc9c9d 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1257,10 +1257,14 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
Instance.GetDependencyDirectives =
GetDependencyDirectives->cloneFor(Instance.getFileManager());
- // If we're collecting module dependencies, we need to share a collector
- // between all of the module CompilerInstances. Other than that, we don't
- // want to produce any dependency output from the module build.
- Instance.setModuleDepCollector(getModuleDepCollector());
+ if (ThreadSafeConfig) {
+ Instance.setModuleDepCollector(ThreadSafeConfig->getModuleDepCollector());
+ } else {
+ // If we're collecting module dependencies, we need to share a collector
+ // between all of the module CompilerInstances. Other than that, we don't
+ // want to produce any dependency output from the module build.
+ Instance.setModuleDepCollector(getModuleDepCollector());
+ }
Inv.getDependencyOutputOpts() = DependencyOutputOptions();
return InstancePtr;