[llvm] [BOLT] Fix enumeration of secondary entry points (PR #86848)
Amir Ayupov via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 27 12:23:57 PDT 2024
https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/86848
>From b4357d14ba7c40e7ffde4036600b351964a23f9e Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Wed, 27 Mar 2024 11:25:34 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
=?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
bolt/lib/Core/BinaryFunction.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index fdadef9dcd3848..c9e037c225dd41 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -3547,7 +3547,7 @@ MCSymbol *BinaryFunction::getSymbolForEntryID(uint64_t EntryID) {
if (!isMultiEntry())
return nullptr;
- uint64_t NumEntries = 0;
+ uint64_t NumEntries = 1;
if (hasCFG()) {
for (BinaryBasicBlock *BB : BasicBlocks) {
MCSymbol *EntrySymbol = getSecondaryEntryPointSymbol(*BB);
@@ -3580,7 +3580,7 @@ uint64_t BinaryFunction::getEntryIDForSymbol(const MCSymbol *Symbol) const {
return 0;
// Check all secondary entries available as either basic blocks or lables.
- uint64_t NumEntries = 0;
+ uint64_t NumEntries = 1;
for (const BinaryBasicBlock *BB : BasicBlocks) {
MCSymbol *EntrySymbol = getSecondaryEntryPointSymbol(*BB);
if (!EntrySymbol)
@@ -3589,7 +3589,7 @@ uint64_t BinaryFunction::getEntryIDForSymbol(const MCSymbol *Symbol) const {
return NumEntries;
++NumEntries;
}
- NumEntries = 0;
+ NumEntries = 1;
for (const std::pair<const uint32_t, MCSymbol *> &KV : Labels) {
MCSymbol *EntrySymbol = getSecondaryEntryPointSymbol(KV.second);
if (!EntrySymbol)
>From 369070387825207d901b842c9b00fb3582c6fd04 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Wed, 27 Mar 2024 12:23:48 -0700
Subject: [PATCH 2/2] Added test
Created using spr 1.3.4
---
.../X86/yaml-secondary-entry-discriminator.s | 71 +++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100644 bolt/test/X86/yaml-secondary-entry-discriminator.s
diff --git a/bolt/test/X86/yaml-secondary-entry-discriminator.s b/bolt/test/X86/yaml-secondary-entry-discriminator.s
new file mode 100644
index 00000000000000..55dc024b325e1f
--- /dev/null
+++ b/bolt/test/X86/yaml-secondary-entry-discriminator.s
@@ -0,0 +1,71 @@
+# This reproduces a bug with BOLT setting incorrect discriminator for
+# secondary entry points in YAML profile.
+
+# REQUIRES: system-linux
+# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
+# RUN: link_fdata %s %t.o %t.fdata
+# RUN: llvm-strip --strip-unneeded %t.o
+# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib
+# RUN: llvm-bolt %t.exe -o %t.out --data %t.fdata -w %t.yaml --print-profile \
+# RUN: --print-only=main | FileCheck %s --check-prefix=CHECK-CFG
+# RUN: FileCheck %s -input-file %t.yaml
+# CHECK: - name: main
+# CHECK-NEXT: fid: 2
+# CHECK-NEXT: hash: 0xADF270D550151185
+# CHECK-NEXT: exec: 0
+# CHECK-NEXT: nblocks: 4
+# CHECK-NEXT: blocks:
+# CHECK: - bid: 1
+# CHECK-NEXT: insns: 1
+# CHECK-NEXT: hash: 0x36A303CBA4360014
+# CHECK-NEXT: calls: [ { off: 0x0, fid: 1, disc: 1, cnt: 1 } ]
+
+# Make sure that the profile is attached correctly
+# RUN: llvm-bolt %t.exe -o %t.out --data %t.yaml --print-profile \
+# RUN: --print-only=main | FileCheck %s --check-prefix=CHECK-CFG
+
+# CHECK-CFG: Binary Function "main" after attaching profile {
+# CHECK-CFG: callq secondary_entry # Offset: [[#]] # Count: 1
+# CHECK-CFG: callq *%rax # Offset: [[#]] # CallProfile: 1 (1 misses) :
+# XXX: uncomment after discriminator is set correctly for indirect calls
+# COM: CHECK-CFG-NEXT: { secondary_entry: 1 (1 misses) }
+# CHECK-CFG: }
+
+.globl func
+.type func, @function
+func:
+ .cfi_startproc
+ pushq %rbp
+ movq %rsp, %rbp
+.globl secondary_entry
+secondary_entry:
+ popq %rbp
+ retq
+ nopl (%rax)
+ .cfi_endproc
+ .size func, .-func
+
+.globl main
+.type main, @function
+main:
+ .cfi_startproc
+ pushq %rbp
+ movq %rsp, %rbp
+ subq $16, %rsp
+ movl $0, -4(%rbp)
+ testq %rax, %rax
+ jne Lindcall
+Lcall:
+ call secondary_entry
+# FDATA: 1 main #Lcall# 1 secondary_entry 0 1 1
+Lindcall:
+ callq *%rax
+# FDATA: 1 main #Lindcall# 1 secondary_entry 0 1 1
+ xorl %eax, %eax
+ addq $16, %rsp
+ popq %rbp
+ retq
+# For relocations against .text
+ call exit
+ .cfi_endproc
+ .size main, .-main
More information about the llvm-commits
mailing list