llvm.org GIT mirror llvm / aeb706b
[InstrProf] Use comdats on COFF for available_externally functions Summary: r262157 added ELF-specific logic to put a comdat on the __profc_* globals created for available_externally functions. We should be able to generalize that logic to all object file formats that support comdats, i.e. everything other than MachO. This fixes duplicate symbol errors, since on COFF, linkonce_odr doesn't make the symbol weak. Fixes PR38251. Reviewers: davidxl, xur Subscribers: hiraditya, dmajor, llvm-commits, aheejin Differential Revision: https://reviews.llvm.org/D49882 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338082 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 1 year, 1 month ago
3 changed file(s) with 20 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
925925 if (F.hasComdat())
926926 return true;
927927
928 Triple TT(M.getTargetTriple());
929 if (!TT.isOSBinFormatELF() && !TT.isOSBinFormatWasm())
928 if (!Triple(M.getTargetTriple()).supportsCOMDAT())
930929 return false;
931930
932931 // See createPGOFuncNameVar for more details. To avoid link errors, profile
3131
3232 ; COMMON: @"__profc_linkage.ll:foo_internal" = internal global
3333 ; COMMON: @"__profd_linkage.ll:foo_internal" = internal global
34 ; COFF: @"__profc_linkage.ll:foo_internal" = internal global
35 ; COFF: @"__profd_linkage.ll:foo_internal" = internal global
3436 define internal void @foo_internal() {
3537 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)
3638 ret void
3840
3941 ; COMMON: @__profc_foo_inline = linkonce_odr hidden global
4042 ; COMMON: @__profd_foo_inline = linkonce_odr hidden global
43 ; FIXME: Should we put a comdat here?
44 ; COFF: @__profc_foo_inline = linkonce_odr hidden global {{.*}}section ".lprfc", align 8
45 ; COFF: @__profd_foo_inline = linkonce_odr hidden global {{.*}}section ".lprfd", align 8
4146 define linkonce_odr void @foo_inline() {
4247 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)
4348 ret void
4752 ; LINUX: @__profd_foo_extern = linkonce_odr hidden global {{.*}}section "__llvm_prf_data", comdat($__profv_foo_extern), align 8
4853 ; OTHER: @__profc_foo_extern = linkonce_odr hidden global
4954 ; OTHER: @__profd_foo_extern = linkonce_odr hidden global
55 ; COFF: @__profc_foo_extern = linkonce_odr hidden global {{.*}}section ".lprfc", comdat, align 8
56 ; COFF: @__profd_foo_extern = linkonce_odr hidden global {{.*}}section ".lprfd", comdat($__profc_foo_extern), align 8
5057 define available_externally void @foo_extern() {
5158 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)
5259 ret void
None ; RUN: opt < %s -mtriple=x86_64-unknown-linux -pgo-instr-gen -do-comdat-renaming=true -S | FileCheck --check-prefixes COMMON,ELFONLY %s
1 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=pgo-instr-gen -do-comdat-renaming=true -S | FileCheck --check-prefixes COMMON,ELFONLY %s
2 ; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -pgo-instr-gen -do-comdat-renaming=true -S | FileCheck --check-prefixes COMMON,COFFONLY %s
3 ; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -passes=pgo-instr-gen -do-comdat-renaming=true -S | FileCheck --check-prefixes COMMON,COFFONLY %s
0 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -pgo-instr-gen -do-comdat-renaming=true -S | FileCheck %s
1 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=pgo-instr-gen -do-comdat-renaming=true -S | FileCheck %s
2 ; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -pgo-instr-gen -do-comdat-renaming=true -S | FileCheck %s
3 ; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -passes=pgo-instr-gen -do-comdat-renaming=true -S | FileCheck %s
44
55 ; Rename Comdat group and its function.
66 $f = comdat any
7 ; COMMON: $f.[[SINGLEBB_HASH:[0-9]+]] = comdat any
7 ; CHECK: $f.[[SINGLEBB_HASH:[0-9]+]] = comdat any
88 define linkonce_odr void @f() comdat($f) {
99 ret void
1010 }
1111
1212 ; Not rename Comdat with right linkage.
1313 $nf = comdat any
14 ; COMMON: $nf = comdat any
14 ; CHECK: $nf = comdat any
1515 define void @nf() comdat($nf) {
1616 ret void
1717 }
1818
1919 ; Not rename Comdat with variable members.
2020 $f_with_var = comdat any
21 ; COMMON: $f_with_var = comdat any
21 ; CHECK: $f_with_var = comdat any
2222 @var = global i32 0, comdat($f_with_var)
2323 define linkonce_odr void @f_with_var() comdat($f_with_var) {
2424 %tmp = load i32, i32* @var, align 4
2929
3030 ; Not rename Comdat with multiple functions.
3131 $tf = comdat any
32 ; COMMON: $tf = comdat any
32 ; CHECK: $tf = comdat any
3333 define linkonce void @tf() comdat($tf) {
3434 ret void
3535 }
3838 }
3939
4040 ; Rename AvailableExternallyLinkage functions
41 ; ELFONLY-DAG: $aef.[[SINGLEBB_HASH]] = comdat any
41 ; CHECK-DAG: $aef.[[SINGLEBB_HASH]] = comdat any
4242
43 ; ELFONLY: @f = weak alias void (), void ()* @f.[[SINGLEBB_HASH]]
44 ; ELFONLY: @aef = weak alias void (), void ()* @aef.[[SINGLEBB_HASH]]
43 ; CHECK: @f = weak alias void (), void ()* @f.[[SINGLEBB_HASH]]
44 ; CHECK: @aef = weak alias void (), void ()* @aef.[[SINGLEBB_HASH]]
4545
4646 define available_externally void @aef() {
47 ; ELFONLY: define linkonce_odr void @aef.[[SINGLEBB_HASH]]() comdat {
48 ; COFFONLY: define available_externally void @aef() {
47 ; CHECK: define linkonce_odr void @aef.[[SINGLEBB_HASH]]() comdat {
4948 ret void
5049 }
5150