[CSSPGO] Introducing dangling pseudo probes.
authorHongtao Yu <hoy@fb.com>
Thu, 25 Feb 2021 08:43:17 +0000 (00:43 -0800)
committerHongtao Yu <hoy@fb.com>
Thu, 4 Mar 2021 06:44:41 +0000 (22:44 -0800)
commitad2a59f5840482d7dd802e83b82262c97704a4eb
tree7853ee1872f031b2c39e6e32519858e120ca7bdd
parent647af31e74830e067834f50985f18ac7cc16c2a3
[CSSPGO] Introducing dangling pseudo probes.

Dangling probes are the probes associated to an empty block. This usually happens when all real instructions are optimized away from the block. There is a problem with dangling probes during the offline counts processing. The way the sample profiler works is that samples collected on the first physical instruction following a probe will be counted towards the probe. This logically equals to treating the instruction next to a probe as if it is from the same block of the probe. In the dangling probe case, the real instruction following a dangling probe actually starts a new block, and samples collected on the new block may cause issues when counted towards the empty block.

To mitigate this issue, we first try to move around a dangling probe inside its owning block. If there are still native instructions preceding the probe in the same block, we can then use them as a place holder to collect samples for the probe. A pass is added to walk each block backwards looking for probes not followed by any real instruction and moving them before the first real instruction. This is done right before the object emission.

If we are unlucky to find such in-block preceding instructions for a probe, the solution we are taking is to tag such probe as dangling so that the samples reported for them will not be trusted by the compiler. We leave it up to the counts inference algorithm to get such probes a reasonable count. The number `UINT64_MAX` is used to mark sample count as collected for a dangling probe.

Reviewed By: wmi

Differential Revision: https://reviews.llvm.org/D95962
llvm/include/llvm/CodeGen/MachineInstr.h
llvm/include/llvm/IR/PseudoProbe.h
llvm/include/llvm/MC/MCPseudoProbe.h
llvm/include/llvm/ProfileData/SampleProf.h
llvm/lib/CodeGen/PseudoProbeInserter.cpp
llvm/lib/ProfileData/SampleProf.cpp
llvm/test/Transforms/SampleProfile/pseudo-probe-dangling.mir [new file with mode: 0644]
llvm/test/tools/llvm-profdata/Inputs/pseudo-probe-profile.proftext
llvm/test/tools/llvm-profdata/merge-probe-profile.test