[PATCH] D131043: [InstrProf] Don't use comdat for private global variables on COFF

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 2 20:24:35 PDT 2022


aeubanks created this revision.
aeubanks added reviewers: MaskRay, rnk.
Herald added subscribers: Enna1, ellis, StephenFan, hiraditya.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

COFF has a verifier check that private global variables don't have a comdat of the same name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131043

Files:
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Instrumentation/InstrProfiling/comdat.ll
  llvm/test/Instrumentation/InstrProfiling/profiling.ll


Index: llvm/test/Instrumentation/InstrProfiling/profiling.ll
===================================================================
--- llvm/test/Instrumentation/InstrProfiling/profiling.ll
+++ llvm/test/Instrumentation/InstrProfiling/profiling.ll
@@ -87,7 +87,7 @@
 ; MACHO: @__profc_foo_extern = linkonce_odr hidden global
 ; MACHO: @__profd_foo_extern = linkonce_odr hidden global
 ; COFF: @__profc_foo_extern = linkonce_odr hidden global {{.*}}section ".lprfc$M", comdat, align 8
-; COFF: @__profd_foo_extern = private global {{.*}}section ".lprfd$M", comdat($__profc_foo_extern), align 8
+; COFF: @__profd_foo_extern = private global {{.*}}section ".lprfd$M", align 8
 ; XCOFF: @__profc_foo_extern = private global
 ; XCOFF: @__profd_foo_extern = private global
 define available_externally void @foo_extern() {
Index: llvm/test/Instrumentation/InstrProfiling/comdat.ll
===================================================================
--- llvm/test/Instrumentation/InstrProfiling/comdat.ll
+++ llvm/test/Instrumentation/InstrProfiling/comdat.ll
@@ -18,9 +18,11 @@
 
 $foo_inline = comdat any
 $foo_extern = comdat any
+$foo_private_profn = comdat any
 
 @__profn_foo_inline = linkonce_odr hidden constant [10 x i8] c"foo_inline"
 @__profn_foo_extern = linkonce_odr hidden constant [10 x i8] c"foo_extern"
+ at __profn_foo_private_profn = private constant [17 x i8] c"foo_private_profn"
 
 ;; When value profiling is disabled, __profd_ variables are not referenced by
 ;; code. We can use private linkage. When enabled, __profd_ needs to be
@@ -30,7 +32,7 @@
 ; ELF0:  @__profd_foo_inline = private global {{.*}}, section "__llvm_prf_data", comdat($__profc_foo_inline), align 8
 ; ELF1:  @__profd_foo_inline = linkonce_odr hidden global {{.*}}, section "__llvm_prf_data", comdat($__profc_foo_inline), align 8
 ; COFF0: @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfc$M", comdat, align 8
-; COFF0: @__profd_foo_inline = private global {{.*}}, section ".lprfd$M", comdat($__profc_foo_inline), align 8
+; COFF0: @__profd_foo_inline = private global {{.*}}, section ".lprfd$M", align 8
 ; COFF1: @__profc_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfc$M", comdat, align 8
 ; COFF1: @__profd_foo_inline = linkonce_odr hidden global {{.*}}, section ".lprfd$M", comdat, align 8
 define weak_odr void @foo_inline() comdat {
@@ -42,16 +44,27 @@
 ; ELF0:  @__profd_foo_extern = private global{{.*}}, section "__llvm_prf_data", comdat($__profc_foo_extern), align 8
 ; ELF1:  @__profd_foo_extern = linkonce_odr hidden global{{.*}}, section "__llvm_prf_data", comdat($__profc_foo_extern), align 8
 ; COFF:  @__profc_foo_extern = linkonce_odr hidden global{{.*}}, section ".lprfc$M", comdat, align 8
-; COFF0: @__profd_foo_extern = private global{{.*}}, section ".lprfd$M", comdat($__profc_foo_extern), align 8
+; COFF0: @__profd_foo_extern = private global{{.*}}, section ".lprfd$M", align 8
 ; COFF1: @__profd_foo_extern = linkonce_odr hidden global{{.*}}, section ".lprfd$M", comdat, align 8
 define available_externally void @foo_extern() {
   call void @llvm.instrprof.increment(ptr @__profn_foo_extern, i64 0, i32 1, i32 0)
   ret void
 }
 
-; ELF:   @llvm.compiler.used = appending global [2 x ptr] [ptr @__profd_foo_inline, ptr @__profd_foo_extern]
-; COFF0: @llvm.compiler.used = appending global [3 x ptr] [ptr @__llvm_profile_runtime_user, ptr @__profd_foo_inline, ptr @__profd_foo_extern]
-; 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]
+; ELF:   @__profc_foo_private_profn = private global{{.*}}, section "__llvm_prf_cnts", comdat, align 8
+; ELF0:  @__profd_foo_private_profn = private global{{.*}}, section "__llvm_prf_data", comdat($__profc_foo_private_profn), align 8
+; ELF1:  @__profd_foo_private_profn = private global{{.*}}, section "__llvm_prf_data", comdat($__profc_foo_private_profn), align 8
+; COFF:  @__profc_foo_private_profn = private global{{.*}}, section ".lprfc$M", align 8
+; COFF0: @__profd_foo_private_profn = private global{{.*}}, section ".lprfd$M", align 8
+; COFF1: @__profd_foo_private_profn = private global{{.*}}, section ".lprfd$M", align 8
+define void @foo_private_profn() comdat {
+  call void @llvm.instrprof.increment(ptr @__profn_foo_private_profn, i64 0, i32 1, i32 0)
+  ret void
+}
+
+; ELF:   @llvm.compiler.used = appending global [3 x ptr] [ptr @__profd_foo_inline, ptr @__profd_foo_extern, ptr @__profd_foo_private_profn]
+; 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]
+; 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]
 
 ;--- disable.ll
 !llvm.module.flags = !{!0}
Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -905,7 +905,8 @@
   std::string DataVarName =
       getVarName(Inc, getInstrProfDataVarPrefix(), Renamed);
   auto MaybeSetComdat = [&](GlobalVariable *GV) {
-    bool UseComdat = (NeedComdat || TT.isOSBinFormatELF());
+    bool UseComdat = (NeedComdat || TT.isOSBinFormatELF()) &&
+                     !(TT.isOSBinFormatCOFF() && GV->hasPrivateLinkage());
     if (UseComdat) {
       StringRef GroupName = TT.isOSBinFormatCOFF() && DataReferencedByCode
                                 ? GV->getName()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131043.449524.patch
Type: text/x-patch
Size: 5681 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220803/82a9f31c/attachment.bin>


More information about the llvm-commits mailing list