From 0185ab1cf30c7394b1ec86ea11b1fad0161e2218 Mon Sep 17 00:00:00 2001 From: Kevin Frei Date: Mon, 22 Apr 2024 16:08:41 -0700 Subject: [PATCH] Clean up the aggregation code, and pass the aggregator by reference --- llvm/include/llvm/DebugInfo/GSYM/OutputAggregator.h | 9 ++++----- llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/DebugInfo/GSYM/OutputAggregator.h b/llvm/include/llvm/DebugInfo/GSYM/OutputAggregator.h index 8deea3bff1ed7..35ef0a8bc8908 100644 --- a/llvm/include/llvm/DebugInfo/GSYM/OutputAggregator.h +++ b/llvm/include/llvm/DebugInfo/GSYM/OutputAggregator.h @@ -57,13 +57,12 @@ class OutputAggregator { } // For multi-threaded usage, we can collect stuff in another aggregator, - // then merge it in here + // then merge it in here. Note that this is *not* thread safe. It is up to + // the caller to ensure that this is only called from one thread at a time. void Merge(const OutputAggregator &other) { for (auto &&[name, count] : other.Aggregation) { - auto it = Aggregation.find(name); - if (it == Aggregation.end()) - Aggregation.emplace(name, count); - else + auto [it, inserted] = Aggregation.emplace(name, count); + if (!inserted) it->second += count; } } diff --git a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp index ff6b560d11726..601686fdd3dd5 100644 --- a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp +++ b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp @@ -612,7 +612,7 @@ Error DwarfTransformer::convert(uint32_t NumThreads, OutputAggregator &Out) { DWARFDie Die = getDie(*CU); if (Die) { CUInfo CUI(DICtx, dyn_cast(CU.get())); - pool.async([this, CUI, &LogMutex, Out, Die]() mutable { + pool.async([this, CUI, &LogMutex, &Out, Die]() mutable { std::string storage; raw_string_ostream StrStream(storage); OutputAggregator ThreadOut(Out.GetOS() ? &StrStream : nullptr);