diff options
| author | Michael Pratt <mpratt@google.com> | 2023-11-06 16:28:25 -0500 |
|---|---|---|
| committer | Michael Pratt <mpratt@google.com> | 2023-11-13 18:17:57 +0000 |
| commit | 42bd21be1cf54876ce24c489852721049ef293e2 (patch) | |
| tree | 448a827e75e06d9fc2bbfdf31de73176d6e42af5 /src/cmd/compile/internal/test/testdata/pgo/devirtualize | |
| parent | fb6ff1e4caaece9be61c45518ffb51081e892a73 (diff) | |
| download | go-42bd21be1cf54876ce24c489852721049ef293e2.tar.xz | |
cmd/compile: support lookup of functions from export data
As of CL 539699, PGO-based devirtualization supports devirtualization of
function values in addition to interface method calls. As with CL
497175, we need to explicitly look up functions from export data that
may not be imported already.
Symbol naming is ambiguous (`foo.Bar.func1` could be a closure or a
method), so we simply attempt to do both types of lookup. That said,
closures are defined in export data only as OCLOSURE nodes in the
enclosing function, which this CL does not yet attempt to expand.
For #61577.
Change-Id: Ic7205b046218a4dfb8c4162ece3620ed1c3cb40a
Reviewed-on: https://go-review.googlesource.com/c/go/+/540258
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/test/testdata/pgo/devirtualize')
| -rw-r--r-- | src/cmd/compile/internal/test/testdata/pgo/devirtualize/devirt.go | 24 | ||||
| -rw-r--r-- | src/cmd/compile/internal/test/testdata/pgo/devirtualize/devirt.pprof | bin | 1411 -> 1345 bytes | |||
| -rw-r--r-- | src/cmd/compile/internal/test/testdata/pgo/devirtualize/mult.pkg/mult.go | 12 |
3 files changed, 15 insertions, 21 deletions
diff --git a/src/cmd/compile/internal/test/testdata/pgo/devirtualize/devirt.go b/src/cmd/compile/internal/test/testdata/pgo/devirtualize/devirt.go index 63de3d3c3f..ac238f6dea 100644 --- a/src/cmd/compile/internal/test/testdata/pgo/devirtualize/devirt.go +++ b/src/cmd/compile/internal/test/testdata/pgo/devirtualize/devirt.go @@ -170,13 +170,7 @@ func ExerciseFuncConcrete(iter int, a1, a2 AddFunc, m1, m2 mult.MultFunc) int { // If they were not mutually exclusive (for example, two // AddFunc calls), then we could not definitively select the // correct callee. - // - // TODO(prattmic): Export data lookup for function value - // callees not implemented, meaning the type is unavailable. - //sink += int(m(42, int64(a(1, 2)))) - - v := selectA(i)(one(i), 2) - val += int(m(42, int64(v))) + val += int(m(42, int64(selectA(i)(one(i), 2)))) } return val } @@ -210,13 +204,7 @@ func ExerciseFuncField(iter int, a1, a2 AddFunc, m1, m2 mult.MultFunc) int { // If they were not mutually exclusive (for example, two // AddFunc calls), then we could not definitively select the // correct callee. - // - // TODO(prattmic): Export data lookup for function value - // callees not implemented, meaning the type is unavailable. - //sink += int(ops.m(42, int64(ops.a(1, 2)))) - - v := ops.a(1, 2) - val += int(ops.m(42, int64(v))) + val += int(ops.m(42, int64(ops.a(1, 2)))) } return val } @@ -258,13 +246,7 @@ func ExerciseFuncClosure(iter int, a1, a2 AddFunc, m1, m2 mult.MultFunc) int { // If they were not mutually exclusive (for example, two // AddFunc calls), then we could not definitively select the // correct callee. - // - // TODO(prattmic): Export data lookup for function value - // callees not implemented, meaning the type is unavailable. - //sink += int(m(42, int64(a(1, 2)))) - - v := a(1, 2) - val += int(m(42, int64(v))) + val += int(m(42, int64(a(1, 2)))) } return val } diff --git a/src/cmd/compile/internal/test/testdata/pgo/devirtualize/devirt.pprof b/src/cmd/compile/internal/test/testdata/pgo/devirtualize/devirt.pprof Binary files differindex de064582ff..2a27f1bb50 100644 --- a/src/cmd/compile/internal/test/testdata/pgo/devirtualize/devirt.pprof +++ b/src/cmd/compile/internal/test/testdata/pgo/devirtualize/devirt.pprof diff --git a/src/cmd/compile/internal/test/testdata/pgo/devirtualize/mult.pkg/mult.go b/src/cmd/compile/internal/test/testdata/pgo/devirtualize/mult.pkg/mult.go index 64f405ff9e..113a5e1a7e 100644 --- a/src/cmd/compile/internal/test/testdata/pgo/devirtualize/mult.pkg/mult.go +++ b/src/cmd/compile/internal/test/testdata/pgo/devirtualize/mult.pkg/mult.go @@ -35,10 +35,16 @@ func (NegMult) Multiply(a, b int) int { type MultFunc func(int64, int64) int64 func MultFn(a, b int64) int64 { + for i := 0; i < 1000; i++ { + sink++ + } return a * b } func NegMultFn(a, b int64) int64 { + for i := 0; i < 1000; i++ { + sink++ + } return -1 * a * b } @@ -47,6 +53,9 @@ func MultClosure() MultFunc { // Explicit closure to differentiate from AddClosure. c := 1 return func(a, b int64) int64 { + for i := 0; i < 1000; i++ { + sink++ + } return a * b * int64(c) } } @@ -55,6 +64,9 @@ func MultClosure() MultFunc { func NegMultClosure() MultFunc { c := 1 return func(a, b int64) int64 { + for i := 0; i < 1000; i++ { + sink++ + } return -1 * a * b * int64(c) } } |
