Skip to content

[SHT_LLVM_BB_ADDR_MAP] Adds pretty printing of BFI and BPI for PGO Analysis Map in tools. #82292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion llvm/docs/CommandGuide/llvm-objdump.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ OPTIONS

When printing a PC-relative global symbol reference, print it as an offset from the leading symbol.

When a bb-address-map section is present (i.e., the object file is built with ``-fbasic-block-sections=labels``), labels are retrieved from that section instead.
When a bb-address-map section is present (i.e., the object file is built with
``-fbasic-block-sections=labels``), labels are retrieved from that section
instead. If a pgo-analysis-map present along side the bb-address-map, any
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
instead. If a pgo-analysis-map present along side the bb-address-map, any
instead. If a pgo-analysis-map is present alongside the bb-address-map, any

Two nits.

available analyses are printed after the relevant block label. By default,
any analysis with a special representation (i.e. BlockFrequency,
BranchProbability, etc) are printed as raw hex values.

Only works with PowerPC objects or X86 linked images.

Expand All @@ -291,6 +296,15 @@ OPTIONS
cmp eax, dword ptr <g>
jge <L0>

.. option:: --pretty-pgo-analysis-map

When using ``--symbolize-operands`` with bb-address-map and pgo-analysis-map,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When using ``--symbolize-operands`` with bb-address-map and pgo-analysis-map,
When using :option:``--symbolize-operands`` with bb-address-map and pgo-analysis-map,

Also applies below - this will ensure the reference becomes a hyperlink to the actual option in the documentation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion!

print analyses using same format as there analysis passes would. An example
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print analyses using same format as there analysis passes would. An example
print analyses using the same format as their analysis passes would. An example

of pretty format, would be printing block frequencies relative to the entry
block, same as BFI.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
of pretty format, would be printing block frequencies relative to the entry
block, same as BFI.
of pretty format would be printing block frequencies relative to the entry
block, the same as BFI.


Only works when ``--symbolize-operands`` is enabled.

.. option:: --triple=<string>

Target triple to disassemble for, see ``--version`` for available targets.
Expand Down
11 changes: 11 additions & 0 deletions llvm/docs/CommandGuide/llvm-readobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ The following options are implemented only for the ELF file format.
Display the contents of the basic block address map section(s), which contain the
address of each function, along with the relative offset of each basic block.

When pgo analysis maps are present, all analyses are printed as there raw
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When pgo analysis maps are present, all analyses are printed as there raw
When pgo analysis maps are present, all analyses are printed as their raw

value.

.. option:: --pretty-pgo-analysis-map

When pgo analysis maps are present in the basic block address map section(s),
analyses with special formats (i.e. BlockFrequency, BranchProbability, etc)
are printed using the same format as there respective analysis pass.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
are printed using the same format as there respective analysis pass.
are printed using the same format as their respective analysis pass.


Requires ``--bb-addr-map`` to have an effect.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Requires ``--bb-addr-map`` to have an effect.
Requires :option:``--bb-addr-map`` to have an effect.


.. option:: --demangle, -C

Display demangled symbol names in the output.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

## Check 64-bit:
# RUN: yaml2obj %s -DBITS=64 -DADDR=0x999999999 -o %t1.x64.o
# RUN: llvm-readobj %t1.x64.o --bb-addr-map 2>&1 | FileCheck %s -DADDR=0x999999999 -DFILE=%t1.x64.o --check-prefixes=CHECK,RAW
# RUN: llvm-readobj %t1.x64.o --bb-addr-map --pretty-pgo-analysis-map 2>&1 | FileCheck %s -DADDR=0x999999999 -DFILE=%t1.x64.o --check-prefixes=CHECK,PRETTY
# RUN: llvm-readobj %t1.x64.o --bb-addr-map 2>&1 | FileCheck --match-full-lines %s -DADDR=0x999999999 -DFILE=%t1.x64.o --check-prefixes=CHECK,RAW
# RUN: llvm-readobj %t1.x64.o --bb-addr-map --pretty-pgo-analysis-map 2>&1 | FileCheck --match-full-lines %s -DADDR=0x999999999 -DFILE=%t1.x64.o --check-prefixes=CHECK,PRETTY
# RUN: llvm-readelf %t1.x64.o --bb-addr-map | FileCheck %s --check-prefix=GNU
# RUN: llvm-readobj %t1.x64.o --pretty-pgo-analysis-map 2>&1 | FileCheck %s --check-prefix=PRETTY-NO-BAM

