From e90f44b7eba3b8dd4971c95babe71d7c92e95156 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Tue, 17 Mar 2020 12:40:19 -0700 Subject: [PATCH] [lld][COFF][ELF][WebAssembly] Replace --[no-]threads /threads[:no] with --threads={1,2,...} /threads:{1,2,...} --no-threads is a name copied from gold. gold has --no-thread, --thread-count and several other --thread-count-*. There are needs to customize the number of threads (running several lld processes concurrently or customizing the number of LTO threads). Having a single --threads=N is a straightforward replacement of gold's --no-threads + --thread-count. --no-threads is used rarely. So just delete --no-threads instead of keeping it for compatibility for a while. If --threads= is specified (ELF,wasm; COFF /threads: is similar), --thinlto-jobs= defaults to --threads=, otherwise all available hardware threads are used. There is currently no way to override a --threads={1,2,...}. It is still a debate whether we should use --threads=all. Reviewed By: rnk, aganea Differential Revision: https://reviews.llvm.org/D76885 --- include/llvm/Support/Parallel.h | 6 ++++++ lib/Support/Parallel.cpp | 8 +++++++- utils/gn/secondary/lld/Common/BUILD.gn | 1 - 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/llvm/Support/Parallel.h b/include/llvm/Support/Parallel.h index 3c0ed2c1112..e9d04bfb279 100644 --- a/include/llvm/Support/Parallel.h +++ b/include/llvm/Support/Parallel.h @@ -12,6 +12,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/Config/llvm-config.h" #include "llvm/Support/MathExtras.h" +#include "llvm/Support/Threading.h" #include #include @@ -33,6 +34,11 @@ struct is_execution_policy constexpr sequential_execution_policy seq{}; constexpr parallel_execution_policy par{}; +// Strategy for the default executor used by the parallel routines provided by +// this file. It defaults to using all hardware threads and should be +// initialized before the first use of parallel routines. +extern ThreadPoolStrategy strategy; + namespace detail { #if LLVM_ENABLE_THREADS diff --git a/lib/Support/Parallel.cpp b/lib/Support/Parallel.cpp index 0272a53beb3..7f6ce82763d 100644 --- a/lib/Support/Parallel.cpp +++ b/lib/Support/Parallel.cpp @@ -20,6 +20,8 @@ #include #include +llvm::ThreadPoolStrategy llvm::parallel::strategy; + namespace llvm { namespace parallel { namespace detail { @@ -78,6 +80,9 @@ public: T.join(); } + struct Creator { + static void *call() { return new ThreadPoolExecutor(strategy); } + }; struct Deleter { static void call(void *Ptr) { ((ThreadPoolExecutor *)Ptr)->stop(); } }; @@ -131,7 +136,8 @@ Executor *Executor::getDefaultExecutor() { // are more frequent with the debug static runtime. // // This also prevents intermittent deadlocks on exit with the MinGW runtime. - static ManagedStatic, + + static ManagedStatic ManagedExec; static std::unique_ptr Exec(&(*ManagedExec)); diff --git a/utils/gn/secondary/lld/Common/BUILD.gn b/utils/gn/secondary/lld/Common/BUILD.gn index 02f91cde674..125cad30a32 100644 --- a/utils/gn/secondary/lld/Common/BUILD.gn +++ b/utils/gn/secondary/lld/Common/BUILD.gn @@ -39,7 +39,6 @@ static_library("Common") { "Reproduce.cpp", "Strings.cpp", "TargetOptionsCommandFlags.cpp", - "Threads.cpp", "Timer.cpp", "Version.cpp", ]