<div dir="ltr">I will try a build with LLVM_ENABLE_THREADS=0 locally and see if I can repro</div><br><div class="gmail_quote"><div dir="ltr">On Wed, May 10, 2017 at 9:28 AM Hans Wennborg <<a href="mailto:hans@chromium.org">hans@chromium.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Oh, it's because of #if LLVM_ENABLE_THREADS<br>
<br>
On Wed, May 10, 2017 at 9:27 AM, Hans Wennborg <<a href="mailto:hans@chromium.org" target="_blank">hans@chromium.org</a>> wrote:<br>
> This broke Chromium's lld builds, e.g.<br>
> <a href="https://build.chromium.org/p/chromium.fyi/builders/ClangToTLinux/builds/8161" rel="noreferrer" target="_blank">https://build.chromium.org/p/chromium.fyi/builders/ClangToTLinux/builds/8161</a><br>
><br>
> I'm not sure why it's not a problem on the regular LLVM buildbots, though.<br>
><br>
> On Tue, May 9, 2017 at 6:16 PM, Zachary Turner via llvm-commits<br>
> <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
>> Author: zturner<br>
>> Date: Tue May 9 20:16:22 2017<br>
>> New Revision: 302613<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=302613&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=302613&view=rev</a><br>
>> Log:<br>
>> [Core] Make parallel algorithms match C++ Parallelism TS.<br>
>><br>
>> Differential Revision: <a href="https://reviews.llvm.org/D33016" rel="noreferrer" target="_blank">https://reviews.llvm.org/D33016</a><br>
>><br>
>> Modified:<br>
>> lld/trunk/COFF/ICF.cpp<br>
>> lld/trunk/COFF/MapFile.cpp<br>
>> lld/trunk/COFF/Writer.cpp<br>
>> lld/trunk/ELF/Threads.h<br>
>> lld/trunk/include/lld/Core/Parallel.h<br>
>> lld/trunk/lib/ReaderWriter/MachO/LayoutPass.cpp<br>
>> lld/trunk/unittests/CoreTests/ParallelTest.cpp<br>
>><br>
>> Modified: lld/trunk/COFF/ICF.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ICF.cpp?rev=302613&r1=302612&r2=302613&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/ICF.cpp?rev=302613&r1=302612&r2=302613&view=diff</a><br>
>> ==============================================================================<br>
>> --- lld/trunk/COFF/ICF.cpp (original)<br>
>> +++ lld/trunk/COFF/ICF.cpp Tue May 9 20:16:22 2017<br>
>> @@ -192,7 +192,7 @@ void ICF::forEachClass(std::function<voi<br>
>> // Split sections into 256 shards and call Fn in parallel.<br>
>> size_t NumShards = 256;<br>
>> size_t Step = Chunks.size() / NumShards;<br>
>> - parallel_for(size_t(0), NumShards, [&](size_t I) {<br>
>> + for_each_n(parallel::par, size_t(0), NumShards, [&](size_t I) {<br>
>> forEachClassRange(I * Step, (I + 1) * Step, Fn);<br>
>> });<br>
>> forEachClassRange(Step * NumShards, Chunks.size(), Fn);<br>
>><br>
>> Modified: lld/trunk/COFF/MapFile.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MapFile.cpp?rev=302613&r1=302612&r2=302613&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MapFile.cpp?rev=302613&r1=302612&r2=302613&view=diff</a><br>
>> ==============================================================================<br>
>> --- lld/trunk/COFF/MapFile.cpp (original)<br>
>> +++ lld/trunk/COFF/MapFile.cpp Tue May 9 20:16:22 2017<br>
>> @@ -76,7 +76,7 @@ static SymbolMapTy getSectionSyms(ArrayR<br>
>> static DenseMap<DefinedRegular *, std::string><br>
>> getSymbolStrings(ArrayRef<DefinedRegular *> Syms) {<br>
>> std::vector<std::string> Str(Syms.size());<br>
>> - parallel_for((size_t)0, Syms.size(), [&](size_t I) {<br>
>> + for_each_n(parallel::par, (size_t)0, Syms.size(), [&](size_t I) {<br>
>> raw_string_ostream OS(Str[I]);<br>
>> writeHeader(OS, Syms[I]->getRVA(), 0, 0);<br>
>> OS << indent(2) << toString(*Syms[I]);<br>
>><br>
>> Modified: lld/trunk/COFF/Writer.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=302613&r1=302612&r2=302613&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=302613&r1=302612&r2=302613&view=diff</a><br>
>> ==============================================================================<br>
>> --- lld/trunk/COFF/Writer.cpp (original)<br>
>> +++ lld/trunk/COFF/Writer.cpp Tue May 9 20:16:22 2017<br>
>> @@ -745,8 +745,8 @@ void Writer::writeSections() {<br>
>> // ADD instructions).<br>
>> if (Sec->getPermissions() & IMAGE_SCN_CNT_CODE)<br>
>> memset(SecBuf, 0xCC, Sec->getRawSize());<br>
>> - parallel_for_each(Sec->getChunks().begin(), Sec->getChunks().end(),<br>
>> - [&](Chunk *C) { C->writeTo(SecBuf); });<br>
>> + for_each(parallel::par, Sec->getChunks().begin(), Sec->getChunks().end(),<br>
>> + [&](Chunk *C) { C->writeTo(SecBuf); });<br>
>> }<br>
>> }<br>
>><br>
>> @@ -760,16 +760,14 @@ void Writer::sortExceptionTable() {<br>
>> uint8_t *End = Begin + Sec->getVirtualSize();<br>
>> if (Config->Machine == AMD64) {<br>
>> struct Entry { ulittle32_t Begin, End, Unwind; };<br>
>> - parallel_sort(<br>
>> - (Entry *)Begin, (Entry *)End,<br>
>> - [](const Entry &A, const Entry &B) { return A.Begin < B.Begin; });<br>
>> + sort(parallel::par, (Entry *)Begin, (Entry *)End,<br>
>> + [](const Entry &A, const Entry &B) { return A.Begin < B.Begin; });<br>
>> return;<br>
>> }<br>
>> if (Config->Machine == ARMNT) {<br>
>> struct Entry { ulittle32_t Begin, Unwind; };<br>
>> - parallel_sort(<br>
>> - (Entry *)Begin, (Entry *)End,<br>
>> - [](const Entry &A, const Entry &B) { return A.Begin < B.Begin; });<br>
>> + sort(parallel::par, (Entry *)Begin, (Entry *)End,<br>
>> + [](const Entry &A, const Entry &B) { return A.Begin < B.Begin; });<br>
>> return;<br>
>> }<br>
>> errs() << "warning: don't know how to handle .pdata.\n";<br>
>><br>
>> Modified: lld/trunk/ELF/Threads.h<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Threads.h?rev=302613&r1=302612&r2=302613&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Threads.h?rev=302613&r1=302612&r2=302613&view=diff</a><br>
>> ==============================================================================<br>
>> --- lld/trunk/ELF/Threads.h (original)<br>
>> +++ lld/trunk/ELF/Threads.h Tue May 9 20:16:22 2017<br>
>> @@ -71,19 +71,17 @@ namespace elf {<br>
>> template <class IterTy, class FuncTy><br>
>> void parallelForEach(IterTy Begin, IterTy End, FuncTy Fn) {<br>
>> if (Config->Threads)<br>
>> - parallel_for_each(Begin, End, Fn);<br>
>> + for_each(parallel::par, Begin, End, Fn);<br>
>> else<br>
>> - std::for_each(Begin, End, Fn);<br>
>> + for_each(parallel::seq, Begin, End, Fn);<br>
>> }<br>
>><br>
>> inline void parallelFor(size_t Begin, size_t End,<br>
>> std::function<void(size_t)> Fn) {<br>
>> - if (Config->Threads) {<br>
>> - parallel_for(Begin, End, Fn);<br>
>> - } else {<br>
>> - for (size_t I = Begin; I < End; ++I)<br>
>> - Fn(I);<br>
>> - }<br>
>> + if (Config->Threads)<br>
>> + for_each_n(parallel::par, Begin, End, Fn);<br>
>> + else<br>
>> + for_each_n(parallel::seq, Begin, End, Fn);<br>
>> }<br>
>> }<br>
>> }<br>
>><br>
>> Modified: lld/trunk/include/lld/Core/Parallel.h<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Parallel.h?rev=302613&r1=302612&r2=302613&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Parallel.h?rev=302613&r1=302612&r2=302613&view=diff</a><br>
>> ==============================================================================<br>
>> --- lld/trunk/include/lld/Core/Parallel.h (original)<br>
>> +++ lld/trunk/include/lld/Core/Parallel.h Tue May 9 20:16:22 2017<br>
>> @@ -12,8 +12,9 @@<br>
>><br>
>> #include "lld/Core/LLVM.h"<br>
>> #include "lld/Core/TaskGroup.h"<br>
>> -#include "llvm/Support/MathExtras.h"<br>
>> +#include "llvm/ADT/STLExtras.h"<br>
>> #include "llvm/Config/llvm-config.h"<br>
>> +#include "llvm/Support/MathExtras.h"<br>
>><br>
>> #include <algorithm><br>
>><br>
>> @@ -24,25 +25,40 @@<br>
>><br>
>> namespace lld {<br>
>><br>
>> -#if !LLVM_ENABLE_THREADS<br>
>> -template <class RandomAccessIterator, class Comparator><br>
>> -void parallel_sort(<br>
>> - RandomAccessIterator Start, RandomAccessIterator End,<br>
>> - const Comparator &Comp = std::less<<br>
>> - typename std::iterator_traits<RandomAccessIterator>::value_type>()) {<br>
>> - std::sort(Start, End, Comp);<br>
>> -}<br>
>> -#elif defined(_MSC_VER)<br>
>> -// Use ppl parallel_sort on Windows.<br>
>> +namespace parallel {<br>
>> +struct sequential_execution_policy {};<br>
>> +struct parallel_execution_policy {};<br>
>> +<br>
>> +template <typename T><br>
>> +struct is_execution_policy<br>
>> + : public std::integral_constant<<br>
>> + bool, llvm::is_one_of<T, sequential_execution_policy,<br>
>> + parallel_execution_policy>::value> {};<br>
>> +<br>
>> +constexpr sequential_execution_policy seq{};<br>
>> +constexpr parallel_execution_policy par{};<br>
>> +<br>
>> +#if LLVM_ENABLE_THREADS<br>
>> +<br>
>> +namespace detail {<br>
>> +<br>
>> +#if defined(_MSC_VER)<br>
>> template <class RandomAccessIterator, class Comparator><br>
>> -void parallel_sort(<br>
>> - RandomAccessIterator Start, RandomAccessIterator End,<br>
>> - const Comparator &Comp = std::less<<br>
>> - typename std::iterator_traits<RandomAccessIterator>::value_type>()) {<br>
>> +void parallel_sort(RandomAccessIterator Start, RandomAccessIterator End,<br>
>> + const Comparator &Comp) {<br>
>> concurrency::parallel_sort(Start, End, Comp);<br>
>> }<br>
>> +template <class IterTy, class FuncTy><br>
>> +void parallel_for_each(IterTy Begin, IterTy End, FuncTy Fn) {<br>
>> + concurrency::parallel_for_each(Begin, End, Fn);<br>
>> +}<br>
>> +<br>
>> +template <class IndexTy, class FuncTy><br>
>> +void parallel_for_each_n(IndexTy Begin, IndexTy End, FuncTy Fn) {<br>
>> + concurrency::parallel_for(Begin, End, Fn);<br>
>> +}<br>
>> +<br>
>> #else<br>
>> -namespace detail {<br>
>> const ptrdiff_t MinParallelSize = 1024;<br>
>><br>
>> /// \brief Inclusive median.<br>
>> @@ -83,46 +99,15 @@ void parallel_quick_sort(RandomAccessIte<br>
>> });<br>
>> parallel_quick_sort(Pivot + 1, End, Comp, TG, Depth - 1);<br>
>> }<br>
>> -}<br>
>><br>
>> template <class RandomAccessIterator, class Comparator><br>
>> -void parallel_sort(<br>
>> - RandomAccessIterator Start, RandomAccessIterator End,<br>
>> - const Comparator &Comp = std::less<<br>
>> - typename std::iterator_traits<RandomAccessIterator>::value_type>()) {<br>
>> +void parallel_sort(RandomAccessIterator Start, RandomAccessIterator End,<br>
>> + const Comparator &Comp) {<br>
>> TaskGroup TG;<br>
>> - detail::parallel_quick_sort(Start, End, Comp, TG,<br>
>> - llvm::Log2_64(std::distance(Start, End)) + 1);<br>
>> -}<br>
>> -#endif<br>
>> -<br>
>> -template <class T> void parallel_sort(T *Start, T *End) {<br>
>> - parallel_sort(Start, End, std::less<T>());<br>
>> -}<br>
>> -<br>
>> -#if !LLVM_ENABLE_THREADS<br>
>> -template <class IterTy, class FuncTy><br>
>> -void parallel_for_each(IterTy Begin, IterTy End, FuncTy Fn) {<br>
>> - std::for_each(Begin, End, Fn);<br>
>> -}<br>
>> -<br>
>> -template <class IndexTy, class FuncTy><br>
>> -void parallel_for(IndexTy Begin, IndexTy End, FuncTy Fn) {<br>
>> - for (IndexTy I = Begin; I != End; ++I)<br>
>> - Fn(I);<br>
>> -}<br>
>> -#elif defined(_MSC_VER)<br>
>> -// Use ppl parallel_for_each on Windows.<br>
>> -template <class IterTy, class FuncTy><br>
>> -void parallel_for_each(IterTy Begin, IterTy End, FuncTy Fn) {<br>
>> - concurrency::parallel_for_each(Begin, End, Fn);<br>
>> + parallel_quick_sort(Start, End, Comp, TG,<br>
>> + llvm::Log2_64(std::distance(Start, End)) + 1);<br>
>> }<br>
>><br>
>> -template <class IndexTy, class FuncTy><br>
>> -void parallel_for(IndexTy Begin, IndexTy End, FuncTy Fn) {<br>
>> - concurrency::parallel_for(Begin, End, Fn);<br>
>> -}<br>
>> -#else<br>
>> template <class IterTy, class FuncTy><br>
>> void parallel_for_each(IterTy Begin, IterTy End, FuncTy Fn) {<br>
>> // TaskGroup has a relatively high overhead, so we want to reduce<br>
>> @@ -142,7 +127,7 @@ void parallel_for_each(IterTy Begin, Ite<br>
>> }<br>
>><br>
>> template <class IndexTy, class FuncTy><br>
>> -void parallel_for(IndexTy Begin, IndexTy End, FuncTy Fn) {<br>
>> +void parallel_for_each_n(IndexTy Begin, IndexTy End, FuncTy Fn) {<br>
>> ptrdiff_t TaskSize = (End - Begin) / 1024;<br>
>> if (TaskSize == 0)<br>
>> TaskSize = 1;<br>
>> @@ -160,7 +145,65 @@ void parallel_for(IndexTy Begin, IndexTy<br>
>> Fn(J);<br>
>> });<br>
>> }<br>
>> +<br>
>> +#endif<br>
>> +<br>
>> +template <typename Iter><br>
>> +using DefComparator =<br>
>> + std::less<typename std::iterator_traits<Iter>::value_type>;<br>
>> +<br>
>> +} // namespace detail<br>
>> #endif<br>
>> +<br>
>> +// sequential algorithm implementations.<br>
>> +template <class Policy, class RandomAccessIterator,<br>
>> + class Comparator = detail::DefComparator<RandomAccessIterator>><br>
>> +void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End,<br>
>> + const Comparator &Comp = Comparator()) {<br>
>> + static_assert(is_execution_policy<Policy>::value,<br>
>> + "Invalid execution policy!");<br>
>> + std::sort(Start, End, Comp);<br>
>> +}<br>
>> +<br>
>> +template <class Policy, class IterTy, class FuncTy><br>
>> +void for_each(Policy policy, IterTy Begin, IterTy End, FuncTy Fn) {<br>
>> + static_assert(is_execution_policy<Policy>::value,<br>
>> + "Invalid execution policy!");<br>
>> + std::for_each(Begin, End, Fn);<br>
>> +}<br>
>> +<br>
>> +template <class Policy, class IndexTy, class FuncTy><br>
>> +void for_each_n(Policy policy, IndexTy Begin, IndexTy End, FuncTy Fn) {<br>
>> + static_assert(is_execution_policy<Policy>::value,<br>
>> + "Invalid execution policy!");<br>
>> + for (IndexTy I = Begin; I != End; ++I)<br>
>> + Fn(I);<br>
>> +}<br>
>> +<br>
>> +// Parallel algorithm implementations, only available when LLVM_ENABLE_THREADS<br>
>> +// is true.<br>
>> +#if defined(LLVM_ENABLE_THREADS)<br>
>> +template <class RandomAccessIterator,<br>
>> + class Comparator = detail::DefComparator<RandomAccessIterator>><br>
>> +void sort(parallel_execution_policy policy, RandomAccessIterator Start,<br>
>> + RandomAccessIterator End, const Comparator &Comp = Comparator()) {<br>
>> + detail::parallel_sort(Start, End, Comp);<br>
>> +}<br>
>> +<br>
>> +template <class IterTy, class FuncTy><br>
>> +void for_each(parallel_execution_policy policy, IterTy Begin, IterTy End,<br>
>> + FuncTy Fn) {<br>
>> + detail::parallel_for_each(Begin, End, Fn);<br>
>> +}<br>
>> +<br>
>> +template <class IndexTy, class FuncTy><br>
>> +void for_each_n(parallel_execution_policy policy, IndexTy Begin, IndexTy End,<br>
>> + FuncTy Fn) {<br>
>> + detail::parallel_for_each_n(Begin, End, Fn);<br>
>> +}<br>
>> +#endif<br>
>> +<br>
>> +} // namespace parallel<br>
>> } // End namespace lld<br>
>><br>
>> #endif // LLD_CORE_PARALLEL_H<br>
>><br>
>> Modified: lld/trunk/lib/ReaderWriter/MachO/LayoutPass.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/LayoutPass.cpp?rev=302613&r1=302612&r2=302613&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/LayoutPass.cpp?rev=302613&r1=302612&r2=302613&view=diff</a><br>
>> ==============================================================================<br>
>> --- lld/trunk/lib/ReaderWriter/MachO/LayoutPass.cpp (original)<br>
>> +++ lld/trunk/lib/ReaderWriter/MachO/LayoutPass.cpp Tue May 9 20:16:22 2017<br>
>> @@ -461,10 +461,10 @@ llvm::Error LayoutPass::perform(SimpleFi<br>
>> });<br>
>><br>
>> std::vector<LayoutPass::SortKey> vec = decorate(atomRange);<br>
>> - parallel_sort(vec.begin(), vec.end(),<br>
>> - [&](const LayoutPass::SortKey &l, const LayoutPass::SortKey &r) -> bool {<br>
>> - return compareAtoms(l, r, _customSorter);<br>
>> - });<br>
>> + sort(parallel::par, vec.begin(), vec.end(),<br>
>> + [&](const LayoutPass::SortKey &l, const LayoutPass::SortKey &r) -> bool {<br>
>> + return compareAtoms(l, r, _customSorter);<br>
>> + });<br>
>> DEBUG(checkTransitivity(vec, _customSorter));<br>
>> undecorate(atomRange, vec);<br>
>><br>
>><br>
>> Modified: lld/trunk/unittests/CoreTests/ParallelTest.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/CoreTests/ParallelTest.cpp?rev=302613&r1=302612&r2=302613&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/CoreTests/ParallelTest.cpp?rev=302613&r1=302612&r2=302613&view=diff</a><br>
>> ==============================================================================<br>
>> --- lld/trunk/unittests/CoreTests/ParallelTest.cpp (original)<br>
>> +++ lld/trunk/unittests/CoreTests/ParallelTest.cpp Tue May 9 20:16:22 2017<br>
>> @@ -26,7 +26,7 @@ TEST(Parallel, sort) {<br>
>> for (auto &i : array)<br>
>> i = dist(randEngine);<br>
>><br>
>> - lld::parallel_sort(std::begin(array), std::end(array));<br>
>> + sort(lld::parallel::par, std::begin(array), std::end(array));<br>
>> ASSERT_TRUE(std::is_sorted(std::begin(array), std::end(array)));<br>
>> }<br>
>><br>
>> @@ -36,7 +36,7 @@ TEST(Parallel, parallel_for) {<br>
>> // writing.<br>
>> uint32_t range[2050];<br>
>> std::fill(range, range + 2050, 1);<br>
>> - lld::parallel_for(0, 2049, [&range](size_t I) { ++range[I]; });<br>
>> + for_each_n(lld::parallel::par, 0, 2049, [&range](size_t I) { ++range[I]; });<br>
>><br>
>> uint32_t expected[2049];<br>
>> std::fill(expected, expected + 2049, 2);<br>
>><br>
>><br>
>> _______________________________________________<br>
>> llvm-commits mailing list<br>
>> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>