mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/pgo: remove ConvertLine2Int
Parts of package pgo fetch the line number of a node by parsing the number out of the string returned from ir.Line(). This is indirect and inefficient, so it should be replaced with a more direct lookup. It is also potentially buggy: ir.Line uses ctxt.OutermostPos, i.e., the line number where an inlined node in inlined. We want ctxt.InnermostPos, because that is the line number used in pprof profiles that we are matching against (See comments on OutermostPos and InnermostPos). I'm not sure whether this was an active, as we use ir.Line before and during inlining. I think we could see CALL nodes with OutermostPos != InnermostPos during midstack inlining, but I am not sure. Regardless, explicitly using the desired position is clearer. For #55022. Change-Id: Ic640761c9e1d01cacbf91f3aaeaf284ad7e38dbd Reviewed-on: https://go-review.googlesource.com/c/go/+/446302 Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
e8ec68edfa
commit
ec0b540293
2 changed files with 45 additions and 18 deletions
|
|
@ -441,10 +441,10 @@ func (v *hairyVisitor) doNode(n ir.Node) bool {
|
|||
// Determine if the callee edge is a for hot callee or not.
|
||||
if base.Flag.PgoProfile != "" && pgo.WeightedCG != nil && v.curFunc != nil {
|
||||
if fn := inlCallee(n.X); fn != nil && typecheck.HaveInlineBody(fn) {
|
||||
ln := pgo.ConvertLine2Int(ir.Line(n))
|
||||
csi := pgo.CallSiteInfo{Line: ln, Caller: v.curFunc, Callee: fn}
|
||||
line := int(base.Ctxt.InnermostPos(n.Pos()).RelLine())
|
||||
csi := pgo.CallSiteInfo{Line: line, Caller: v.curFunc, Callee: fn}
|
||||
if _, o := candHotEdgeMap[csi]; o {
|
||||
pgo.ListOfHotCallSites[pgo.CallSiteInfo{Line: ln, Caller: v.curFunc}] = struct{}{}
|
||||
pgo.ListOfHotCallSites[pgo.CallSiteInfo{Line: line, Caller: v.curFunc}] = struct{}{}
|
||||
if base.Debug.PGOInline > 0 {
|
||||
fmt.Printf("hot-callsite identified at line=%v for func=%v\n", ir.Line(n), ir.PkgFuncName(v.curFunc))
|
||||
}
|
||||
|
|
@ -873,8 +873,8 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlCalls *[]*ir.Inlin
|
|||
}
|
||||
if fn.Inl.Cost > maxCost {
|
||||
// If the callsite is hot and it is under the inlineHotMaxBudget budget, then try to inline it, or else bail.
|
||||
ln := pgo.ConvertLine2Int(ir.Line(n))
|
||||
csi := pgo.CallSiteInfo{Line: ln, Caller: ir.CurFunc}
|
||||
line := int(base.Ctxt.InnermostPos(n.Pos()).RelLine())
|
||||
csi := pgo.CallSiteInfo{Line: line, Caller: ir.CurFunc}
|
||||
if _, ok := pgo.ListOfHotCallSites[csi]; ok {
|
||||
if fn.Inl.Cost > inlineHotMaxBudget {
|
||||
if logopt.Enabled() {
|
||||
|
|
@ -1038,8 +1038,8 @@ func mkinlcall(n *ir.CallExpr, fn *ir.Func, maxCost int32, inlCalls *[]*ir.Inlin
|
|||
}
|
||||
|
||||
if base.Debug.PGOInline > 0 {
|
||||
ln := pgo.ConvertLine2Int(ir.Line(n))
|
||||
csi := pgo.CallSiteInfo{Line: ln, Caller: ir.CurFunc}
|
||||
line := int(base.Ctxt.InnermostPos(n.Pos()).RelLine())
|
||||
csi := pgo.CallSiteInfo{Line: line, Caller: ir.CurFunc}
|
||||
if _, ok := inlinedCallSites[csi]; !ok {
|
||||
inlinedCallSites[csi] = struct{}{}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue