From: Fangrui Song Date: Thu, 17 Jun 2021 21:16:54 +0000 (-0700) Subject: [InstrProfiling] Make __profd_ unconditionally private for ELF X-Git-Tag: llvmorg-14-init~3670 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=76d0747e0807307780ba84cbd7e5c80b20c26bd7;p=platform%2Fupstream%2Fllvm.git [InstrProfiling] Make __profd_ unconditionally private for ELF 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. Reviewed By: davidxl, rnk Differential Revision: https://reviews.llvm.org/D103717 --- diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp index 4a5511d..6b5ca89 100644 --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -929,10 +929,12 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) { #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; } diff --git a/llvm/test/Transforms/PGOProfile/indirect_call_profile.ll b/llvm/test/Transforms/PGOProfile/indirect_call_profile.ll index a3c05e5..0fa6c52 100644 --- a/llvm/test/Transforms/PGOProfile/indirect_call_profile.ll +++ b/llvm/test/Transforms/PGOProfile/indirect_call_profile.ll @@ -54,7 +54,7 @@ bb11: ; preds = %bb2 } ; 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