Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/bolt
diff options
context:
space:
mode:
authorMaksim Panchenko <maks@fb.com>2022-04-21 02:59:41 +0300
committerMaksim Panchenko <maks@fb.com>2022-04-21 03:00:21 +0300
commit76981fbcf6222271f4f1c166789cf1a0d6077e7e (patch)
treeac6eacb52e68458b7d82e1172a61f8c5e4d65f3b /bolt
parentaa643f455a5362de7189eac630050d2c8aefe8f2 (diff)
[BOLT] Add fuzzy function name matching for LLVM LTO
LLVM with LTO can generate function names in the form func.llvm.<number>, where <number> could vary based on the compilation environment. As a result, if a profiled binary originated from a different build than a corresponding binary used for BOLT optimization, then profiles for such LTO functions will be ignored. To fix the problem, use "fuzzy" matching with "func.llvm.*" form. Reviewed By: yota9, Amir Differential Revision: https://reviews.llvm.org/D124117
Diffstat (limited to 'bolt')
-rw-r--r--bolt/lib/Profile/DataReader.cpp2
-rw-r--r--bolt/test/X86/lto-name-match.s49
2 files changed, 51 insertions, 0 deletions
diff --git a/bolt/lib/Profile/DataReader.cpp b/bolt/lib/Profile/DataReader.cpp
index 041990c13c82..3351bb5ddf06 100644
--- a/bolt/lib/Profile/DataReader.cpp
+++ b/bolt/lib/Profile/DataReader.cpp
@@ -47,6 +47,8 @@ Optional<StringRef> getLTOCommonName(const StringRef Name) {
return Name.substr(0, LTOSuffixPos + 10);
if ((LTOSuffixPos = Name.find(".constprop.")) != StringRef::npos)
return Name.substr(0, LTOSuffixPos + 11);
+ if ((LTOSuffixPos = Name.find(".llvm.")) != StringRef::npos)
+ return Name.substr(0, LTOSuffixPos + 6);
return NoneType();
}
diff --git a/bolt/test/X86/lto-name-match.s b/bolt/test/X86/lto-name-match.s
new file mode 100644
index 000000000000..0bc5066488fa
--- /dev/null
+++ b/bolt/test/X86/lto-name-match.s
@@ -0,0 +1,49 @@
+# 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
+# RUN: llvm-bolt %t.exe -data %t.fdata -o /dev/null | FileCheck %s
+
+## Check that profile is correctly matched by functions with variable suffixes.
+## E.g., LTO-generated name foo.llvm.123 should match foo.llvm.*.
+
+# CHECK: 4 out of {{.*}} functions in the binary {{.*}} have non-empty execution profile
+# CHECK-NOT: profile for {{.*}} objects was ignored
+
+ .globl _start
+_start:
+
+LL_start_0:
+# FDATA: 1 _start #LL_start_0# 1 foo.llvm.321 0 0 1
+ call foo.llvm.123
+
+LL_start_1:
+# FDATA: 1 _start #LL_start_1# 1 foo.constprop.321 0 0 1
+ call foo.constprop.123
+
+LL_start_2:
+# FDATA: 1 _start #LL_start_2# 1 foo.lto_priv.321 0 0 1
+ call foo.lto_priv.123
+
+ call exit
+ .size _start, .-_start
+
+ .globl foo.llvm.123
+ .type foo.llvm.123,@function
+foo.llvm.123:
+ ret
+ .size foo.llvm.123, .-foo.llvm.123
+
+ .globl foo.constprop.123
+ .type foo.constprop.123,@function
+foo.constprop.123:
+ ret
+ .size foo.constprop.123, .-foo.constprop.123
+
+ .globl foo.lto_priv.123
+ .type foo.lto_priv.123,@function
+foo.lto_priv.123:
+ ret
+ .size foo.lto_priv.123, .-foo.lto_priv.123