[lld] 52b3e89 - [ELF] Simplify GdbIndexSection. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 8 11:45:48 PST 2024
Author: Fangrui Song
Date: 2024-03-08T11:45:43-08:00
New Revision: 52b3e89ff4517521e40f5e416a40e574321eaee9
URL: https://github.com/llvm/llvm-project/commit/52b3e89ff4517521e40f5e416a40e574321eaee9
DIFF: https://github.com/llvm/llvm-project/commit/52b3e89ff4517521e40f5e416a40e574321eaee9.diff
LOG: [ELF] Simplify GdbIndexSection. NFC
Added:
Modified:
lld/ELF/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index b6bdc350bc0dd1..66b3e835cabc57 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2805,21 +2805,16 @@ createSymbols(
cuIdx += chunks[i].compilationUnits.size();
}
- // The number of symbols we will handle in this function is of the order
- // of millions for very large executables, so we use multi-threading to
- // speed it up.
+ // Collect the compilation unitss for each unique name. Speed it up using
+ // multi-threading as the number of symbols can be in the order of millions.
+ // Shard GdbSymbols by hash's high bits.
constexpr size_t numShards = 32;
const size_t concurrency =
llvm::bit_floor(std::min<size_t>(config->threadCount, numShards));
-
- // A sharded map to uniquify symbols by name.
+ const size_t shift = 32 - llvm::countr_zero(numShards);
auto map =
std::make_unique<DenseMap<CachedHashStringRef, size_t>[]>(numShards);
- size_t shift = 32 - llvm::countr_zero(numShards);
-
- // Instantiate GdbSymbols while uniqufying them by name.
auto symbols = std::make_unique<SmallVector<GdbSymbol, 0>[]>(numShards);
-
parallelFor(0, concurrency, [&](size_t threadId) {
uint32_t i = 0;
for (ArrayRef<NameAttrEntry> entries : nameAttrs) {
@@ -2829,14 +2824,12 @@ createSymbols(
continue;
uint32_t v = ent.cuIndexAndAttrs + cuIdxs[i];
- size_t &idx = map[shardId][ent.name];
- if (idx) {
- symbols[shardId][idx - 1].cuVector.push_back(v);
- continue;
- }
-
- idx = symbols[shardId].size() + 1;
- symbols[shardId].push_back({ent.name, {v}, 0, 0});
+ auto [it, inserted] =
+ map[shardId].try_emplace(ent.name, symbols[shardId].size());
+ if (inserted)
+ symbols[shardId].push_back({ent.name, {v}, 0, 0});
+ else
+ symbols[shardId][it->second].cuVector.push_back(v);
}
++i;
}
More information about the llvm-commits
mailing list