Source file src/cmd/compile/internal/inline/inlheur/testdata/props/calls.go

     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  // DO NOT EDIT (use 'go test -v -update-expected' instead.)
     6  // See cmd/compile/internal/inline/inlheur/testdata/props/README.txt
     7  // for more information on the format of this file.
     8  // <endfilepreamble>
     9  package calls
    10  
    11  import "os"
    12  
    13  // calls.go T_call_in_panic_arg 19 0 1
    14  // <endpropsdump>
    15  // {"Flags":0,"ParamFlags":[0],"ResultFlags":null}
    16  // callsite: calls.go:21:15|0 flagstr "CallSiteOnPanicPath" flagval 2 score 42 mask 1 maskstr "panicPathAdj"
    17  // <endcallsites>
    18  // <endfuncpreamble>
    19  func T_call_in_panic_arg(x int) {
    20  	if x < G {
    21  		panic(callee(x))
    22  	}
    23  }
    24  
    25  // calls.go T_calls_in_loops 32 0 1
    26  // <endpropsdump>
    27  // {"Flags":0,"ParamFlags":[0,0],"ResultFlags":null}
    28  // callsite: calls.go:34:9|0 flagstr "CallSiteInLoop" flagval 1 score -3 mask 4 maskstr "inLoopAdj"
    29  // callsite: calls.go:37:9|1 flagstr "CallSiteInLoop" flagval 1 score -3 mask 4 maskstr "inLoopAdj"
    30  // <endcallsites>
    31  // <endfuncpreamble>
    32  func T_calls_in_loops(x int, q []string) {
    33  	for i := 0; i < x; i++ {
    34  		callee(i)
    35  	}
    36  	for _, s := range q {
    37  		callee(len(s))
    38  	}
    39  }
    40  
    41  // calls.go T_calls_in_pseudo_loop 48 0 1
    42  // <endpropsdump>
    43  // {"Flags":0,"ParamFlags":[0,0],"ResultFlags":null}
    44  // callsite: calls.go:50:9|0 flagstr "" flagval 0 score 2 mask 0 maskstr ""
    45  // callsite: calls.go:54:9|1 flagstr "" flagval 0 score 2 mask 0 maskstr ""
    46  // <endcallsites>
    47  // <endfuncpreamble>
    48  func T_calls_in_pseudo_loop(x int, q []string) {
    49  	for i := 0; i < x; i++ {
    50  		callee(i)
    51  		return
    52  	}
    53  	for _, s := range q {
    54  		callee(len(s))
    55  		break
    56  	}
    57  }
    58  
    59  // calls.go T_calls_on_panic_paths 67 0 1
    60  // <endpropsdump>
    61  // {"Flags":0,"ParamFlags":[0,0],"ResultFlags":null}
    62  // callsite: calls.go:69:9|0 flagstr "CallSiteOnPanicPath" flagval 2 score 42 mask 1 maskstr "panicPathAdj"
    63  // callsite: calls.go:73:9|1 flagstr "CallSiteOnPanicPath" flagval 2 score 42 mask 1 maskstr "panicPathAdj"
    64  // callsite: calls.go:77:12|2 flagstr "CallSiteOnPanicPath" flagval 2 score 102 mask 1 maskstr "panicPathAdj"
    65  // <endcallsites>
    66  // <endfuncpreamble>
    67  func T_calls_on_panic_paths(x int, q []string) {
    68  	if x+G == 101 {
    69  		callee(x)
    70  		panic("ouch")
    71  	}
    72  	if x < G-101 {
    73  		callee(x)
    74  		if len(q) == 0 {
    75  			G++
    76  		}
    77  		callsexit(x)
    78  	}
    79  }
    80  
    81  // calls.go T_calls_not_on_panic_paths 93 0 1
    82  // ParamFlags
    83  //   0 ParamFeedsIfOrSwitch|ParamMayFeedIfOrSwitch
    84  //   1 ParamNoInfo
    85  // <endpropsdump>
    86  // {"Flags":0,"ParamFlags":[96,0],"ResultFlags":null}
    87  // callsite: calls.go:103:9|0 flagstr "" flagval 0 score 2 mask 0 maskstr ""
    88  // callsite: calls.go:112:9|1 flagstr "" flagval 0 score 2 mask 0 maskstr ""
    89  // callsite: calls.go:115:9|2 flagstr "" flagval 0 score 2 mask 0 maskstr ""
    90  // callsite: calls.go:119:12|3 flagstr "CallSiteOnPanicPath" flagval 2 score 102 mask 1 maskstr "panicPathAdj"
    91  // <endcallsites>
    92  // <endfuncpreamble>
    93  func T_calls_not_on_panic_paths(x int, q []string) {
    94  	if x != G {
    95  		panic("ouch")
    96  		/* Notes: */
    97  		/* - we only look for post-dominating panic/exit, so */
    98  		/*   this site will on fact not have a panicpath flag */
    99  		/* - vet will complain about this site as unreachable */
   100  		callee(x)
   101  	}
   102  	if x != G {
   103  		callee(x)
   104  		if x < 100 {
   105  			panic("ouch")
   106  		}
   107  	}
   108  	if x+G == 101 {
   109  		if x < 100 {
   110  			panic("ouch")
   111  		}
   112  		callee(x)
   113  	}
   114  	if x < -101 {
   115  		callee(x)
   116  		if len(q) == 0 {
   117  			return
   118  		}
   119  		callsexit(x)
   120  	}
   121  }
   122  
   123  // calls.go init.0 129 0 1
   124  // <endpropsdump>
   125  // {"Flags":0,"ParamFlags":null,"ResultFlags":null}
   126  // callsite: calls.go:130:16|0 flagstr "CallSiteInInitFunc" flagval 4 score 22 mask 2 maskstr "initFuncAdj"
   127  // <endcallsites>
   128  // <endfuncpreamble>
   129  func init() {
   130  	println(callee(5))
   131  }
   132  
   133  // calls.go T_pass_inlinable_func_to_param_feeding_indirect_call 140 0 1
   134  // <endpropsdump>
   135  // {"Flags":0,"ParamFlags":[0],"ResultFlags":[0]}
   136  // callsite: calls.go:141:19|0 flagstr "" flagval 0 score 16 mask 512 maskstr "passInlinableFuncToIndCallAdj"
   137  // callsite: calls.go:141:19|calls.go:232:10|0 flagstr "" flagval 0 score 2 mask 0 maskstr ""
   138  // <endcallsites>
   139  // <endfuncpreamble>
   140  func T_pass_inlinable_func_to_param_feeding_indirect_call(x int) int {
   141  	return callsParam(x, callee)
   142  }
   143  
   144  // calls.go T_pass_noninlinable_func_to_param_feeding_indirect_call 150 0 1
   145  // <endpropsdump>
   146  // {"Flags":0,"ParamFlags":[0],"ResultFlags":[0]}
   147  // callsite: calls.go:153:19|0 flagstr "" flagval 0 score 36 mask 128 maskstr "passFuncToIndCallAdj"
   148  // <endcallsites>
   149  // <endfuncpreamble>
   150  func T_pass_noninlinable_func_to_param_feeding_indirect_call(x int) int {
   151  	// if we inline callsParam we can convert the indirect call
   152  	// to a direct call, but we can't inline it.
   153  	return callsParam(x, calleeNoInline)
   154  }
   155  
   156  // calls.go T_pass_inlinable_func_to_param_feeding_nested_indirect_call 165 0 1
   157  // ParamFlags
   158  //   0 ParamFeedsIfOrSwitch
   159  // <endpropsdump>
   160  // {"Flags":0,"ParamFlags":[32],"ResultFlags":[0]}
   161  // callsite: calls.go:166:25|0 flagstr "" flagval 0 score 27 mask 1024 maskstr "passInlinableFuncToNestedIndCallAdj"
   162  // callsite: calls.go:166:25|calls.go:237:11|0 flagstr "" flagval 0 score 2 mask 0 maskstr ""
   163  // <endcallsites>
   164  // <endfuncpreamble>
   165  func T_pass_inlinable_func_to_param_feeding_nested_indirect_call(x int) int {
   166  	return callsParamNested(x, callee)
   167  }
   168  
   169  // calls.go T_pass_noninlinable_func_to_param_feeding_nested_indirect_call 177 0 1
   170  // ParamFlags
   171  //   0 ParamFeedsIfOrSwitch
   172  // <endpropsdump>
   173  // {"Flags":0,"ParamFlags":[32],"ResultFlags":[0]}
   174  // callsite: calls.go:178:25|0 flagstr "" flagval 0 score 47 mask 256 maskstr "passFuncToNestedIndCallAdj"
   175  // <endcallsites>
   176  // <endfuncpreamble>
   177  func T_pass_noninlinable_func_to_param_feeding_nested_indirect_call(x int) int {
   178  	return callsParamNested(x, calleeNoInline)
   179  }
   180  
   181  // calls.go T_call_scoring_in_noninlinable_func 195 0 1
   182  // <endpropsdump>
   183  // {"Flags":0,"ParamFlags":[0,0],"ResultFlags":[0]}
   184  // callsite: calls.go:209:14|0 flagstr "CallSiteOnPanicPath" flagval 2 score 42 mask 1 maskstr "panicPathAdj"
   185  // callsite: calls.go:210:15|1 flagstr "CallSiteOnPanicPath" flagval 2 score 42 mask 1 maskstr "panicPathAdj"
   186  // callsite: calls.go:212:19|2 flagstr "" flagval 0 score 16 mask 512 maskstr "passInlinableFuncToIndCallAdj"
   187  // callsite: calls.go:212:19|calls.go:232:10|0 flagstr "" flagval 0 score 4 mask 0 maskstr ""
   188  // <endcallsites>
   189  // <endfuncpreamble>
   190  // calls.go T_call_scoring_in_noninlinable_func.func1 212 0 1
   191  // <endpropsdump>
   192  // {"Flags":0,"ParamFlags":[0],"ResultFlags":[0]}
   193  // <endcallsites>
   194  // <endfuncpreamble>
   195  func T_call_scoring_in_noninlinable_func(x int, sl []int) int {
   196  	if x == 101 {
   197  		// Drive up the cost of inlining this funcfunc over the
   198  		// regular threshold.
   199  		for i := 0; i < 10; i++ {
   200  			for j := 0; j < i; j++ {
   201  				sl = append(sl, append(sl, append(sl, append(sl, x)...)...)...)
   202  				sl = append(sl, sl[0], sl[1], sl[2])
   203  				x += calleeNoInline(x)
   204  			}
   205  		}
   206  	}
   207  	if x < 100 {
   208  		// make sure this callsite is scored properly
   209  		G += callee(101)
   210  		panic(callee(x))
   211  	}
   212  	return callsParam(x, func(y int) int { return y + x })
   213  }
   214  
   215  var G int
   216  
   217  func callee(x int) int {
   218  	return x
   219  }
   220  
   221  func calleeNoInline(x int) int {
   222  	defer func() { G++ }()
   223  	return x
   224  }
   225  
   226  func callsexit(x int) {
   227  	println(x)
   228  	os.Exit(x)
   229  }
   230  
   231  func callsParam(x int, f func(int) int) int {
   232  	return f(x)
   233  }
   234  
   235  func callsParamNested(x int, f func(int) int) int {
   236  	if x < 0 {
   237  		return f(x)
   238  	}
   239  	return 0
   240  }
   241  

View as plain text