llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lld-macho @llvm/pr-subscribers-lld Author: Jez Ng (int3) <details> <summary>Changes</summary> `S_ATTR_LIVE_SUPPORT` sections are live if they point to something live, so `markTransitively` rescans them on every loop iteration. It finds them by walking all of `inputSections` and checking each one's flags, and a FIXME asks whether keeping them in a separate vector would be faster. Benchmarking showed that to indeed be the case, so this PR collects the live-support sections in the loop that already walks every input section for the roots. --- Full diff: https://github.com/llvm/llvm-project/pull/242230.diff 1 Files Affected: - (modified) lld/MachO/MarkLive.cpp (+17-6) ``````````diff diff --git a/lld/MachO/MarkLive.cpp b/lld/MachO/MarkLive.cpp index 8e34f88684585..053e60f3cf21c 100644 --- a/lld/MachO/MarkLive.cpp +++ b/lld/MachO/MarkLive.cpp @@ -45,9 +45,17 @@ class MarkLive { // optimization; flushing shortly after the worklist is populated means its // entries are likely still in cache. virtual void flush(size_t shard) = 0; + void addLiveSupport(ConcatInputSection *isec, size_t shard) { + liveSupportShards[shard].push_back(isec); + } // Flushes all the shards into `nextLevel` before doing the marking. virtual void markTransitively() = 0; virtual ~MarkLive() = default; + +protected: + const size_t numThreads = parallel::getThreadCount(); + std::vector<SmallVector<ConcatInputSection *, 0>> liveSupportShards{ + numThreads}; }; // Sets `flag` and returns true if no other thread set it first. @@ -88,7 +96,7 @@ template <bool RecordWhyLive> class MarkLiveImpl : public MarkLive { std::conditional_t<RecordWhyLive, WhyLiveEntry, InputSection>; using Worklist = SmallVector<WorklistEntry *, 0>; - MarkLiveImpl() : shards(parallel::getThreadCount()) {} + MarkLiveImpl() : shards(numThreads) {} void enqueue(InputSection *isec, uint64_t off, size_t shard) override { enqueue(isec, off, nullptr, shards[shard]); } @@ -207,7 +215,6 @@ void MarkLiveImpl<RecordWhyLive>::visit(WorklistEntry *entry, // their stacks to the next level. The last join makes every live bit visible // to the live-support scan, which reads them with plain loads. template <bool RecordWhyLive> void MarkLiveImpl<RecordWhyLive>::drain() { - const size_t numThreads = parallel::getThreadCount(); // The minimum number of visits a worker makes in a level before it may hand // back its stack. This keeps levels with fewer sections than workers from // ending after a visit or two, which would result in a lot of fork-join @@ -286,6 +293,9 @@ template <bool RecordWhyLive> void MarkLiveImpl<RecordWhyLive>::markTransitively() { for (size_t shard = 0; shard != shards.size(); ++shard) flush(shard); + SmallVector<ConcatInputSection *, 0> liveSupport; + for (SmallVector<ConcatInputSection *, 0> &s : liveSupportShards) + liveSupport.append(s); do { // Mark things reachable from GC roots as live. drain(); @@ -293,12 +303,10 @@ void MarkLiveImpl<RecordWhyLive>::markTransitively() { // S_ATTR_LIVE_SUPPORT sections are live if they point _to_ a live // section. Process them in a second pass. parallelForChunks( - ArrayRef(inputSections), 256, + ArrayRef(liveSupport), 256, [&](size_t shard, ArrayRef<ConcatInputSection *> chunk) { for (ConcatInputSection *isec : chunk) { - // FIXME: Check if copying all S_ATTR_LIVE_SUPPORT sections into a - // separate vector and only walking that here is faster. - if (!(isec->getFlags() & S_ATTR_LIVE_SUPPORT) || isec->isLive(0)) + if (isec->isLive(0)) continue; for (const Relocation &r : isec->relocs) { @@ -400,6 +408,9 @@ void markLive() { ArrayRef(inputSections), 256, [&](size_t shard, ArrayRef<ConcatInputSection *> chunk) { for (ConcatInputSection *isec : chunk) { + if (isec->getFlags() & S_ATTR_LIVE_SUPPORT) + marker->addLiveSupport(isec, shard); + // Sections marked no_dead_strip if (isec->getFlags() & S_ATTR_NO_DEAD_STRIP) { marker->enqueue(isec, 0, shard); `````````` </details> https://github.com/llvm/llvm-project/pull/242230 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
