[llvm] [llvm-profgen] Generate profiles from basic perf events (PR #222624)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 05:17:09 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-binary-utilities
Author: jacobhodgsonARM
<details>
<summary>Changes</summary>
Add --basic-events to generate flat LLVM sample profiles from sampled
instruction pointers in perf.data or perfscript.
Validation:
- llvm-profgen test suite: 67 passed, 7 unsupported, 1 expected failure.
- Real perf.data and perfscript replays agree for thread-lifetime and executable-remapping recordings.
- Unsymbolised profile round-trip checks pass.
AI assistance: OpenAI Codex was used during development and testing.
---
Patch is 151.28 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/222624.diff
25 Files Affected:
- (modified) llvm/docs/CommandGuide/llvm-profgen.md (+16)
- (added) llvm/test/tools/llvm-profgen/AArch64/Inputs/basic-events-mixed-pseudoprobe.yaml (+189)
- (added) llvm/test/tools/llvm-profgen/AArch64/Inputs/basic-events.yaml (+243)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-consumer.test (+89)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-flat.test (+320)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-fork.test (+37)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-invalid.test (+79)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-kernel.test (+151)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-mixed-pseudoprobe.test (+99)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-mmap-zero.test (+54)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-overlapping-zero-ranges.test (+204)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-raw-base.test (+141)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-retained-leaf.test (+188)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-segment-order.test (+213)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-shared-file-pages.test (+454)
- (added) llvm/test/tools/llvm-profgen/AArch64/basic-events-zero-fill.test (+185)
- (modified) llvm/test/tools/llvm-profgen/AArch64/load-segment-64k-align.test (+20)
- (modified) llvm/test/tools/llvm-profgen/AArch64/warn-not-symbolized-mmap.test (+13)
- (modified) llvm/tools/llvm-profgen/PerfReader.cpp (+487-71)
- (modified) llvm/tools/llvm-profgen/PerfReader.h (+60-10)
- (modified) llvm/tools/llvm-profgen/ProfileGenerator.cpp (+53-30)
- (modified) llvm/tools/llvm-profgen/ProfileGenerator.h (+4-2)
- (modified) llvm/tools/llvm-profgen/ProfiledBinary.cpp (+1)
- (modified) llvm/tools/llvm-profgen/ProfiledBinary.h (+6)
- (modified) llvm/tools/llvm-profgen/llvm-profgen.cpp (+30-3)
``````````diff
diff --git a/llvm/docs/CommandGuide/llvm-profgen.md b/llvm/docs/CommandGuide/llvm-profgen.md
index 631a3e00f3ce2..e6f5792cf1bd0 100644
--- a/llvm/docs/CommandGuide/llvm-profgen.md
+++ b/llvm/docs/CommandGuide/llvm-profgen.md
@@ -36,6 +36,10 @@ must contain branch stacks, for example from recording with `-b`.
:::{option} --unsymbolized-profile=<unsymbolized profile>, --up
Path of the unsymbolized profile created by `llvm-profgen` with
`--skip-symbolization`.
+
+A Basic profile's content marker selects Basic mode when replayed with this
+option. Use the same `llvm-profgen` build, binary and address-base options as
+when it was produced.
:::
:::{option} --llvm-sample-profile=<llvm sample profile>
@@ -59,6 +63,17 @@ Path of the output profile file.
{program}`llvm-profgen` supports the following options:
+:::{option} --basic-events, --ba
+Generate a flat, line-number sample profile from sampled instruction-pointer
+perf events. Use this option with `--perfdata` or `--perfscript`.
+
+With `--perfdata`, llvm-profgen invokes `perf script` with the required
+options. `--perfscript` accepts user-space output generated by
+`perf script --show-mmap-events --show-task-events -F pid,ip,time -G`, or
+kernel output generated by `perf script --show-mmap-events -F pid,ip -G`.
+Kernel input requires `--kernel` when invoking `llvm-profgen`.
+:::
+
:::{option} --format=[text|binary|extbinary|compbinary|gcc]
Specify the format of the generated profile. Supported \<format> are `text`,
`binary`, `extbinary`, `compbinary`, `gcc`, see `llvm-profdata` for more
@@ -103,5 +118,6 @@ Path of the output profile file.
:::{option} --data-access-perftrace=<data-access-perftrace>
File path of a Linux perf raw trace (generated by `perf report -D`)
consisting of memory access events.
+Use this option with flat, line-number branch-stack profiles.
:::
diff --git a/llvm/test/tools/llvm-profgen/AArch64/Inputs/basic-events-mixed-pseudoprobe.yaml b/llvm/test/tools/llvm-profgen/AArch64/Inputs/basic-events-mixed-pseudoprobe.yaml
new file mode 100644
index 0000000000000..57aa8e9a45178
--- /dev/null
+++ b/llvm/test/tools/llvm-profgen/AArch64/Inputs/basic-events-mixed-pseudoprobe.yaml
@@ -0,0 +1,189 @@
+## Only probed_anchor has a pseudo-probe descriptor and a block probe.
+## unprobed_sampled has source offsets 0 and 1; main has offset 0 with base
+## discriminators 0 and 1.
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_AARCH64
+ Entry: 0x21014c
+ProgramHeaders:
+ - Type: PT_LOAD
+ Flags: [ PF_R, PF_X ]
+ Offset: 0
+ VAddr: 0x210000
+ FileSize: 0x164
+ MemSize: 0x164
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x210120
+ Offset: 0x120
+ AddressAlign: 4
+ ## probed_anchor: stp; mov; add w0, w0, #7; ldp; ret.
+ ## unprobed_sampled: stp; mov; add w8, w0, w0, lsl #1;
+ ## add w0, w8, #1; ldp; ret.
+ ## main: stp; mov; mov w0, #4; bl probed_anchor; ldp; b unprobed_sampled.
+ Content: 'FD7BBFA9FD030091001C0011FD7BC1A8C0035FD6FD7BBFA9FD0300910804000B00050011FD7BC1A8C0035FD6FD7BBFA9FD03009180008052F2FFFF97FD7BC1A8F5FFFF17'
+ - Name: .pseudo_probe_desc
+ Type: SHT_PROGBITS
+ ## GUID 0x659ca2661d55e251, CFG hash 0xffffffff, name "probed_anchor".
+ Content: '51E2551D66A29C65FFFFFFFF000000000D70726F6265645F616E63686F72'
+ - Name: .pseudo_probe
+ Type: SHT_PROGBITS
+ Flags: [ SHF_LINK_ORDER ]
+ Link: .text
+ ## The same GUID, one probe, zero inlinees, block probe 1 at function + 8.
+ Content: '51E2551D66A29C650100018008'
+Symbols:
+ - Name: probed_anchor
+ Type: STT_FUNC
+ Section: .text
+ Binding: STB_GLOBAL
+ Value: 0x210120
+ Size: 0x14
+ - Name: unprobed_sampled
+ Type: STT_FUNC
+ Section: .text
+ Binding: STB_GLOBAL
+ Value: 0x210134
+ Size: 0x18
+ - Name: main
+ Type: STT_FUNC
+ Section: .text
+ Binding: STB_GLOBAL
+ Value: 0x21014c
+ Size: 0x18
+DWARF:
+ debug_abbrev:
+ - Table:
+ - Code: 1
+ Tag: DW_TAG_compile_unit
+ Children: DW_CHILDREN_yes
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Attribute: DW_AT_stmt_list
+ Form: DW_FORM_sec_offset
+ - Attribute: DW_AT_low_pc
+ Form: DW_FORM_addr
+ - Attribute: DW_AT_high_pc
+ Form: DW_FORM_data4
+ - Code: 2
+ Tag: DW_TAG_subprogram
+ Children: DW_CHILDREN_no
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Attribute: DW_AT_low_pc
+ Form: DW_FORM_addr
+ - Attribute: DW_AT_high_pc
+ Form: DW_FORM_data4
+ - Attribute: DW_AT_decl_file
+ Form: DW_FORM_data1
+ - Attribute: DW_AT_decl_line
+ Form: DW_FORM_data1
+ debug_info:
+ - Version: 4
+ AddrSize: 8
+ Entries:
+ - AbbrCode: 1
+ Values:
+ - CStr: probed.c
+ - Value: 0
+ - Value: 0x210120
+ - Value: 0x14
+ - AbbrCode: 2
+ Values:
+ - CStr: probed_anchor
+ - Value: 0x210120
+ - Value: 0x14
+ - Value: 1
+ - Value: 1
+ - AbbrCode: 0
+ - Version: 4
+ AbbrevTableID: 0
+ AddrSize: 8
+ Entries:
+ - AbbrCode: 1
+ Values:
+ - CStr: unprobed.c
+ - Value: 0x3b
+ - Value: 0x210134
+ - Value: 0x30
+ - AbbrCode: 2
+ Values:
+ - CStr: unprobed_sampled
+ - Value: 0x210134
+ - Value: 0x18
+ - Value: 1
+ - Value: 3
+ - AbbrCode: 2
+ Values:
+ - CStr: main
+ - Value: 0x21014c
+ - Value: 0x18
+ - Value: 1
+ - Value: 7
+ - AbbrCode: 0
+ debug_line:
+ - Version: 4
+ MinInstLength: 1
+ MaxOpsPerInst: 1
+ DefaultIsStmt: 1
+ LineBase: 251
+ LineRange: 14
+ Files:
+ - Name: probed.c
+ DirIdx: 0
+ ModTime: 0
+ Length: 0
+ Opcodes:
+ - Opcode: DW_LNS_extended_op
+ SubOpcode: DW_LNE_set_address
+ Data: 0x210120
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 0x14
+ - Opcode: DW_LNS_extended_op
+ SubOpcode: DW_LNE_end_sequence
+ - Version: 4
+ MinInstLength: 1
+ MaxOpsPerInst: 1
+ DefaultIsStmt: 1
+ LineBase: 251
+ LineRange: 14
+ Files:
+ - Name: unprobed.c
+ DirIdx: 0
+ ModTime: 0
+ Length: 0
+ Opcodes:
+ - Opcode: DW_LNS_extended_op
+ SubOpcode: DW_LNE_set_address
+ Data: 0x210134
+ - Opcode: DW_LNS_advance_line
+ SData: 2
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 8
+ - Opcode: DW_LNS_advance_line
+ SData: 1
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 0x10
+ - Opcode: DW_LNS_advance_line
+ SData: 3
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 0x10
+ - Opcode: DW_LNS_extended_op
+ SubOpcode: DW_LNE_set_discriminator
+ Data: 2
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 8
+ - Opcode: DW_LNS_extended_op
+ SubOpcode: DW_LNE_end_sequence
diff --git a/llvm/test/tools/llvm-profgen/AArch64/Inputs/basic-events.yaml b/llvm/test/tools/llvm-profgen/AArch64/Inputs/basic-events.yaml
new file mode 100644
index 0000000000000..16d3e166c290a
--- /dev/null
+++ b/llvm/test/tools/llvm-profgen/AArch64/Inputs/basic-events.yaml
@@ -0,0 +1,243 @@
+## bar has locations at offsets 0, 1, 2, 4 and 5. The instructions at
+## 0x5dc and 0x5e0 share source offset 4, allowing tests to check line maxima
+## independently of the four-byte instruction weight used for function totals.
+## foo inlines bar, including a line-zero location. partition_pivot_last has
+## discriminator 514 at 0x6b4: base discriminator one and duplication factor two.
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_AARCH64
+ Entry: 0x5b0
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x5b0
+ Offset: 0x5b0
+ AddressAlign: 4
+ Content: '1F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D51F2003D5C0035FD6'
+ - Name: .text.foo
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x620
+ Offset: 0x620
+ AddressAlign: 4
+ Content: '1F2003D51F2003D5C0035FD6'
+ - Name: .text.duplication
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x6b0
+ Offset: 0x6b0
+ AddressAlign: 4
+ Content: '1F2003D5C0035FD6'
+ProgramHeaders:
+ - Type: PT_LOAD
+ Flags: [ PF_R, PF_X ]
+ Offset: 0
+ VAddr: 0
+ FileSize: 0x6b8
+ MemSize: 0x6b8
+Symbols:
+ - Name: bar
+ Type: STT_FUNC
+ Section: .text
+ Binding: STB_GLOBAL
+ Value: 0x5b0
+ Size: 0x38
+ - Name: foo
+ Type: STT_FUNC
+ Section: .text.foo
+ Binding: STB_GLOBAL
+ Value: 0x620
+ Size: 0xc
+ - Name: partition_pivot_last
+ Type: STT_FUNC
+ Section: .text.duplication
+ Binding: STB_GLOBAL
+ Value: 0x6b0
+ Size: 8
+DWARF:
+ debug_abbrev:
+ - Table:
+ - Code: 1
+ Tag: DW_TAG_compile_unit
+ Children: DW_CHILDREN_yes
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Attribute: DW_AT_stmt_list
+ Form: DW_FORM_sec_offset
+ - Attribute: DW_AT_low_pc
+ Form: DW_FORM_addr
+ - Attribute: DW_AT_high_pc
+ Form: DW_FORM_data4
+ - Code: 2
+ Tag: DW_TAG_subprogram
+ Children: DW_CHILDREN_no
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Attribute: DW_AT_low_pc
+ Form: DW_FORM_addr
+ - Attribute: DW_AT_high_pc
+ Form: DW_FORM_data4
+ - Attribute: DW_AT_decl_file
+ Form: DW_FORM_data1
+ - Attribute: DW_AT_decl_line
+ Form: DW_FORM_data1
+ - Code: 3
+ Tag: DW_TAG_subprogram
+ Children: DW_CHILDREN_yes
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Attribute: DW_AT_low_pc
+ Form: DW_FORM_addr
+ - Attribute: DW_AT_high_pc
+ Form: DW_FORM_data4
+ - Attribute: DW_AT_decl_file
+ Form: DW_FORM_data1
+ - Attribute: DW_AT_decl_line
+ Form: DW_FORM_data1
+ - Code: 4
+ Tag: DW_TAG_inlined_subroutine
+ Children: DW_CHILDREN_no
+ Attributes:
+ - Attribute: DW_AT_name
+ Form: DW_FORM_string
+ - Attribute: DW_AT_low_pc
+ Form: DW_FORM_addr
+ - Attribute: DW_AT_high_pc
+ Form: DW_FORM_data4
+ - Attribute: DW_AT_decl_file
+ Form: DW_FORM_data1
+ - Attribute: DW_AT_decl_line
+ Form: DW_FORM_data1
+ - Attribute: DW_AT_call_file
+ Form: DW_FORM_data1
+ - Attribute: DW_AT_call_line
+ Form: DW_FORM_data1
+ - Attribute: DW_AT_GNU_discriminator
+ Form: DW_FORM_data1
+ debug_info:
+ - Version: 4
+ AddrSize: 8
+ Entries:
+ - AbbrCode: 1
+ Values:
+ - CStr: basic.c
+ - Value: 0
+ - Value: 0x5b0
+ - Value: 0x108
+ - AbbrCode: 2
+ Values:
+ - CStr: bar
+ - Value: 0x5b0
+ - Value: 0x38
+ - Value: 1
+ - Value: 1
+ - AbbrCode: 3
+ Values:
+ - CStr: foo
+ - Value: 0x620
+ - Value: 0xc
+ - Value: 1
+ - Value: 10
+ - AbbrCode: 4
+ Values:
+ - CStr: bar
+ - Value: 0x620
+ - Value: 8
+ - Value: 1
+ - Value: 1
+ - Value: 1
+ - Value: 13
+ - Value: 2
+ - AbbrCode: 0
+ - AbbrCode: 2
+ Values:
+ - CStr: partition_pivot_last
+ - Value: 0x6b0
+ - Value: 8
+ - Value: 1
+ - Value: 1
+ - AbbrCode: 0
+ debug_line:
+ - Version: 4
+ MinInstLength: 1
+ MaxOpsPerInst: 1
+ DefaultIsStmt: 1
+ LineBase: 251
+ LineRange: 14
+ Files:
+ - Name: basic.c
+ DirIdx: 0
+ ModTime: 0
+ Length: 0
+ Opcodes:
+ - Opcode: DW_LNS_extended_op
+ SubOpcode: DW_LNE_set_address
+ Data: 0x5b0
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 4
+ - Opcode: DW_LNS_advance_line
+ SData: 1
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 4
+ - Opcode: DW_LNS_advance_line
+ SData: 1
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 0x24
+ - Opcode: DW_LNS_advance_line
+ SData: 2
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 8
+ - Opcode: DW_LNS_advance_line
+ SData: 1
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 4
+ - Opcode: DW_LNS_extended_op
+ SubOpcode: DW_LNE_end_sequence
+ - Opcode: DW_LNS_extended_op
+ SubOpcode: DW_LNE_set_address
+ Data: 0x620
+ - Opcode: DW_LNS_advance_line
+ SData: -1
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 4
+ - Opcode: DW_LNS_advance_line
+ SData: 2
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 4
+ - Opcode: DW_LNS_advance_line
+ SData: 12
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 4
+ - Opcode: DW_LNS_extended_op
+ SubOpcode: DW_LNE_end_sequence
+ - Opcode: DW_LNS_extended_op
+ SubOpcode: DW_LNE_set_address
+ Data: 0x6b0
+ - Opcode: DW_LNS_advance_line
+ SData: 3
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 4
+ - Opcode: DW_LNS_extended_op
+ SubOpcode: DW_LNE_set_discriminator
+ Data: 514
+ - Opcode: DW_LNS_copy
+ - Opcode: DW_LNS_advance_pc
+ Data: 4
+ - Opcode: DW_LNS_extended_op
+ SubOpcode: DW_LNE_end_sequence
diff --git a/llvm/test/tools/llvm-profgen/AArch64/basic-events-consumer.test b/llvm/test/tools/llvm-profgen/AArch64/basic-events-consumer.test
new file mode 100644
index 0000000000000..9002250a418b5
--- /dev/null
+++ b/llvm/test/tools/llvm-profgen/AArch64/basic-events-consumer.test
@@ -0,0 +1,89 @@
+; REQUIRES: aarch64-registered-target
+
+; RUN: rm -rf %t && split-file %s %t
+; RUN: yaml2obj %S/Inputs/basic-events.yaml -o %t/binary
+; RUN: llvm-dwarfdump --verify %t/binary
+
+; Five samples at 0x5dc and seven at 0x5e0 map to bar's line offset 4.
+; Each instruction is four bytes long: the function total is 48 and the
+; line count is seven. Exercise the default output format and its consumer.
+; RUN: llvm-profgen --basic-events --perfscript=%t/basic.perfscript \
+; RUN: --binary=%t/binary --output=%t/basic.prof
+; RUN: llvm-profdata merge --sample --text %t/basic.prof -o - \
+; RUN: | FileCheck %s --match-full-lines --check-prefix=PROFILE
+; RUN: opt -passes=sample-profile -verify-each \
+; RUN: -sample-profile-file=%t/basic.prof -S %t/input.ll \
+; RUN: | FileCheck %s --check-prefix=LOADED
+
+; Keep the generated profile and rename the consumer function. Its summary
+; still loads, but only the matching function receives branch weights.
+; RUN: sed -e 's/@bar(/@unrelated(/' -e 's/name: "bar"/name: "unrelated"/' \
+; RUN: %t/input.ll > %t/unrelated.ll
+; RUN: opt -passes=sample-profile -verify-each \
+; RUN: -sample-profile-file=%t/basic.prof -S %t/unrelated.ll \
+; RUN: | FileCheck %s --check-prefix=UNRELATED --implicit-check-not=branch_weights
+
+; PROFILE: bar:48:0
+; PROFILE-NEXT: 0: 0
+; PROFILE-NEXT: 1: 0
+; PROFILE-NEXT: 2: 0
+; PROFILE-NEXT: 4: 7
+; PROFILE-NEXT: 5: 0
+; PROFILE-NOT: {{.}}
+
+; LOADED-LABEL: define i32 @bar(
+; LOADED: br i1 %cond, label %hot, label %cold, {{.*}}!prof ![[WEIGHTS:[0-9]+]]
+; LOADED: !{!"function_entry_count", i64 1}
+; LOADED: ![[WEIGHTS]] = !{!"branch_weights", i32 8, i32 1}
+
+; UNRELATED-LABEL: define i32 @unrelated(
+; UNRELATED: !{i32 1, !"ProfileSummary",
+; UNRELATED: !{!"function_entry_count", i64 -1}
+
+;--- basic.perfscript
+PERF_RECORD_MMAP2 100/100: [0x500000(0x1000) @ 0 00:1d 1 1]: r-xp /tmp/binary
+100 5005dc
+100 5005dc
+100 5005dc
+100 5005dc
+100 5005dc
+100 5005e0
+100 5005e0
+100 5005e0
+100 5005e0
+100 5005e0
+100 5005e0
+100 5005e0
+
+;--- input.ll
+source_filename = "basic-events-consumer.c"
+target triple = "aarch64-unknown-linux-gnu"
+
+define i32 @bar(i32 %x, i32 %y) #0 !dbg !5 {
+entry:
+ %cond = icmp sgt i32 %x, 0, !dbg !10
+ br i1 %cond, label %hot, label %cold, !dbg !10
+hot:
+ %add = add i32 %x, %y, !dbg !11
+ ret i32 %add, !dbg !12
+cold:
+ %sub = sub i32 %x, %y, !dbg !13
+ ret i32 %sub, !dbg !13
+}
+
+attributes #0 = { "use-sample-profile" }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!7, !8}
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "test", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly)
+!1 = !DIFile(filename: "basic-events-consumer.c", directory: "/")
+!2 = !DISubroutineType(types: !3)
+!3 = !{!4, !4, !4}
+!4 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!5 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !2, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+!7 = !{i32 2, !"Dwarf Version", i32 4}
+!8 = !{i32 2, !"Debug Info Version", i32 3}
+!10 = !DILocation(line: 2, column: 1, scope: !5)
+!11 = !DILocation(line: 5, column: 1, scope: !5)
+!12 = !DILocation(line: 6, column: 1, scope: !5)
+!13 = !DILocation(line: 3, column: 1, scope: !5)
diff --git a/llvm/test/tools/llvm-profgen/AArch64/basic-events-flat.test b/llvm/test/tools/llvm-profgen/AArch64/basic-events-flat.test
new file mode 100644
index 0000000000000..829b55d274d23
--- /dev/null
+++ b/llvm/test/tools/llvm-profgen/AArch64/basic-events-flat.test
@@ -0,0 +1,320 @@
+; REQUIRES: aarch64-registered-target
+; UNSUPPORTED: system-windows
+
+; RUN: rm -rf %t && split-file %s %t
+; RUN: yaml2obj %S/Inputs/basic-events.yaml -o %t/binary
+; RUN: llvm-dwarfdump --verify %t/binary
+
+; Two processes map the same binary at different runtime addresses. Basic
+; samples must be relocated to binary addresses before they are aggregated.
+; RUN: llvm-profgen --format=text --basic-events \
+; RUN: --perfscript=%t/flat.perfscript \
+; RUN: --binary=%t/binary \
+; RUN: --output=%t/flat.raw --skip-symbolization
+; RUN: FileCheck %s --match-full-lines --check-prefix=BASIC-RAW \
+; RUN: --input-file=%t/flat.raw
+; RUN: llvm-profgen --format=text --basic-events \
+; RUN: --perfscript=%t/flat.perfscript \
+; RUN: --binary=%t/binary \
+; RUN: --profile-summary-cold-count=0 --output=%t/flat.direct
+; RUN: llvm-profgen --format=text --unsymbolized-profile=%t/flat.raw \
+; RUN: --binary=%t/binary \
+; RUN: --profile-summary-cold-count=0 --output=%t/flat.roundtrip
+; RUN: cmp %t/flat.direct %t/flat.roundtrip
+; RUN: FileCheck %s --match-full-lines --check-prefix=BASIC-PROFILE \
+; RUN: --input-file=%t/flat.direct
+
+; An explicit PID filter must select the mapping and samples owned by that PID.
+; RUN: llvm-profgen --format=text --basic-events --pid=200 \
+; RUN: --perfscript=%t/flat.perfscript \
+; RUN: --binary=%t/binary \
+; RUN: --output=%t/pid.raw --skip-symbolization
+; RUN: FileCheck %s --match-full-lines --check-prefix=PID-R...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/222624
More information about the llvm-commits
mailing list