[PATCH] D103717: [InstrProfiling] Make __profd_ unconditionally private for ELF

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 4 13:55:54 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: davidxl, rnk, vsk.
Herald added subscribers: wenlei, hiraditya.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

For ELF, since all counters/data are in a section group (either `comdat any` or
`comdat noduplicates`), and the signature for `comdat any` is `__profc_`, the
D1003372 optimization prerequisite (linker GC cannot discard data variables
while the text section is retained) is always satisified, we can make __profd_
unconditionally private.

I'll wait til D103372 <https://reviews.llvm.org/D103372> proves to be stable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103717

Files:
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/test/Transforms/PGOProfile/indirect_call_profile.ll


Index: llvm/test/Transforms/PGOProfile/indirect_call_profile.ll
===================================================================
--- llvm/test/Transforms/PGOProfile/indirect_call_profile.ll
+++ llvm/test/Transforms/PGOProfile/indirect_call_profile.ll
@@ -54,7 +54,7 @@
 }
 
 ; Test that comdat function's address is recorded.
-; LOWER: @__profd_foo3.[[FOO3_HASH:[0-9]+]] = linkonce_odr{{.*}}@__profc_foo3.[[FOO3_HASH]]
+; LOWER: @__profd_foo3.[[FOO3_HASH:[0-9]+]] = private {{.*}} @__profc_foo3.[[FOO3_HASH]]
 ; Function Attrs: nounwind uwtable
 define linkonce_odr i32 @foo3()  comdat  {
   ret i32 1
Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -929,10 +929,12 @@
 #define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Init,
 #include "llvm/ProfileData/InstrProfData.inc"
   };
-  // If code never references data variables (the symbol is unneeded), and
-  // linker GC cannot discard data variables while the text section is retained,
-  // data variables can be private. This optimization applies on COFF and ELF.
-  if (!DataReferencedByCode && !TT.isOSBinFormatMachO()) {
+  // If linker GC cannot discard data variables while the text section is
+  // retained, data variables can be private. This optimization applies on ELF.
+  // On COFF, when DataReferencedByCode is false, __profd_ is never a comdat
+  // leader, this is applicable as well.
+  if (TT.isOSBinFormatELF() ||
+      (!DataReferencedByCode && TT.isOSBinFormatCOFF())) {
     Linkage = GlobalValue::PrivateLinkage;
     Visibility = GlobalValue::DefaultVisibility;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103717.349964.patch
Type: text/x-patch
Size: 1752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210604/78add193/attachment.bin>


More information about the llvm-commits mailing list