package devirtualize

import "cmd/compile/internal/devirtualize"

Package devirtualize implements two "devirtualization" optimization passes:

Index

Functions

func ProfileGuided

func ProfileGuided(fn *ir.Func, p *pgo.Profile)

ProfileGuided performs call devirtualization of indirect calls based on profile information.

Specifically, it performs conditional devirtualization of interface calls for the hottest callee. That is, it performs a transformation like:

type Iface interface {
	Foo()
}

type Concrete struct{}

func (Concrete) Foo() {}

func foo(i Iface) {
	i.Foo()
}

to:

func foo(i Iface) {
	if c, ok := i.(Concrete); ok {
		c.Foo()
	} else {
		i.Foo()
	}
}

The primary benefit of this transformation is enabling inlining of the direct call.

func Static

func Static(fn *ir.Func)

Static devirtualizes calls within fn where possible when the concrete callee is available statically.

Types

type CallStat

type CallStat struct {
	Pkg string // base.Ctxt.Pkgpath
	Pos string // file:line:col of call.

	Caller string // Linker symbol name of calling function.

	// Direct or indirect call.
	Direct bool

	// For indirect calls, interface call or other indirect function call.
	Interface bool

	// Total edge weight from this call site.
	Weight int64

	// Hottest callee from this call site, regardless of type
	// compatibility.
	Hottest       string
	HottestWeight int64

	// Devirtualized callee if != "".
	//
	// Note that this may be different than Hottest because we apply
	// type-check restrictions, which helps distinguish multiple calls on
	// the same line.
	Devirtualized       string
	DevirtualizedWeight int64
}

CallStat summarizes a single call site.

This is used only for debug logging.

Source Files

devirtualize.go pgo.go

Version
v1.21.12
Published
Jun 27, 2024
Platform
linux/amd64
Imports
11 packages
Last checked
3 minutes ago

Tools for package owners.