Skip to content

Commit 52b3e89

Browse files
committed
[ELF] Simplify GdbIndexSection. NFC
1 parent 0876668 commit 52b3e89

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

lld/ELF/SyntheticSections.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2805,21 +2805,16 @@ createSymbols(
28052805
cuIdx += chunks[i].compilationUnits.size();
28062806
}
28072807

2808-
// The number of symbols we will handle in this function is of the order
2809-
// of millions for very large executables, so we use multi-threading to
2810-
// speed it up.
2808+
// Collect the compilation unitss for each unique name. Speed it up using
2809+
// multi-threading as the number of symbols can be in the order of millions.
2810+
// Shard GdbSymbols by hash's high bits.
28112811
constexpr size_t numShards = 32;
28122812
const size_t concurrency =
28132813
llvm::bit_floor(std::min<size_t>(config->threadCount, numShards));
2814-
2815-
// A sharded map to uniquify symbols by name.
2814+
const size_t shift = 32 - llvm::countr_zero(numShards);
28162815
auto map =
28172816
std::make_unique<DenseMap<CachedHashStringRef, size_t>[]>(numShards);
2818-
size_t shift = 32 - llvm::countr_zero(numShards);
2819-
2820-
// Instantiate GdbSymbols while uniqufying them by name.
28212817
auto symbols = std::make_unique<SmallVector<GdbSymbol, 0>[]>(numShards);
2822-
28232818
parallelFor(0, concurrency, [&](size_t threadId) {
28242819
uint32_t i = 0;
28252820
for (ArrayRef<NameAttrEntry> entries : nameAttrs) {
@@ -2829,14 +2824,12 @@ createSymbols(
28292824
continue;
28302825

28312826
uint32_t v = ent.cuIndexAndAttrs + cuIdxs[i];
2832-
size_t &idx = map[shardId][ent.name];
2833-
if (idx) {
2834-
symbols[shardId][idx - 1].cuVector.push_back(v);
2835-
continue;
2836-
}
2837-
2838-
idx = symbols[shardId].size() + 1;
2839-
symbols[shardId].push_back({ent.name, {v}, 0, 0});
2827+
auto [it, inserted] =
2828+
map[shardId].try_emplace(ent.name, symbols[shardId].size());
2829+
if (inserted)
2830+
symbols[shardId].push_back({ent.name, {v}, 0, 0});
2831+
else
2832+
symbols[shardId][it->second].cuVector.push_back(v);
28402833
}
28412834
++i;
28422835
}

0 commit comments

Comments
 (0)