Skip to content

Commit cce6769

Browse files
committed
cmd/compile: remove post-inlining PGO graph dump
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 <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Michael Pratt <[email protected]>
1 parent 4b6a542 commit cce6769

File tree

2 files changed

+0
-100
lines changed

2 files changed

+0
-100
lines changed

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ var (
6363
// TODO(prattmic): Make this non-global.
6464
candHotEdgeMap = make(map[pgo.CallSiteInfo]struct{})
6565

66-
// List of inlined call sites. CallSiteInfo.Callee is always nil.
67-
// TODO(prattmic): Make this non-global.
68-
inlinedCallSites = make(map[pgo.CallSiteInfo]struct{})
69-
7066
// Threshold in percentage for hot callsite inlining.
7167
inlineHotCallSiteThresholdPercent float64
7268

@@ -158,23 +154,6 @@ func hotNodesFromCDF(p *pgo.Profile) (float64, []pgo.NodeMapKey) {
158154
return 0, nodes
159155
}
160156

161-
// pgoInlineEpilogue updates IRGraph after inlining.
162-
func pgoInlineEpilogue(p *pgo.Profile, decls []ir.Node) {
163-
if base.Debug.PGOInline >= 2 {
164-
ir.VisitFuncsBottomUp(decls, func(list []*ir.Func, recursive bool) {
165-
for _, f := range list {
166-
name := ir.LinkFuncName(f)
167-
if n, ok := p.WeightedCG.IRNodes[name]; ok {
168-
p.RedirectEdges(n, inlinedCallSites)
169-
}
170-
}
171-
})
172-
// Print the call-graph after inlining. This is a debugging feature.
173-
fmt.Printf("hot-cg after inline in dot:")
174-
p.PrintWeightedCallGraphDOT(inlineHotCallSiteThresholdPercent)
175-
}
176-
}
177-
178157
// InlinePackage finds functions that can be inlined and clones them before walk expands them.
179158
func InlinePackage(p *pgo.Profile) {
180159
InlineDecls(p, typecheck.Target.Decls, true)
@@ -223,10 +202,6 @@ func InlineDecls(p *pgo.Profile, decls []ir.Node, doInline bool) {
223202
}
224203
}
225204
})
226-
227-
if p != nil {
228-
pgoInlineEpilogue(p, decls)
229-
}
230205
}
231206

232207
// garbageCollectUnreferencedHiddenClosures makes a pass over all the
@@ -1147,13 +1122,6 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, bigCaller bool, inlCalls *[]*ir.Inli
11471122
fmt.Printf("%v: Before inlining: %+v\n", ir.Line(n), n)
11481123
}
11491124

1150-
if base.Debug.PGOInline > 0 {
1151-
csi := pgo.CallSiteInfo{LineOffset: pgo.NodeLineOffset(n, fn), Caller: ir.CurFunc}
1152-
if _, ok := inlinedCallSites[csi]; !ok {
1153-
inlinedCallSites[csi] = struct{}{}
1154-
}
1155-
}
1156-
11571125
res := InlineCall(n, fn, inlIndex)
11581126

11591127
if res == nil {

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

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -415,74 +415,6 @@ func (p *Profile) PrintWeightedCallGraphDOT(edgeThreshold float64) {
415415
fmt.Printf("}\n")
416416
}
417417

418-
// RedirectEdges deletes and redirects out-edges from node cur based on
419-
// inlining information via inlinedCallSites.
420-
//
421-
// CallSiteInfo.Callee must be nil.
422-
func (p *Profile) RedirectEdges(cur *IRNode, inlinedCallSites map[CallSiteInfo]struct{}) {
423-
g := p.WeightedCG
424-
425-
i := 0
426-
outs := g.OutEdges[cur]
427-
for i < len(outs) {
428-
outEdge := outs[i]
429-
redirected := false
430-
_, found := inlinedCallSites[CallSiteInfo{LineOffset: outEdge.CallSiteOffset, Caller: cur.AST}]
431-
if !found {
432-
for _, InEdge := range g.InEdges[cur] {
433-
if _, ok := inlinedCallSites[CallSiteInfo{LineOffset: InEdge.CallSiteOffset, Caller: InEdge.Src.AST}]; ok {
434-
weight := g.calculateWeight(InEdge.Src, cur)
435-
g.redirectEdge(InEdge.Src, outEdge, weight)
436-
redirected = true
437-
}
438-
}
439-
}
440-
if found || redirected {
441-
g.remove(cur, i)
442-
outs = g.OutEdges[cur]
443-
continue
444-
}
445-
i++
446-
}
447-
}
448-
449-
// redirectEdge redirects a node's out-edge to one of its parent nodes, cloning is
450-
// required as the node might be inlined in multiple call-sites.
451-
// TODO: adjust the in-edges of outEdge.Dst if necessary
452-
func (g *IRGraph) redirectEdge(parent *IRNode, outEdge *IREdge, weight int64) {
453-
edge := &IREdge{Src: parent, Dst: outEdge.Dst, Weight: weight * outEdge.Weight, CallSiteOffset: outEdge.CallSiteOffset}
454-
g.OutEdges[parent] = append(g.OutEdges[parent], edge)
455-
}
456-
457-
// remove deletes the cur-node's out-edges at index idx.
458-
func (g *IRGraph) remove(cur *IRNode, i int) {
459-
if len(g.OutEdges[cur]) >= 2 {
460-
g.OutEdges[cur][i] = g.OutEdges[cur][len(g.OutEdges[cur])-1]
461-
g.OutEdges[cur] = g.OutEdges[cur][:len(g.OutEdges[cur])-1]
462-
} else {
463-
delete(g.OutEdges, cur)
464-
}
465-
}
466-
467-
// calculateWeight calculates the weight of the new redirected edge.
468-
func (g *IRGraph) calculateWeight(parent *IRNode, cur *IRNode) int64 {
469-
sum := int64(0)
470-
pw := int64(0)
471-
for _, InEdge := range g.InEdges[cur] {
472-
sum += InEdge.Weight
473-
if InEdge.Src == parent {
474-
pw = InEdge.Weight
475-
}
476-
}
477-
weight := int64(0)
478-
if sum != 0 {
479-
weight = pw / sum
480-
} else {
481-
weight = pw
482-
}
483-
return weight
484-
}
485-
486418
// inlCallee is same as the implementation for inl.go with one change. The change is that we do not invoke CanInline on a closure.
487419
func inlCallee(fn ir.Node) *ir.Func {
488420
fn = ir.StaticValue(fn)

0 commit comments

Comments
 (0)