Imports #
"bufio"
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
"cmd/internal/pgo"
"fmt"
"maps"
"os"
"bufio"
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
"cmd/internal/pgo"
"fmt"
"maps"
"os"
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 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
CallSiteInfo captures call-site information and its caller/callee.
type CallSiteInfo struct {
LineOffset int
Caller *ir.Func
Callee *ir.Func
}
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 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 represents a node (function) in the IRGraph.
type IRNode struct {
AST *ir.Func
LinkerSymbolName string
OutEdges map[pgo.NamedCallEdge]*IREdge
}
Profile contains the processed PGO profile and weighted call graph used for PGO optimizations.
type Profile struct {
*pgo.Profile
WeightedCG *IRGraph
}
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 returns the symbol name of this function.
func (i *IRNode) Name() string
New generates a profile-graph from the profile or pre-processed profile.
func New(profileFile string) (*Profile, error)
NodeLineOffset returns the line offset of n in fn.
func NodeLineOffset(n ir.Node, fn *ir.Func) int
PrintWeightedCallGraphDOT prints IRGraph in DOT format.
func (p *Profile) PrintWeightedCallGraphDOT(edgeThreshold float64)
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 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)
initializeIRGraph builds the IRGraph by visiting all the ir.Func in decl list of a package.
func createIRGraph(namedEdgeMap pgo.NamedEdgeMap) *IRGraph
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 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