@@ -13,37 +13,7 @@ import (
13
13
14
14
// createGo emits code to start a new goroutine.
15
15
func (b * builder ) createGo (instr * ssa.Go ) {
16
- // Get all function parameters to pass to the goroutine.
17
- var params []llvm.Value
18
- for _ , param := range instr .Call .Args {
19
- params = append (params , b .getValue (param , getPos (instr )))
20
- }
21
-
22
- var prefix string
23
- var funcPtr llvm.Value
24
- var funcType llvm.Type
25
- hasContext := false
26
- if callee := instr .Call .StaticCallee (); callee != nil {
27
- // Static callee is known. This makes it easier to start a new
28
- // goroutine.
29
- var context llvm.Value
30
- switch value := instr .Call .Value .(type ) {
31
- case * ssa.Function :
32
- // Goroutine call is regular function call. No context is necessary.
33
- case * ssa.MakeClosure :
34
- // A goroutine call on a func value, but the callee is trivial to find. For
35
- // example: immediately applied functions.
36
- funcValue := b .getValue (value , getPos (instr ))
37
- context = b .extractFuncContext (funcValue )
38
- default :
39
- panic ("StaticCallee returned an unexpected value" )
40
- }
41
- if ! context .IsNil () {
42
- params = append (params , context ) // context parameter
43
- hasContext = true
44
- }
45
- funcType , funcPtr = b .getFunction (callee )
46
- } else if builtin , ok := instr .Call .Value .(* ssa.Builtin ); ok {
16
+ if builtin , ok := instr .Call .Value .(* ssa.Builtin ); ok {
47
17
// We cheat. None of the builtins do any long or blocking operation, so
48
18
// we might as well run these builtins right away without the program
49
19
// noticing the difference.
@@ -74,6 +44,38 @@ func (b *builder) createGo(instr *ssa.Go) {
74
44
}
75
45
b .createBuiltin (argTypes , argValues , builtin .Name (), instr .Pos ())
76
46
return
47
+ }
48
+
49
+ // Get all function parameters to pass to the goroutine.
50
+ var params []llvm.Value
51
+ for _ , param := range instr .Call .Args {
52
+ params = append (params , b .getValue (param , getPos (instr )))
53
+ }
54
+
55
+ var prefix string
56
+ var funcPtr llvm.Value
57
+ var funcType llvm.Type
58
+ hasContext := false
59
+ if callee := instr .Call .StaticCallee (); callee != nil {
60
+ // Static callee is known. This makes it easier to start a new
61
+ // goroutine.
62
+ var context llvm.Value
63
+ switch value := instr .Call .Value .(type ) {
64
+ case * ssa.Function :
65
+ // Goroutine call is regular function call. No context is necessary.
66
+ case * ssa.MakeClosure :
67
+ // A goroutine call on a func value, but the callee is trivial to find. For
68
+ // example: immediately applied functions.
69
+ funcValue := b .getValue (value , getPos (instr ))
70
+ context = b .extractFuncContext (funcValue )
71
+ default :
72
+ panic ("StaticCallee returned an unexpected value" )
73
+ }
74
+ if ! context .IsNil () {
75
+ params = append (params , context ) // context parameter
76
+ hasContext = true
77
+ }
78
+ funcType , funcPtr = b .getFunction (callee )
77
79
} else if instr .Call .IsInvoke () {
78
80
// This is a method call on an interface value.
79
81
itf := b .getValue (instr .Call .Value , getPos (instr ))
0 commit comments