Skip to content

Commit 30fb74c

Browse files
committed
[clang] Enable making the CompilerInstance module dependency collector thread-safe
The same principle as llvm#135473, llvm#135737, llvm#136178, llvm#136601 & llvm#137059.
1 parent 2bc6f9d commit 30fb74c

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

clang/include/clang/Frontend/CompilerInstance.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -839,16 +839,23 @@ class CompilerInstance : public ModuleLoader {
839839
class ThreadSafeCloneConfig {
840840
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
841841
DiagnosticConsumer &DiagConsumer;
842+
std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector;
842843

843844
public:
844-
ThreadSafeCloneConfig(IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
845-
DiagnosticConsumer &DiagConsumer)
846-
: VFS(std::move(VFS)), DiagConsumer(DiagConsumer) {
845+
ThreadSafeCloneConfig(
846+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
847+
DiagnosticConsumer &DiagConsumer,
848+
std::shared_ptr<ModuleDependencyCollector> ModuleDepCollector = nullptr)
849+
: VFS(std::move(VFS)), DiagConsumer(DiagConsumer),
850+
ModuleDepCollector(std::move(ModuleDepCollector)) {
847851
assert(this->VFS && "Clone config requires non-null VFS");
848852
}
849853

850854
IntrusiveRefCntPtr<llvm::vfs::FileSystem> getVFS() const { return VFS; }
851855
DiagnosticConsumer &getDiagConsumer() const { return DiagConsumer; }
856+
std::shared_ptr<ModuleDependencyCollector> getModuleDepCollector() const {
857+
return ModuleDepCollector;
858+
}
852859
};
853860

854861
private:

clang/lib/Frontend/CompilerInstance.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -1257,10 +1257,14 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
12571257
Instance.GetDependencyDirectives =
12581258
GetDependencyDirectives->cloneFor(Instance.getFileManager());
12591259

1260-
// If we're collecting module dependencies, we need to share a collector
1261-
// between all of the module CompilerInstances. Other than that, we don't
1262-
// want to produce any dependency output from the module build.
1263-
Instance.setModuleDepCollector(getModuleDepCollector());
1260+
if (ThreadSafeConfig) {
1261+
Instance.setModuleDepCollector(ThreadSafeConfig->getModuleDepCollector());
1262+
} else {
1263+
// If we're collecting module dependencies, we need to share a collector
1264+
// between all of the module CompilerInstances. Other than that, we don't
1265+
// want to produce any dependency output from the module build.
1266+
Instance.setModuleDepCollector(getModuleDepCollector());
1267+
}
12641268
Inv.getDependencyOutputOpts() = DependencyOutputOptions();
12651269

12661270
return InstancePtr;

0 commit comments

Comments
 (0)