From 6eb31c1a00327fb1c757d78519f8dcc9ace6ceaf Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Mon, 31 Jul 2023 15:26:26 -0400 Subject: [PATCH] cmd/compile/internal/inline: refactor inline budget computation Split out the code that computes the initial inline "hairyness" budget for a function so that it can be reused (in a later patch). This is a pure refactoring; no change in compiler functionality. Change-Id: I9b1b7b10a7c480559b837492b10eb08771b7a145 Reviewed-on: https://go-review.googlesource.com/c/go/+/514795 Run-TryBot: Than McIntosh TryBot-Result: Gopher Robot Reviewed-by: Keith Randall Reviewed-by: Keith Randall --- src/cmd/compile/internal/inline/inl.go | 34 +++++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go index 00a8bb52e3..414129d937 100644 --- a/src/cmd/compile/internal/inline/inl.go +++ b/src/cmd/compile/internal/inline/inl.go @@ -266,6 +266,26 @@ func garbageCollectUnreferencedHiddenClosures() { } } +// inlineBudget determines the max budget for function 'fn' prior to +// analyzing the hairyness of the body of 'fn'. We pass in the pgo +// profile if available, which can change the budget. If 'verbose' is +// set, then print a remark where we boost the budget due to PGO. +func inlineBudget(fn *ir.Func, profile *pgo.Profile, verbose bool) int32 { + // Update the budget for profile-guided inlining. + budget := int32(inlineMaxBudget) + if profile != nil { + if n, ok := profile.WeightedCG.IRNodes[ir.LinkFuncName(fn)]; ok { + if _, ok := candHotCalleeMap[n]; ok { + budget = int32(inlineHotMaxBudget) + if verbose { + fmt.Printf("hot-node enabled increased budget=%v for func=%v\n", budget, ir.PkgFuncName(fn)) + } + } + } + } + return budget +} + // CanInline determines whether fn is inlineable. // If so, CanInline saves copies of fn.Body and fn.Dcl in fn.Inl. // fn and fn.Body will already have been typechecked. @@ -311,18 +331,8 @@ func CanInline(fn *ir.Func, profile *pgo.Profile) { cc = 1 // this appears to yield better performance than 0. } - // Update the budget for profile-guided inlining. - budget := int32(inlineMaxBudget) - if profile != nil { - if n, ok := profile.WeightedCG.IRNodes[ir.LinkFuncName(fn)]; ok { - if _, ok := candHotCalleeMap[n]; ok { - budget = int32(inlineHotMaxBudget) - if base.Debug.PGODebug > 0 { - fmt.Printf("hot-node enabled increased budget=%v for func=%v\n", budget, ir.PkgFuncName(fn)) - } - } - } - } + // Compute the inline budget for this function. + budget := inlineBudget(fn, profile, base.Debug.PGODebug > 0) // At this point in the game the function we're looking at may // have "stale" autos, vars that still appear in the Dcl list, but -- 2.50.0