]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: remove post-inlining PGO graph dump
authorMichael Pratt <mpratt@google.com>
Fri, 12 May 2023 15:54:47 +0000 (11:54 -0400)
committerMichael Pratt <mpratt@google.com>
Fri, 12 May 2023 20:17:06 +0000 (20:17 +0000)
The RedirectEdges logic is fragile and not quite complete (doesn't
update in-edges), which adds overhead to maintaining this package.

In my opinion, the post-inlining graph doesn't provide as much value as
the pre-inlining graph. Even the latter I am not convinced should be in
the compiler rather than an external tool, but it is comparatively
easier to maintain.

Drop it for now. Perhaps we'll want it back in the future for tracking
follow-up optimizations, but for now keep things simple.

Change-Id: I3133a2eb97893a14a6770547f96a3f1796798d17
Reviewed-on: https://go-review.googlesource.com/c/go/+/494655
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>

src/cmd/compile/internal/inline/inl.go
src/cmd/compile/internal/pgo/irgraph.go

index 528e96461121444616a5d39dd168c20e1b0f43b1..6677f907412694deba2c719b5c0b4d041051b02d 100644 (file)
@@ -63,10 +63,6 @@ var (
        // TODO(prattmic): Make this non-global.
        candHotEdgeMap = make(map[pgo.CallSiteInfo]struct{})
 
-       // List of inlined call sites. CallSiteInfo.Callee is always nil.
-       // TODO(prattmic): Make this non-global.
-       inlinedCallSites = make(map[pgo.CallSiteInfo]struct{})
-
        // Threshold in percentage for hot callsite inlining.
        inlineHotCallSiteThresholdPercent float64
 
@@ -158,23 +154,6 @@ func hotNodesFromCDF(p *pgo.Profile) (float64, []pgo.NodeMapKey) {
        return 0, nodes
 }
 
-// pgoInlineEpilogue updates IRGraph after inlining.
-func pgoInlineEpilogue(p *pgo.Profile, decls []ir.Node) {
-       if base.Debug.PGOInline >= 2 {
-               ir.VisitFuncsBottomUp(decls, func(list []*ir.Func, recursive bool) {
-                       for _, f := range list {
-                               name := ir.LinkFuncName(f)
-                               if n, ok := p.WeightedCG.IRNodes[name]; ok {
-                                       p.RedirectEdges(n, inlinedCallSites)
-                               }
-                       }
-               })
-               // Print the call-graph after inlining. This is a debugging feature.
-               fmt.Printf("hot-cg after inline in dot:")
-               p.PrintWeightedCallGraphDOT(inlineHotCallSiteThresholdPercent)
-       }
-}
-
 // InlinePackage finds functions that can be inlined and clones them before walk expands them.
 func InlinePackage(p *pgo.Profile) {
        InlineDecls(p, typecheck.Target.Decls, true)
@@ -223,10 +202,6 @@ func InlineDecls(p *pgo.Profile, decls []ir.Node, doInline bool) {
                        }
                }
        })
-
-       if p != nil {
-               pgoInlineEpilogue(p, decls)
-       }
 }
 
 // garbageCollectUnreferencedHiddenClosures makes a pass over all the
@@ -1147,13 +1122,6 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, bigCaller bool, inlCalls *[]*ir.Inli
                fmt.Printf("%v: Before inlining: %+v\n", ir.Line(n), n)
        }
 
-       if base.Debug.PGOInline > 0 {
-               csi := pgo.CallSiteInfo{LineOffset: pgo.NodeLineOffset(n, fn), Caller: ir.CurFunc}
-               if _, ok := inlinedCallSites[csi]; !ok {
-                       inlinedCallSites[csi] = struct{}{}
-               }
-       }
-
        res := InlineCall(n, fn, inlIndex)
 
        if res == nil {
index f3f6e3fdc6b4989633607d42ea6a8e4070bf1187..b9c39f6090ec3e6e7b890a29a67c6f7d5857dd1a 100644 (file)
@@ -415,74 +415,6 @@ func (p *Profile) PrintWeightedCallGraphDOT(edgeThreshold float64) {
        fmt.Printf("}\n")
 }
 
-// RedirectEdges deletes and redirects out-edges from node cur based on
-// inlining information via inlinedCallSites.
-//
-// CallSiteInfo.Callee must be nil.
-func (p *Profile) RedirectEdges(cur *IRNode, inlinedCallSites map[CallSiteInfo]struct{}) {
-       g := p.WeightedCG
-
-       i := 0
-       outs := g.OutEdges[cur]
-       for i < len(outs) {
-               outEdge := outs[i]
-               redirected := false
-               _, found := inlinedCallSites[CallSiteInfo{LineOffset: outEdge.CallSiteOffset, Caller: cur.AST}]
-               if !found {
-                       for _, InEdge := range g.InEdges[cur] {
-                               if _, ok := inlinedCallSites[CallSiteInfo{LineOffset: InEdge.CallSiteOffset, Caller: InEdge.Src.AST}]; ok {
-                                       weight := g.calculateWeight(InEdge.Src, cur)
-                                       g.redirectEdge(InEdge.Src, outEdge, weight)
-                                       redirected = true
-                               }
-                       }
-               }
-               if found || redirected {
-                       g.remove(cur, i)
-                       outs = g.OutEdges[cur]
-                       continue
-               }
-               i++
-       }
-}
-
-// redirectEdge redirects a node's out-edge to one of its parent nodes, cloning is
-// required as the node might be inlined in multiple call-sites.
-// TODO: adjust the in-edges of outEdge.Dst if necessary
-func (g *IRGraph) redirectEdge(parent *IRNode, outEdge *IREdge, weight int64) {
-       edge := &IREdge{Src: parent, Dst: outEdge.Dst, Weight: weight * outEdge.Weight, CallSiteOffset: outEdge.CallSiteOffset}
-       g.OutEdges[parent] = append(g.OutEdges[parent], edge)
-}
-
-// remove deletes the cur-node's out-edges at index idx.
-func (g *IRGraph) remove(cur *IRNode, i int) {
-       if len(g.OutEdges[cur]) >= 2 {
-               g.OutEdges[cur][i] = g.OutEdges[cur][len(g.OutEdges[cur])-1]
-               g.OutEdges[cur] = g.OutEdges[cur][:len(g.OutEdges[cur])-1]
-       } else {
-               delete(g.OutEdges, cur)
-       }
-}
-
-// calculateWeight calculates the weight of the new redirected edge.
-func (g *IRGraph) calculateWeight(parent *IRNode, cur *IRNode) int64 {
-       sum := int64(0)
-       pw := int64(0)
-       for _, InEdge := range g.InEdges[cur] {
-               sum += InEdge.Weight
-               if InEdge.Src == parent {
-                       pw = InEdge.Weight
-               }
-       }
-       weight := int64(0)
-       if sum != 0 {
-               weight = pw / sum
-       } else {
-               weight = pw
-       }
-       return weight
-}
-
 // inlCallee is same as the implementation for inl.go with one change. The change is that we do not invoke CanInline on a closure.
 func inlCallee(fn ir.Node) *ir.Func {
        fn = ir.StaticValue(fn)