]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal: small tweak to merge locals trace output
authorThan McIntosh <thanm@google.com>
Fri, 5 Apr 2024 12:53:20 +0000 (12:53 +0000)
committerThan McIntosh <thanm@google.com>
Tue, 9 Apr 2024 16:41:32 +0000 (16:41 +0000)
For -gcflags=-d=mergelocalstrace=1 (which reports estimated savings
from stack slot merging), emit separate values for pointerful vs
non-pointerful variables, for a bit more detail.

Updates #62737.
Updates #65532.
Updates #65495.

Change-Id: I9dd27d2a254036448c85c13d189d1ed36157c9d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/576680
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/compile/internal/liveness/mergelocals.go
src/cmd/compile/internal/ssagen/pgen.go

index a1342efce6b34992ab9a85586480d8835d0a3915..82440beb6c51cee7e94fe955b2bffb8fe3d89337 100644 (file)
@@ -139,16 +139,22 @@ func (mls *MergeLocalsState) Followers(n *ir.Name, tmp []*ir.Name) []*ir.Name {
        return tmp
 }
 
-// EstSavings returns the estimated reduction in stack size for
-// the given merge locals state.
-func (mls *MergeLocalsState) EstSavings() int {
-       tot := 0
+// EstSavings returns the estimated reduction in stack size (number of bytes) for
+// the given merge locals state via a pair of ints, the first for non-pointer types and the second for pointer types.
+func (mls *MergeLocalsState) EstSavings() (int, int) {
+       totnp := 0
+       totp := 0
        for n := range mls.partition {
                if mls.Subsumed(n) {
-                       tot += int(n.Type().Size())
+                       sz := int(n.Type().Size())
+                       if n.Type().HasPointers() {
+                               totp += sz
+                       } else {
+                               totnp += sz
+                       }
                }
        }
-       return tot
+       return totnp, totp
 }
 
 // check tests for various inconsistencies and problems in mls,
index d0045e7ee3280214446dc568ca2387f77a779d71..bef9049126f9d2b765566da480edef27037fd24d 100644 (file)
@@ -155,8 +155,9 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
        var mls *liveness.MergeLocalsState
        if base.Debug.MergeLocals != 0 {
                mls = liveness.MergeLocals(fn, f)
-               if base.Debug.MergeLocalsTrace == 1 && mls != nil {
-                       fmt.Fprintf(os.Stderr, "%s: %d bytes of stack space saved via stack slot merging\n", ir.FuncName(fn), mls.EstSavings())
+               if base.Debug.MergeLocalsTrace > 0 && mls != nil {
+                       savedNP, savedP := mls.EstSavings()
+                       fmt.Fprintf(os.Stderr, "%s: %d bytes of stack space saved via stack slot merging (%d nonpointer %d pointer)\n", ir.FuncName(fn), savedNP+savedP, savedNP, savedP)
                        if base.Debug.MergeLocalsTrace > 1 {
                                fmt.Fprintf(os.Stderr, "=-= merge locals state for %v:\n%v",
                                        fn, mls)