Skip to content

Commit 4a90cdb

Browse files
mdempskygopherbot
authored andcommitted
cmd/compile: interleave devirtualization and inlining
This CL interleaves devirtualization and inlining, so that devirtualized calls can be inlined. Fixes golang#52193. Change-Id: I681e7c55bdb90ebf6df315d334e7a58f05110d9c Reviewed-on: https://go-review.googlesource.com/c/go/+/528321 Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Bypass: Matthew Dempsky <mdempsky@google.com>
1 parent ee6b347 commit 4a90cdb

File tree

9 files changed

+265
-207
lines changed

9 files changed

+265
-207
lines changed

src/cmd/compile/internal/devirtualize/devirtualize.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,9 @@ import (
1818
"cmd/compile/internal/types"
1919
)
2020

21-
// Static devirtualizes calls within fn where possible when the concrete callee
21+
// StaticCall devirtualizes the given call if possible when the concrete callee
2222
// is available statically.
23-
func Static(fn *ir.Func) {
24-
ir.CurFunc = fn
25-
26-
ir.VisitList(fn.Body, func(n ir.Node) {
27-
switch n := n.(type) {
28-
case *ir.CallExpr:
29-
staticCall(n)
30-
}
31-
})
32-
}
33-
34-
// staticCall devirtualizes the given call if possible when the concrete callee
35-
// is available statically.
36-
func staticCall(call *ir.CallExpr) {
23+
func StaticCall(call *ir.CallExpr) {
3724
// For promoted methods (including value-receiver methods promoted
3825
// to pointer-receivers), the interface method wrapper may contain
3926
// expressions that can panic (e.g., ODEREF, ODOTPTR,
@@ -51,6 +38,7 @@ func staticCall(call *ir.CallExpr) {
5138
if call.Op() != ir.OCALLINTER {
5239
return
5340
}
41+
5442
sel := call.Fun.(*ir.SelectorExpr)
5543
r := ir.StaticValue(sel.X)
5644
if r.Op() != ir.OCONVIFACE {

src/cmd/compile/internal/gc/main.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"bytes"
1010
"cmd/compile/internal/base"
1111
"cmd/compile/internal/coverage"
12-
"cmd/compile/internal/devirtualize"
1312
"cmd/compile/internal/dwarfgen"
1413
"cmd/compile/internal/escape"
1514
"cmd/compile/internal/inline"
15+
"cmd/compile/internal/inline/interleaved"
1616
"cmd/compile/internal/ir"
1717
"cmd/compile/internal/logopt"
1818
"cmd/compile/internal/loopvar"
@@ -224,30 +224,15 @@ func Main(archInit func(*ssagen.ArchInfo)) {
224224
}
225225
}
226226

227-
base.Timer.Start("fe", "pgo-devirtualization")
228-
if profile != nil && base.Debug.PGODevirtualize > 0 {
229-
// TODO(prattmic): No need to use bottom-up visit order. This
230-
// is mirroring the PGO IRGraph visit order, which also need
231-
// not be bottom-up.
232-
ir.VisitFuncsBottomUp(typecheck.Target.Funcs, func(list []*ir.Func, recursive bool) {
233-
for _, fn := range list {
234-
devirtualize.ProfileGuided(fn, profile)
235-
}
236-
})
237-
ir.CurFunc = nil
238-
}
227+
// Interleaved devirtualization and inlining.
228+
base.Timer.Start("fe", "devirtualize-and-inline")
229+
interleaved.DevirtualizeAndInlinePackage(typecheck.Target, profile)
239230

240-
// Inlining
241-
base.Timer.Start("fe", "inlining")
242-
if base.Flag.LowerL != 0 {
243-
inline.InlinePackage(profile)
244-
}
245231
noder.MakeWrappers(typecheck.Target) // must happen after inlining
246232

247-
// Devirtualize and get variable capture right in for loops
233+
// Get variable capture right in for loops.
248234
var transformed []loopvar.VarAndLoop
249235
for _, fn := range typecheck.Target.Funcs {
250-
devirtualize.Static(fn)
251236
transformed = append(transformed, loopvar.ForCapture(fn)...)
252237
}
253238
ir.CurFunc = nil

0 commit comments

Comments
 (0)