[lld] 115bb87 - [lld] BPSectionOrderer: replace Symbol with Defined and optimize getSymbols. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 2 15:43:07 PST 2025
Author: Fangrui Song
Date: 2025-02-02T15:43:01-08:00
New Revision: 115bb87ad0a85d8ab4d907399db130cb1f2c63f2
URL: https://github.com/llvm/llvm-project/commit/115bb87ad0a85d8ab4d907399db130cb1f2c63f2
DIFF: https://github.com/llvm/llvm-project/commit/115bb87ad0a85d8ab4d907399db130cb1f2c63f2.diff
LOG: [lld] BPSectionOrderer: replace Symbol with Defined and optimize getSymbols. NFC
Added:
Modified:
lld/MachO/BPSectionOrderer.cpp
lld/include/lld/Common/BPSectionOrdererBase.inc
Removed:
################################################################################
diff --git a/lld/MachO/BPSectionOrderer.cpp b/lld/MachO/BPSectionOrderer.cpp
index e2f7a387deebc4..ee0a62cb0a2d80 100644
--- a/lld/MachO/BPSectionOrderer.cpp
+++ b/lld/MachO/BPSectionOrderer.cpp
@@ -26,7 +26,7 @@ struct BPOrdererMachO;
}
template <> struct lld::BPOrdererTraits<struct BPOrdererMachO> {
using Section = macho::InputSection;
- using Symbol = macho::Symbol;
+ using Defined = macho::Defined;
};
namespace {
struct BPOrdererMachO : lld::BPOrderer<BPOrdererMachO> {
@@ -34,12 +34,8 @@ struct BPOrdererMachO : lld::BPOrderer<BPOrdererMachO> {
static bool isCodeSection(const Section &sec) {
return macho::isCodeSection(&sec);
}
- static SmallVector<Symbol *, 0> getSymbols(const Section &sec) {
- SmallVector<Symbol *, 0> symbols;
- for (auto *sym : sec.symbols)
- if (auto *d = llvm::dyn_cast_or_null<Defined>(sym))
- symbols.emplace_back(d);
- return symbols;
+ static ArrayRef<Defined *> getSymbols(const Section &sec) {
+ return sec.symbols;
}
// Linkage names can be prefixed with "_" or "l_" on Mach-O. See
@@ -80,17 +76,11 @@ struct BPOrdererMachO : lld::BPOrderer<BPOrdererMachO> {
hashes.erase(std::unique(hashes.begin(), hashes.end()), hashes.end());
}
- static llvm::StringRef getSymName(const Symbol &sym) { return sym.getName(); }
- static uint64_t getSymValue(const Symbol &sym) {
- if (auto *d = dyn_cast<Defined>(&sym))
- return d->value;
- return 0;
- }
- static uint64_t getSymSize(const Symbol &sym) {
- if (auto *d = dyn_cast<Defined>(&sym))
- return d->size;
- return 0;
+ static llvm::StringRef getSymName(const Defined &sym) {
+ return sym.getName();
}
+ static uint64_t getSymValue(const Defined &sym) { return sym.value; }
+ static uint64_t getSymSize(const Defined &sym) { return sym.size; }
private:
static uint64_t
@@ -141,8 +131,8 @@ DenseMap<const InputSection *, int> lld::macho::runBalancedPartitioning(
}
}
- return BPOrdererMachO::computeOrder(profilePath, forFunctionCompression,
- forDataCompression,
- compressionSortStartupFunctions, verbose,
- sections, rootSymbolToSectionIdxs);
+ return BPOrdererMachO().computeOrder(profilePath, forFunctionCompression,
+ forDataCompression,
+ compressionSortStartupFunctions, verbose,
+ sections, rootSymbolToSectionIdxs);
}
diff --git a/lld/include/lld/Common/BPSectionOrdererBase.inc b/lld/include/lld/Common/BPSectionOrdererBase.inc
index 9a2ee4d507384a..cb6e7ebcbd96b7 100644
--- a/lld/include/lld/Common/BPSectionOrdererBase.inc
+++ b/lld/include/lld/Common/BPSectionOrdererBase.inc
@@ -46,7 +46,7 @@ template <class D> struct BPOrdererTraits;
template <class D> struct BPOrderer {
using Section = typename BPOrdererTraits<D>::Section;
- using Symbol = typename BPOrdererTraits<D>::Symbol;
+ using Defined = typename BPOrdererTraits<D>::Defined;
// Compute a section order using the Balanced Partitioning algorithm.
//
@@ -56,12 +56,12 @@ template <class D> struct BPOrderer {
// program startup.
// * compressionSortStartupFunctions: if profilePath is specified, allocate
// extra utility vertices to prioritize nearby function similarity.
- static auto
- computeOrder(llvm::StringRef profilePath, bool forFunctionCompression,
- bool forDataCompression, bool compressionSortStartupFunctions,
- bool verbose, llvm::ArrayRef<Section *> sections,
- const DenseMap<CachedHashStringRef, DenseSet<unsigned>>
- &rootSymbolToSectionIdxs)
+ auto computeOrder(llvm::StringRef profilePath, bool forFunctionCompression,
+ bool forDataCompression,
+ bool compressionSortStartupFunctions, bool verbose,
+ llvm::ArrayRef<Section *> sections,
+ const DenseMap<CachedHashStringRef, DenseSet<unsigned>>
+ &rootSymbolToSectionIdxs)
-> llvm::DenseMap<const Section *, int>;
};
} // namespace lld
@@ -357,7 +357,7 @@ auto BPOrderer<D>::computeOrder(
const uint64_t pageSize = (1 << 14);
uint64_t currentAddress = 0;
for (const auto *isec : orderedSections) {
- for (auto *sym : D::getSymbols(*isec)) {
+ for (auto *sym : static_cast<D *>(this)->getSymbols(*isec)) {
uint64_t startAddress = currentAddress + D::getSymValue(*sym);
uint64_t endAddress = startAddress + D::getSymSize(*sym);
uint64_t firstPage = startAddress / pageSize;
More information about the llvm-commits
mailing list