## Check 32-bit:
# RUN: yaml2obj %s -DBITS=32 -o %t1.x32.o
# RUN: llvm-readobj %t1.x32.o --bb-addr-map 2>&1 | FileCheck -DADDR=0x11111 %s -DFILE=%t1.x32.o --check-prefixes=CHECK,RAW
# RUN: llvm-readobj %t1.x32.o --bb-addr-map 2>&1 | FileCheck --match-full-lines -DADDR=0x11111 %s -DFILE=%t1.x32.o --check-prefixes=CHECK,RAW
# RUN: llvm-readelf %t1.x32.o --bb-addr-map | FileCheck %s --check-prefix=GNU

## Check that a malformed section can be handled.
# RUN: yaml2obj %s -DBITS=32 -DSIZE=24 -o %t2.o
# RUN: llvm-readobj %t2.o --bb-addr-map 2>&1 | FileCheck %s -DOFFSET=0x00000018 -DFILE=%t2.o --check-prefix=TRUNCATED
# RUN: llvm-readobj %t2.o --bb-addr-map 2>&1 | FileCheck --match-full-lines %s -DOFFSET=0x00000018 -DFILE=%t2.o --check-prefix=TRUNCATED

## Check that missing features can be handled.
# RUN: yaml2obj %s -DBITS=32 -DFEATURE=0x2 -o %t3.o
Expand All @@ -24,7 +24,7 @@
# CHECK: BBAddrMap [
# CHECK-NEXT: Function {
# CHECK-NEXT: At: [[ADDR]]
# CHECK-NEXT: warning: '[[FILE]]': could not identify function symbol for address ([[ADDR]]) in SHT_LLVM_BB_ADDR_MAP section with index 3
# CHECK-NEXT: {{.*}}: warning: '[[FILE]]': could not identify function symbol for address ([[ADDR]]) in SHT_LLVM_BB_ADDR_MAP section with index 3
# CHECK-NEXT: Name: <?>
# CHECK-NEXT: BB Ranges [
# CHECK-NEXT: {
Expand Down Expand Up @@ -113,7 +113,7 @@
# PRETTY-NO-BAM: warning: --bb-addr-map must be enabled for --pretty-pgo-analysis-map to have an effect

# TRUNCATED: BBAddrMap [
# TRUNCATED-NEXT: warning: '[[FILE]]': unable to dump SHT_LLVM_BB_ADDR_MAP section with index 3: unable to decode LEB128 at offset [[OFFSET]]: malformed uleb128, extends past end
# TRUNCATED-NEXT: {{.*}}: warning: '[[FILE]]': unable to dump SHT_LLVM_BB_ADDR_MAP section with index 3: unable to decode LEB128 at offset [[OFFSET]]: malformed uleb128, extends past end
# TRUNCATED-NEXT: ]
## Check that the other valid section is properly dumped.
# TRUNCATED-NEXT: BBAddrMap [
Expand Down
4 changes: 4 additions & 0 deletions llvm/tools/llvm-objdump/ObjdumpOpts.td
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ def : Flag<["-"], "t">, Alias<syms>, HelpText<"Alias for --syms">;
def symbolize_operands : Flag<["--"], "symbolize-operands">,
HelpText<"Symbolize instruction operands when disassembling">;

def pretty_pgo_analysis_map : Flag<["--"], "pretty-pgo-analysis-map">,
HelpText<"Display PGO analysis values with "
"formatting rather than raw numbers">;

def dynamic_syms : Flag<["--"], "dynamic-syms">,
HelpText<"Display the contents of the dynamic symbol table">;
def : Flag<["-"], "T">, Alias<dynamic_syms>,
Expand Down