2222#include " lld/Common/ErrorHandler.h"
2323#include " llvm/ADT/CachedHashString.h"
2424#include " llvm/ADT/DenseMap.h"
25- #include " llvm/ADT/MapVector .h"
25+ #include " llvm/ADT/DenseSet .h"
2626#include " llvm/ADT/SetVector.h"
2727#include " llvm/ADT/SmallSet.h"
2828#include " llvm/ADT/SmallVector.h"
3535#include " llvm/Support/VirtualFileSystem.h"
3636#include < memory>
3737#include < optional>
38- #include < set>
3938
4039#define DEBUG_TYPE " bp-section-orderer"
4140
@@ -61,13 +60,9 @@ template <class D> struct BPOrderer {
6160 bool forDataCompression,
6261 bool compressionSortStartupFunctions, bool verbose,
6362 llvm::ArrayRef<Section *> sections,
64- const DenseMap<CachedHashStringRef, std::set <unsigned >>
63+ const DenseMap<CachedHashStringRef, DenseSet <unsigned >>
6564 &rootSymbolToSectionIdxs)
6665 -> llvm::DenseMap<const Section *, int>;
67-
68- std::optional<StringRef> static getResolvedLinkageName (llvm::StringRef name) {
69- return {};
70- }
7166};
7267} // namespace lld
7368
@@ -78,7 +73,7 @@ static SmallVector<std::pair<unsigned, UtilityNodes>> getUnsForCompression(
7873 ArrayRef<const typename D::Section *> sections,
7974 const DenseMap<const void *, uint64_t > §ionToIdx,
8075 ArrayRef<unsigned > sectionIdxs,
81- DenseMap<unsigned , SmallVector<unsigned , 0 >> *duplicateSectionIdxs,
76+ DenseMap<unsigned , SmallVector<unsigned >> *duplicateSectionIdxs,
8277 BPFunctionNode::UtilityNodeT &maxUN) {
8378 TimeTraceScope timeScope (" Build nodes for compression" );
8479
@@ -93,7 +88,7 @@ static SmallVector<std::pair<unsigned, UtilityNodes>> getUnsForCompression(
9388 hashes.clear ();
9489 }
9590
96- MapVector <uint64_t , unsigned > hashFrequency;
91+ DenseMap <uint64_t , unsigned > hashFrequency;
9792 for (auto &[sectionIdx, hashes] : sectionHashes)
9893 for (auto hash : hashes)
9994 ++hashFrequency[hash];
@@ -102,11 +97,10 @@ static SmallVector<std::pair<unsigned, UtilityNodes>> getUnsForCompression(
10297 // Merge sections that are nearly identical
10398 SmallVector<std::pair<unsigned , SmallVector<uint64_t >>> newSectionHashes;
10499 DenseMap<uint64_t , unsigned > wholeHashToSectionIdx;
105- unsigned threshold = sectionHashes.size () > 10000 ? 5 : 0 ;
106100 for (auto &[sectionIdx, hashes] : sectionHashes) {
107101 uint64_t wholeHash = 0 ;
108102 for (auto hash : hashes)
109- if (hashFrequency[hash] > threshold )
103+ if (hashFrequency[hash] > 5 )
110104 wholeHash ^= hash;
111105 auto [it, wasInserted] =
112106 wholeHashToSectionIdx.insert (std::make_pair (wholeHash, sectionIdx));
@@ -162,7 +156,7 @@ auto BPOrderer<D>::computeOrder(
162156 StringRef profilePath, bool forFunctionCompression, bool forDataCompression,
163157 bool compressionSortStartupFunctions, bool verbose,
164158 ArrayRef<Section *> sections,
165- const DenseMap<CachedHashStringRef, std::set <unsigned >>
159+ const DenseMap<CachedHashStringRef, DenseSet <unsigned >>
166160 &rootSymbolToSectionIdxs) -> DenseMap<const Section *, int > {
167161 TimeTraceScope timeScope (" Setup Balanced Partitioning" );
168162 DenseMap<const void *, uint64_t > sectionToIdx;
@@ -186,7 +180,7 @@ auto BPOrderer<D>::computeOrder(
186180 }
187181 auto &traces = reader->getTemporalProfTraces ();
188182
189- MapVector <unsigned , BPFunctionNode::UtilityNodeT> sectionIdxToFirstUN;
183+ DenseMap <unsigned , BPFunctionNode::UtilityNodeT> sectionIdxToFirstUN;
190184 for (size_t traceIdx = 0 ; traceIdx < traces.size (); traceIdx++) {
191185 uint64_t currentSize = 0 , cutoffSize = 1 ;
192186 size_t cutoffTimestamp = 1 ;
@@ -263,7 +257,7 @@ auto BPOrderer<D>::computeOrder(
263257
264258 // Map a section index (order directly) to a list of duplicate section indices
265259 // (not ordered directly).
266- DenseMap<unsigned , SmallVector<unsigned , 0 >> duplicateSectionIdxs;
260+ DenseMap<unsigned , SmallVector<unsigned >> duplicateSectionIdxs;
267261 auto unsForFunctionCompression = getUnsForCompression<D>(
268262 sections, sectionToIdx, sectionIdxsForFunctionCompression,
269263 &duplicateSectionIdxs, maxUN);
0 commit comments