github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/compile/internal/inline/inl.go (about)

     1  // Copyright 2011 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  //
     5  // The inlining facility makes 2 passes: first CanInline determines which
     6  // functions are suitable for inlining, and for those that are it
     7  // saves a copy of the body. Then InlineCalls walks each function body to
     8  // expand calls to inlinable functions.
     9  //
    10  // The Debug.l flag controls the aggressiveness. Note that main() swaps level 0 and 1,
    11  // making 1 the default and -l disable. Additional levels (beyond -l) may be buggy and
    12  // are not supported.
    13  //      0: disabled
    14  //      1: 80-nodes leaf functions, oneliners, panic, lazy typechecking (default)
    15  //      2: (unassigned)
    16  //      3: (unassigned)
    17  //      4: allow non-leaf functions
    18  //
    19  // At some point this may get another default and become switch-offable with -N.
    20  //
    21  // The -d typcheckinl flag enables early typechecking of all imported bodies,
    22  // which is useful to flush out bugs.
    23  //
    24  // The Debug.m flag enables diagnostic output.  a single -m is useful for verifying
    25  // which calls get inlined or not, more is for debugging, and may go away at any point.
    26  
    27  package inline
    28  
    29  import (
    30  	"github.com/shogo82148/std/cmd/compile/internal/base"
    31  	"github.com/shogo82148/std/cmd/compile/internal/ir"
    32  	"github.com/shogo82148/std/cmd/compile/internal/pgo"
    33  )
    34  
    35  // PGOInlinePrologue records the hot callsites from ir-graph.
    36  func PGOInlinePrologue(p *pgo.Profile)
    37  
    38  // CanInlineFuncs computes whether a batch of functions are inlinable.
    39  func CanInlineFuncs(funcs []*ir.Func, profile *pgo.Profile)
    40  
    41  // GarbageCollectUnreferencedHiddenClosures makes a pass over all the
    42  // top-level (non-hidden-closure) functions looking for nested closure
    43  // functions that are reachable, then sweeps through the Target.Decls
    44  // list and marks any non-reachable hidden closure function as dead.
    45  // See issues #59404 and #59638 for more context.
    46  func GarbageCollectUnreferencedHiddenClosures()
    47  
    48  // CanInline determines whether fn is inlineable.
    49  // If so, CanInline saves copies of fn.Body and fn.Dcl in fn.Inl.
    50  // fn and fn.Body will already have been typechecked.
    51  func CanInline(fn *ir.Func, profile *pgo.Profile)
    52  
    53  // InlineImpossible returns a non-empty reason string if fn is impossible to
    54  // inline regardless of cost or contents.
    55  func InlineImpossible(fn *ir.Func) string
    56  
    57  // IsBigFunc reports whether fn is a "big" function.
    58  //
    59  // Note: The criteria for "big" is heuristic and subject to change.
    60  func IsBigFunc(fn *ir.Func) bool
    61  
    62  // TryInlineCall returns an inlined call expression for call, or nil
    63  // if inlining is not possible.
    64  func TryInlineCall(callerfn *ir.Func, call *ir.CallExpr, bigCaller bool, profile *pgo.Profile) *ir.InlinedCallExpr
    65  
    66  // SSADumpInline gives the SSA back end a chance to dump the function
    67  // when producing output for debugging the compiler itself.
    68  var SSADumpInline = func(*ir.Func) {}
    69  
    70  // InlineCall allows the inliner implementation to be overridden.
    71  // If it returns nil, the function will not be inlined.
    72  var InlineCall = func(callerfn *ir.Func, call *ir.CallExpr, fn *ir.Func, inlIndex int) *ir.InlinedCallExpr {
    73  	base.Fatalf("inline.InlineCall not overridden")
    74  	panic("unreachable")
    75  }
    76  
    77  // CalleeEffects appends any side effects from evaluating callee to init.
    78  func CalleeEffects(init *ir.Nodes, callee ir.Node)
    79  
    80  func PostProcessCallSites(profile *pgo.Profile)