[llvm] r338082 - [InstrProf] Use comdats on COFF for available_externally functions
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 26 15:59:17 PDT 2018
Author: rnk
Date: Thu Jul 26 15:59:17 2018
New Revision: 338082
URL: http://llvm.org/viewvc/llvm-project?rev=338082&view=rev
Log:
[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
Modified:
llvm/trunk/lib/ProfileData/InstrProf.cpp
llvm/trunk/test/Instrumentation/InstrProfiling/linkage.ll
llvm/trunk/test/Transforms/PGOProfile/comdat_rename.ll
Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=338082&r1=338081&r2=338082&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Thu Jul 26 15:59:17 2018
@@ -926,8 +926,7 @@ bool needsComdatForCounter(const Functio
if (F.hasComdat())
return true;
- Triple TT(M.getTargetTriple());
- if (!TT.isOSBinFormatELF() && !TT.isOSBinFormatWasm())
+ if (!Triple(M.getTargetTriple()).supportsCOMDAT())
return false;
// See createPGOFuncNameVar for more details. To avoid link errors, profile
Modified: llvm/trunk/test/Instrumentation/InstrProfiling/linkage.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/InstrProfiling/linkage.ll?rev=338082&r1=338081&r2=338082&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/InstrProfiling/linkage.ll (original)
+++ llvm/trunk/test/Instrumentation/InstrProfiling/linkage.ll Thu Jul 26 15:59:17 2018
@@ -32,6 +32,8 @@ define weak void @foo_weak() {
; COMMON: @"__profc_linkage.ll:foo_internal" = internal global
; COMMON: @"__profd_linkage.ll:foo_internal" = internal global
+; COFF: @"__profc_linkage.ll:foo_internal" = internal global
+; COFF: @"__profd_linkage.ll:foo_internal" = internal global
define internal void @foo_internal() {
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)
ret void
@@ -39,6 +41,9 @@ define internal void @foo_internal() {
; COMMON: @__profc_foo_inline = linkonce_odr hidden global
; COMMON: @__profd_foo_inline = linkonce_odr hidden global
+; FIXME: Should we put a comdat here?
+; COFF: @__profc_foo_inline = linkonce_odr hidden global {{.*}}section ".lprfc", align 8
+; COFF: @__profd_foo_inline = linkonce_odr hidden global {{.*}}section ".lprfd", align 8
define linkonce_odr void @foo_inline() {
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
@@ -48,6 +53,8 @@ define linkonce_odr void @foo_inline() {
; LINUX: @__profd_foo_extern = linkonce_odr hidden global {{.*}}section "__llvm_prf_data", comdat($__profv_foo_extern), align 8
; OTHER: @__profc_foo_extern = linkonce_odr hidden global
; OTHER: @__profd_foo_extern = linkonce_odr hidden global
+; COFF: @__profc_foo_extern = linkonce_odr hidden global {{.*}}section ".lprfc", comdat, align 8
+; COFF: @__profd_foo_extern = linkonce_odr hidden global {{.*}}section ".lprfd", comdat($__profc_foo_extern), 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
Modified: llvm/trunk/test/Transforms/PGOProfile/comdat_rename.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/comdat_rename.ll?rev=338082&r1=338081&r2=338082&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/comdat_rename.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/comdat_rename.ll Thu Jul 26 15:59:17 2018
@@ -1,25 +1,25 @@
-; RUN: opt < %s -mtriple=x86_64-unknown-linux -pgo-instr-gen -do-comdat-renaming=true -S | FileCheck --check-prefixes COMMON,ELFONLY %s
-; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=pgo-instr-gen -do-comdat-renaming=true -S | FileCheck --check-prefixes COMMON,ELFONLY %s
-; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -pgo-instr-gen -do-comdat-renaming=true -S | FileCheck --check-prefixes COMMON,COFFONLY %s
-; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -passes=pgo-instr-gen -do-comdat-renaming=true -S | FileCheck --check-prefixes COMMON,COFFONLY %s
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -pgo-instr-gen -do-comdat-renaming=true -S | FileCheck %s
+; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=pgo-instr-gen -do-comdat-renaming=true -S | FileCheck %s
+; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -pgo-instr-gen -do-comdat-renaming=true -S | FileCheck %s
+; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -passes=pgo-instr-gen -do-comdat-renaming=true -S | FileCheck %s
; Rename Comdat group and its function.
$f = comdat any
-; COMMON: $f.[[SINGLEBB_HASH:[0-9]+]] = comdat any
+; CHECK: $f.[[SINGLEBB_HASH:[0-9]+]] = comdat any
define linkonce_odr void @f() comdat($f) {
ret void
}
; Not rename Comdat with right linkage.
$nf = comdat any
-; COMMON: $nf = comdat any
+; CHECK: $nf = comdat any
define void @nf() comdat($nf) {
ret void
}
; Not rename Comdat with variable members.
$f_with_var = comdat any
-; COMMON: $f_with_var = comdat any
+; CHECK: $f_with_var = comdat any
@var = global i32 0, comdat($f_with_var)
define linkonce_odr void @f_with_var() comdat($f_with_var) {
%tmp = load i32, i32* @var, align 4
@@ -30,7 +30,7 @@ define linkonce_odr void @f_with_var() c
; Not rename Comdat with multiple functions.
$tf = comdat any
-; COMMON: $tf = comdat any
+; CHECK: $tf = comdat any
define linkonce void @tf() comdat($tf) {
ret void
}
@@ -39,14 +39,13 @@ define linkonce void @tf2() comdat($tf)
}
; Rename AvailableExternallyLinkage functions
-; ELFONLY-DAG: $aef.[[SINGLEBB_HASH]] = comdat any
+; CHECK-DAG: $aef.[[SINGLEBB_HASH]] = comdat any
-; ELFONLY: @f = weak alias void (), void ()* @f.[[SINGLEBB_HASH]]
-; ELFONLY: @aef = weak alias void (), void ()* @aef.[[SINGLEBB_HASH]]
+; CHECK: @f = weak alias void (), void ()* @f.[[SINGLEBB_HASH]]
+; CHECK: @aef = weak alias void (), void ()* @aef.[[SINGLEBB_HASH]]
define available_externally void @aef() {
-; ELFONLY: define linkonce_odr void @aef.[[SINGLEBB_HASH]]() comdat {
-; COFFONLY: define available_externally void @aef() {
+; CHECK: define linkonce_odr void @aef.[[SINGLEBB_HASH]]() comdat {
ret void
}
More information about the llvm-commits
mailing list