From 76981fbcf6222271f4f1c166789cf1a0d6077e7e Mon Sep 17 00:00:00 2001 From: Maksim Panchenko Date: Wed, 20 Apr 2022 16:59:41 -0700 Subject: [BOLT] Add fuzzy function name matching for LLVM LTO LLVM with LTO can generate function names in the form func.llvm., where 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 --- bolt/lib/Profile/DataReader.cpp | 2 ++ bolt/test/X86/lto-name-match.s | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 bolt/test/X86/lto-name-match.s (limited to 'bolt') 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 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 -- cgit v1.2.3