aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/ELF.cpp
diff options
context:
space:
mode:
authorLei Wang <wlei@fb.com>2024-11-22 11:51:34 -0800
committerGitHub <noreply@github.com>2024-11-22 11:51:34 -0800
commitcf83a7fdc2dfac8220d9923a831181dccb9f7277 (patch)
tree465bf6a12c7c3bcc4638ca78b687d36ce2bbc226 /llvm/lib/Object/ELF.cpp
parent1434d2ab215e3ea9c5f34689d056edd3d4423a78 (diff)
downloadllvm-cf83a7fdc2dfac8220d9923a831181dccb9f7277.zip
llvm-cf83a7fdc2dfac8220d9923a831181dccb9f7277.tar.gz
llvm-cf83a7fdc2dfac8220d9923a831181dccb9f7277.tar.bz2
[SHT_LLVM_BB_ADDR_MAP] Add an option to skip emitting bb entries (#114447)
Sometimes we want to use a `PgoAnalysisMap` feature that doesn't require the BB entries info, e.g. only the `FuncEntryCount`, but the BB entries is emitted by default, so I'm adding an option to skip the info for this case to save the binary size(can save ~90% size of the section). For implementation, it extends a new field(`OmitBBEntries`) in `BBAddrMap::Features` for this and it's controlled by a switch `--basic-block-address-map-skip-bb-entries`. Note that this naturally supports backwards compatibility as the field is zero for the old version, matches the decoding in the new version llvm.
Diffstat (limited to 'llvm/lib/Object/ELF.cpp')
-rw-r--r--llvm/lib/Object/ELF.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp
index 545a672..b6d0699 100644
--- a/llvm/lib/Object/ELF.cpp
+++ b/llvm/lib/Object/ELF.cpp
@@ -851,29 +851,31 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF,
NumBlocksInBBRange = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
}
std::vector<BBAddrMap::BBEntry> BBEntries;
- for (uint32_t BlockIndex = 0; !MetadataDecodeErr && !ULEBSizeErr && Cur &&
- (BlockIndex < NumBlocksInBBRange);
- ++BlockIndex) {
- uint32_t ID = Version >= 2
- ? readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr)
- : BlockIndex;
- uint32_t Offset = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
- uint32_t Size = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
- uint32_t MD = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
- if (Version >= 1) {
- // Offset is calculated relative to the end of the previous BB.
- Offset += PrevBBEndOffset;
- PrevBBEndOffset = Offset + Size;
- }
- Expected<BBAddrMap::BBEntry::Metadata> MetadataOrErr =
- BBAddrMap::BBEntry::Metadata::decode(MD);
- if (!MetadataOrErr) {
- MetadataDecodeErr = MetadataOrErr.takeError();
- break;
+ if (!FeatEnable.OmitBBEntries) {
+ for (uint32_t BlockIndex = 0; !MetadataDecodeErr && !ULEBSizeErr &&
+ Cur && (BlockIndex < NumBlocksInBBRange);
+ ++BlockIndex) {
+ uint32_t ID = Version >= 2
+ ? readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr)
+ : BlockIndex;
+ uint32_t Offset = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
+ uint32_t Size = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
+ uint32_t MD = readULEB128As<uint32_t>(Data, Cur, ULEBSizeErr);
+ if (Version >= 1) {
+ // Offset is calculated relative to the end of the previous BB.
+ Offset += PrevBBEndOffset;
+ PrevBBEndOffset = Offset + Size;
+ }
+ Expected<BBAddrMap::BBEntry::Metadata> MetadataOrErr =
+ BBAddrMap::BBEntry::Metadata::decode(MD);
+ if (!MetadataOrErr) {
+ MetadataDecodeErr = MetadataOrErr.takeError();
+ break;
+ }
+ BBEntries.push_back({ID, Offset, Size, *MetadataOrErr});
}
- BBEntries.push_back({ID, Offset, Size, *MetadataOrErr});
+ TotalNumBlocks += BBEntries.size();
}
- TotalNumBlocks += BBEntries.size();
BBRangeEntries.push_back({RangeBaseAddress, std::move(BBEntries)});
}
FunctionEntries.push_back({std::move(BBRangeEntries)});