Re-land [ThinLTO] Re-order modules for optimal multi-threaded processing
authorAlexandre Ganea <alexandre.ganea@ubisoft.com>
Wed, 14 Oct 2020 01:54:00 +0000 (21:54 -0400)
committerAlexandre Ganea <alexandre.ganea@ubisoft.com>
Wed, 14 Oct 2020 01:54:15 +0000 (21:54 -0400)
commit617d64f6c5f8fdcdacc4401704146247152b96aa
tree4015d1ac3864a3e42eaa24defbe1a1d2fca23824
parent8f8b9f2cca0b73314342c721186ae9c860ca273c
Re-land [ThinLTO] Re-order modules for optimal multi-threaded processing

This reverts 9b5b3050237db3642ed7ab1bdb3ffa2202511b99 and fixes the unwanted re-ordering when generating ThinLTO indexes.

The goal of this patch is to better balance thread utilization during ThinLTO in-process linking (in llvm-lto2 or in LLD). Before this patch, large modules would often be scheduled late during execution, taking a long time to complete, thus starving the thread pool.

We now sort modules in descending order, based on each module's bitcode size, so that larger modules are processed first. By doing so, smaller modules have a better chance to keep the thread pool active, and thus avoid starvation when the bitcode compilation is almost complete.

In our case (on dual Intel Xeon Gold 6140, Windows 10 version 2004, two-stage build), this saves 15 sec when linking `clang.exe` with LLD & -flto=thin, /opt:lldltojobs=all, no ThinLTO cache, -DLLVM_INTEGRATED_CRT_ALLOC=d:\git\rpmalloc.

Before patch: 100 sec
After patch: 85 sec

Inspired by the work done by David Callahan in D60495.

Differential Revision: https://reviews.llvm.org/D87966
lld/test/COFF/thinlto-module-order.ll [new file with mode: 0644]
llvm/include/llvm/LTO/LTO.h
llvm/lib/LTO/LTO.cpp
llvm/lib/LTO/ThinLTOCodeGenerator.cpp