Skip to content

Commit 115bb87

Browse files
committed
[lld] BPSectionOrderer: replace Symbol with Defined and optimize getSymbols. NFC
1 parent da2b415 commit 115bb87

File tree

2 files changed

+19
-29
lines changed

2 files changed

+19
-29
lines changed

lld/MachO/BPSectionOrderer.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,16 @@ struct BPOrdererMachO;
2626
}
2727
template <> struct lld::BPOrdererTraits<struct BPOrdererMachO> {
2828
using Section = macho::InputSection;
29-
using Symbol = macho::Symbol;
29+
using Defined = macho::Defined;
3030
};
3131
namespace {
3232
struct BPOrdererMachO : lld::BPOrderer<BPOrdererMachO> {
3333
static uint64_t getSize(const Section &sec) { return sec.getSize(); }
3434
static bool isCodeSection(const Section &sec) {
3535
return macho::isCodeSection(&sec);
3636
}
37-
static SmallVector<Symbol *, 0> getSymbols(const Section &sec) {
38-
SmallVector<Symbol *, 0> symbols;
39-
for (auto *sym : sec.symbols)
40-
if (auto *d = llvm::dyn_cast_or_null<Defined>(sym))
41-
symbols.emplace_back(d);
42-
return symbols;
37+
static ArrayRef<Defined *> getSymbols(const Section &sec) {
38+
return sec.symbols;
4339
}
4440

4541
// Linkage names can be prefixed with "_" or "l_" on Mach-O. See
@@ -80,17 +76,11 @@ struct BPOrdererMachO : lld::BPOrderer<BPOrdererMachO> {
8076
hashes.erase(std::unique(hashes.begin(), hashes.end()), hashes.end());
8177
}
8278

83-
static llvm::StringRef getSymName(const Symbol &sym) { return sym.getName(); }
84-
static uint64_t getSymValue(const Symbol &sym) {
85-
if (auto *d = dyn_cast<Defined>(&sym))
86-
return d->value;
87-
return 0;
88-
}
89-
static uint64_t getSymSize(const Symbol &sym) {
90-
if (auto *d = dyn_cast<Defined>(&sym))
91-
return d->size;
92-
return 0;
79+
static llvm::StringRef getSymName(const Defined &sym) {
80+
return sym.getName();
9381
}
82+
static uint64_t getSymValue(const Defined &sym) { return sym.value; }
83+
static uint64_t getSymSize(const Defined &sym) { return sym.size; }
9484

9585
private:
9686
static uint64_t
@@ -141,8 +131,8 @@ DenseMap<const InputSection *, int> lld::macho::runBalancedPartitioning(
141131
}
142132
}
143133

144-
return BPOrdererMachO::computeOrder(profilePath, forFunctionCompression,
145-
forDataCompression,
146-
compressionSortStartupFunctions, verbose,
147-
sections, rootSymbolToSectionIdxs);
134+
return BPOrdererMachO().computeOrder(profilePath, forFunctionCompression,
135+
forDataCompression,
136+
compressionSortStartupFunctions, verbose,
137+
sections, rootSymbolToSectionIdxs);
148138
}

lld/include/lld/Common/BPSectionOrdererBase.inc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ template <class D> struct BPOrdererTraits;
4646

4747
template <class D> struct BPOrderer {
4848
using Section = typename BPOrdererTraits<D>::Section;
49-
using Symbol = typename BPOrdererTraits<D>::Symbol;
49+
using Defined = typename BPOrdererTraits<D>::Defined;
5050

5151
// Compute a section order using the Balanced Partitioning algorithm.
5252
//
@@ -56,12 +56,12 @@ template <class D> struct BPOrderer {
5656
// program startup.
5757
// * compressionSortStartupFunctions: if profilePath is specified, allocate
5858
// extra utility vertices to prioritize nearby function similarity.
59-
static auto
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)
59+
auto computeOrder(llvm::StringRef profilePath, bool forFunctionCompression,
60+
bool forDataCompression,
61+
bool compressionSortStartupFunctions, bool verbose,
62+
llvm::ArrayRef<Section *> sections,
63+
const DenseMap<CachedHashStringRef, DenseSet<unsigned>>
64+
&rootSymbolToSectionIdxs)
6565
-> llvm::DenseMap<const Section *, int>;
6666
};
6767
} // namespace lld
@@ -357,7 +357,7 @@ auto BPOrderer<D>::computeOrder(
357357
const uint64_t pageSize = (1 << 14);
358358
uint64_t currentAddress = 0;
359359
for (const auto *isec : orderedSections) {
360-
for (auto *sym : D::getSymbols(*isec)) {
360+
for (auto *sym : static_cast<D *>(this)->getSymbols(*isec)) {
361361
uint64_t startAddress = currentAddress + D::getSymValue(*sym);
362362
uint64_t endAddress = startAddress + D::getSymSize(*sym);
363363
uint64_t firstPage = startAddress / pageSize;

0 commit comments

Comments
 (0)