diff options
| author | Cherry Mui <cherryyz@google.com> | 2023-09-15 12:13:09 -0400 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2023-09-19 15:42:58 +0000 |
| commit | 3fb86fb8645ceb6163d1a9f573c2b4eec2a310f9 (patch) | |
| tree | 92c0f9ea7adc8d2a042971fabdb56396f050a9bc /src/cmd/compile/internal/base/hashdebug.go | |
| parent | eca5a97340e6b475268a522012f30e8e25bb8b8f (diff) | |
| download | go-3fb86fb8645ceb6163d1a9f573c2b4eec2a310f9.tar.xz | |
cmd/compile: add pgohash for debugging/bisecting PGO optimizations
When a PGO build fails or produces incorrect program, it is often
unclear what the problem is. Add pgo hash so we can bisect to
individual optimization decisions, which often helps debugging.
Related to #58153.
Change-Id: I651ffd9c53bad60f2f28c8ec2a90a3f532982712
Reviewed-on: https://go-review.googlesource.com/c/go/+/528400
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/cmd/compile/internal/base/hashdebug.go')
| -rw-r--r-- | src/cmd/compile/internal/base/hashdebug.go | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/base/hashdebug.go b/src/cmd/compile/internal/base/hashdebug.go index 167b0df4f0..de7f01f09e 100644 --- a/src/cmd/compile/internal/base/hashdebug.go +++ b/src/cmd/compile/internal/base/hashdebug.go @@ -55,6 +55,7 @@ var hashDebug *HashDebug var FmaHash *HashDebug // for debugging fused-multiply-add floating point changes var LoopVarHash *HashDebug // for debugging shared/private loop variable changes +var PGOHash *HashDebug // for debugging PGO optimization decisions // DebugHashMatchPkgFunc reports whether debug variable Gossahash // @@ -274,8 +275,36 @@ func (d *HashDebug) MatchPos(pos src.XPos, desc func() string) bool { } func (d *HashDebug) matchPos(ctxt *obj.Link, pos src.XPos, note func() string) bool { + return d.matchPosWithInfo(ctxt, pos, nil, note) +} + +func (d *HashDebug) matchPosWithInfo(ctxt *obj.Link, pos src.XPos, info any, note func() string) bool { hash := d.hashPos(ctxt, pos) - return d.matchAndLog(hash, func() string { return d.fmtPos(ctxt, pos) }, note) + if info != nil { + hash = bisect.Hash(hash, info) + } + return d.matchAndLog(hash, + func() string { + r := d.fmtPos(ctxt, pos) + if info != nil { + r += fmt.Sprintf(" (%v)", info) + } + return r + }, + note) +} + +// MatchPosWithInfo is similar to MatchPos, but with additional information +// that is included for hash computation, so it can distinguish multiple +// matches on the same source location. +// Note that the default answer for no environment variable (d == nil) +// is "yes", do the thing. +func (d *HashDebug) MatchPosWithInfo(pos src.XPos, info any, desc func() string) bool { + if d == nil { + return true + } + // Written this way to make inlining likely. + return d.matchPosWithInfo(Ctxt, pos, info, desc) } // matchAndLog is the core matcher. It reports whether the hash matches the pattern. |
