-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[BOLT] Use heuristic for matching split local functions #90424
Merged
aaupov
merged 10 commits into
main
from
users/spr/aaupov/bolt-use-heuristic-for-matching-bolt-split-functions
Apr 29, 2024
Merged
[BOLT] Use heuristic for matching split local functions #90424
aaupov
merged 10 commits into
main
from
users/spr/aaupov/bolt-use-heuristic-for-matching-bolt-split-functions
Apr 29, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Created using spr 1.3.5 [skip ci]
Created using spr 1.3.5
@llvm/pr-subscribers-bolt Author: Amir Ayupov (aaupov) ChangesUse known order of BOLT split function symbols: fragment symbols Depends On: #89648 Test Plan: updated cdsplit-symbol-names.s Full diff: https://github.com/llvm/llvm-project/pull/90424.diff 2 Files Affected:
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index d08c760f4da18d..8eb2e5a9d9120a 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1510,6 +1510,26 @@ void RewriteInstance::registerFragments() {
StopSymbol = *FSI;
uint64_t ParentAddress{0};
+
+ // BOLT split fragment symbols are emitted just before the main function
+ // symbol.
+ for (ELFSymbolRef NextSymbol = Symbol; NextSymbol < StopSymbol;
+ NextSymbol.moveNext()) {
+ Expected<StringRef> NameOrError = Symbol.getName();
+ if (!NameOrError)
+ break;
+ StringRef Name = *NameOrError;
+ if (Name == ParentName) {
+ ParentAddress = cantFail(NextSymbol.getValue());
+ goto registerParent;
+ }
+ if (Name.starts_with(ParentName))
+ // With multi-way splitting, there are multiple fragments with different
+ // suffixes. Parent follows the last fragment.
+ continue;
+ break;
+ }
+
// Iterate over local file symbols and check symbol names to match parent.
for (ELFSymbolRef Symbol(FSI[-1]); Symbol < StopSymbol; Symbol.moveNext()) {
if (cantFail(Symbol.getName()) == ParentName) {
@@ -1518,6 +1538,7 @@ void RewriteInstance::registerFragments() {
}
}
+registerParent:
// No local parent is found, use global parent function.
if (!ParentAddress)
if (BinaryData *ParentBD = BC->getBinaryDataByName(ParentName))
diff --git a/bolt/test/X86/cdsplit-symbol-names.s b/bolt/test/X86/cdsplit-symbol-names.s
index e53863e22246d6..1d3fa91936af04 100644
--- a/bolt/test/X86/cdsplit-symbol-names.s
+++ b/bolt/test/X86/cdsplit-symbol-names.s
@@ -7,7 +7,7 @@
# RUN: llvm-strip --strip-unneeded %t.o
# 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
+# RUN: --call-scale=2 --data=%t.fdata --reorder-blocks=ext-tsp --enable-bat
# RUN: llvm-objdump --syms %t.bolt | FileCheck %s --check-prefix=CHECK-SYMS-WARM
# CHECK-SYMS-WARM: 0000000000000000 l df *ABS* 0000000000000000 bolt-pseudo.o
@@ -16,8 +16,19 @@
# 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)
+
.text
- .globl chain
+ .type chain, @function
+chain:
+ ret
+ .size chain, .-chain
+
.type chain, @function
chain:
pushq %rbp
|
Created using spr 1.3.5 [skip ci]
Created using spr 1.3.5
maksfb
approved these changes
Apr 29, 2024
Created using spr 1.3.5 [skip ci]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use known order of BOLT split function symbols: fragment symbols
immediately precede the parent fragment symbol.
Depends On: #89648
Test Plan: Added register-fragments-bolt-symbols.s