xref: /llvm-project/llvm/test/Instrumentation/InstrProfiling/comdat.ll (revision 6e45162adfec14ef4f53ec99312cb26d23f929bc)
1987d331fSReid Kleckner; There are two main cases where comdats are necessary:
2987d331fSReid Kleckner; 1. standard inline functions (weak_odr / linkonce_odr)
3987d331fSReid Kleckner; 2. available externally functions (C99 inline / extern template / dllimport)
4987d331fSReid Kleckner; Check that we do the right thing for the two object formats with comdats, ELF
5987d331fSReid Kleckner; and COFF.
67145c6caSFangrui Song;
77145c6caSFangrui Song; Test comdat functions. Non-comdat functions are tested in linkage.ll.
87145c6caSFangrui Song; RUN: split-file %s %t
97145c6caSFangrui Song; RUN: cat %t/main.ll %t/disable.ll > %t0.ll
107145c6caSFangrui Song; RUN: cat %t/main.ll %t/enable.ll > %t1.ll
119ff36df5SFangrui Song; RUN: opt < %t0.ll -mtriple=x86_64-linux -passes=instrprof -S | FileCheck %s --check-prefixes=ELF,ELF0
129ff36df5SFangrui Song; RUN: opt < %t1.ll -mtriple=x86_64-linux -passes=instrprof -S | FileCheck %s --check-prefixes=ELF,ELF1
139ff36df5SFangrui Song; RUN: opt < %t0.ll -mtriple=x86_64-windows -passes=instrprof -S | FileCheck %s --check-prefixes=COFF,COFF0
149ff36df5SFangrui Song; RUN: opt < %t1.ll -mtriple=x86_64-windows -passes=instrprof -S | FileCheck %s --check-prefixes=COFF,COFF1
15987d331fSReid Kleckner
167145c6caSFangrui Song;--- main.ll
179ff36df5SFangrui Songdeclare void @llvm.instrprof.increment(ptr, i64, i32, i32)
18987d331fSReid Kleckner
19987d331fSReid Kleckner$foo_inline = comdat any
207145c6caSFangrui Song$foo_extern = comdat any
21*6e45162aSArthur Eubanks$foo_private_profn = comdat any
22987d331fSReid Kleckner
23987d331fSReid Kleckner@__profn_foo_inline = linkonce_odr hidden constant [10 x i8] c"foo_inline"
247145c6caSFangrui Song@__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern"
25*6e45162aSArthur Eubanks@__profn_foo_private_profn = private constant [17 x i8] c"foo_private_profn"
26987d331fSReid Kleckner
279e51d1f3SFangrui Song;; When value profiling is disabled, __profd_ variables are not referenced by
289e51d1f3SFangrui Song;; code. We can use private linkage. When enabled, __profd_ needs to be
299e51d1f3SFangrui Song;; non-local which requires separate comdat on COFF due to a link.exe limitation.
309e51d1f3SFangrui Song
319e51d1f3SFangrui Song; ELF:   @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section "__llvm_prf_cnts", comdat, align 8
329e51d1f3SFangrui Song; ELF0:  @__profd_foo_inline = private global {{.*}}, section "__llvm_prf_data", comdat($__profc_foo_inline), align 8
339e51d1f3SFangrui Song; ELF1:  @__profd_foo_inline = linkonce_odr hidden global {{.*}}, section "__llvm_prf_data", comdat($__profc_foo_inline), align 8
349e51d1f3SFangrui Song; COFF0: @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfc$M", comdat, align 8
35*6e45162aSArthur Eubanks; COFF0: @__profd_foo_inline = internal global {{.*}}, section ".lprfd$M", comdat($__profc_foo_inline), align 8
369e51d1f3SFangrui Song; COFF1: @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfc$M", comdat, align 8
379e51d1f3SFangrui Song; COFF1: @__profd_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfd$M", comdat, align 8
38987d331fSReid Klecknerdefine weak_odr void @foo_inline() comdat {
399ff36df5SFangrui Song  call void @llvm.instrprof.increment(ptr @__profn_foo_inline, i64 0, i32 1, i32 0)
40987d331fSReid Kleckner  ret void
41987d331fSReid Kleckner}
42987d331fSReid Kleckner
439e51d1f3SFangrui Song; ELF:   @__profc_foo_extern = linkonce_odr hidden global{{.*}}, section "__llvm_prf_cnts", comdat, align 8
449e51d1f3SFangrui Song; ELF0:  @__profd_foo_extern = private global{{.*}}, section "__llvm_prf_data", comdat($__profc_foo_extern), align 8
459e51d1f3SFangrui Song; ELF1:  @__profd_foo_extern = linkonce_odr hidden global{{.*}}, section "__llvm_prf_data", comdat($__profc_foo_extern), align 8
46b959906cSFangrui Song; COFF:  @__profc_foo_extern = linkonce_odr hidden global{{.*}}, section ".lprfc$M", comdat, align 8
47*6e45162aSArthur Eubanks; COFF0: @__profd_foo_extern = internal global{{.*}}, section ".lprfd$M", comdat($__profc_foo_extern), align 8
489e51d1f3SFangrui Song; COFF1: @__profd_foo_extern = linkonce_odr hidden global{{.*}}, section ".lprfd$M", comdat, align 8
49987d331fSReid Klecknerdefine available_externally void @foo_extern() {
509ff36df5SFangrui Song  call void @llvm.instrprof.increment(ptr @__profn_foo_extern, i64 0, i32 1, i32 0)
51987d331fSReid Kleckner  ret void
52987d331fSReid Kleckner}
537145c6caSFangrui Song
54*6e45162aSArthur Eubanks; ELF:   @__profc_foo_private_profn = private global{{.*}}, section "__llvm_prf_cnts", comdat, align 8
55*6e45162aSArthur Eubanks; ELF0:  @__profd_foo_private_profn = private global{{.*}}, section "__llvm_prf_data", comdat($__profc_foo_private_profn), align 8
56*6e45162aSArthur Eubanks; ELF1:  @__profd_foo_private_profn = private global{{.*}}, section "__llvm_prf_data", comdat($__profc_foo_private_profn), align 8
57*6e45162aSArthur Eubanks; COFF:  @__profc_foo_private_profn = internal global{{.*}}, section ".lprfc$M", comdat, align 8
58*6e45162aSArthur Eubanks; COFF0: @__profd_foo_private_profn = internal global{{.*}}, section ".lprfd$M", comdat($__profc_foo_private_profn), align 8
59*6e45162aSArthur Eubanks; COFF1: @__profd_foo_private_profn = internal global{{.*}}, section ".lprfd$M", comdat, align 8
60*6e45162aSArthur Eubanksdefine void @foo_private_profn() comdat {
61*6e45162aSArthur Eubanks  call void @llvm.instrprof.increment(ptr @__profn_foo_private_profn, i64 0, i32 1, i32 0)
62*6e45162aSArthur Eubanks  ret void
63*6e45162aSArthur Eubanks}
64*6e45162aSArthur Eubanks
65*6e45162aSArthur Eubanks; ELF:   @llvm.compiler.used = appending global [3 x ptr] [ptr @__profd_foo_inline, ptr @__profd_foo_extern, ptr @__profd_foo_private_profn]
66*6e45162aSArthur Eubanks; COFF0: @llvm.compiler.used = appending global [4 x ptr] [ptr @__llvm_profile_runtime_user, ptr @__profd_foo_inline, ptr @__profd_foo_extern, ptr @__profd_foo_private_profn]
67*6e45162aSArthur Eubanks; COFF1: @llvm.used = appending global [5 x ptr] [ptr @__llvm_profile_runtime_user, ptr @__profd_foo_inline, ptr @__profd_foo_extern, ptr @__profd_foo_private_profn, ptr @__llvm_prf_nm]
687145c6caSFangrui Song
697145c6caSFangrui Song;--- disable.ll
707145c6caSFangrui Song!llvm.module.flags = !{!0}
717145c6caSFangrui Song!0 = !{i32 2, !"EnableValueProfiling", i32 0}
727145c6caSFangrui Song
737145c6caSFangrui Song;--- enable.ll
747145c6caSFangrui Song!llvm.module.flags = !{!0}
757145c6caSFangrui Song!0 = !{i32 2, !"EnableValueProfiling", i32 1}
76