mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 07:23:39 +00:00
compiler,runtime: use LLVM intrinsics for memcpy/memmove
This replaces the custom runtime.memcpy and runtime.memmove functions with calls to LLVM builtins that should hopefully allow LLVM to better optimize such calls. They will be lowered to regular libc memcpy/memmove when they can't be optimized away. When testing this change with some smoke tests, I found that many smoke tests resulted in slightly larger binary sizes with this commit applied. I looked into it and it appears that machine.sendUSBPacket was not inlined before while it is with this commit applied. Additionally, when I compared all driver smoke tests with -opt=1 I saw that many were reduced slightly in binary size and none increased in size.
This commit is contained in:
committed by
Ron Evans
parent
c01f81144e
commit
eaa54bc7e3
+2
-11
@@ -330,7 +330,6 @@ func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Con
|
||||
return c.ctx.CreateEnumAttribute(attrKind, 0)
|
||||
}
|
||||
nocapture := getAttr("nocapture")
|
||||
writeonly := getAttr("writeonly")
|
||||
readonly := getAttr("readonly")
|
||||
|
||||
// Tell the optimizer that runtime.alloc is an allocator, meaning that it
|
||||
@@ -354,16 +353,6 @@ func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Con
|
||||
trackPointer.AddAttributeAtIndex(1, readonly)
|
||||
}
|
||||
|
||||
// Memory copy operations do not capture pointers, even though some weird
|
||||
// pointer arithmetic is happening in the Go implementation.
|
||||
for _, fnName := range []string{"runtime.memcpy", "runtime.memmove"} {
|
||||
fn := c.mod.NamedFunction(fnName)
|
||||
fn.AddAttributeAtIndex(1, nocapture)
|
||||
fn.AddAttributeAtIndex(1, writeonly)
|
||||
fn.AddAttributeAtIndex(2, nocapture)
|
||||
fn.AddAttributeAtIndex(2, readonly)
|
||||
}
|
||||
|
||||
// see: https://reviews.llvm.org/D18355
|
||||
if c.Debug() {
|
||||
c.mod.AddNamedMetadataOperand("llvm.module.flags",
|
||||
@@ -1352,6 +1341,8 @@ func (b *builder) createFunctionCall(instr *ssa.CallCommon) (llvm.Value, error)
|
||||
// applied) function call. If it is anonymous, it may be a closure.
|
||||
name := fn.RelString(nil)
|
||||
switch {
|
||||
case name == "runtime.memcpy" || name == "runtime.memmove" || name == "reflect.memcpy":
|
||||
return b.createMemoryCopyCall(fn, instr.Args)
|
||||
case name == "device/arm.ReadRegister" || name == "device/riscv.ReadRegister":
|
||||
return b.createReadRegister(name, instr.Args)
|
||||
case name == "device/arm.Asm" || name == "device/avr.Asm" || name == "device/riscv.Asm":
|
||||
|
||||
Reference in New Issue
Block a user