[PATCH] D103717: [InstrProfiling][ELF] Make __profd_ private if the function does not use value profiling
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 18 00:31:30 PDT 2021
MaskRay updated this revision to Diff 352926.
MaskRay retitled this revision from "[InstrProfiling] Make __profd_ unconditionally private for ELF" to "[InstrProfiling][ELF] Make __profd_ private if the function does not use value profiling".
MaskRay edited the summary of this revision.
MaskRay added a comment.
I need to add a test case, but this is the sketch.
I am not sure whether this value profiling detection is correct.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103717/new/
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
@@ -887,10 +887,10 @@
// Allocate statically the array of pointers to value profile nodes for
// the current function.
Constant *ValuesPtrExpr = ConstantPointerNull::get(Int8PtrTy);
+ uint64_t NS = 0;
+ for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
+ NS += PD.NumValueSites[Kind];
if (ValueProfileStaticAlloc && !needsRuntimeRegistrationOfSectionRange(TT)) {
- uint64_t NS = 0;
- for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
- NS += PD.NumValueSites[Kind];
if (NS) {
ArrayType *ValuesTy = ArrayType::get(Type::getInt64Ty(Ctx), NS);
@@ -929,10 +929,13 @@
#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 the data variable is not referenced by code, and linker GC can retain
+ // the data variable if the associated counter is retained, the data variable
+ // 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() && NS == 0) || (!DataReferencedByCode &&
+ TT.isOSBinFormatCOFF())) {
Linkage = GlobalValue::PrivateLinkage;
Visibility = GlobalValue::DefaultVisibility;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103717.352926.patch
Type: text/x-patch
Size: 2428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210618/9c0c38df/attachment.bin>
More information about the llvm-commits
mailing list