]> Cypherpunks.ru repositories - gostls13.git/commit
[dev.regabi] cmd/compile: reorganize escape analysis somewhat
authorMatthew Dempsky <mdempsky@google.com>
Sat, 2 Jan 2021 10:40:42 +0000 (02:40 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Sun, 3 Jan 2021 06:16:32 +0000 (06:16 +0000)
commitb1747756e30a4e1ea0698ddbbb08f5cb7d97b1ba
tree71f57c7f8f4ef0027fc1bb6fe7d1371d0c3d4a83
parentf2538033c08a8c215a19610680d66f5909c5bcdd
[dev.regabi] cmd/compile: reorganize escape analysis somewhat

To do closure conversion during escape analysis, we need to walk the
AST in order. So this CL makes a few changes:

1. Function literals are walked where they appear in their enclosing
function, rather than as independent functions.

2. Walking "range" and "switch" statements is reordered to visit the
X/Tag expression up front, before the body.

3. Most assignments are refactored to use a new assignList helper,
which handles 1:1, 2:1, and N:N assignments. N:1 function call
assignments are still handled directly by the OAS2FUNC case.

4. A latent missed-optimization in escape.addr is fixed: the
ONAMEOFFSET case was failing to update k with the result of calling
e.addr(n.Name_). In partice, this probably wasn't an issue because
ONAMEOFFSET is likely only used for PEXTERN variables (which are
treated as heap memory anyway) or code generated by walk (which has
already gone through escape analysis).

5. Finally, don't replace k with discardHole at the end of
escape.addr. This is already handled at the start of escape.expr, and
we'll want to be able to access the hole's location after escape.expr
returns.

Passes toolstash -cmp.

Change-Id: I2325234346b12b10056a360c489692bab8fdbd93
Reviewed-on: https://go-review.googlesource.com/c/go/+/281003
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/escape/escape.go