@@ -2805,21 +2805,16 @@ createSymbols(
2805
2805
cuIdx += chunks[i].compilationUnits .size ();
2806
2806
}
2807
2807
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 .
2811
2811
constexpr size_t numShards = 32 ;
2812
2812
const size_t concurrency =
2813
2813
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);
2816
2815
auto map =
2817
2816
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.
2821
2817
auto symbols = std::make_unique<SmallVector<GdbSymbol, 0 >[]>(numShards);
2822
-
2823
2818
parallelFor (0 , concurrency, [&](size_t threadId) {
2824
2819
uint32_t i = 0 ;
2825
2820
for (ArrayRef<NameAttrEntry> entries : nameAttrs) {
@@ -2829,14 +2824,12 @@ createSymbols(
2829
2824
continue ;
2830
2825
2831
2826
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);
2840
2833
}
2841
2834
++i;
2842
2835
}
0 commit comments