Skip to content

Commit 197ee8b

Browse files
committed
more comment. optimize
Created using spr 1.3.5-bogner
1 parent 4ba6a90 commit 197ee8b

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

lld/MachO/BPSectionOrderer.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,32 +118,31 @@ struct BPOrdererMachO : lld::BPOrderer<BPOrdererMachO> {
118118
DenseMap<const InputSection *, int> lld::macho::runBalancedPartitioning(
119119
StringRef profilePath, bool forFunctionCompression, bool forDataCompression,
120120
bool compressionSortStartupFunctions, bool verbose) {
121+
// Collect candidate sections and associated symbols.
121122
SmallVector<InputSection *> sections;
122-
DenseMap<StringRef, DenseSet<unsigned>> symbolToSectionIdxs;
123+
DenseMap<CachedHashStringRef, DenseSet<unsigned>> rootSymbolToSectionIdxs;
123124
for (const auto *file : inputFiles) {
124125
for (auto *sec : file->sections) {
125126
for (auto &subsec : sec->subsections) {
126127
auto *isec = subsec.isec;
127128
if (!isec || isec->data.empty())
128129
continue;
129-
for (auto *sym : BPOrdererMachO::getSymbols(*isec))
130-
symbolToSectionIdxs[sym->getName()].insert(sections.size());
130+
size_t idx = sections.size();
131131
sections.emplace_back(isec);
132+
for (auto *sym : BPOrdererMachO::getSymbols(*isec)) {
133+
auto rootName = getRootSymbol(sym->getName());
134+
rootSymbolToSectionIdxs[CachedHashStringRef(rootName)].insert(idx);
135+
if (auto linkageName =
136+
BPOrdererMachO::getResolvedLinkageName(rootName))
137+
rootSymbolToSectionIdxs[CachedHashStringRef(*linkageName)].insert(
138+
idx);
139+
}
132140
}
133141
}
134142
}
135143

136-
DenseMap<CachedHashStringRef, DenseSet<unsigned>> rootSymbolToSectionIdxs;
137-
for (auto &[name, sectionIdxs] : symbolToSectionIdxs) {
138-
auto rootName = getRootSymbol(name);
139-
rootSymbolToSectionIdxs[CachedHashStringRef(rootName)].insert(
140-
sectionIdxs.begin(), sectionIdxs.end());
141-
if (auto linkageName = BPOrdererMachO::getResolvedLinkageName(rootName))
142-
rootSymbolToSectionIdxs[CachedHashStringRef(*linkageName)].insert(
143-
sectionIdxs.begin(), sectionIdxs.end());
144-
}
145-
return BPOrdererMachO::reorderSections(
146-
profilePath, forFunctionCompression, forDataCompression,
147-
compressionSortStartupFunctions, verbose, sections,
148-
rootSymbolToSectionIdxs);
144+
return BPOrdererMachO::computeOrder(profilePath, forFunctionCompression,
145+
forDataCompression,
146+
compressionSortStartupFunctions, verbose,
147+
sections, rootSymbolToSectionIdxs);
149148
}

lld/include/lld/Common/BPSectionOrdererBase.inc

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@ template <class D> struct BPOrderer {
4848
using Section = typename BPOrdererTraits<D>::Section;
4949
using Symbol = typename BPOrdererTraits<D>::Symbol;
5050

51-
// Reorder sections using balanced partitioning algorithm based on profile.
51+
// Compute a section order using the Balanced Partitioning algorithm.
52+
//
53+
// * for*Compresion: Improve Lempel-Ziv compression by grouping
54+
// similar sections together.
55+
// * profilePath: Utilize a temporal profile file to reduce page faults during
56+
// program startup.
57+
// * compressionSortStartupFunctions: if profilePath is specified, allocate
58+
// extra utility vertices to prioritize nearby function similarity.
5259
static auto
53-
reorderSections(llvm::StringRef profilePath, bool forFunctionCompression,
54-
bool forDataCompression, bool compressionSortStartupFunctions,
55-
bool verbose, llvm::ArrayRef<Section *> sections,
56-
const DenseMap<CachedHashStringRef, DenseSet<unsigned>>
57-
&rootSymbolToSectionIdxs)
60+
computeOrder(llvm::StringRef profilePath, bool forFunctionCompression,
61+
bool forDataCompression, bool compressionSortStartupFunctions,
62+
bool verbose, llvm::ArrayRef<Section *> sections,
63+
const DenseMap<CachedHashStringRef, DenseSet<unsigned>>
64+
&rootSymbolToSectionIdxs)
5865
-> llvm::DenseMap<const Section *, int>;
5966
};
6067
} // namespace lld
@@ -145,7 +152,7 @@ inline StringRef getRootSymbol(StringRef name) {
145152
}
146153

147154
template <class D>
148-
auto BPOrderer<D>::reorderSections(
155+
auto BPOrderer<D>::computeOrder(
149156
StringRef profilePath, bool forFunctionCompression, bool forDataCompression,
150157
bool compressionSortStartupFunctions, bool verbose,
151158
ArrayRef<Section *> sections,

0 commit comments

Comments
 (0)