[InstrProfiling][ELF] Make __profd_ private if the function does not use value profiling
authorFangrui Song <i@maskray.me>
Sat, 19 Jun 2021 00:01:17 +0000 (17:01 -0700)
committerFangrui Song <i@maskray.me>
Sat, 19 Jun 2021 00:01:17 +0000 (17:01 -0700)
commit3307240f057b856bfb01c1e42e260aa3f896c592
treedfbb0483f5dea3d64cc78ecedb89cea70ab9471a
parentb3c1f53c989f6aefad581955e3add222cfb5d890
[InstrProfiling][ELF] Make __profd_ private if the function does not use value profiling

On ELF, the D1003372 optimization can apply to more cases. There are two
prerequisites for making `__profd_` private:

* `__profc_` keeps `__profd_` live under compiler/linker GC
* `__profd_` is not referenced by code

The first is satisfied because all counters/data are in a section group (either
`comdat any` or `comdat noduplicates`). The second requires that the function
does not use value profiling.

Regarding the second point: `__profd_` may be referenced by other text sections
due to inlining. There will be a linker error if a prevailing text section
references the non-prevailing local symbol.

With this change, a stage 2 (`-DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_BUILD_INSTRUMENTED=IR`)
clang is 4.2% smaller (1-169620032/177066968).
`stat -c %s **/*.o | awk '{s+=$1}END{print s}' is 2.5% smaller.

Reviewed By: davidxl, rnk

Differential Revision: https://reviews.llvm.org/D103717
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/test/Transforms/PGOProfile/indirect_call_profile.ll