[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 Jul 30 02:52:16 PDT 2025
================
@@ -282,11 +286,122 @@ static void saveThinArchiveToRepro(ArchiveFile const *file) {
": Archive::children failed: " + toString(std::move(e)));
}
-static InputFile *addFile(StringRef path, LoadType loadType,
- bool isLazy = false, bool isExplicit = true,
- bool isBundleLoader = false,
- bool isForceHidden = false) {
- std::optional<MemoryBufferRef> buffer = readFile(path);
+class DeferredFile {
+public:
+ DeferredFile(StringRef path, bool isLazy, MemoryBufferRef buffer)
+ : path(path), isLazy(isLazy), buffer(buffer) {}
+ StringRef path;
+ bool isLazy;
+ MemoryBufferRef buffer;
+};
+using DeferredFiles = std::vector<DeferredFile>;
+
+class SerialBackgroundQueue {
+ std::deque<std::function<void()>> queue;
+ std::thread *running;
+ std::mutex mutex;
+
+public:
+ void queueWork(std::function<void()> work, bool reap) {
+ mutex.lock();
+ if (running && (queue.empty() || reap)) {
+ mutex.unlock();
+ running->join();
+ mutex.lock();
+ delete running;
+ running = nullptr;
+ }
+
+ if (!reap) {
+ queue.emplace_back(std::move(work));
+ if (!running)
+ running = new std::thread([&]() {
+ bool shouldPop = false;
+ while (true) {
+ mutex.lock();
+ if (shouldPop)
+ queue.pop_front();
+ if (queue.empty()) {
+ mutex.unlock();
+ break;
+ }
+ auto work = std::move(queue.front());
+ shouldPop = true;
+ mutex.unlock();
+ work();
+ }
+ });
+ }
+ mutex.unlock();
+ }
+};
+
+#ifndef NDEBUG
+#include <iomanip>
+#include <iostream>
+#endif
----------------
johnno1962 wrote:
I've removed the includes and the std::setprecision(4) that required them. Guess I'm just going to have to view times in scientific notation.
https://github.com/llvm/llvm-project/pull/147134
More information about the llvm-commits
mailing list