`__profd_*` variables are referenced by code only when value profiling is enabled. If disabled (e.g. default -fprofile-instr-generate), the symbols just waste space on ELF/Mach-O. We change the comdat symbol from `__profd_*` to `__profc_*` because an internal symbol does not provide deduplication features on COFF. The choice doesn't matter on ELF. (In -DLLVM_BUILD_INSTRUMENTED_COVERAGE=on build, there is now no `__profd_*` symbols.) On Windows this enables further optimization. We are no longer affected by the link.exe limitation: an external symbol in IMAGE_COMDAT_SELECT_ASSOCIATIVE can cause duplicate definition error. https://lists.llvm.org/pipermail/llvm-dev/2021-May/150758.html We can thus use llvm.compiler.used instead of llvm.used like ELF (D97585). This avoids many `/INCLUDE:` directives in `.drectve`. Here is rnk's measurement for Chrome: ``` This reduced object file size of base_unittests.exe, compiled with coverage, optimizations, and gmlt debug info by 10%: #BEFORE $ find . -iname '*.obj' | xargs du -b | awk '{ sum += $1 } END { print sum}' 1047758867 $ du -cksh base_unittests.exe 82M base_unittests.exe 82M total # AFTER $ find . -iname '*.obj' | xargs du -b | awk '{ sum += $1 } END { print sum}' 937886499 $ du -cksh base_unittests.exe 78M base_unittests.exe 78M total ``` The change is NFC for Mach-O. Reviewed By: davidxl, rnk Differential Revision: https://reviews.llvm.org/D103372
63 lines
3.7 KiB
LLVM
63 lines
3.7 KiB
LLVM
; 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.
|
|
;
|
|
; Test comdat functions. Non-comdat functions are tested in linkage.ll.
|
|
; RUN: split-file %s %t
|
|
; RUN: cat %t/main.ll %t/disable.ll > %t0.ll
|
|
; RUN: cat %t/main.ll %t/enable.ll > %t1.ll
|
|
; RUN: opt < %t0.ll -mtriple=x86_64-linux -passes=instrprof -S | FileCheck %s --check-prefixes=ELF
|
|
; RUN: opt < %t1.ll -mtriple=x86_64-linux -passes=instrprof -S | FileCheck %s --check-prefixes=ELF
|
|
; RUN: opt < %t0.ll -mtriple=x86_64-windows -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
|
|
; RUN: opt < %t1.ll -mtriple=x86_64-windows -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
|
|
|
|
;--- main.ll
|
|
declare void @llvm.instrprof.increment(i8*, i64, i32, i32)
|
|
|
|
$foo_inline = comdat any
|
|
$foo_extern = comdat any
|
|
|
|
@__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"
|
|
|
|
;; When value profiling is disabled, __profd_ variables are not referenced by
|
|
;; code. We can use private linkage. When enabled, __profd_ needs to be
|
|
;; non-local which requires separate comdat on COFF due to a link.exe limitation.
|
|
|
|
; ELF: @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section "__llvm_prf_cnts", comdat, align 8
|
|
; ELF0: @__profd_foo_inline = private global {{.*}}, section "__llvm_prf_data", comdat($__profc_foo_inline), align 8
|
|
; ELF1: @__profd_foo_inline = linkonce_odr hidden global {{.*}}, section "__llvm_prf_data", comdat($__profc_foo_inline), align 8
|
|
; COFF0: @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfc$M", comdat, align 8
|
|
; COFF0: @__profd_foo_inline = private global {{.*}}, section ".lprfd$M", comdat($__profc_foo_inline), align 8
|
|
; COFF1: @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfc$M", comdat, align 8
|
|
; COFF1: @__profd_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfd$M", comdat, 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
|
|
}
|
|
|
|
; ELF: @__profc_foo_extern = linkonce_odr hidden global{{.*}}, section "__llvm_prf_cnts", comdat, align 8
|
|
; ELF0: @__profd_foo_extern = private global{{.*}}, section "__llvm_prf_data", comdat($__profc_foo_extern), align 8
|
|
; ELF1: @__profd_foo_extern = linkonce_odr hidden global{{.*}}, section "__llvm_prf_data", comdat($__profc_foo_extern), align 8
|
|
; COFF: @__profc_foo_extern = linkonce_odr hidden global{{.*}}, section ".lprfc$M", comdat, align 8
|
|
; COFF0: @__profd_foo_extern = private global{{.*}}, section ".lprfd$M", comdat($__profc_foo_extern), align 8
|
|
; COFF1: @__profd_foo_extern = linkonce_odr hidden global{{.*}}, section ".lprfd$M", comdat, 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
|
|
}
|
|
|
|
; ELF: @llvm.compiler.used = appending global {{.*}} @__profd_foo_inline {{.*}} @__profd_foo_extern
|
|
; COFF0: @llvm.compiler.used = appending global {{.*}} @__llvm_profile_runtime_user {{.*}} @__profd_foo_inline {{.*}} @__profd_foo_extern
|
|
; COFF1: @llvm.used = appending global {{.*}} @__llvm_profile_runtime_user {{.*}} @__profd_foo_inline {{.*}} @__profd_foo_extern
|
|
|
|
;--- disable.ll
|
|
!llvm.module.flags = !{!0}
|
|
!0 = !{i32 2, !"EnableValueProfiling", i32 0}
|
|
|
|
;--- enable.ll
|
|
!llvm.module.flags = !{!0}
|
|
!0 = !{i32 2, !"EnableValueProfiling", i32 1}
|