]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile/internal/inline: refactor inline budget computation
authorThan McIntosh <thanm@google.com>
Mon, 31 Jul 2023 19:26:26 +0000 (15:26 -0400)
committerThan McIntosh <thanm@google.com>
Thu, 10 Aug 2023 18:54:11 +0000 (18:54 +0000)
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 <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/inline/inl.go

index 00a8bb52e3f5ec19d40c966fd2b0f9f63a76042c..414129d937af6314515478c45c7e8b497a3269ed 100644 (file)
@@ -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