llvm-project/llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
Rahman Lavaee 7841e21c98 Let -basic-block-sections=labels emit basicblock metadata in a new .bb_addr_map section, instead of emitting special unary-encoded symbols.
This patch introduces the new .bb_addr_map section feature which allows us to emit the bits needed for mapping binary profiles to basic blocks into a separate section.
The format of the emitted data is represented as follows. It includes a header for every function:

|  Address of the function                      |  -> 8 bytes (pointer size)
|  Number of basic blocks in this function (>0) |  -> ULEB128

The header is followed by a BB record for every basic block. These records are ordered in the same order as MachineBasicBlocks are placed in the function. Each BB Info is structured as follows:

|  Offset of the basic block relative to function begin |  -> ULEB128
|  Binary size of the basic block                       |  -> ULEB128
|  BB metadata                                          |  -> ULEB128  [ MBB.isReturn() OR MBB.hasTailCall() << 1  OR  MBB.isEHPad() << 2 ]

The new feature will replace the existing "BB labels" functionality with -basic-block-sections=labels.
The .bb_addr_map section scrubs the specially-encoded BB symbols from the binary and makes it friendly to profilers and debuggers.
Furthermore, the new feature reduces the binary size overhead from 70% bloat to only 12%.

For more information and results please refer to the RFC: https://lists.llvm.org/pipermail/llvm-dev/2020-July/143512.html

Reviewed By: MaskRay, snehasish

Differential Revision: https://reviews.llvm.org/D85408
2020-09-14 10:16:44 -07:00

36 lines
1.3 KiB
LLVM

; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=labels | FileCheck %s
$_Z4fooTIiET_v = comdat any
define dso_local i32 @_Z3barv() {
ret i32 0
}
;; Check we add SHF_LINK_ORDER for .bb_addr_map and link it with the corresponding .text sections.
; CHECK: .section .text._Z3barv,"ax",@progbits
; CHECK-LABEL: _Z3barv:
; CHECK-NEXT: [[BAR_BEGIN:.Lfunc_begin[0-9]+]]:
; CHECK: .section .bb_addr_map,"o",@progbits,.text._Z3barv{{$}}
; CHECK-NEXT: .quad [[BAR_BEGIN]]
define dso_local i32 @_Z3foov() {
%1 = call i32 @_Z4fooTIiET_v()
ret i32 %1
}
; CHECK: .section .text._Z3foov,"ax",@progbits
; CHECK-LABEL: _Z3foov:
; CHECK-NEXT: [[FOO_BEGIN:.Lfunc_begin[0-9]+]]:
; CHECK: .section .bb_addr_map,"o",@progbits,.text._Z3foov{{$}}
; CHECK-NEXT: .quad [[FOO_BEGIN]]
define linkonce_odr dso_local i32 @_Z4fooTIiET_v() comdat {
ret i32 0
}
;; Check we add .bb_addr_map section to a COMDAT group with the corresponding .text section if such a COMDAT exists.
; CHECK: .section .text._Z4fooTIiET_v,"axG",@progbits,_Z4fooTIiET_v,comdat
; CHECK-LABEL: _Z4fooTIiET_v:
; CHECK-NEXT: [[FOOCOMDAT_BEGIN:.Lfunc_begin[0-9]+]]:
; CHECK: .section .bb_addr_map,"Go",@progbits,_Z4fooTIiET_v,comdat,.text._Z4fooTIiET_v{{$}}
; CHECK-NEXT: .quad [[FOOCOMDAT_BEGIN]]