pgoir

Imports

Imports #

"bufio"
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
"cmd/internal/pgo"
"fmt"
"maps"
"os"

Constants & Variables

LookupFunc var #

LookupFunc looks up a function or method in export data. It is expected to be overridden by package noder, to break a dependency cycle.

var LookupFunc = *ast.FuncLit

PostLookupCleanup var #

PostLookupCleanup performs any remaining cleanup operations needed after a series of calls to LookupFunc, specifically reading in the bodies of functions that may have been delayed due being encountered in a stage where the reader's curfn state was not set up.

var PostLookupCleanup = *ast.FuncLit

Structs

CallSiteInfo struct #

CallSiteInfo captures call-site information and its caller/callee.

type CallSiteInfo struct {
LineOffset int
Caller *ir.Func
Callee *ir.Func
}

IREdge struct #

IREdge represents a call edge in the IRGraph with source, destination, weight, callsite, and line number information.

type IREdge struct {
Src *IRNode
Dst *IRNode
Weight int64
CallSiteOffset int
}

IRGraph struct #

IRGraph is a call graph with nodes pointing to IRs of functions and edges carrying weights and callsite information. Nodes for indirect calls may have missing IR (IRNode.AST == nil) if the node is not visible from this package (e.g., not in the transitive deps). Keeping these nodes allows determining the hottest edge from a call even if that callee is not available. TODO(prattmic): Consider merging this data structure with Graph. This is effectively a copy of Graph aggregated to line number and pointing to IR.

type IRGraph struct {
IRNodes map[string]*IRNode
}

IRNode struct #

IRNode represents a node (function) in the IRGraph.

type IRNode struct {
AST *ir.Func
LinkerSymbolName string
OutEdges map[pgo.NamedCallEdge]*IREdge
}

Profile struct #

Profile contains the processed PGO profile and weighted call graph used for PGO optimizations.

type Profile struct {
*pgo.Profile
WeightedCG *IRGraph
}

Functions

DirectCallee function #

DirectCallee takes a function-typed expression and returns the underlying function that it refers to if statically known. Otherwise, it returns nil. Equivalent to inline.inlCallee without calling CanInline on closures.

func DirectCallee(fn ir.Node) *ir.Func

Name method #

Name returns the symbol name of this function.

func (i *IRNode) Name() string

New function #

New generates a profile-graph from the profile or pre-processed profile.

func New(profileFile string) (*Profile, error)

NodeLineOffset function #

NodeLineOffset returns the line offset of n in fn.

func NodeLineOffset(n ir.Node, fn *ir.Func) int

PrintWeightedCallGraphDOT method #

PrintWeightedCallGraphDOT prints IRGraph in DOT format.

func (p *Profile) PrintWeightedCallGraphDOT(edgeThreshold float64)

addIREdge function #

addIREdge adds an edge between caller and new node that points to `callee` based on the profile-graph and NodeMap.

func addIREdge(callerNode *IRNode, callerName string, call ir.Node, callee *ir.Func, namedEdgeMap pgo.NamedEdgeMap, g *IRGraph)

addIndirectEdges function #

addIndirectEdges adds indirect call edges found in the profile to the graph, to be used for devirtualization. N.B. despite the name, addIndirectEdges will add any edges discovered via the profile. We don't know for sure that they are indirect, but assume they are since direct calls would already be added. (e.g., direct calls that have been deleted from source since the profile was taken would be added here). TODO(prattmic): Devirtualization runs before inlining, so we can't devirtualize calls inside inlined call bodies. If we did add that, we'd need edges from inlined bodies as well.

func addIndirectEdges(g *IRGraph, namedEdgeMap pgo.NamedEdgeMap)

createIRGraph function #

initializeIRGraph builds the IRGraph by visiting all the ir.Func in decl list of a package.

func createIRGraph(namedEdgeMap pgo.NamedEdgeMap) *IRGraph

createIRGraphEdge function #

createIRGraphEdge traverses the nodes in the body of ir.Func and adds edges between the callernode which points to the ir.Func and the nodes in the body.

func createIRGraphEdge(fn *ir.Func, callernode *IRNode, name string, namedEdgeMap pgo.NamedEdgeMap, g *IRGraph)

visitIR function #

visitIR traverses the body of each ir.Func adds edges to g from ir.Func to any called function in the body.

func visitIR(fn *ir.Func, namedEdgeMap pgo.NamedEdgeMap, g *IRGraph)

Generated with Arrow