summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/Common/CMakeLists.txt1
-rw-r--r--lld/Common/Threads.cpp (renamed from lld/ELF/Threads.cpp)8
-rw-r--r--lld/ELF/CMakeLists.txt1
-rw-r--r--lld/ELF/Config.h1
-rw-r--r--lld/ELF/Driver.cpp4
-rw-r--r--lld/ELF/Error.cpp3
-rw-r--r--lld/ELF/Filesystem.cpp4
-rw-r--r--lld/ELF/ICF.cpp4
-rw-r--r--lld/ELF/LinkerScript.cpp2
-rw-r--r--lld/ELF/MapFile.cpp3
-rw-r--r--lld/ELF/OutputSections.cpp2
-rw-r--r--lld/ELF/SyntheticSections.cpp4
-rw-r--r--lld/ELF/Writer.cpp2
-rw-r--r--lld/include/lld/Common/Threads.h (renamed from lld/ELF/Threads.h)14
14 files changed, 27 insertions, 26 deletions
diff --git a/lld/Common/CMakeLists.txt b/lld/Common/CMakeLists.txt
index a3d42a43dc2..97187cb2b8b 100644
--- a/lld/Common/CMakeLists.txt
+++ b/lld/Common/CMakeLists.txt
@@ -5,6 +5,7 @@ endif()
add_lld_library(lldCommon
Reproduce.cpp
TargetOptionsCommandFlags.cpp
+ Threads.cpp
Version.cpp
ADDITIONAL_HEADER_DIRS
diff --git a/lld/ELF/Threads.cpp b/lld/Common/Threads.cpp
index b3625b9e278..86c8f43f5fc 100644
--- a/lld/ELF/Threads.cpp
+++ b/lld/Common/Threads.cpp
@@ -7,13 +7,15 @@
//
//===----------------------------------------------------------------------===//
-#include "Threads.h"
+#include "lld/Common/Threads.h"
#include <thread>
static std::vector<std::thread> Threads;
+bool lld::ThreadsEnabled = true;
+
// Runs a given function in a new thread.
-void lld::elf::runBackground(std::function<void()> Fn) {
+void lld::runBackground(std::function<void()> Fn) {
Threads.emplace_back(Fn);
}
@@ -22,7 +24,7 @@ void lld::elf::runBackground(std::function<void()> Fn) {
// You need to call this function from the main thread before exiting
// because it is not defined what will happen to non-main threads when
// the main thread exits.
-void lld::elf::waitForBackgroundThreads() {
+void lld::waitForBackgroundThreads() {
for (std::thread &T : Threads)
if (T.joinable())
T.join();
diff --git a/lld/ELF/CMakeLists.txt b/lld/ELF/CMakeLists.txt
index c4db3e9069f..2057029751e 100644
--- a/lld/ELF/CMakeLists.txt
+++ b/lld/ELF/CMakeLists.txt
@@ -40,7 +40,6 @@ add_lld_library(lldELF
Symbols.cpp
SyntheticSections.cpp
Target.cpp
- Threads.cpp
Thunks.cpp
Writer.cpp
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 83c25faa31e..0410bc4c04e 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -139,7 +139,6 @@ struct Configuration {
bool Static = false;
bool SysvHash = false;
bool Target1Rel;
- bool Threads;
bool Trace;
bool Verbose;
bool WarnCommon;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 04c1c3fc504..af56b2ba3aa 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -38,9 +38,9 @@
#include "SymbolTable.h"
#include "SyntheticSections.h"
#include "Target.h"
-#include "Threads.h"
#include "Writer.h"
#include "lld/Common/Driver.h"
+#include "lld/Common/Threads.h"
#include "lld/Common/Version.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
@@ -684,7 +684,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
parseCachePruningPolicy(Args.getLastArgValue(OPT_thinlto_cache_policy)),
"--thinlto-cache-policy: invalid cache policy");
Config->ThinLTOJobs = getInteger(Args, OPT_thinlto_jobs, -1u);
- Config->Threads = getArg(Args, OPT_threads, OPT_no_threads, true);
+ ThreadsEnabled = getArg(Args, OPT_threads, OPT_no_threads, true);
Config->Trace = Args.hasArg(OPT_trace);
Config->Undefined = getArgs(Args, OPT_undefined);
Config->UnresolvedSymbols = getUnresolvedSymbolPolicy(Args);
diff --git a/lld/ELF/Error.cpp b/lld/ELF/Error.cpp
index f2d40a01306..8173d6ff220 100644
--- a/lld/ELF/Error.cpp
+++ b/lld/ELF/Error.cpp
@@ -9,7 +9,8 @@
#include "Error.h"
#include "Config.h"
-#include "Threads.h"
+
+#include "lld/Common/Threads.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Error.h"
diff --git a/lld/ELF/Filesystem.cpp b/lld/ELF/Filesystem.cpp
index 03dd2e8d177..35310b05254 100644
--- a/lld/ELF/Filesystem.cpp
+++ b/lld/ELF/Filesystem.cpp
@@ -13,7 +13,7 @@
#include "Filesystem.h"
#include "Config.h"
-#include "Threads.h"
+#include "lld/Common/Threads.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/FileSystem.h"
@@ -38,7 +38,7 @@ using namespace lld::elf;
// This function spawns a background thread to call unlink.
// The calling thread returns almost immediately.
void elf::unlinkAsync(StringRef Path) {
- if (!Config->Threads || !sys::fs::exists(Config->OutputFile) ||
+ if (!ThreadsEnabled || !sys::fs::exists(Config->OutputFile) ||
!sys::fs::is_regular_file(Config->OutputFile))
return;
diff --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp
index 30b9be91bd3..4de4054fe3c 100644
--- a/lld/ELF/ICF.cpp
+++ b/lld/ELF/ICF.cpp
@@ -76,7 +76,7 @@
#include "ICF.h"
#include "Config.h"
#include "SymbolTable.h"
-#include "Threads.h"
+#include "lld/Common/Threads.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/Object/ELF.h"
@@ -366,7 +366,7 @@ template <class ELFT>
void ICF<ELFT>::forEachClass(std::function<void(size_t, size_t)> Fn) {
// If threading is disabled or the number of sections are
// too small to use threading, call Fn sequentially.
- if (!Config->Threads || Sections.size() < 1024) {
+ if (!ThreadsEnabled || Sections.size() < 1024) {
forEachClassRange(0, Sections.size(), Fn);
++Cnt;
return;
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 90a7e95534a..3149c98e3c6 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -21,8 +21,8 @@
#include "Symbols.h"
#include "SyntheticSections.h"
#include "Target.h"
-#include "Threads.h"
#include "Writer.h"
+#include "lld/Common/Threads.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/ELF.h"
diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp
index 968dc611b81..ad80b0696eb 100644
--- a/lld/ELF/MapFile.cpp
+++ b/lld/ELF/MapFile.cpp
@@ -26,7 +26,8 @@
#include "Strings.h"
#include "SymbolTable.h"
#include "SyntheticSections.h"
-#include "Threads.h"
+
+#include "lld/Common/Threads.h"
#include "llvm/Support/raw_ostream.h"
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 477d0b3a722..800ab2eb3cc 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -15,7 +15,7 @@
#include "SymbolTable.h"
#include "SyntheticSections.h"
#include "Target.h"
-#include "Threads.h"
+#include "lld/Common/Threads.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/Support/Compression.h"
#include "llvm/Support/MD5.h"
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 6020c0de375..ec823bec2b6 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -24,8 +24,8 @@
#include "Strings.h"
#include "SymbolTable.h"
#include "Target.h"
-#include "Threads.h"
#include "Writer.h"
+#include "lld/Common/Threads.h"
#include "lld/Common/Version.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
@@ -2258,7 +2258,7 @@ void MergeNoTailSection::finalizeContents() {
// Concurrency level. Must be a power of 2 to avoid expensive modulo
// operations in the following tight loop.
size_t Concurrency = 1;
- if (Config->Threads)
+ if (ThreadsEnabled)
Concurrency =
std::min<size_t>(PowerOf2Floor(hardware_concurrency()), NumShards);
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index ebb042e05aa..950fcdd2037 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -19,7 +19,7 @@
#include "SymbolTable.h"
#include "SyntheticSections.h"
#include "Target.h"
-#include "Threads.h"
+#include "lld/Common/Threads.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/FileOutputBuffer.h"
diff --git a/lld/ELF/Threads.h b/lld/include/lld/Common/Threads.h
index f29e4e96f99..981946723bc 100644
--- a/lld/ELF/Threads.h
+++ b/lld/include/lld/Common/Threads.h
@@ -56,19 +56,18 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLD_ELF_THREADS_H
-#define LLD_ELF_THREADS_H
-
-#include "Config.h"
+#ifndef LLD_COMMON_THREADS_H
+#define LLD_COMMON_THREADS_H
#include "llvm/Support/Parallel.h"
#include <functional>
namespace lld {
-namespace elf {
+
+extern bool ThreadsEnabled;
template <typename R, class FuncTy> void parallelForEach(R &&Range, FuncTy Fn) {
- if (Config->Threads)
+ if (ThreadsEnabled)
for_each(llvm::parallel::par, std::begin(Range), std::end(Range), Fn);
else
for_each(llvm::parallel::seq, std::begin(Range), std::end(Range), Fn);
@@ -76,7 +75,7 @@ template <typename R, class FuncTy> void parallelForEach(R &&Range, FuncTy Fn) {
inline void parallelForEachN(size_t Begin, size_t End,
std::function<void(size_t)> Fn) {
- if (Config->Threads)
+ if (ThreadsEnabled)
for_each_n(llvm::parallel::par, Begin, End, Fn);
else
for_each_n(llvm::parallel::seq, Begin, End, Fn);
@@ -85,7 +84,6 @@ inline void parallelForEachN(size_t Begin, size_t End,
void runBackground(std::function<void()> Fn);
void waitForBackgroundThreads();
-} // namespace elf
} // namespace lld
#endif
OpenPOWER on IntegriCloud