diff options
author | Micah Weston <micahsweston@gmail.com> | 2023-12-12 10:23:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-12 10:23:16 -0500 |
commit | 105adf2cd9588b4839fbdc7287bb76a962fdb8ca (patch) | |
tree | 97b61f42c2cbb7cfab57545ba350362be932378d /llvm/lib/Object/ELFObjectFile.cpp | |
parent | ef35da825f38a86e4621c13a2898d561da88991c (diff) | |
download | llvm-105adf2cd9588b4839fbdc7287bb76a962fdb8ca.zip llvm-105adf2cd9588b4839fbdc7287bb76a962fdb8ca.tar.gz llvm-105adf2cd9588b4839fbdc7287bb76a962fdb8ca.tar.bz2 |
[SHT_LLVM_BB_ADDR_MAP] Implements PGOAnalysisMap in Object and ObjectYAML with tests.
Reviewed in PR (#71750). A part of [RFC - PGO Accuracy Metrics: Emitting and Evaluating Branch
and Block
Analysis](https://discourse.llvm.org/t/rfc-pgo-accuracy-metrics-emitting-and-evaluating-branch-and-block-analysis/73902).
This PR adds the PGOAnalysisMap data structure and implements encoding and
decoding through Object and ObjectYAML along with associated tests. When
emitted into the bb-addr-map section, each function is followed by the associated
pgo-analysis-map for that function. The emitting of each analysis in the map is
controlled by a bit in the bb-addr-map feature byte. All existing bb-addr-map
code can ignore the pgo-analysis-map if the caller does not request the data.
Diffstat (limited to 'llvm/lib/Object/ELFObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/ELFObjectFile.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp index 25dbcbd..3c86b0f 100644 --- a/llvm/lib/Object/ELFObjectFile.cpp +++ b/llvm/lib/Object/ELFObjectFile.cpp @@ -716,10 +716,13 @@ std::vector<ELFPltEntry> ELFObjectFileBase::getPltEntries() const { template <class ELFT> Expected<std::vector<BBAddrMap>> static readBBAddrMapImpl( - const ELFFile<ELFT> &EF, std::optional<unsigned> TextSectionIndex) { + const ELFFile<ELFT> &EF, std::optional<unsigned> TextSectionIndex, + std::vector<PGOAnalysisMap> *PGOAnalyses) { using Elf_Shdr = typename ELFT::Shdr; bool IsRelocatable = EF.getHeader().e_type == ELF::ET_REL; std::vector<BBAddrMap> BBAddrMaps; + if (PGOAnalyses) + PGOAnalyses->clear(); const auto &Sections = cantFail(EF.sections()); auto IsMatch = [&](const Elf_Shdr &Sec) -> Expected<bool> { @@ -748,10 +751,13 @@ Expected<std::vector<BBAddrMap>> static readBBAddrMapImpl( return createError("unable to get relocation section for " + describe(EF, *Sec)); Expected<std::vector<BBAddrMap>> BBAddrMapOrErr = - EF.decodeBBAddrMap(*Sec, RelocSec); - if (!BBAddrMapOrErr) + EF.decodeBBAddrMap(*Sec, RelocSec, PGOAnalyses); + if (!BBAddrMapOrErr) { + if (PGOAnalyses) + PGOAnalyses->clear(); return createError("unable to read " + describe(EF, *Sec) + ": " + toString(BBAddrMapOrErr.takeError())); + } std::move(BBAddrMapOrErr->begin(), BBAddrMapOrErr->end(), std::back_inserter(BBAddrMaps)); } @@ -828,13 +834,14 @@ ELFObjectFileBase::readDynsymVersions() const { } Expected<std::vector<BBAddrMap>> ELFObjectFileBase::readBBAddrMap( - std::optional<unsigned> TextSectionIndex) const { + std::optional<unsigned> TextSectionIndex, + std::vector<PGOAnalysisMap> *PGOAnalyses) const { if (const auto *Obj = dyn_cast<ELF32LEObjectFile>(this)) - return readBBAddrMapImpl(Obj->getELFFile(), TextSectionIndex); + return readBBAddrMapImpl(Obj->getELFFile(), TextSectionIndex, PGOAnalyses); if (const auto *Obj = dyn_cast<ELF64LEObjectFile>(this)) - return readBBAddrMapImpl(Obj->getELFFile(), TextSectionIndex); + return readBBAddrMapImpl(Obj->getELFFile(), TextSectionIndex, PGOAnalyses); if (const auto *Obj = dyn_cast<ELF32BEObjectFile>(this)) - return readBBAddrMapImpl(Obj->getELFFile(), TextSectionIndex); + return readBBAddrMapImpl(Obj->getELFFile(), TextSectionIndex, PGOAnalyses); return readBBAddrMapImpl(cast<ELF64BEObjectFile>(this)->getELFFile(), - TextSectionIndex); + TextSectionIndex, PGOAnalyses); } |