[lld] 12607f5 - [ELF] Cache compute_thread_count. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 12 19:09:16 PDT 2022
Author: Fangrui Song
Date: 2022-09-12T19:09:08-07:00
New Revision: 12607f57da9aa990eb9ec3f671214058d86ab1b1
URL: https://github.com/llvm/llvm-project/commit/12607f57da9aa990eb9ec3f671214058d86ab1b1
DIFF: https://github.com/llvm/llvm-project/commit/12607f57da9aa990eb9ec3f671214058d86ab1b1.diff
LOG: [ELF] Cache compute_thread_count. NFC
Added:
Modified:
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 26a6d63818957..fcba9216aa966 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -364,6 +364,8 @@ struct Configuration {
// this means to map the primary and thread stacks as PROT_MTE. Note: This is
// not supported on Android 11 & 12.
bool androidMemtagStack;
+
+ unsigned threadCount;
};
// The only instance of Configuration struct.
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 369ef02947177..85d1fb4a749ce 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1363,6 +1363,7 @@ static void readConfigs(opt::InputArgList &args) {
}
if (auto *arg = args.getLastArg(OPT_thinlto_jobs))
config->thinLTOJobs = arg->getValue();
+ config->threadCount = parallel::strategy.compute_thread_count();
if (config->ltoo > 3)
error("invalid optimization level for LTO: " + Twine(config->ltoo));
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 291c925cfb044..ce041c2053ed9 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2769,10 +2769,8 @@ createSymbols(
// of millions for very large executables, so we use multi-threading to
// speed it up.
constexpr size_t numShards = 32;
- size_t concurrency = PowerOf2Floor(
- std::min<size_t>(hardware_concurrency(parallel::strategy.ThreadsRequested)
- .compute_thread_count(),
- numShards));
+ const size_t concurrency =
+ PowerOf2Floor(std::min<size_t>(config->threadCount, numShards));
// A sharded map to uniquify symbols by name.
auto map =
@@ -3257,10 +3255,8 @@ void MergeNoTailSection::finalizeContents() {
// Concurrency level. Must be a power of 2 to avoid expensive modulo
// operations in the following tight loop.
- size_t concurrency = PowerOf2Floor(
- std::min<size_t>(hardware_concurrency(parallel::strategy.ThreadsRequested)
- .compute_thread_count(),
- numShards));
+ const size_t concurrency =
+ PowerOf2Floor(std::min<size_t>(config->threadCount, numShards));
// Add section pieces to the builders.
parallelFor(0, concurrency, [&](size_t threadId) {
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 9124961a5089f..cc8742e652b64 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -317,7 +317,7 @@ template <class ELFT> void elf::createSyntheticSections() {
StringRef relaDynName = config->isRela ? ".rela.dyn" : ".rel.dyn";
- const unsigned threadCount = parallel::strategy.compute_thread_count();
+ const unsigned threadCount = config->threadCount;
for (Partition &part : partitions) {
auto add = [&](SyntheticSection &sec) {
sec.partition = part.getNumber();
More information about the llvm-commits
mailing list