mirror of
https://github.com/golang/go
synced 2024-10-14 03:43:28 +00:00
cmd/compiler/internal/ssagen: refactor code to sort stack vars
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>
This commit is contained in:
parent
29fcd1569a
commit
593daf785f
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue