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

     1  // Copyright 2023 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  package inlheur
     6  
     7  // FuncProps describes a set of function or method properties that may
     8  // be useful for inlining heuristics. Here 'Flags' are properties that
     9  // we think apply to the entire function; 'RecvrParamFlags' are
    10  // properties of specific function params (or the receiver), and
    11  // 'ResultFlags' are things properties we think will apply to values
    12  // of specific results. Note that 'ParamFlags' includes and entry for
    13  // the receiver if applicable, and does include etries for blank
    14  // params; for a function such as "func foo(_ int, b byte, _ float32)"
    15  // the length of ParamFlags will be 3.
    16  type FuncProps struct {
    17  	Flags       FuncPropBits
    18  	ParamFlags  []ParamPropBits
    19  	ResultFlags []ResultPropBits
    20  }
    21  
    22  type FuncPropBits uint32
    23  
    24  const (
    25  	// Function always panics or invokes os.Exit() or a func that does
    26  	// likewise.
    27  	FuncPropNeverReturns FuncPropBits = 1 << iota
    28  )
    29  
    30  type ParamPropBits uint32
    31  
    32  const (
    33  	// No info about this param
    34  	ParamNoInfo ParamPropBits = 0
    35  
    36  	// Parameter value feeds unmodified into a top-level interface
    37  	// call (this assumes the parameter is of interface type).
    38  	ParamFeedsInterfaceMethodCall ParamPropBits = 1 << iota
    39  
    40  	// Parameter value feeds unmodified into an interface call that
    41  	// may be conditional/nested and not always executed (this assumes
    42  	// the parameter is of interface type).
    43  	ParamMayFeedInterfaceMethodCall ParamPropBits = 1 << iota
    44  
    45  	// Parameter value feeds unmodified into a top level indirect
    46  	// function call (assumes parameter is of function type).
    47  	ParamFeedsIndirectCall
    48  
    49  	// Parameter value feeds unmodified into an indirect function call
    50  	// that is conditional/nested (not guaranteed to execute). Assumes
    51  	// parameter is of function type.
    52  	ParamMayFeedIndirectCall
    53  
    54  	// Parameter value feeds unmodified into a top level "switch"
    55  	// statement or "if" statement simple expressions (see more on
    56  	// "simple" expression classification below).
    57  	ParamFeedsIfOrSwitch
    58  
    59  	// Parameter value feeds unmodified into a "switch" or "if"
    60  	// statement simple expressions (see more on "simple" expression
    61  	// classification below), where the if/switch is
    62  	// conditional/nested.
    63  	ParamMayFeedIfOrSwitch
    64  )
    65  
    66  type ResultPropBits uint32
    67  
    68  const (
    69  	// No info about this result
    70  	ResultNoInfo ResultPropBits = 0
    71  	// This result always contains allocated memory.
    72  	ResultIsAllocatedMem ResultPropBits = 1 << iota
    73  	// This result is always a single concrete type that is
    74  	// implicitly converted to interface.
    75  	ResultIsConcreteTypeConvertedToInterface
    76  	// Result is always the same non-composite compile time constant.
    77  	ResultAlwaysSameConstant
    78  	// Result is always the same function or closure.
    79  	ResultAlwaysSameFunc
    80  	// Result is always the same (potentially) inlinable function or closure.
    81  	ResultAlwaysSameInlinableFunc
    82  )