1
0
mirror of https://github.com/golang/go synced 2024-11-26 03:37:57 -07:00

[dev.regabi] cmd/compile: decouple escape analysis from Name.Vargen

Escape analysis needs to know the index of result parameters for
recording escape-flow information. It currently relies on Vargen for
this, but it can easily figure this out for itself. So just do that
instead, so that we can remove Vargen.

Passes toolstash -cmp.

For #43633.

Change-Id: I65dedc2d73bc25e85ff400f308e50b73dc503630
Reviewed-on: https://go-review.googlesource.com/c/go/+/283192
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
This commit is contained in:
Matthew Dempsky 2021-01-11 14:30:16 -08:00
parent 7fd84c6e46
commit f57f484053

View File

@ -126,6 +126,11 @@ type location struct {
edges []edge // incoming edges edges []edge // incoming edges
loopDepth int // loopDepth at declaration loopDepth int // loopDepth at declaration
// resultIndex records the tuple index (starting at 1) for
// PPARAMOUT variables within their function's result type.
// For non-PPARAMOUT variables it's 0.
resultIndex int
// derefs and walkgen are used during walkOne to track the // derefs and walkgen are used during walkOne to track the
// minimal dereferences from the walk root. // minimal dereferences from the walk root.
derefs int // >= -1 derefs int // >= -1
@ -259,11 +264,16 @@ func (b *batch) initFunc(fn *ir.Func) {
} }
// Allocate locations for local variables. // Allocate locations for local variables.
for _, dcl := range fn.Dcl { for _, n := range fn.Dcl {
if dcl.Op() == ir.ONAME { if n.Op() == ir.ONAME {
e.newLoc(dcl, false) e.newLoc(n, false)
} }
} }
// Initialize resultIndex for result parameters.
for i, f := range fn.Type().Results().FieldSlice() {
e.oldLoc(f.Nname.(*ir.Name)).resultIndex = 1 + i
}
} }
func (b *batch) walkFunc(fn *ir.Func) { func (b *batch) walkFunc(fn *ir.Func) {
@ -1609,8 +1619,7 @@ func (l *location) leakTo(sink *location, derefs int) {
// If sink is a result parameter and we can fit return bits // If sink is a result parameter and we can fit return bits
// into the escape analysis tag, then record a return leak. // into the escape analysis tag, then record a return leak.
if sink.isName(ir.PPARAMOUT) && sink.curfn == l.curfn { if sink.isName(ir.PPARAMOUT) && sink.curfn == l.curfn {
// TODO(mdempsky): Eliminate dependency on Vargen here. ri := sink.resultIndex - 1
ri := int(sink.n.Name().Vargen) - 1
if ri < numEscResults { if ri < numEscResults {
// Leak to result parameter. // Leak to result parameter.
l.paramEsc.AddResult(ri, derefs) l.paramEsc.AddResult(ri, derefs)