[ThinLTO] Re-order modules for optimal multi-threaded processing
authorAlexandre Ganea <alexandre.ganea@ubisoft.com>
Tue, 22 Sep 2020 15:24:36 +0000 (11:24 -0400)
committerAlexandre Ganea <alexandre.ganea@ubisoft.com>
Tue, 22 Sep 2020 15:25:59 +0000 (11:25 -0400)
commit6537004913f3009d896bc30856698e7d22199ba7
tree621ad964b9bda8b7a116d16c1bd8322ae37a19d2
parent7b51961cd0748ed5bd3b6fdacbfe596c374c93bc
[ThinLTO] Re-order modules for optimal multi-threaded processing

Re-use an optimizition from the old LTO API (used by ld64).
This sorts modules in ascending order, based on bitcode size, so that larger modules are processed first. This allows for smaller modules to be process last, and better fill free threads 'slots', and thusly allow for better multi-thread load balancing.

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: 102 sec
After patch: 85 sec

Inspired by the work done by David Callahan in D60495.

Differential Revision: https://reviews.llvm.org/D87966
llvm/include/llvm/LTO/LTO.h
llvm/lib/LTO/LTO.cpp
llvm/lib/LTO/ThinLTOCodeGenerator.cpp