Skip to content

Commit 76981fb

Browse files
committed
[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
1 parent aa643f4 commit 76981fb

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

bolt/lib/Profile/DataReader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Optional<StringRef> getLTOCommonName(const StringRef Name) {
4747
return Name.substr(0, LTOSuffixPos + 10);
4848
if ((LTOSuffixPos = Name.find(".constprop.")) != StringRef::npos)
4949
return Name.substr(0, LTOSuffixPos + 11);
50+
if ((LTOSuffixPos = Name.find(".llvm.")) != StringRef::npos)
51+
return Name.substr(0, LTOSuffixPos + 6);
5052
return NoneType();
5153
}
5254

bolt/test/X86/lto-name-match.s

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# REQUIRES: system-linux
2+
3+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
4+
# RUN: link_fdata %s %t.o %t.fdata
5+
# RUN: llvm-strip --strip-unneeded %t.o
6+
# RUN: %clang %cflags %t.o -o %t.exe
7+
# RUN: llvm-bolt %t.exe -data %t.fdata -o /dev/null | FileCheck %s
8+
9+
## Check that profile is correctly matched by functions with variable suffixes.
10+
## E.g., LTO-generated name foo.llvm.123 should match foo.llvm.*.
11+
12+
# CHECK: 4 out of {{.*}} functions in the binary {{.*}} have non-empty execution profile
13+
# CHECK-NOT: profile for {{.*}} objects was ignored
14+
15+
.globl _start
16+
_start:
17+
18+
LL_start_0:
19+
# FDATA: 1 _start #LL_start_0# 1 foo.llvm.321 0 0 1
20+
call foo.llvm.123
21+
22+
LL_start_1:
23+
# FDATA: 1 _start #LL_start_1# 1 foo.constprop.321 0 0 1
24+
call foo.constprop.123
25+
26+
LL_start_2:
27+
# FDATA: 1 _start #LL_start_2# 1 foo.lto_priv.321 0 0 1
28+
call foo.lto_priv.123
29+
30+
call exit
31+
.size _start, .-_start
32+
33+
.globl foo.llvm.123
34+
.type foo.llvm.123,@function
35+
foo.llvm.123:
36+
ret
37+
.size foo.llvm.123, .-foo.llvm.123
38+
39+
.globl foo.constprop.123
40+
.type foo.constprop.123,@function
41+
foo.constprop.123:
42+
ret
43+
.size foo.constprop.123, .-foo.constprop.123
44+
45+
.globl foo.lto_priv.123
46+
.type foo.lto_priv.123,@function
47+
foo.lto_priv.123:
48+
ret
49+
.size foo.lto_priv.123, .-foo.lto_priv.123

0 commit comments

Comments
 (0)