]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compiler/internal/ssagen: refactor code to sort stack vars
authorThan McIntosh <thanm@google.com>
Thu, 22 Feb 2024 14:12:06 +0000 (14:12 +0000)
committerThan McIntosh <thanm@google.com>
Fri, 29 Mar 2024 21:55:16 +0000 (21:55 +0000)
Minor refactoring of the code that sorts stack variables to move
from sort.Stable to sort.SliceStable. No change in semantics; this
is intended to lay the groundwork for a future change.

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

index e7a0699641bf8ddfce8487e4f4ee9ec0ac6fc445..c3d9ec30919cb2ae33e2f0fd71a9501c44b13336 100644 (file)
@@ -84,13 +84,6 @@ func cmpstackvarlt(a, b *ir.Name) bool {
        return a.Sym().Name < b.Sym().Name
 }
 
-// byStackVar implements sort.Interface for []*Node using cmpstackvarlt.
-type byStackVar []*ir.Name
-
-func (s byStackVar) Len() int           { return len(s) }
-func (s byStackVar) Less(i, j int) bool { return cmpstackvarlt(s[i], s[j]) }
-func (s byStackVar) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
-
 // needAlloc reports whether n is within the current frame, for which we need to
 // allocate space. In particular, it excludes arguments and results, which are in
 // the callers frame.
@@ -158,10 +151,12 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
                }
        }
 
-       // Use sort.Stable instead of sort.Sort so stack layout (and thus
+       // Use sort.SliceStable instead of sort.Slice so stack layout (and thus
        // compiler output) is less sensitive to frontend changes that
        // introduce or remove unused variables.
-       sort.Stable(byStackVar(fn.Dcl))
+       sort.SliceStable(fn.Dcl, func(i, j int) bool {
+               return cmpstackvarlt(fn.Dcl[i], fn.Dcl[j])
+       })
 
        // Reassign stack offsets of the locals that are used.
        lastHasPtr := false