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 12; RUN: opt < %t1.ll -mtriple=x86_64-linux -passes=instrprof -S | FileCheck %s --check-prefixes=ELF 13; RUN: opt < %t0.ll -mtriple=x86_64-windows -passes=instrprof -S | FileCheck %s --check-prefixes=COFF 14; RUN: opt < %t1.ll -mtriple=x86_64-windows -passes=instrprof -S | FileCheck %s --check-prefixes=COFF 15 16;--- main.ll 17declare void @llvm.instrprof.increment(i8*, 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; ELF: @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section "__llvm_prf_cnts", comdat($__profd_foo_inline), align 8 26; ELF: @__profd_foo_inline = linkonce_odr hidden global {{.*}}, section "__llvm_prf_data", comdat, align 8 27; COFF: @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfc$M", comdat, align 8 28; COFF: @__profd_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfd$M", comdat, align 8 29define weak_odr void @foo_inline() comdat { 30 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) 31 ret void 32} 33 34; ELF: @__profc_foo_extern = linkonce_odr hidden global{{.*}}, section "__llvm_prf_cnts", comdat($__profd_foo_extern), align 8 35; ELF: @__profd_foo_extern = linkonce_odr hidden global{{.*}}, section "__llvm_prf_data", comdat, align 8 36; COFF: @__profc_foo_extern = linkonce_odr hidden global{{.*}}, section ".lprfc$M", comdat, align 8 37; COFF: @__profd_foo_extern = linkonce_odr hidden global{{.*}}, section ".lprfd$M", comdat, align 8 38define available_externally void @foo_extern() { 39 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) 40 ret void 41} 42 43; ELF: @llvm.compiler.used = appending global {{.*}} @__profd_foo_inline {{.*}} @__profd_foo_extern 44; COFF: @llvm.used = appending global {{.*}} @__llvm_profile_runtime_user {{.*}} @__profd_foo_inline {{.*}} @__profd_foo_extern 45 46;--- disable.ll 47!llvm.module.flags = !{!0} 48!0 = !{i32 2, !"EnableValueProfiling", i32 0} 49 50;--- enable.ll 51!llvm.module.flags = !{!0} 52!0 = !{i32 2, !"EnableValueProfiling", i32 1} 53