Skip to content

Commit 932f027

Browse files
committed
[Support] Move LLD's parallel algorithm wrappers to support
Essentially takes the lld/Common/Threads.h wrappers and moves them to the llvm/Support/Paralle.h algorithm header. The changes are: - Remove policy parameter, since all clients use `par`. - Rename the methods to `parallelSort` etc to match LLVM style, since they are no longer C++17 pstl compatible. - Move algorithms from llvm::parallel:: to llvm::, since they have "parallel" in the name and are no longer overloads of the regular algorithms. - Add range overloads - Use the sequential algorithm directly when 1 thread is requested (skips task grouping) - Fix the index type of parallelForEachN to size_t. Nobody in LLVM was using any other parameter, and it made overload resolution hard for for_each_n(par, 0, foo.size(), ...) because 0 is int, not size_t. Remove Threads.h and update LLD for that. This is a prerequisite for parallel public symbol processing in the PDB library, which is in LLVM. Reviewed By: MaskRay, aganea Differential Revision: https://reviews.llvm.org/D79390
1 parent 855e02e commit 932f027

File tree

25 files changed

+67
-175
lines changed

25 files changed

+67
-175
lines changed

lld/COFF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "lld/Common/ErrorHandler.h"
2222
#include "lld/Common/Filesystem.h"
2323
#include "lld/Common/Memory.h"
24-
#include "lld/Common/Threads.h"
2524
#include "lld/Common/Timer.h"
2625
#include "lld/Common/Version.h"
2726
#include "llvm/ADT/Optional.h"
@@ -39,6 +38,7 @@
3938
#include "llvm/Support/Debug.h"
4039
#include "llvm/Support/LEB128.h"
4140
#include "llvm/Support/MathExtras.h"
41+
#include "llvm/Support/Parallel.h"
4242
#include "llvm/Support/Path.h"
4343
#include "llvm/Support/Process.h"
4444
#include "llvm/Support/TarWriter.h"

lld/COFF/ICF.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "Chunks.h"
2222
#include "Symbols.h"
2323
#include "lld/Common/ErrorHandler.h"
24-
#include "lld/Common/Threads.h"
2524
#include "lld/Common/Timer.h"
2625
#include "llvm/ADT/Hashing.h"
2726
#include "llvm/Support/Debug.h"

lld/COFF/LLDMapFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "Symbols.h"
2424
#include "Writer.h"
2525
#include "lld/Common/ErrorHandler.h"
26-
#include "lld/Common/Threads.h"
26+
#include "llvm/Support/Parallel.h"
2727
#include "llvm/Support/raw_ostream.h"
2828

2929
using namespace llvm;

lld/COFF/MapFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
#include "Symbols.h"
3333
#include "Writer.h"
3434
#include "lld/Common/ErrorHandler.h"
35-
#include "lld/Common/Threads.h"
3635
#include "lld/Common/Timer.h"
36+
#include "llvm/Support/Parallel.h"
3737
#include "llvm/Support/Path.h"
3838
#include "llvm/Support/raw_ostream.h"
3939

lld/COFF/PDB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "TypeMerger.h"
1717
#include "Writer.h"
1818
#include "lld/Common/ErrorHandler.h"
19-
#include "lld/Common/Threads.h"
2019
#include "lld/Common/Timer.h"
2120
#include "llvm/DebugInfo/CodeView/DebugFrameDataSubsection.h"
2221
#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
@@ -57,6 +56,7 @@
5756
#include "llvm/Support/Errc.h"
5857
#include "llvm/Support/FormatAdapters.h"
5958
#include "llvm/Support/FormatVariadic.h"
59+
#include "llvm/Support/Parallel.h"
6060
#include "llvm/Support/Path.h"
6161
#include "llvm/Support/ScopedPrinter.h"
6262
#include <memory>

lld/COFF/Writer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "Symbols.h"
1818
#include "lld/Common/ErrorHandler.h"
1919
#include "lld/Common/Memory.h"
20-
#include "lld/Common/Threads.h"
2120
#include "lld/Common/Timer.h"
2221
#include "llvm/ADT/DenseMap.h"
2322
#include "llvm/ADT/STLExtras.h"

lld/Common/ErrorHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "lld/Common/ErrorHandler.h"
1010

11-
#include "lld/Common/Threads.h"
11+
#include "llvm/Support/Parallel.h"
1212

1313
#include "llvm/ADT/Twine.h"
1414
#include "llvm/IR/DiagnosticInfo.h"

lld/Common/Filesystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "lld/Common/Filesystem.h"
14-
#include "lld/Common/Threads.h"
1514
#include "llvm/Config/llvm-config.h"
1615
#include "llvm/Support/FileOutputBuffer.h"
1716
#include "llvm/Support/FileSystem.h"
17+
#include "llvm/Support/Parallel.h"
1818
#if LLVM_ON_UNIX
1919
#include <unistd.h>
2020
#endif

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include "lld/Common/Memory.h"
4444
#include "lld/Common/Strings.h"
4545
#include "lld/Common/TargetOptionsCommandFlags.h"
46-
#include "lld/Common/Threads.h"
4746
#include "lld/Common/Version.h"
4847
#include "llvm/ADT/SetVector.h"
4948
#include "llvm/ADT/StringExtras.h"
@@ -53,6 +52,7 @@
5352
#include "llvm/Support/Compression.h"
5453
#include "llvm/Support/GlobPattern.h"
5554
#include "llvm/Support/LEB128.h"
55+
#include "llvm/Support/Parallel.h"
5656
#include "llvm/Support/Path.h"
5757
#include "llvm/Support/TarWriter.h"
5858
#include "llvm/Support/TargetSelect.h"

lld/ELF/ICF.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@
8080
#include "Symbols.h"
8181
#include "SyntheticSections.h"
8282
#include "Writer.h"
83-
#include "lld/Common/Threads.h"
8483
#include "llvm/ADT/StringExtras.h"
8584
#include "llvm/BinaryFormat/ELF.h"
8685
#include "llvm/Object/ELF.h"
86+
#include "llvm/Support/Parallel.h"
8787
#include "llvm/Support/TimeProfiler.h"
8888
#include "llvm/Support/xxhash.h"
8989
#include <algorithm>
@@ -467,9 +467,8 @@ template <class ELFT> void ICF<ELFT>::run() {
467467
}
468468

469469
// Initially, we use hash values to partition sections.
470-
parallelForEach(sections, [&](InputSection *s) {
471-
s->eqClass[0] = xxHash64(s->data());
472-
});
470+
parallelForEach(
471+
sections, [&](InputSection *s) { s->eqClass[0] = xxHash64(s->data()); });
473472

474473
for (unsigned cnt = 0; cnt != 2; ++cnt) {
475474
parallelForEach(sections, [&](InputSection *s) {

0 commit comments

Comments
 (0)