]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile/internal/escape: optimize indirect closure calls
authorMatthew Dempsky <mdempsky@google.com>
Tue, 15 Aug 2023 23:45:52 +0000 (16:45 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 17 Aug 2023 16:36:09 +0000 (16:36 +0000)
commitff47dd1d665d30d5f3d26f031192afebb4422c3c
treeb688caf64d48a7c96cbce1e36ce10c865f8418d9
parentf278ae61d551ebd12956a1ed21ad6131495a2513
cmd/compile/internal/escape: optimize indirect closure calls

This CL extends escape analysis in two ways.

First, we already optimize directly called closures. For example,
given:

var x int  // already stack allocated today
p := func() *int { return &x }()

we don't need to move x to the heap, because we can statically track
where &x flows. This CL extends the same idea to work for indirectly
called closures too, as long as we know everywhere that they're
called. For example:

var x int  // stack allocated after this CL
f := func() *int { return &x }
p := f()

This will allow a subsequent CL to move the generation of go/defer
wrappers earlier.

Second, this CL adds tracking to detect when pointer values flow to
the pointee operand of an indirect assignment statement (i.e., flows
to p in "*p = x") or to builtins that modify memory (append, copy,
clear). This isn't utilized in the current CL, but a subsequent CL
will make use of it to better optimize string->[]byte conversions.

Updates #2205.

Change-Id: I610f9c531e135129c947684833e288ce64406f35
Reviewed-on: https://go-review.googlesource.com/c/go/+/520259
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/cmd/compile/internal/escape/assign.go
src/cmd/compile/internal/escape/call.go
src/cmd/compile/internal/escape/escape.go
src/cmd/compile/internal/escape/graph.go
src/cmd/compile/internal/escape/leaks.go
src/cmd/compile/internal/escape/solve.go
src/cmd/compile/internal/ir/func.go
test/escape_closure.go
test/inline_big.go