aboutsummaryrefslogtreecommitdiffhomepage
path: root/ir
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2018-12-09 16:14:47 +0100
committerAyke van Laethem <[email protected]>2018-12-09 16:44:37 +0100
commit3fec22e819206f1748a010705304beb8c8b47af4 (patch)
tree3afb78da67b16d6b7d03a73e5362891638ae9c90 /ir
parente42289ce61f4877bcc077192ce32c05af614f07f (diff)
downloadtinygo-3fec22e819206f1748a010705304beb8c8b47af4.tar.gz
tinygo-3fec22e819206f1748a010705304beb8c8b47af4.zip
compiler: avoid function pointers in defer calls
Implement defer in a different way, which results in smaller binaries. The binary produced from testdata/calls.go (the only test case with defer) is reduced a bit in size, but the savings in bytes greatly vary by architecture: Cortex-M0: -96 .text / flash WebAssembly: -215 entire file Linux x64: -32 .text Deferred functions in TinyGo were implemented by creating a linked list of struct objects that contain a function pointer to a thunk, a pointer to the next object, and a list of parameters. When it was time to run deferred functions, a helper runtime function called each function pointer (the thunk) with the struct pointer as a parameter. This thunk would then in turn extract the saved function parameter from the struct and call the real function. What this commit changes, is that the loop to call deferred functions is moved into the end of the function (practically inlining it) and replacing the thunks with direct calls inside this loop. This makes it much easier for LLVM to perform all kinds of optimizations like inlining and dead argument elimination.
Diffstat (limited to 'ir')
0 files changed, 0 insertions, 0 deletions