]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/compile/internal/inline/inl.go
cmd/compile/internal/inline: rework call scoring for non-inlinable funcs
[gostls13.git] / src / cmd / compile / internal / inline / inl.go
index 992ae632e272c0dab23a4bab4770cca24a79a248..50f06f270eebdfd242b38aa3f616682f64a33692 100644 (file)
@@ -151,7 +151,7 @@ func InlinePackage(p *pgo.Profile) {
        if base.Debug.DumpInlFuncProps != "" {
                inlheur.DumpFuncProps(nil, base.Debug.DumpInlFuncProps, nil, inlineMaxBudget)
        }
-       if goexperiment.NewInliner {
+       if useNewInliner() {
                postProcessCallSites(p)
        }
 }
@@ -282,9 +282,13 @@ func CanInline(fn *ir.Func, profile *pgo.Profile) {
        }
 
        var funcProps *inlheur.FuncProps
-       if goexperiment.NewInliner || inlheur.UnitTesting() {
+       if useNewInliner() {
                callCanInline := func(fn *ir.Func) { CanInline(fn, profile) }
                funcProps = inlheur.AnalyzeFunc(fn, callCanInline, inlineMaxBudget)
+               budgetForFunc := func(fn *ir.Func) int32 {
+                       return inlineBudget(fn, profile, true, false)
+               }
+               defer func() { inlheur.RevisitInlinability(fn, budgetForFunc) }()
        }
 
        var reason string // reason, if any, that the function was not inlined
@@ -320,11 +324,8 @@ func CanInline(fn *ir.Func, profile *pgo.Profile) {
                cc = 1 // this appears to yield better performance than 0.
        }
 
-       // Used a "relaxed" inline budget if goexperiment.NewInliner is in
-       // effect, or if we're producing a debugging dump.
-       relaxed := goexperiment.NewInliner ||
-               (base.Debug.DumpInlFuncProps != "" ||
-                       base.Debug.DumpInlCallSiteScores != 0)
+       // Used a "relaxed" inline budget if the new inliner is enabled.
+       relaxed := useNewInliner()
 
        // Compute the inline budget for this func.
        budget := inlineBudget(fn, profile, relaxed, base.Debug.PGODebug > 0)
@@ -358,7 +359,7 @@ func CanInline(fn *ir.Func, profile *pgo.Profile) {
 
                CanDelayResults: canDelayResults(fn),
        }
-       if goexperiment.NewInliner {
+       if useNewInliner() {
                n.Func.Inl.Properties = funcProps.SerializeToString()
        }
 
@@ -797,8 +798,9 @@ func isBigFunc(fn *ir.Func) bool {
 // InlineCalls/inlnode walks fn's statements and expressions and substitutes any
 // calls made to inlineable functions. This is the external entry point.
 func InlineCalls(fn *ir.Func, profile *pgo.Profile) {
-       if goexperiment.NewInliner && !fn.Wrapper() {
+       if useNewInliner() && !fn.Wrapper() {
                inlheur.ScoreCalls(fn)
+               defer inlheur.ScoreCallsCleanup()
        }
        if base.Debug.DumpInlFuncProps != "" && !fn.Wrapper() {
                inlheur.DumpFuncProps(fn, base.Debug.DumpInlFuncProps,
@@ -977,8 +979,8 @@ func inlineCostOK(n *ir.CallExpr, caller, callee *ir.Func, bigCaller bool) (bool
        }
 
        metric := callee.Inl.Cost
-       if goexperiment.NewInliner {
-               ok, score := inlheur.GetCallSiteScore(n)
+       if useNewInliner() {
+               score, ok := inlheur.GetCallSiteScore(caller, n)
                if ok {
                        metric = int32(score)
                }
@@ -1295,6 +1297,11 @@ func isAtomicCoverageCounterUpdate(cn *ir.CallExpr) bool {
        return v
 }
 
+func useNewInliner() bool {
+       return goexperiment.NewInliner ||
+               inlheur.UnitTesting()
+}
+
 func postProcessCallSites(profile *pgo.Profile) {
        if base.Debug.DumpInlCallSiteScores != 0 {
                budgetCallback := func(fn *ir.Func, prof *pgo.Profile) (int32, bool) {