[llvm] [BOLT] Adding a unittest that covers Arm SPE PBT aggregation (PR #160095)

Paschalis Mpeis via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 24 03:11:24 PDT 2025


================
@@ -161,4 +161,58 @@ TEST_F(PerfSpeEventsTestHelper, SpeBranchesWithBrstack) {
   parseAndCheckBrstackEvents(1234, ExpectedSamples);
 }
 
+TEST_F(PerfSpeEventsTestHelper, SpeBranchesWithBrstackAndPbt) {
+  // Check perf input with SPE branch events as brstack format by
+  // combining with the previous branch target address (named as PBT).
+  // Example collection command:
+  // ```
+  // perf record -e 'arm_spe_0/branch_filter=1/u' -- BINARY
+  // ```
+  // How Bolt extracts the branch events:
+  // ```
+  // perf script -F pid,brstack --itrace=bl
+  // ```
+
+  opts::ArmSPE = true;
+  opts::ReadPerfEvents =
+      "  4567  0xa002/0xa003/PN/-/-/10/COND/- 0x0/0xa001/-/-/-/0//-\n"
+      "  4567  0xb002/0xb003/P/-/-/4/RET/- 0x0/0xb001/-/-/-/0//-\n"
+      "  4567  0xc456/0xc789/P/-/-/13/-/- 0x0/0xc123/-/-/-/0//-\n"
+      "  4567  0xd456/0xd789/M/-/-/7/RET/- 0x0/0xd123/-/-/-/0//-\n"
+      "  4567  0xe005/0xe009/P/-/-/14/RET/- 0x0/0xe001/-/-/-/0//-\n"
+      "  4567  0xd456/0xd789/M/-/-/7/RET/- 0x0/0xd123/-/-/-/0//-\n"
+      "  4567  0xf002/0xf003/MN/-/-/8/COND/- 0x0/0xf001/-/-/-/0//-\n"
+      "  4567  0xc456/0xc789/P/-/-/13/-/- 0x0/0xc123/-/-/-/0//-\n";
+
+  // ExpectedSamples contains the aggregated information about
+  // a branch {{From, To, TraceTo}, {TakenCount, MispredCount}}.
+  // If the PBT feture is availabe, an SPE sample has two entries.
+  // These two entries form a chain of two consecutive branches.
+  // However PBT lacks associated information such as branch
+  // source address, branch type, and prediction bit.
+  // For the first branch stack, please see the description above.
+  // Consider this example for PBT trace: {{0x0, 0xc123, 0xc456}, {2, 0}}.
+  // This entry has a TakenCount = 2, as we have two samples for
+  // this entry (0x0,d123) in our input. It has MispredsCount = 0,
+  // as it lacks prediction information.
+  // It also has no infromation about source branch address therefore
----------------
paschalis-mpeis wrote:

typo
```suggestion
  // It also has no information about source branch address therefore
```

https://github.com/llvm/llvm-project/pull/160095


More information about the llvm-commits mailing list