aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/devirtualize
diff options
context:
space:
mode:
authorthepudds <thepudds@users.noreply.github.com>2023-06-03 00:56:31 +0000
committerCherry Mui <cherryyz@google.com>2023-06-03 01:13:08 +0000
commit363713223385476b87dc5f26d267df8c67d13006 (patch)
treedff37ab5aafe60af5618fd95d2a2befbec89e3b0 /src/cmd/compile/internal/devirtualize
parent3fd867cecc2b31c767f8a60f49ac4138dea69d0f (diff)
downloadgo-363713223385476b87dc5f26d267df8c67d13006.tar.xz
cmd/compile/internal/devirtualize: devirtualize methods in other packages if current package has a concrete reference
The new PGO-driven indirect call specialization from CL 492436 in theory should allow for devirtualization on methods in another package when those methods are directly referenced in the current package. However, inline.InlineImpossible was checking for a zero-length fn.Body and would cause devirtualization to fail with a debug log message like: "should not PGO devirtualize (*Speaker1).Speak: no function body" Previously, the logic in inline.InlineImpossible was only called on local functions, but with PGO-based devirtualization, it can now be called on imported functions, where inlinable imported functions will have a zero-length fn.Body but a non-nil fn.Inl. We update inline.InlineImpossible to handle imported functions by adding a call to typecheck.HaveInlineBody in the check that was previously failing. For the test, we need to have a hopefully temporary workaround of adding explicit references to the callees in another package for devirtualization to work. CL 497175 or similar should enable removing this workaround. Fixes #60561 Updates #59959 Change-Id: I48449b7d8b329d84151bd3b506b8093c262eb2a3 GitHub-Last-Rev: 2d53c55fd895ad8fefd25510a6e6969e89d54a6d GitHub-Pull-Request: golang/go#60565 Reviewed-on: https://go-review.googlesource.com/c/go/+/500155 Run-TryBot: thepudds <thepudds1460@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/devirtualize')
-rw-r--r--src/cmd/compile/internal/devirtualize/pgo.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/devirtualize/pgo.go b/src/cmd/compile/internal/devirtualize/pgo.go
index 69c421ca5a..979483a46f 100644
--- a/src/cmd/compile/internal/devirtualize/pgo.go
+++ b/src/cmd/compile/internal/devirtualize/pgo.go
@@ -357,11 +357,11 @@ func rewriteCondCall(call *ir.CallExpr, curfn, callee *ir.Func, concretetyp *typ
elseBlock.Append(call)
} else {
// Copy slice so edits in one location don't affect another.
- thenRet := append([]ir.Node(nil), retvars...)
+ thenRet := append([]ir.Node(nil), retvars...)
thenAsList := ir.NewAssignListStmt(pos, ir.OAS2, thenRet, []ir.Node{concreteCall})
thenBlock.Append(typecheck.Stmt(thenAsList))
- elseRet := append([]ir.Node(nil), retvars...)
+ elseRet := append([]ir.Node(nil), retvars...)
elseAsList := ir.NewAssignListStmt(pos, ir.OAS2, elseRet, []ir.Node{call})
elseBlock.Append(typecheck.Stmt(elseAsList))
}