cmd/compile/internal/pgo: check repeated edge only when node is seen

When adding weights for a call stack, for recursive calls, to
avoid double counting we check if we already saw the node and the
edge. We check the node first. An edge can be repeated if the node
is repeated. Most stacks are not recursive, so check repeated edge
only conditionally.

Change-Id: I4b8f039289dcd3383ca89593d6d16d903b94c3dd
Reviewed-on: https://go-review.googlesource.com/c/go/+/447804
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
Cherry Mui 2022-11-03 21:22:44 -04:00
parent 9dcc873413
commit f187c6b08e
1 changed files with 3 additions and 2 deletions

View File

@ -282,12 +282,13 @@ func newGraph(prof *profile.Profile, o *Options) (*Graph, map[uint64]Nodes) {
continue
}
// Add cum weight to all nodes in stack, avoiding double counting.
if _, ok := seenNode[n]; !ok {
_, sawNode := seenNode[n]
if !sawNode {
seenNode[n] = true
n.addSample(dw, w, false)
}
// Update edge weights for all edges in stack, avoiding double counting.
if _, ok := seenEdge[nodePair{n, parent}]; !ok && parent != nil && n != parent {
if (!sawNode || !seenEdge[nodePair{n, parent}]) && parent != nil && n != parent {
seenEdge[nodePair{n, parent}] = true
parent.AddToEdgeDiv(n, dw, w, residual, ni != len(locNodes)-1)
}