[llvm] [PseudoProbe] Extend to skip instrumenting probe into the dests of invoke (PR #79919)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 27 18:54:09 PST 2024
================
@@ -173,21 +173,108 @@ SampleProfileProber::SampleProfileProber(Function &Func,
BlockProbeIds.clear();
CallProbeIds.clear();
LastProbeId = (uint32_t)PseudoProbeReservedId::Last;
- computeProbeIdForBlocks();
- computeProbeIdForCallsites();
- computeCFGHash();
+
+ DenseSet<BasicBlock *> BlocksToIgnore;
+ DenseSet<BasicBlock *> BlocksAndCallsToIgnore;
+ computeBlocksToIgnore(BlocksToIgnore, BlocksAndCallsToIgnore);
+
+ computeProbeIdForBlocks(BlocksToIgnore);
+ computeProbeIdForCallsites(BlocksAndCallsToIgnore);
+ computeCFGHash(BlocksToIgnore);
+}
+
+// Two purposes to compute the blocks to ignore:
+// 1. Reduce the IR size.
+// 2. Make the instrumentation(checksum) stable. e.g. the frondend may
+// generate unstable IR while optimizing nounwind attribute, some versions are
+// optimized with the call-to-invoke conversion, while other versions do not.
+// This discrepancy in probe ID could cause profile mismatching issues.
+// Note that those ignored blocks are either cold blocks or new split blocks
+// whose original blocks are instrumented, so it shouldn't degrade the profile
+// quailty.
+void SampleProfileProber::computeBlocksToIgnore(
+ DenseSet<BasicBlock *> &BlocksToIgnore,
+ DenseSet<BasicBlock *> &BlocksAndCallsToIgnore) {
+ // Ignore the cold EH and unreachable blocks and calls.
+ computeEHOnlyBlocks(*F, BlocksAndCallsToIgnore);
+ findUnreachableBlocks(BlocksAndCallsToIgnore);
+
+ BlocksToIgnore.insert(BlocksAndCallsToIgnore.begin(),
+ BlocksAndCallsToIgnore.end());
+ // Handle the call-to-invoke conversion case, ignore the normal dests of
+ // invoke.
+ findInvokeNormalDests(BlocksToIgnore);
+}
+
+void SampleProfileProber::findUnreachableBlocks(
----------------
WenleiHe wrote:
Also add a comment explain why unreachable blocks are ignored
https://github.com/llvm/llvm-project/pull/79919
More information about the llvm-commits
mailing list