[PATCH] D106421: Encode address offsets of basic blocks relative to the end of the previous basic blocks.
Rahman Lavaee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 20 22:23:44 PDT 2021
rahmanl created this revision.
rahmanl added a reviewer: tmsriram.
Herald added subscribers: pengfei, rupprecht, hiraditya, emaste.
Herald added a reviewer: jhenderson.
rahmanl requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.
This encoding uses smaller values compared to the existing one (offsets relative to function symbol).
Smaller values tend to occupy fewer bytes in ULEB128 encoding. As a result, we get about 25% reduction
in the size of the bb-address-map section. (reduction from about 9MB to 7MB).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D106421
Files:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/CodeGen/BasicBlockSections.cpp
llvm/test/CodeGen/X86/basic-block-sections-labels.ll
llvm/test/tools/llvm-readobj/ELF/bb-addr-map.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -6753,10 +6753,13 @@
W.printString("Name", FuncName);
ListScope L(W, "BB entries");
+ uint32_t FunctionRelativeAddress = 0;
for (const typename Elf_BBAddrMap::BBEntry &BBE : AM.BBEntries) {
DictScope L(W);
- W.printHex("Offset", BBE.Offset);
+ FunctionRelativeAddress += BBE.Offset;
+ W.printHex("Offset", FunctionRelativeAddress);
W.printHex("Size", BBE.Size);
+ FunctionRelativeAddress += BBE.Size;
W.printBoolean("HasReturn", BBE.HasReturn);
W.printBoolean("HasTailCall", BBE.HasTailCall);
W.printBoolean("IsEHPad", BBE.IsEHPad);
Index: llvm/test/tools/llvm-readobj/ELF/bb-addr-map.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/bb-addr-map.test
+++ llvm/test/tools/llvm-readobj/ELF/bb-addr-map.test
@@ -30,7 +30,7 @@
# LLVM-NEXT: CanFallThrough: No
# LLVM-NEXT: }
# LLVM-NEXT: {
-# LLVM-NEXT: Offset: 0x3
+# LLVM-NEXT: Offset: 0x4
# LLVM-NEXT: Size: 0x4
# LLVM-NEXT: HasReturn: Yes
# LLVM-NEXT: HasTailCall: No
Index: llvm/test/CodeGen/X86/basic-block-sections-labels.ll
===================================================================
--- llvm/test/CodeGen/X86/basic-block-sections-labels.ll
+++ llvm/test/CodeGen/X86/basic-block-sections-labels.ll
@@ -51,12 +51,12 @@
; CHECK-NEXT: .uleb128 .Lfunc_begin0-.Lfunc_begin0
; CHECK-NEXT: .uleb128 .LBB_END0_0-.Lfunc_begin0
; CHECK-NEXT: .byte 8
-; CHECK-NEXT: .uleb128 .LBB0_1-.Lfunc_begin0
+; CHECK-NEXT: .uleb128 .LBB0_1-.LBB_END0_0
; CHECK-NEXT: .uleb128 .LBB_END0_1-.LBB0_1
; CHECK-NEXT: .byte 8
-; CHECK-NEXT: .uleb128 .LBB0_2-.Lfunc_begin0
+; CHECK-NEXT: .uleb128 .LBB0_2-.LBB_END0_1
; CHECK-NEXT: .uleb128 .LBB_END0_2-.LBB0_2
; CHECK-NEXT: .byte 1
-; CHECK-NEXT: .uleb128 .LBB0_3-.Lfunc_begin0
+; CHECK-NEXT: .uleb128 .LBB0_3-.LBB_END0_2
; CHECK-NEXT: .uleb128 .LBB_END0_3-.LBB0_3
; CHECK-NEXT: .byte 5
Index: llvm/lib/CodeGen/BasicBlockSections.cpp
===================================================================
--- llvm/lib/CodeGen/BasicBlockSections.cpp
+++ llvm/lib/CodeGen/BasicBlockSections.cpp
@@ -48,7 +48,7 @@
// Basic Block Labels
// ==================
//
-// With -fbasic-block-sections=labels, we emit the offsets of BB addresses of
+// With -fbasic-block-sections=labels, we encode the offsets of BB addresses of
// every function into the .llvm_bb_addr_map section. Along with the function
// symbols, this allows for mapping of virtual addresses in PMU profiles back to
// the corresponding basic blocks. This logic is implemented in AsmPrinter. This
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1137,16 +1137,19 @@
OutStreamer->emitSymbolValue(FunctionSymbol, getPointerSize());
// Emit the total number of basic blocks in this function.
OutStreamer->emitULEB128IntValue(MF.size());
+ const MCSymbol *PrevMBBEndSymbol = FunctionSymbol;
// Emit BB Information for each basic block in the funciton.
for (const MachineBasicBlock &MBB : MF) {
const MCSymbol *MBBSymbol =
MBB.isEntryBlock() ? FunctionSymbol : MBB.getSymbol();
- // Emit the basic block offset.
- emitLabelDifferenceAsULEB128(MBBSymbol, FunctionSymbol);
+ // Emit the basic block offset relative to the end of the previous block.
+ // This is zero unless the block is padded due to alignment.
+ emitLabelDifferenceAsULEB128(MBBSymbol, PrevMBBEndSymbol);
// Emit the basic block size. When BBs have alignments, their size cannot
// always be computed from their offsets.
emitLabelDifferenceAsULEB128(MBB.getEndSymbol(), MBBSymbol);
OutStreamer->emitULEB128IntValue(getBBAddrMapMetadata(MBB));
+ PrevMBBEndSymbol = MBB.getEndSymbol();
}
OutStreamer->PopSection();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106421.360359.patch
Type: text/x-patch
Size: 4198 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210721/d2fe06dc/attachment-0001.bin>
More information about the llvm-commits
mailing list