diff options
| author | Reid Kleckner <rnk@google.com> | 2019-02-08 19:03:50 +0000 |
|---|---|---|
| committer | Reid Kleckner <rnk@google.com> | 2019-02-08 19:03:50 +0000 |
| commit | 987d331fab577b33255e93ce5a53850e36b9b180 (patch) | |
| tree | 4d6f14f7d44f1d884bed60e20c287e9d98bf6e11 /llvm/test/Instrumentation | |
| parent | eb6a47a46274378f8665057bf28ec62d266600dc (diff) | |
| download | bcm5719-llvm-987d331fab577b33255e93ce5a53850e36b9b180.tar.gz bcm5719-llvm-987d331fab577b33255e93ce5a53850e36b9b180.zip | |
[InstrProf] Implement static profdata registration
Summary:
The motivating use case is eliminating duplicate profile data registered
for the same inline function in two object files. Before this change,
users would observe multiple symbol definition errors with VC link, but
links with LLD would succeed.
Users (Mozilla) have reported that PGO works well with clang-cl and LLD,
but when using LLD without this static registration, we would get into a
"relocation against a discarded section" situation. I'm not sure what
happens in that situation, but I suspect that duplicate, unused profile
information was retained. If so, this change will reduce the size of
such binaries with LLD.
Now, Windows uses static registration and is in line with all the other
platforms.
Reviewers: davidxl, wmi, inglorion, void, calixte
Subscribers: mgorny, krytarowski, eraman, fedor.sergeev, hiraditya, #sanitizers, dmajor, llvm-commits
Tags: #sanitizers, #llvm
Differential Revision: https://reviews.llvm.org/D57929
llvm-svn: 353547
Diffstat (limited to 'llvm/test/Instrumentation')
4 files changed, 71 insertions, 28 deletions
diff --git a/llvm/test/Instrumentation/InstrProfiling/PR23499.ll b/llvm/test/Instrumentation/InstrProfiling/PR23499.ll index 101fad19950..7f6bed68995 100644 --- a/llvm/test/Instrumentation/InstrProfiling/PR23499.ll +++ b/llvm/test/Instrumentation/InstrProfiling/PR23499.ll @@ -20,8 +20,8 @@ $_Z3barIvEvv = comdat any ; COFF-NOT: __profn__Z3barIvEvv -; COFF: @__profc__Z3barIvEvv = linkonce_odr hidden global [1 x i64] zeroinitializer, section "{{.*}}prfc", comdat, align 8 -; COFF: @__profd__Z3barIvEvv = linkonce_odr hidden global { i64, i64, i64*, i8*, i8*, i32, [2 x i16] } { i64 4947693190065689389, i64 0, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc__Z3barIvEvv, i32 0, i32 0), i8*{{.*}}, i8* null, i32 1, [2 x i16] zeroinitializer }, section "{{.*}}prfd{{.*}}", comdat($__profc__Z3barIvEvv), align 8 +; COFF: @__profc__Z3barIvEvv = internal global [1 x i64] zeroinitializer, section "{{.*}}prfc$M", comdat($_Z3barIvEvv), align 8 +; COFF: @__profd__Z3barIvEvv = internal global { i64, i64, i64*, i8*, i8*, i32, [2 x i16] } { i64 4947693190065689389, i64 0, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc__Z3barIvEvv, i32 0, i32 0), i8*{{.*}}, i8* null, i32 1, [2 x i16] zeroinitializer }, section "{{.*}}prfd{{.*}}", comdat($_Z3barIvEvv), align 8 declare void @llvm.instrprof.increment(i8*, i64, i32, i32) #1 diff --git a/llvm/test/Instrumentation/InstrProfiling/comdat.ll b/llvm/test/Instrumentation/InstrProfiling/comdat.ll new file mode 100644 index 00000000000..c3bb7be47f6 --- /dev/null +++ b/llvm/test/Instrumentation/InstrProfiling/comdat.ll @@ -0,0 +1,38 @@ +; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -S | FileCheck %s --check-prefixes=ELF +; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -instrprof -S | FileCheck %s --check-prefixes=COFF +; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefixes=ELF +; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF + +; There are two main cases where comdats are necessary: +; 1. standard inline functions (weak_odr / linkonce_odr) +; 2. available externally functions (C99 inline / extern template / dllimport) +; Check that we do the right thing for the two object formats with comdats, ELF +; and COFF. + +declare void @llvm.instrprof.increment(i8*, i64, i32, i32) + +$foo_inline = comdat any + +@__profn_foo_inline = linkonce_odr hidden constant [10 x i8] c"foo_inline" + +; ELF: @__profc_foo_inline = linkonce_odr hidden global{{.*}}, section "__llvm_prf_cnts", comdat($__profv_foo_inline), align 8 +; ELF: @__profd_foo_inline = linkonce_odr hidden global{{.*}}, section "__llvm_prf_data", comdat($__profv_foo_inline), align 8 +; COFF: @__profc_foo_inline = internal global{{.*}}, section ".lprfc$M", comdat($foo_inline), align 8 +; COFF: @__profd_foo_inline = internal global{{.*}}, section ".lprfd$M", comdat($foo_inline), align 8 +define weak_odr void @foo_inline() comdat { + call void @llvm.instrprof.increment(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__profn_foo_inline, i32 0, i32 0), i64 0, i32 1, i32 0) + ret void +} + +$foo_extern = comdat any + +@__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern" + +; ELF: @__profc_foo_extern = linkonce_odr hidden global{{.*}}, section "__llvm_prf_cnts", comdat($__profv_foo_extern) +; ELF: @__profd_foo_extern = linkonce_odr hidden global{{.*}}, section "__llvm_prf_data", comdat($__profv_foo_extern) +; COFF: @__profc_foo_extern = linkonce_odr dso_local global{{.*}}, section ".lprfc$M", comdat, align 8 +; COFF: @__profd_foo_extern = internal global{{.*}}, section ".lprfd$M", comdat($__profc_foo_extern), align 8 +define available_externally void @foo_extern() { + call void @llvm.instrprof.increment(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__profn_foo_extern, i32 0, i32 0), i64 0, i32 1, i32 0) + ret void +} diff --git a/llvm/test/Instrumentation/InstrProfiling/linkage.ll b/llvm/test/Instrumentation/InstrProfiling/linkage.ll index 97537579b17..29ae5d6e90c 100644 --- a/llvm/test/Instrumentation/InstrProfiling/linkage.ll +++ b/llvm/test/Instrumentation/InstrProfiling/linkage.ll @@ -1,11 +1,11 @@ ;; Check that runtime symbols get appropriate linkage. -; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -instrprof -S | FileCheck %s --check-prefixes=COMMON,MACHO -; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -S | FileCheck %s --check-prefixes=COMMON,LINUX -; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -instrprof -S | FileCheck %s --check-prefixes=COMMON,COFF -; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -passes=instrprof -S | FileCheck %s --check-prefixes=COMMON,MACHO -; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefixes=COMMON,LINUX -; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COMMON,COFF +; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -instrprof -S | FileCheck %s --check-prefixes=POSIX,MACHO +; RUN: opt < %s -mtriple=x86_64-unknown-linux -instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX +; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -instrprof -S | FileCheck %s --check-prefixes=COFF +; RUN: opt < %s -mtriple=x86_64-apple-macosx10.10.0 -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,MACHO +; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=instrprof -S | FileCheck %s --check-prefixes=POSIX,LINUX +; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF ; MACHO: @__llvm_profile_runtime = external global i32 ; LINUX-NOT: @__llvm_profile_runtime = external global i32 @@ -16,31 +16,38 @@ @__profn_foo_inline = linkonce_odr hidden constant [10 x i8] c"foo_inline" @__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern" -; COMMON: @__profc_foo = hidden global -; COMMON: @__profd_foo = hidden global +; POSIX: @__profc_foo = hidden global +; POSIX: @__profd_foo = hidden global +; COFF: @__profc_foo = internal global +; COFF-NOT: comdat +; COFF: @__profd_foo = internal global define void @foo() { call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 0, i32 1, i32 0) ret void } -; COMMON: @__profc_foo_weak = weak hidden global -; COMMON: @__profd_foo_weak = weak hidden global +; POSIX: @__profc_foo_weak = weak hidden global +; POSIX: @__profd_foo_weak = weak hidden global +; COFF: @__profc_foo_weak = internal global +; COFF: @__profd_foo_weak = internal global define weak void @foo_weak() { call void @llvm.instrprof.increment(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @__profn_foo_weak, i32 0, i32 0), i64 0, i32 1, i32 0) ret void } -; COMMON: @"__profc_linkage.ll:foo_internal" = internal global -; COMMON: @"__profd_linkage.ll:foo_internal" = internal global +; POSIX: @"__profc_linkage.ll:foo_internal" = internal global +; POSIX: @"__profd_linkage.ll:foo_internal" = internal global +; COFF: @"__profc_linkage.ll:foo_internal" = internal global +; COFF: @"__profd_linkage.ll:foo_internal" = internal global define internal void @foo_internal() { call void @llvm.instrprof.increment(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @"__profn_linkage.ll:foo_internal", i32 0, i32 0), i64 0, i32 1, i32 0) ret void } -; COMMON: @__profc_foo_inline = linkonce_odr hidden global -; COFF-SAME: section ".lprfc", align 8 -; COMMON: @__profd_foo_inline = linkonce_odr hidden global -; COFF-SAME: section ".lprfd", align 8 +; POSIX: @__profc_foo_inline = linkonce_odr hidden global +; POSIX: @__profd_foo_inline = linkonce_odr hidden global +; COFF: @__profc_foo_inline = internal global{{.*}} section ".lprfc$M", align 8 +; COFF: @__profd_foo_inline = internal global{{.*}} section ".lprfd$M", align 8 define linkonce_odr void @foo_inline() { call void @llvm.instrprof.increment(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__profn_foo_inline, i32 0, i32 0), i64 0, i32 1, i32 0) ret void @@ -50,8 +57,8 @@ define linkonce_odr void @foo_inline() { ; LINUX: @__profd_foo_extern = linkonce_odr hidden global {{.*}}section "__llvm_prf_data", comdat($__profv_foo_extern), align 8 ; MACHO: @__profc_foo_extern = linkonce_odr hidden global ; MACHO: @__profd_foo_extern = linkonce_odr hidden global -; COFF: @__profc_foo_extern = linkonce_odr hidden global {{.*}}section ".lprfc", comdat, align 8 -; COFF: @__profd_foo_extern = linkonce_odr hidden global {{.*}}section ".lprfd", comdat($__profc_foo_extern), align 8 +; COFF: @__profc_foo_extern = linkonce_odr dso_local global {{.*}}section ".lprfc$M", comdat, align 8 +; COFF: @__profd_foo_extern = internal global {{.*}}section ".lprfd$M", comdat($__profc_foo_extern), align 8 define available_externally void @foo_extern() { call void @llvm.instrprof.increment(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__profn_foo_extern, i32 0, i32 0), i64 0, i32 1, i32 0) ret void diff --git a/llvm/test/Instrumentation/InstrProfiling/platform.ll b/llvm/test/Instrumentation/InstrProfiling/platform.ll index dbdde08b815..4c54aea9aec 100644 --- a/llvm/test/Instrumentation/InstrProfiling/platform.ll +++ b/llvm/test/Instrumentation/InstrProfiling/platform.ll @@ -20,13 +20,14 @@ ; MACHO: @__profc_foo = hidden global [1 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8 ; ELF: @__profc_foo = hidden global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", align 8 -; WINDOWS: @__profc_foo = hidden global [1 x i64] zeroinitializer, section ".lprfc", align 8 +; WINDOWS: @__profc_foo = internal global [1 x i64] zeroinitializer, section ".lprfc$M", align 8 ; MACHO: @__profd_foo = hidden {{.*}}, section "__DATA,__llvm_prf_data,regular,live_support", align 8 ; ELF: @__profd_foo = hidden {{.*}}, section "__llvm_prf_data", align 8 -; WINDOWS: @__profd_foo = hidden {{.*}}, section ".lprfd", align 8 +; WINDOWS: @__profd_foo = internal global {{.*}}, section ".lprfd$M", align 8 -; ELF: @__llvm_prf_nm = private constant [{{.*}} x i8] c"{{.*}}", section "{{.*}}__llvm_prf_names" +; ELF: @__llvm_prf_nm = private constant [{{.*}} x i8] c"{{.*}}", section "{{.*}}__llvm_prf_names", align 1 +; WINDOWS: @__llvm_prf_nm = private constant [{{.*}} x i8] c"{{.*}}", section "{{.*}}lprfn$M", align 1 define void @foo() { call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 0, i32 1, i32 0) @@ -42,14 +43,11 @@ declare void @llvm.instrprof.increment(i8*, i64, i32, i32) ; LINUX-NOT: define internal void @__llvm_profile_register_functions ; FREEBSD-NOT: define internal void @__llvm_profile_register_functions ; PS4-NOT: define internal void @__llvm_profile_register_functions +; WINDOWS-NOT: define internal void @__llvm_profile_register_functions ;; PR38340: When dynamic registration is used, we had a bug where we'd register ;; something that's not a __profd_* variable. -; WINDOWS: define internal void @__llvm_profile_register_functions() -; WINDOWS-NOT: __llvm_profile_runtime_user -; WINDOWS: ret void - ; SOLARIS: define internal void @__llvm_profile_register_functions ; SOLARIS-NOT: __llvm_profile_runtime_user ; SOLARIS: ret void @@ -58,5 +56,5 @@ declare void @llvm.instrprof.increment(i8*, i64, i32, i32) ; LINUX-NOT: define internal void @__llvm_profile_init ; FREEBSD-NOT: define internal void @__llvm_profile_init ; PS4-NOT: define internal void @__llvm_profile_init +; WINDOWS-NOT: define internal void @__llvm_profile_init ; SOLARIS: define internal void @__llvm_profile_init -; WINDOWS: define internal void @__llvm_profile_init |

