aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/devirtualize
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-12-24 16:03:47 -0800
committerMatthew Dempsky <mdempsky@google.com>2020-12-25 00:39:43 +0000
commit2785c691c2ba63d284bdaf0f3bcdb678c3f16cd0 (patch)
tree22feafe558e070f8b796ca326dfd7ca7648cc86f /src/cmd/compile/internal/devirtualize
parent4b1d0fe66f3fcd80febc0e4be2850c06e3469da3 (diff)
downloadgo-2785c691c2ba63d284bdaf0f3bcdb678c3f16cd0.tar.gz
go-2785c691c2ba63d284bdaf0f3bcdb678c3f16cd0.zip
[dev.regabi] cmd/compile: cleanup devirtualization docs
Change-Id: I8e319f55fad6e9ed857aa020a96f3a89ccaadcea Reviewed-on: https://go-review.googlesource.com/c/go/+/280213 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/devirtualize')
-rw-r--r--src/cmd/compile/internal/devirtualize/devirtualize.go38
1 files changed, 11 insertions, 27 deletions
diff --git a/src/cmd/compile/internal/devirtualize/devirtualize.go b/src/cmd/compile/internal/devirtualize/devirtualize.go
index 95b28eff61..60ba208d08 100644
--- a/src/cmd/compile/internal/devirtualize/devirtualize.go
+++ b/src/cmd/compile/internal/devirtualize/devirtualize.go
@@ -1,29 +1,10 @@
-// Copyright 2011 The Go Authors. All rights reserved.
+// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//
-// The inlining facility makes 2 passes: first caninl determines which
-// functions are suitable for inlining, and for those that are it
-// saves a copy of the body. Then inlcalls walks each function body to
-// expand calls to inlinable functions.
-//
-// The Debug.l flag controls the aggressiveness. Note that main() swaps level 0 and 1,
-// making 1 the default and -l disable. Additional levels (beyond -l) may be buggy and
-// are not supported.
-// 0: disabled
-// 1: 80-nodes leaf functions, oneliners, panic, lazy typechecking (default)
-// 2: (unassigned)
-// 3: (unassigned)
-// 4: allow non-leaf functions
-//
-// At some point this may get another default and become switch-offable with -N.
-//
-// The -d typcheckinl flag enables early typechecking of all imported bodies,
-// which is useful to flush out bugs.
-//
-// The Debug.m flag enables diagnostic output. a single -m is useful for verifying
-// which calls get inlined or not, more is for debugging, and may go away at any point.
+// Package devirtualize implements a simple "devirtualization"
+// optimization pass, which replaces interface method calls with
+// direct concrete-type method calls where possible.
package devirtualize
import (
@@ -33,18 +14,21 @@ import (
"cmd/compile/internal/types"
)
-// Devirtualize replaces interface method calls within fn with direct
-// concrete-type method calls where applicable.
+// Func devirtualizes calls within fn where possible.
func Func(fn *ir.Func) {
ir.CurFunc = fn
ir.VisitList(fn.Body, func(n ir.Node) {
- if n.Op() == ir.OCALLINTER {
- Call(n.(*ir.CallExpr))
+ if call, ok := n.(*ir.CallExpr); ok {
+ Call(call)
}
})
}
+// Call devirtualizes the given call if possible.
func Call(call *ir.CallExpr) {
+ if call.Op() != ir.OCALLINTER {
+ return
+ }
sel := call.X.(*ir.SelectorExpr)
r := ir.StaticValue(sel.X)
if r.Op() != ir.OCONVIFACE {