[llvm-branch-commits] [llvm] [BOLT] Use heuristic for matching split local functions (PR #90424)
Amir Ayupov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Apr 29 16:05:22 PDT 2024
https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/90424
>From b9a8ff53a491f126fb0dcf8cc371ed7a053e859b Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Mon, 29 Apr 2024 12:48:24 -0700
Subject: [PATCH 1/4] Revert cdsplit-symbol-names.s
---
bolt/test/X86/cdsplit-symbol-names.s | 24 ++++--------------------
1 file changed, 4 insertions(+), 20 deletions(-)
diff --git a/bolt/test/X86/cdsplit-symbol-names.s b/bolt/test/X86/cdsplit-symbol-names.s
index 0d9149f49db908..e53863e22246d6 100644
--- a/bolt/test/X86/cdsplit-symbol-names.s
+++ b/bolt/test/X86/cdsplit-symbol-names.s
@@ -2,14 +2,12 @@
# Warm section should have name .text.warm and warm function fragments should
# have symbol names ending in warm.
-# RUN: split-file %s %t
-# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/main.s -o %t.o
-# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %t/chain.s -o %t.chain.o
+# 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 %t.chain.o -o %t.exe -Wl,-q
+# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
# RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=cdsplit \
-# RUN: --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp --enable-bat
+# RUN: --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp
# RUN: llvm-objdump --syms %t.bolt | FileCheck %s --check-prefix=CHECK-SYMS-WARM
# CHECK-SYMS-WARM: 0000000000000000 l df *ABS* 0000000000000000 bolt-pseudo.o
@@ -18,22 +16,8 @@
# CHECK-SYMS-WARM: .text.cold
# CHECK-SYMS-WARM-SAME: dummy.cold
-# RUN: link_fdata %s %t.bolt %t.preagg PREAGG
-# PREAGG: B X:0 #chain.warm# 1 0
-# RUN: perf2bolt %t.bolt -p %t.preagg --pa -o %t.bat.fdata -w %t.bat.yaml -v=1 \
-# RUN: | FileCheck %s --check-prefix=CHECK-REGISTER
-
-# CHECK-REGISTER: BOLT-INFO: marking chain.warm/1(*2) as a fragment of chain/2(*2)
-
-#--- chain.s
- .text
- .type chain, @function
-chain:
- ret
- .size chain, .-chain
-
-#--- main.s
.text
+ .globl chain
.type chain, @function
chain:
pushq %rbp
>From 7c92aca6a0cba71bfde9eb2127575d93e210d346 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Mon, 29 Apr 2024 12:48:39 -0700
Subject: [PATCH 2/4] Add register-fragments-bolt-symbols.s
---
.../X86/register-fragments-bolt-symbols.s | 32 +++++++++++++++++++
1 file changed, 32 insertions(+)
create mode 100644 bolt/test/X86/register-fragments-bolt-symbols.s
diff --git a/bolt/test/X86/register-fragments-bolt-symbols.s b/bolt/test/X86/register-fragments-bolt-symbols.s
new file mode 100644
index 00000000000000..fa9b70e0b2d891
--- /dev/null
+++ b/bolt/test/X86/register-fragments-bolt-symbols.s
@@ -0,0 +1,32 @@
+# Test the heuristics for matching BOLT-added split functions.
+
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %S/cdsplit-symbol-names.s -o %t.main.o
+# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.chain.o
+# RUN: link_fdata %S/cdsplit-symbol-names.s %t.main.o %t.fdata
+# RUN: sed -i 's|chain|chain/2|g' %t.fdata
+# RUN: llvm-strip --strip-unneeded %t.main.o
+# RUN: llvm-objcopy --localize-symbol=chain %t.main.o
+# RUN: %clang %cflags %t.chain.o %t.main.o -o %t.exe -Wl,-q
+# RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-strategy=randomN \
+# RUN: --reorder-blocks=ext-tsp --enable-bat --bolt-seed=7 --data=%t.fdata
+# RUN: llvm-objdump --syms %t.bolt | FileCheck %s --check-prefix=CHECK-SYMS
+
+# RUN: link_fdata %s %t.bolt %t.preagg PREAGG
+# PREAGG: B X:0 #chain.cold.0# 1 0
+# RUN: perf2bolt %t.bolt -p %t.preagg --pa -o %t.bat.fdata -w %t.bat.yaml -v=1 \
+# RUN: | FileCheck %s --check-prefix=CHECK-REGISTER
+
+# CHECK-SYMS: l df *ABS* [[#]] chain.s
+# CHECK-SYMS: l F .bolt.org.text [[#]] chain
+# CHECK-SYMS: l F .text.cold [[#]] chain.cold.0
+# CHECK-SYMS: l F .text [[#]] chain
+# CHECK-SYMS: l df *ABS* [[#]] bolt-pseudo.o
+
+# CHECK-REGISTER: BOLT-INFO: marking chain.cold.0/1(*2) as a fragment of chain/2(*2)
+
+.file "chain.s"
+ .text
+ .type chain, @function
+chain:
+ ret
+ .size chain, .-chain
>From a94e14566de73e4a54a28086c95d742a1f09e7b4 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Mon, 29 Apr 2024 12:50:07 -0700
Subject: [PATCH 3/4] Fix a mistake in NameOrError
---
bolt/lib/Rewrite/RewriteInstance.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 8eb2e5a9d9120a..5e7bcd06df82c4 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1515,7 +1515,7 @@ void RewriteInstance::registerFragments() {
// symbol.
for (ELFSymbolRef NextSymbol = Symbol; NextSymbol < StopSymbol;
NextSymbol.moveNext()) {
- Expected<StringRef> NameOrError = Symbol.getName();
+ Expected<StringRef> NameOrError = NextSymbol.getName();
if (!NameOrError)
break;
StringRef Name = *NameOrError;
>From b39489c935a41882b55f6dba3a31e1c9fdb3e4b5 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Mon, 29 Apr 2024 16:05:05 -0700
Subject: [PATCH 4/4] Use cantFail(Symbol.getName()) for consistency
---
bolt/lib/Rewrite/RewriteInstance.cpp | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 5e7bcd06df82c4..997b158315fd76 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1515,10 +1515,7 @@ void RewriteInstance::registerFragments() {
// symbol.
for (ELFSymbolRef NextSymbol = Symbol; NextSymbol < StopSymbol;
NextSymbol.moveNext()) {
- Expected<StringRef> NameOrError = NextSymbol.getName();
- if (!NameOrError)
- break;
- StringRef Name = *NameOrError;
+ StringRef Name = cantFail(NextSymbol.getName());
if (Name == ParentName) {
ParentAddress = cantFail(NextSymbol.getValue());
goto registerParent;
More information about the llvm-branch-commits
mailing list