llvm-project/llvm/test/Transforms/PGOProfile
Fangrui Song a1532ed275 [InstrProfiling] Make CountersPtr in __profd_ relative
Change `CountersPtr` in `__profd_` to a label difference, which is a link-time
constant. On ELF, when linking a shared object, this requires that `__profc_` is
either private or linkonce/linkonce_odr hidden. On COFF, we need D104564 so that
`.quad a-b` (64-bit label difference) can lower to a 32-bit PC-relative relocation.

```
# ELF: R_X86_64_PC64 (PC-relative)
.quad .L__profc_foo-.L__profd_foo

# Mach-O: a pair of 8-byte X86_64_RELOC_UNSIGNED and X86_64_RELOC_SUBTRACTOR
.quad l___profc_foo-l___profd_foo

# COFF: we actually use IMAGE_REL_AMD64_REL32/IMAGE_REL_ARM64_REL32 so
# the high 32-bit value is zero even if .L__profc_foo < .L__profd_foo
# As compensation, we truncate CountersDelta in the header so that
# __llvm_profile_merge_from_buffer and llvm-profdata reader keep working.
.quad .L__profc_foo-.L__profd_foo
```

(Note: link.exe sorts `.lprfc` before `.lprfd` even if the object writer
has `.lprfd` before `.lprfc`, so we cannot work around by reordering
`.lprfc` and `.lprfd`.)

With this change, a stage 2 (`-DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_BUILD_INSTRUMENTED=IR`)
`ld -pie` linked clang is 1.74% smaller due to fewer R_X86_64_RELATIVE relocations.
```
% readelf -r pie | awk '$3~/R.*/{s[$3]++} END {for (k in s) print k, s[k]}'
R_X86_64_JUMP_SLO 331
R_X86_64_TPOFF64 2
R_X86_64_RELATIVE 476059  # was: 607712
R_X86_64_64 2616
R_X86_64_GLOB_DAT 31
```

The absolute function address (used by llvm-profdata to collect indirect call
targets) can be converted to relative as well, but is not done in this patch.

Differential Revision: https://reviews.llvm.org/D104556
2021-07-30 11:52:18 -07:00
..
Inputs [Passes] Run sinking/hoisting in SimplifyCFG earlier. 2021-04-30 12:23:57 +01:00
X86
PR28219.ll
PR41279.ll
PR41279_2.ll
bfi_verification.ll [PGO] Use the sum of profile counts to fix the function entry count 2020-12-16 13:37:43 -08:00
branch1.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
branch2.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
callbr.ll
chr.ll [SimplifyCFG] Don't speculatively execute BB[s] if they are predictably not taken 2021-07-26 02:55:15 +03:00
comdat_internal.ll [InstrProfiling] Make CountersPtr in __profd_ relative 2021-07-30 11:52:18 -07:00
comdat_rename.ll
consecutive-zeros.ll [LTO] Fix test failures caused by 6da7d31416 2021-02-23 14:58:30 -08:00
counter_promo.ll [InstrProfiling] Use ELF section groups for counters, data and values 2021-02-22 14:00:02 -08:00
counter_promo_exit_catchswitch.ll
counter_promo_exit_merge.ll
counter_promo_mexits.ll [InstrProfiling] Use ELF section groups for counters, data and values 2021-02-22 14:00:02 -08:00
counter_promo_nest-inseltpoison.ll Precommit transform tests that have poison as insertelement's placeholder 2020-12-24 11:46:17 +09:00
counter_promo_nest.ll
criticaledge.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
cspgo_profile_summary.ll [SimplifyCFG] Rerun PHI deduplication after common code sinkinkg (PR51092) 2021-07-15 16:34:34 +03:00
diag_FE_profile.ll
diag_mismatch.ll [llvm-profdata] Make diagnostics consistent with the (no capitalization, no period) style 2021-06-19 14:54:25 -07:00
diag_no_funcprofdata.ll [llvm-profdata] Make diagnostics consistent with the (no capitalization, no period) style 2021-06-19 14:54:25 -07:00
diag_no_profile.ll
diag_no_value_sites.ll
do-not-instrument.ll
fix_bfi.ll [PGO] Use the sum of profile counts to fix the function entry count 2020-12-16 13:37:43 -08:00
fix_entry_count.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
func_entry.ll
hash_mismatch_metadata.ll Emit metadata when instr. profiles hash mismatch occurs. 2021-01-29 12:56:01 -08:00
icp_covariant_call_return.ll [ICP] Don't promote when target not defined in module 2020-12-08 07:45:36 -08:00
icp_covariant_invoke_return.ll [ICP] Don't promote when target not defined in module 2020-12-08 07:45:36 -08:00
icp_invoke.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
icp_invoke_nouse.ll
icp_mismatch_msg.ll
icp_sample.ll
icp_vararg.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
icp_vararg_sret.ll OpaquePtr: Bulk update tests to use typed sret 2020-11-20 17:58:26 -05:00
indirect_call_annotation.ll
indirect_call_profile.ll [InstrProfiling] Make CountersPtr in __profd_ relative 2021-07-30 11:52:18 -07:00
indirect_call_profile_funclet.ll
indirect_call_promotion.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
indirect_call_promotion_byval.ll OpaquePtr: Bulk update tests to use typed byval 2020-11-20 14:00:46 -05:00
indirect_call_promotion_musttail.ll [ICP] Don't promote when target not defined in module 2020-12-08 07:45:36 -08:00
indirect_call_promotion_unique.ll [IndirectCallPromotion] Recommit "Don't strip ".__uniq." suffix when it strips 2021-03-12 13:48:14 -08:00
indirect_call_promotion_vla.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
indirectbr.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
infinite_loop.ll
infinite_loop_gen.ll
instr_entry_bb.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
irreducible.ll
landingpad.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
large_count_remarks.ll
loop1.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
loop2.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
memcpy.ll [InstrProfiling] Make CountersPtr in __profd_ relative 2021-07-30 11:52:18 -07:00
memop_clone.ll
memop_hash.ll
memop_profile_funclet.ll
memop_size_annotation.ll
memop_size_from_strlen.ll
memop_size_opt.ll [PGO] Fix two issues in PGOMemOPSizeOpt. 2021-03-11 09:53:05 -08:00
memop_size_opt_skip_ranges_promote_three.ll [PGO] Fix two issues in PGOMemOPSizeOpt. 2021-03-11 09:53:05 -08:00
memop_size_opt_zero.ll
multiple_hash_profile.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
noprofile.ll Support for instrumenting only selected files or functions 2021-01-26 17:13:34 -08:00
noreturncall.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
not_promote_ret_exit.ll
preinline.ll
remap.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
select1.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
select2.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
select_hash_conflict.ll
single_bb.ll
split-indirectbr-critical-edges.ll
statics_counter_naming.ll
suppl-profile.ll
switch.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
thinlto_cspgo_gen.ll
thinlto_cspgo_use.ll [Passes] Run sinking/hoisting in SimplifyCFG earlier. 2021-04-30 12:23:57 +01:00
thinlto_indirect_call_promotion.ll Revert "Use uint64_t for branch weights instead of uint32_t" 2020-10-31 00:25:32 -07:00
thinlto_samplepgo_icp.ll
thinlto_samplepgo_icp2.ll
thinlto_samplepgo_icp3.ll
thinlto_samplepgo_icp_droppeddead.ll
unreachable_bb.ll