1; There are two main cases where comdats are necessary:
2; 1. standard inline functions (weak_odr / linkonce_odr)
3; 2. available externally functions (C99 inline / extern template / dllimport)
4; Check that we do the right thing for the two object formats with comdats, ELF
5; and COFF.
6;
7; Test comdat functions. Non-comdat functions are tested in linkage.ll.
8; RUN: split-file %s %t
9; RUN: cat %t/main.ll %t/disable.ll > %t0.ll
10; RUN: cat %t/main.ll %t/enable.ll > %t1.ll
11; RUN: opt < %t0.ll -mtriple=x86_64-linux -passes=instrprof -S | FileCheck %s --check-prefixes=ELF,ELF0
12; RUN: opt < %t1.ll -mtriple=x86_64-linux -passes=instrprof -S | FileCheck %s --check-prefixes=ELF,ELF1
13; RUN: opt < %t0.ll -mtriple=x86_64-windows -passes=instrprof -S | FileCheck %s --check-prefixes=COFF,COFF0
14; RUN: opt < %t1.ll -mtriple=x86_64-windows -passes=instrprof -S | FileCheck %s --check-prefixes=COFF,COFF1
15
16;--- main.ll
17declare void @llvm.instrprof.increment(ptr, i64, i32, i32)
18
19$foo_inline = comdat any
20$foo_extern = comdat any
21
22@__profn_foo_inline = linkonce_odr hidden constant [10 x i8] c"foo_inline"
23@__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern"
24
25;; When value profiling is disabled, __profd_ variables are not referenced by
26;; code. We can use private linkage. When enabled, __profd_ needs to be
27;; non-local which requires separate comdat on COFF due to a link.exe limitation.
28
29; ELF:   @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section "__llvm_prf_cnts", comdat, align 8
30; ELF0:  @__profd_foo_inline = private global {{.*}}, section "__llvm_prf_data", comdat($__profc_foo_inline), align 8
31; ELF1:  @__profd_foo_inline = linkonce_odr hidden global {{.*}}, section "__llvm_prf_data", comdat($__profc_foo_inline), align 8
32; COFF0: @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfc$M", comdat, align 8
33; COFF0: @__profd_foo_inline = private global {{.*}}, section ".lprfd$M", comdat($__profc_foo_inline), align 8
34; COFF1: @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfc$M", comdat, align 8
35; COFF1: @__profd_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfd$M", comdat, align 8
36define weak_odr void @foo_inline() comdat {
37  call void @llvm.instrprof.increment(ptr @__profn_foo_inline, i64 0, i32 1, i32 0)
38  ret void
39}
40
41; ELF:   @__profc_foo_extern = linkonce_odr hidden global{{.*}}, section "__llvm_prf_cnts", comdat, align 8
42; ELF0:  @__profd_foo_extern = private global{{.*}}, section "__llvm_prf_data", comdat($__profc_foo_extern), align 8
43; ELF1:  @__profd_foo_extern = linkonce_odr hidden global{{.*}}, section "__llvm_prf_data", comdat($__profc_foo_extern), align 8
44; COFF:  @__profc_foo_extern = linkonce_odr hidden global{{.*}}, section ".lprfc$M", comdat, align 8
45; COFF0: @__profd_foo_extern = private global{{.*}}, section ".lprfd$M", comdat($__profc_foo_extern), align 8
46; COFF1: @__profd_foo_extern = linkonce_odr hidden global{{.*}}, section ".lprfd$M", comdat, align 8
47define available_externally void @foo_extern() {
48  call void @llvm.instrprof.increment(ptr @__profn_foo_extern, i64 0, i32 1, i32 0)
49  ret void
50}
51
52; ELF:   @llvm.compiler.used = appending global [2 x ptr] [ptr @__profd_foo_inline, ptr @__profd_foo_extern]
53; COFF0: @llvm.compiler.used = appending global [3 x ptr] [ptr @__llvm_profile_runtime_user, ptr @__profd_foo_inline, ptr @__profd_foo_extern]
54; COFF1: @llvm.used = appending global [4 x ptr] [ptr @__llvm_profile_runtime_user, ptr @__profd_foo_inline, ptr @__profd_foo_extern, ptr @__llvm_prf_nm]
55
56;--- disable.ll
57!llvm.module.flags = !{!0}
58!0 = !{i32 2, !"EnableValueProfiling", i32 0}
59
60;--- enable.ll
61!llvm.module.flags = !{!0}
62!0 = !{i32 2, !"EnableValueProfiling", i32 1}
63