From 4a90cdb03d9c103abb0d44ff42dde7121ac6cd34 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Sat, 18 Nov 2023 20:16:47 -0800 Subject: cmd/compile: interleave devirtualization and inlining This CL interleaves devirtualization and inlining, so that devirtualized calls can be inlined. Fixes #52193. Change-Id: I681e7c55bdb90ebf6df315d334e7a58f05110d9c Reviewed-on: https://go-review.googlesource.com/c/go/+/528321 Auto-Submit: Matthew Dempsky Reviewed-by: Than McIntosh Reviewed-by: Cherry Mui TryBot-Bypass: Matthew Dempsky --- src/cmd/compile/internal/devirtualize/devirtualize.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src/cmd/compile/internal/devirtualize/devirtualize.go') diff --git a/src/cmd/compile/internal/devirtualize/devirtualize.go b/src/cmd/compile/internal/devirtualize/devirtualize.go index 9e26f66a1c..5d1b952627 100644 --- a/src/cmd/compile/internal/devirtualize/devirtualize.go +++ b/src/cmd/compile/internal/devirtualize/devirtualize.go @@ -18,22 +18,9 @@ import ( "cmd/compile/internal/types" ) -// Static devirtualizes calls within fn where possible when the concrete callee +// StaticCall devirtualizes the given call if possible when the concrete callee // is available statically. -func Static(fn *ir.Func) { - ir.CurFunc = fn - - ir.VisitList(fn.Body, func(n ir.Node) { - switch n := n.(type) { - case *ir.CallExpr: - staticCall(n) - } - }) -} - -// staticCall devirtualizes the given call if possible when the concrete callee -// is available statically. -func staticCall(call *ir.CallExpr) { +func StaticCall(call *ir.CallExpr) { // For promoted methods (including value-receiver methods promoted // to pointer-receivers), the interface method wrapper may contain // expressions that can panic (e.g., ODEREF, ODOTPTR, @@ -51,6 +38,7 @@ func staticCall(call *ir.CallExpr) { if call.Op() != ir.OCALLINTER { return } + sel := call.Fun.(*ir.SelectorExpr) r := ir.StaticValue(sel.X) if r.Op() != ir.OCONVIFACE { -- cgit v1.3