[lld] [lld][MachO]Multi-threaded i/o. Twice as fast linking a large project. (PR #147134)
John Holdsworth via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 24 06:54:31 PDT 2025
johnno1962 wrote:
Thanks for stepping in @DavidSpickett, You can certain broaden the scope of the '#if LLVM_ENABLE_THREADS':
```
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 7ce987e400a2..7ed19ba7e346 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -291,6 +291,7 @@ struct DeferredFile {
};
using DeferredFiles = std::vector<DeferredFile>;
+#if LLVM_ENABLE_THREADS
class SerialBackgroundQueue {
std::deque<std::function<void()>> queue;
std::thread *running;
@@ -359,7 +360,6 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
(void)t;
}
};
-#if LLVM_ENABLE_THREADS
{ // Create scope for waiting for the taskGroup
std::atomic_size_t index = 0;
llvm::parallel::TaskGroup taskGroup;
@@ -373,7 +373,6 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
}
});
}
-#endif
#ifndef NDEBUG
auto dt = high_resolution_clock::now() - t0;
if (Process::GetEnv("LLD_MULTI_THREAD_PAGE"))
@@ -382,13 +381,16 @@ void multiThreadedPageInBackground(DeferredFiles &deferred) {
<< duration_cast<milliseconds>(dt).count() / 1000. << "\n";
#endif
}
+#endif
static void multiThreadedPageIn(const DeferredFiles &deferred) {
+ #if LLVM_ENABLE_THREADS
static SerialBackgroundQueue pageInQueue;
pageInQueue.queueWork([=]() {
DeferredFiles files = deferred;
multiThreadedPageInBackground(files);
});
+ #endif
}
static InputFile *processFile(std::optional<MemoryBufferRef> buffer,
@@ -1834,6 +1836,7 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
}
if (auto *arg = args.getLastArg(OPT_read_workers)) {
+ #if LLVM_ENABLE_THREADS
StringRef v(arg->getValue());
unsigned workers = 0;
if (!llvm::to_integer(v, workers, 0))
@@ -1841,6 +1844,10 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
": expected a non-negative integer, but got '" + arg->getValue() +
"'");
config->readWorkers = workers;
+ #else
+ error(arg->getSpelling() +
+ ": option unavailable");
+ #endif
}
if (auto *arg = args.getLastArg(OPT_threads_eq)) {
StringRef v(arg->getValue());
```
This should get things up and running again while I look into trying to replicate what the issue is.
https://github.com/llvm/llvm-project/pull/147134
More information about the llvm-commits
mailing list