[lld] [lld][ELF] Extend profile guided function ordering to ELF binaries (PR #117514)
Ellis Hoag via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 12 09:58:13 PST 2024
================
@@ -123,13 +124,17 @@ class BPSectionMacho : public BPSectionBase {
static bool classof(const BPSectionBase *s) { return true; }
private:
- static uint64_t getRelocHash(const Reloc &reloc,
- const BPSectionMacho *section) {
+ static uint64_t getRelocHash(
+ const Reloc &reloc,
+ const llvm::DenseMap<const BPSectionBase *, uint64_t> §ionToIdx) {
auto *isec = reloc.getReferentInputSection();
std::optional<uint64_t> sectionIdx;
- if (isec && isec == section->getSection())
- sectionIdx = section->getSectionIdx();
-
+ for (const auto &entry : sectionToIdx)
+ if (const auto *bpSection = llvm::dyn_cast<BPSectionMacho>(entry.first))
+ if (bpSection->getSection() == isec) {
+ sectionIdx = entry.second;
+ break;
+ }
----------------
ellishg wrote:
This seems to do what we want, but it is very inefficient because we are iterating over the whole map. We should instead use `DenseMap<const InputSection *, uint64_t>` so we can simply use `sectionToIdx.find(isec)`.
https://github.com/llvm/llvm-project/pull/117514
More information about the llvm-commits
mailing list