@@ -20,6 +20,10 @@ import (
20
20
func (b * builder ) defineIntrinsicFunction () {
21
21
name := b .fn .RelString (nil )
22
22
switch {
23
+ case name == "runtime.memcpy" || name == "runtime.memmove" :
24
+ b .createMemoryCopyImpl ()
25
+ case name == "runtime.memzero" :
26
+ b .createMemoryZeroImpl ()
23
27
case strings .HasPrefix (name , "runtime/volatile.Load" ):
24
28
b .createVolatileLoad ()
25
29
case strings .HasPrefix (name , "runtime/volatile.Store" ):
@@ -35,44 +39,46 @@ func (b *builder) defineIntrinsicFunction() {
35
39
}
36
40
}
37
41
38
- // createMemoryCopyCall creates a call to a builtin LLVM memcpy or memmove
42
+ // createMemoryCopyImpl creates a call to a builtin LLVM memcpy or memmove
39
43
// function, declaring this function if needed. These calls are treated
40
44
// specially by optimization passes possibly resulting in better generated code,
41
45
// and will otherwise be lowered to regular libc memcpy/memmove calls.
42
- func (b * builder ) createMemoryCopyCall (fn * ssa.Function , args []ssa.Value ) (llvm.Value , error ) {
43
- fnName := "llvm." + fn .Name () + ".p0i8.p0i8.i" + strconv .Itoa (b .uintptrType .IntTypeWidth ())
46
+ func (b * builder ) createMemoryCopyImpl () {
47
+ b .createFunctionStart ()
48
+ fnName := "llvm." + b .fn .Name () + ".p0i8.p0i8.i" + strconv .Itoa (b .uintptrType .IntTypeWidth ())
44
49
llvmFn := b .mod .NamedFunction (fnName )
45
50
if llvmFn .IsNil () {
46
51
fnType := llvm .FunctionType (b .ctx .VoidType (), []llvm.Type {b .i8ptrType , b .i8ptrType , b .uintptrType , b .ctx .Int1Type ()}, false )
47
52
llvmFn = llvm .AddFunction (b .mod , fnName , fnType )
48
53
}
49
54
var params []llvm.Value
50
- for _ , param := range args {
55
+ for _ , param := range b . fn . Params {
51
56
params = append (params , b .getValue (param ))
52
57
}
53
58
params = append (params , llvm .ConstInt (b .ctx .Int1Type (), 0 , false ))
54
59
b .CreateCall (llvmFn , params , "" )
55
- return llvm. Value {}, nil
60
+ b . CreateRetVoid ()
56
61
}
57
62
58
- // createMemoryZeroCall creates calls to llvm.memset.* to zero a block of
63
+ // createMemoryZeroImpl creates calls to llvm.memset.* to zero a block of
59
64
// memory, declaring the function if needed. These calls will be lowered to
60
65
// regular libc memset calls if they aren't optimized out in a different way.
61
- func (b * builder ) createMemoryZeroCall (args []ssa.Value ) (llvm.Value , error ) {
66
+ func (b * builder ) createMemoryZeroImpl () {
67
+ b .createFunctionStart ()
62
68
fnName := "llvm.memset.p0i8.i" + strconv .Itoa (b .uintptrType .IntTypeWidth ())
63
69
llvmFn := b .mod .NamedFunction (fnName )
64
70
if llvmFn .IsNil () {
65
71
fnType := llvm .FunctionType (b .ctx .VoidType (), []llvm.Type {b .i8ptrType , b .ctx .Int8Type (), b .uintptrType , b .ctx .Int1Type ()}, false )
66
72
llvmFn = llvm .AddFunction (b .mod , fnName , fnType )
67
73
}
68
74
params := []llvm.Value {
69
- b .getValue (args [0 ]),
75
+ b .getValue (b . fn . Params [0 ]),
70
76
llvm .ConstInt (b .ctx .Int8Type (), 0 , false ),
71
- b .getValue (args [1 ]),
77
+ b .getValue (b . fn . Params [1 ]),
72
78
llvm .ConstInt (b .ctx .Int1Type (), 0 , false ),
73
79
}
74
80
b .CreateCall (llvmFn , params , "" )
75
- return llvm. Value {}, nil
81
+ b . CreateRetVoid ()
76
82
}
77
83
78
84
var mathToLLVMMapping = map [string ]string {
0 commit comments