Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 1d0a2ff

Browse files
mehdi_aminijoker-eph
authored andcommitted
ThinLTO: sort inputs and schedule by decreasing size
This is a compile time optimization: keeping a large file to process at the end hurts parallelism. The heurisitic used right now is the input buffer size, however we may want to consider the number of functions to import or the different number of files to load for importing as well. From: Mehdi Amini <[email protected]> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269684 91177308-0d34-0410-b5e6-96231b3b80d8 Conflicts: lib/LTO/ThinLTOCodeGenerator.cpp
1 parent 8251e8c commit 1d0a2ff

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
#include "llvm/Transforms/ObjCARC.h"
5353
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
5454

55+
#include <numeric>
56+
5557
using namespace llvm;
5658

5759
#define DEBUG_TYPE "thinlto"
@@ -881,11 +883,24 @@ void ThinLTOCodeGenerator::run() {
881883
for (auto &DefinedGVSummaries : ModuleToDefinedGVSummaries)
882884
ExportLists[DefinedGVSummaries.first()];
883885

886+
// Compute the ordering we will process the inputs: the rough heuristic here
887+
// is to sort them per size so that the largest module get schedule as soon as
888+
// possible. This is purely a compile-time optimization.
889+
std::vector<int> ModulesOrdering;
890+
ModulesOrdering.resize(Modules.size());
891+
std::iota(ModulesOrdering.begin(), ModulesOrdering.end(), 0);
892+
std::sort(ModulesOrdering.begin(), ModulesOrdering.end(),
893+
[&](int LeftIndex, int RightIndex) {
894+
auto LSize = Modules[LeftIndex].getBufferSize();
895+
auto RSize = Modules[RightIndex].getBufferSize();
896+
return LSize > RSize;
897+
});
898+
884899
// Parallel optimizer + codegen
885900
{
886901
ThreadPool Pool(getNumCores());
887-
int count = 0;
888-
for (auto &ModuleBuffer : Modules) {
902+
for (auto IndexCount : ModulesOrdering) {
903+
auto &ModuleBuffer = Modules[IndexCount];
889904
Pool.async([&](int count) {
890905
auto ModuleIdentifier = ModuleBuffer.getBufferIdentifier();
891906
auto &ExportList = ExportLists[ModuleIdentifier];
@@ -937,8 +952,7 @@ void ThinLTOCodeGenerator::run() {
937952

938953
OutputBuffer = CacheEntry.write(std::move(OutputBuffer));
939954
ProducedBinaries[count] = std::move(OutputBuffer);
940-
}, count);
941-
count++;
955+
}, IndexCount);
942956
}
943957
}
944958

0 commit comments

Comments
 (0)